using AutoMapper;
|
using DTO;
|
using IServices;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using zhengcaioa.Models;
|
|
namespace Services
|
{
|
public class LiaotianService: ILiaotianService
|
{
|
private readonly zhengcaioaContext _context;
|
private readonly IMapper _mapper;
|
public LiaotianService(zhengcaioaContext context, IMapper mapper)
|
{
|
_context = context;
|
_mapper = mapper;
|
}
|
|
public ResultEntity saveLiaotian(LiaotianDTO liaotiandto)
|
{
|
ResultEntity resultEntity = new ResultEntity();
|
try
|
{
|
|
var checkUserSn = _context.Liaotians.Where(x => x.Question == liaotiandto.Question && x.RecStatus == "A" && x.Id != liaotiandto.Id).FirstOrDefault();
|
if (checkUserSn != null && (string.IsNullOrWhiteSpace(liaotiandto.Id) || (!string.IsNullOrWhiteSpace(liaotiandto.Id) && checkUserSn.Id != liaotiandto.Id)))
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "问题重复";
|
return resultEntity;
|
}
|
|
var liaotian = _mapper.Map<Liaotian>(liaotiandto);
|
if (String.IsNullOrEmpty(liaotian.Id))
|
{
|
liaotian.Id = Guid.NewGuid().ToString();
|
liaotiandto.Id = liaotian.Id;
|
_context.Liaotians.Add(liaotian);
|
}
|
else
|
{
|
var updateliaotian = _context.Liaotians.Find(liaotian.Id);
|
updateliaotian.Question = liaotian.Question;
|
updateliaotian.Anwser = liaotian.Anwser;
|
updateliaotian.RecStatus = liaotian.RecStatus;
|
updateliaotian.Clientid = liaotian.Clientid;
|
// updateliaotian.Creater = liaotian.Creater;
|
//updateliaotian.Createtime = liaotian.Createtime;
|
updateliaotian.Modifier = liaotian.Modifier;
|
updateliaotian.Modifytime = liaotian.Modifytime;
|
updateliaotian.Questiontype = liaotian.Questiontype;
|
updateliaotian.Problemtype = liaotian.Problemtype;
|
updateliaotian.Shiyongfatiao = liaotian.Shiyongfatiao;
|
}
|
|
_context.SaveChanges();
|
resultEntity.ReturnID = liaotian.Id;
|
resultEntity.Result = true;
|
}
|
catch (Exception ex)
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "保存失败,请联系管理员";
|
|
}
|
return resultEntity;
|
}
|
|
public LiaotianDTO GetLiaotianEntity(string id)
|
{
|
|
|
Liaotian entity = _context.Liaotians.Find(id);
|
|
if (entity.RecStatus != "A")
|
{
|
entity = new Liaotian();
|
}
|
var liaotiandto = _mapper.Map<LiaotianDTO>(entity);
|
return liaotiandto;
|
}
|
|
public List<SysCodeDtl> GetSYScode(string code_table,string code_field)
|
{
|
|
|
List<SysCodeDtl> sysCodeDtls = (from e in _context.SysCodes
|
join c in _context.SysCodeDtls
|
on e.Id equals c.CodeId
|
where e.RecStatus == "A"
|
&& c.RecStatus == "A"
|
&& e.CodeTable == code_table
|
&& e.CodeField == code_field
|
select c).OrderBy(x=>x.Sort).ToList();
|
|
|
|
|
|
|
|
return sysCodeDtls;
|
}
|
|
public ResultDataEntity<LiaotianDTO> SearchByPaging(LiaotianDTOSearch searchEntity)
|
{
|
ResultDataEntity<LiaotianDTO> data = new ResultDataEntity<LiaotianDTO>();
|
List<LiaotianDTO> list = new List<LiaotianDTO>();
|
//筛选
|
var query = _context.Liaotians
|
.Where(b => b.RecStatus=="A")
|
.ToList();
|
|
if (!string.IsNullOrEmpty(searchEntity.Question))
|
{
|
query = query.Where(m => m.Question.Contains(searchEntity.Question)).ToList();
|
}
|
if (!string.IsNullOrEmpty(searchEntity.Questiontype))
|
{
|
query = query.Where(m => m.Questiontype == searchEntity.Questiontype).ToList();
|
}
|
if (!string.IsNullOrEmpty(searchEntity.Problemtype))
|
{
|
query = query.Where(m => m.Problemtype.Contains(searchEntity.Problemtype)).ToList();
|
}
|
if (!string.IsNullOrEmpty(searchEntity.Shifoushenhe))
|
{
|
query = query.Where(m => m.Clientid == searchEntity.Shifoushenhe ).ToList();
|
}
|
|
DateTime Createtimestart = DateTime.Now;
|
DateTime Createtimeend = DateTime.Now;
|
if (!string.IsNullOrWhiteSpace(searchEntity.Createtime))
|
{
|
string[] Createtimes = searchEntity.Createtime.Split("|");
|
DateTime.TryParse(Createtimes[0], out Createtimestart);
|
DateTime.TryParse(Createtimes[1], out Createtimeend);
|
Createtimeend = Createtimeend.AddDays(1);
|
}
|
if (!string.IsNullOrEmpty(searchEntity.Createtime))
|
{
|
query = query.Where(m => m.Createtime >= Createtimestart).ToList();
|
}
|
if (!string.IsNullOrEmpty(searchEntity.Createtime))
|
{
|
query = query.Where(m => m.Createtime <= Createtimeend).ToList();
|
}
|
if (!string.IsNullOrEmpty(searchEntity.Creater))
|
{
|
query = query.Where(m => m.Creater == searchEntity.Creater).ToList();
|
}
|
|
if (!string.IsNullOrEmpty(searchEntity.Info))
|
{
|
var check = searchEntity.Info.Split(' ');
|
List<Liaotian> liaotians = new List<Liaotian>();
|
if(check!=null&& check.Length > 0)
|
{
|
for(int i = 0;i< check.Length; i++)
|
{
|
if (!string.IsNullOrWhiteSpace(check[i])){
|
liaotians = liaotians.Union(query.Where(m => m.Question.Contains(check[i])).ToList()).Distinct().ToList();
|
}
|
|
}
|
|
}
|
|
query = liaotians;
|
|
|
}
|
else
|
{
|
query = query.OrderByDescending(x => x.Modifytime).ToList();
|
}
|
|
|
if (searchEntity.totalrows == 0)
|
searchEntity.totalrows = query.Count();
|
var lianlist = query.Skip((searchEntity.page - 1) * searchEntity.rows).Take(searchEntity.rows).ToList();
|
list = _mapper.Map<List<LiaotianDTO>>(lianlist);
|
data.LoadData(searchEntity, list);
|
return data;
|
}
|
|
|
/// <summary>
|
/// 修改主表状态
|
/// </summary>
|
/// <param name="id">主id</param>
|
/// <param name="userid">用户</param>
|
/// <returns></returns>
|
public ResultEntity ModifyStatus(string id, string userid)
|
{
|
ResultEntity result = new ResultEntity();
|
result.Result = true;
|
|
var model = _context.Liaotians.Find(id);
|
if (model != null)
|
{
|
model.RecStatus = "D";
|
model.Modifier = userid;
|
model.Modifytime = DateTime.Now;
|
_context.SaveChanges();
|
}
|
|
return result;
|
}
|
|
|
/// <summary>
|
/// 查询打印信息
|
/// </summary>
|
/// <param name="searchEntity">查询条件</param>
|
/// <returns></returns>
|
public List<LiaotianDTO> SearchForPrint(LiaotianDTOSearch searchEntity)
|
{
|
|
List<LiaotianDTO> list = new List<LiaotianDTO>();
|
//筛选
|
var query = _context.Liaotians
|
.Where(b => b.RecStatus == "A")
|
.ToList();
|
|
if (!string.IsNullOrEmpty(searchEntity.Question))
|
{
|
query = query.Where(m => m.Question.Contains(searchEntity.Question)).ToList();
|
}
|
if (!string.IsNullOrEmpty(searchEntity.Questiontype))
|
{
|
query = query.Where(m => m.Questiontype == searchEntity.Questiontype).ToList();
|
}
|
if (!string.IsNullOrEmpty(searchEntity.Problemtype))
|
{
|
query = query.Where(m => m.Problemtype.Contains(searchEntity.Problemtype)).ToList();
|
}
|
if (!string.IsNullOrEmpty(searchEntity.Info))
|
{
|
var check = searchEntity.Info.Split(' ');
|
List<Liaotian> liaotians = new List<Liaotian>();
|
if (check != null && check.Length > 0)
|
{
|
for (int i = 0; i < check.Length; i++)
|
{
|
if (!string.IsNullOrWhiteSpace(check[i]))
|
{
|
liaotians = liaotians.Union(query.Where(m => m.Question.Contains(check[i])).ToList()).Distinct().ToList();
|
}
|
|
}
|
|
}
|
|
query = liaotians;
|
|
|
}
|
|
|
query = query.OrderByDescending(x => x.Modifytime).ToList();
|
|
list = _mapper.Map<List<LiaotianDTO>>(query);
|
|
return list;
|
}
|
}
|
}
|