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;
|
updateliaotian.ChushuStatus = liaotian.ChushuStatus;
|
}
|
|
_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>();
|
|
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);
|
}
|
//筛选
|
var query = (from a in _context.Liaotians
|
|
|
join h in _context.LiaotianShoucangs.Where(x => x.RecStatus == "A" && x.Creater == searchEntity.ShouCangCreater)
|
on a.Id equals h.LiaotianId
|
into hsss
|
from hhh in hsss.DefaultIfEmpty()
|
|
|
where a.RecStatus == "A"
|
&& (string.IsNullOrWhiteSpace(searchEntity.Createtime) || (a.Createtime >= Createtimestart && a.Createtime <= Createtimeend))
|
|
&& (string.IsNullOrWhiteSpace(searchEntity.Question) || (a.Question.Contains(searchEntity.Question.Trim())))
|
&& (string.IsNullOrWhiteSpace(searchEntity.Questiontype) || (a.Questiontype == searchEntity.Questiontype.Trim()))
|
&& (string.IsNullOrWhiteSpace(searchEntity.Problemtype) || (a.Problemtype.Contains(searchEntity.Problemtype.Trim())))
|
&& (string.IsNullOrWhiteSpace(searchEntity.Shifoushenhe) || (a.Clientid == searchEntity.Shifoushenhe.Trim()))
|
&& (string.IsNullOrWhiteSpace(searchEntity.ChushuStatus) || (a.ChushuStatus == searchEntity.ChushuStatus.Trim()))
|
&& (string.IsNullOrWhiteSpace(searchEntity.Creater) || (a.Creater == searchEntity.Creater.Trim()))
|
&& (string.IsNullOrWhiteSpace(searchEntity.ShouCangStatus) || (searchEntity.ShouCangStatus == "A" && hhh.Id !=null) || (searchEntity.ShouCangStatus != "A" && hhh.Id == null))
|
select new LiaotianDTO
|
{
|
Id = a.Id,
|
Question = a.Question,
|
Anwser = a.Anwser,
|
RecStatus = a.RecStatus,
|
Creater = a.Creater,
|
Createtime = a.Createtime,
|
Modifier = a.Modifier,
|
Modifytime = a.Modifytime,
|
Clientid = a.Clientid,
|
Questiontype = a.Questiontype,
|
Problemtype = a.Problemtype,
|
Shiyongfatiao = a.Shiyongfatiao,
|
ChushuStatus= a.ChushuStatus,
|
}
|
)
|
.Distinct() .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, query);
|
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;
|
}
|
|
|
|
public ResultEntity saveLiaotianShoucang(LiaotianShoucangDTO dto)
|
{
|
ResultEntity resultEntity = new ResultEntity();
|
try
|
{
|
|
|
var liaotian = _mapper.Map<LiaotianShoucang>(dto);
|
if (String.IsNullOrEmpty(liaotian.Id))
|
{
|
liaotian.Id = Guid.NewGuid().ToString();
|
dto.Id = liaotian.Id;
|
_context.LiaotianShoucangs.Add(liaotian);
|
}
|
else
|
{
|
var updateliaotian = _context.LiaotianShoucangs.Find(liaotian.Id);
|
updateliaotian.LiaotianId = liaotian.LiaotianId;
|
|
updateliaotian.RecStatus = liaotian.RecStatus;
|
|
// updateliaotian.Creater = liaotian.Creater;
|
//updateliaotian.Createtime = liaotian.Createtime;
|
updateliaotian.Modifier = liaotian.Modifier;
|
updateliaotian.Modifytime = liaotian.Modifytime;
|
|
}
|
|
_context.SaveChanges();
|
resultEntity.ReturnID = liaotian.Id;
|
resultEntity.Result = true;
|
}
|
catch (Exception ex)
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "保存失败,请联系管理员";
|
|
}
|
return resultEntity;
|
}
|
|
public ResultEntity ModifyStatusLiaotianShoucang(string id, string userid)
|
{
|
ResultEntity result = new ResultEntity();
|
result.Result = true;
|
|
var model = _context.LiaotianShoucangs.Find(id);
|
if (model != null)
|
{
|
model.RecStatus = "D";
|
model.Modifier = userid;
|
model.Modifytime = DateTime.Now;
|
_context.SaveChanges();
|
}
|
|
return result;
|
}
|
|
public List<LiaotianShoucangDTO> getListLiaotianShoucang(string userId, string LiaotianId)
|
{
|
List<LiaotianShoucangDTO> result = new List<LiaotianShoucangDTO>();
|
|
|
var listFiServices = _context.LiaotianShoucangs.Where(r => r.RecStatus == "A" && (string.IsNullOrEmpty(userId) || r.Creater == userId) && (string.IsNullOrEmpty(LiaotianId) || r.LiaotianId == LiaotianId)).OrderBy(x => x.Createtime).ToList();
|
|
result = _mapper.Map<List<LiaotianShoucangDTO>>(listFiServices);
|
|
return result;
|
}
|
}
|
}
|