using AutoMapper;
|
using DTO;
|
using DTO.Models;
|
using IServices;
|
using Microsoft.EntityFrameworkCore;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Threading.Tasks;
|
using zhengcaioa.IService;
|
using zhengcaioa.Models;
|
|
namespace Services
|
{
|
public class WfNeeddeelService: IWfNeeddeelService
|
{
|
private readonly zhengcaioaContext _context;
|
private readonly IMapper _mapper;
|
public WfNeeddeelService(zhengcaioaContext context, IMapper mapper)
|
{
|
_context = context;
|
_mapper = mapper;
|
}
|
|
|
public ResultEntity save(WfNeeddeelDTO dto)
|
{
|
ResultEntity resultEntity = new ResultEntity();
|
try
|
{
|
var model = _mapper.Map<WfNeeddeel>(dto);
|
if (String.IsNullOrEmpty(model.Id))
|
{
|
model.Id = Guid.NewGuid().ToString();
|
_context.WfNeeddeels.Add(model);
|
}
|
else
|
{
|
var updateWfNeeddeel = _context.WfNeeddeels.Find(model.Id);
|
updateWfNeeddeel.RunProcessId = model.RunProcessId;
|
updateWfNeeddeel.SendUserId = model.SendUserId;
|
updateWfNeeddeel.DeelUserId = model.DeelUserId;
|
updateWfNeeddeel.Sendtime = model.Sendtime;
|
updateWfNeeddeel.Resivetime = model.Resivetime;
|
updateWfNeeddeel.Step = model.Step;
|
updateWfNeeddeel.ChuliStatus = model.ChuliStatus;
|
updateWfNeeddeel.Deelurl = model.Deelurl;
|
updateWfNeeddeel.NeeddeelType = model.NeeddeelType;
|
updateWfNeeddeel.Sort = model.Sort;
|
updateWfNeeddeel.Content = model.Content;
|
|
|
updateWfNeeddeel.RecStatus = model.RecStatus;
|
// updateWfNeeddeel.Creater = WfNeeddeel.Creater;
|
//updateWfNeeddeel.Createtime = WfNeeddeel.Createtime;
|
updateWfNeeddeel.Modifier = model.Modifier;
|
updateWfNeeddeel.Modifytime = model.Modifytime;
|
|
}
|
|
_context.SaveChanges();
|
resultEntity.ReturnID = model.Id;
|
resultEntity.Result = true;
|
}
|
catch (Exception ex)
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "保存失败,请联系管理员";
|
|
}
|
return resultEntity;
|
}
|
|
public WfNeeddeelDTO Get(string id)
|
{
|
WfNeeddeel entity = _context.WfNeeddeels.Find(id);
|
if (entity.RecStatus != "A")
|
{
|
entity = new WfNeeddeel();
|
}
|
|
var WfNeeddeelDTO = _mapper.Map<WfNeeddeelDTO>(entity);
|
return WfNeeddeelDTO;
|
}
|
|
public ResultDataEntity<WfNeeddeelDTO> SearchByPaging(WfNeeddeelDTOSearch searchEntity)
|
{
|
|
|
|
ResultDataEntity<WfNeeddeelDTO> data = new ResultDataEntity<WfNeeddeelDTO>();
|
List<WfNeeddeelDTO> list = new List<WfNeeddeelDTO>();
|
|
|
|
|
var listCode = (from a in _context.SysCodeDtls
|
join b in _context.SysCodes
|
on a.CodeId equals b.Id
|
where a.RecStatus == "A"
|
&& b.RecStatus == "A"
|
select new CodeDataEntity()
|
{
|
CodeId = b.Id,
|
CodeTable = b.CodeTable,
|
CodeField = b.CodeField,
|
CodeSn = a.CodeSn,
|
Comments = a.Comments,
|
Contents = a.Contents,
|
RecStatus = a.RecStatus,
|
Sort = a.Sort
|
}
|
);
|
DateTime Applytimestart = DateTime.Now;
|
DateTime Applytimeend = DateTime.Now;
|
if (!string.IsNullOrWhiteSpace(searchEntity.Applytime))
|
{
|
string[] Applytimes = searchEntity.Applytime.Split("|");
|
DateTime.TryParse(Applytimes[0], out Applytimestart);
|
DateTime.TryParse(Applytimes[1], out Applytimeend);
|
Applytimeend = Applytimeend.AddDays(1);
|
}
|
|
///WfNeeddeels
|
var query = (from a in _context.WfNeeddeels
|
|
|
|
|
|
join k in _context.WfRunProcesses.Where(x => x.RecStatus == "A")
|
on a.RunProcessId equals k.Id
|
|
join e in listCode.Where(x => x.CodeTable == "wf_run_process" && x.CodeField == "shenpi_status")
|
on k.ShenpiStatus equals e.CodeSn
|
into esssss
|
from eee in esssss.DefaultIfEmpty()
|
|
join f in listCode.Where(x => x.CodeTable == "wf_needdeel" && x.CodeField == "needdeel_type")
|
on a.NeeddeelType equals f.CodeSn
|
into fsssss
|
from fff in fsssss.DefaultIfEmpty()
|
|
join d in _context.WfApplytypes
|
on k.Applytiye equals d.Applyno
|
|
join b in _context.PltUsers
|
on k.Creater equals b.Id
|
|
|
join c in _context.HrDepts
|
on b.DeptId equals c.Id
|
|
|
where a.RecStatus == "A"
|
&& (string.IsNullOrWhiteSpace(searchEntity.Applytime) || (k.Applytime >= Applytimestart && k.Applytime <= Applytimeend))
|
&& (string.IsNullOrWhiteSpace(searchEntity.DeptId) || b.DeptId == searchEntity.DeptId.Trim())
|
&& (string.IsNullOrWhiteSpace(searchEntity.ApplyUserName) || b.UserName.Contains(searchEntity.ApplyUserName.Trim()))
|
&& (string.IsNullOrWhiteSpace(searchEntity.Applytiye) || k.Applytiye == searchEntity.Applytiye.Trim())
|
&& (string.IsNullOrWhiteSpace(searchEntity.ShenpiStatus) || k.ShenpiStatus == searchEntity.ShenpiStatus.Trim())
|
&& (string.IsNullOrWhiteSpace(searchEntity.RunProcessId) || a.RunProcessId == searchEntity.RunProcessId.Trim())
|
|
&& (string.IsNullOrWhiteSpace(searchEntity.Applyno) || k.Applyno == searchEntity.Applyno.Trim())
|
&& (string.IsNullOrWhiteSpace(searchEntity.Creater) || a.DeelUserId == searchEntity.Creater.Trim())
|
|
select new WfNeeddeelDTO
|
{
|
Id = a.Id,
|
//DocType = a.DocType,
|
//ApplytimeName = a.Applytime.ToString("yyyy-MM-dd"),
|
//DocTypeName = ggg.DocName,
|
//DocDept = a.DocDept,
|
//DocDeptName = kkk.DeptName,
|
//DocNo = a.DocNo,
|
//DocTitle = a.DocTitle,
|
//// DocContent = a.DocContent,
|
//DocZtc = a.DocZtc,
|
//DocCsdw = a.DocCsdw,
|
//Applytime = a.Applytime,
|
//PrintStatus = a.PrintStatus,
|
//PrintStatusName = eee.Comments,
|
//Printtimes = a.Printtimes ?? 0,
|
|
ApplytimeName = k.Applytime.Value.ToString("yyyy-MM-dd"),
|
Applyno = k.Applyno,
|
CreaterName = b.UserName,
|
DeptName = c.DeptName,
|
Applytiye = d.Applytiye,
|
Content = k.Content,
|
ShenpiStatusName = eee.Comments,
|
Resivetime = a.Resivetime,
|
NeeddeelType = a.NeeddeelType,
|
NeeddeelTypeName = fff.Comments,
|
Contentyijian = a.Content,
|
Sort = a.Sort,
|
Deelurl = a.Deelurl,
|
Creater = a.Creater,
|
Createtime = a.Createtime,
|
Step = a.Step,
|
RecStatus = a.RecStatus,
|
Modifier = a.Modifier,
|
Modifytime = a.Modifytime,
|
|
}
|
).OrderBy(x => x.Sort).ThenByDescending(x => x.Resivetime).ToList();
|
|
|
|
//if (searchEntity.totalrows == 0)
|
searchEntity.totalrows = query.Count();
|
var lianlist = query.Skip((searchEntity.page - 1) * searchEntity.rows).Take(searchEntity.rows).ToList();
|
data.LoadData(searchEntity, lianlist);
|
return data;
|
}
|
|
public ResultEntity ModifyStatus(string id, string userid)
|
{
|
|
ResultEntity result = new ResultEntity();
|
result.Result = true;
|
|
var model = _context.WfNeeddeels.Find(id);
|
if (model != null)
|
{
|
model.RecStatus = "D";
|
model.Modifier = userid;
|
model.Modifytime = DateTime.Now;
|
_context.SaveChanges();
|
}
|
|
return result;
|
}
|
|
|
|
/// <summary>
|
/// 获取所有有效流程类型
|
/// </summary>
|
/// <returns></returns>
|
public List<WfNeeddeelDTO> GetList(string RunProcessId = "", string step = "")
|
{
|
|
|
var listRole = _context.WfNeeddeels.AsNoTracking().Where(r => r.RecStatus == "A").ToList();
|
|
if (!string.IsNullOrEmpty(RunProcessId) && !string.IsNullOrEmpty(step))
|
{
|
listRole = listRole.Where(x => x.RunProcessId == RunProcessId && x.Step == step).ToList();
|
}
|
|
var list = _mapper.Map<List<WfNeeddeelDTO>>(listRole);
|
return list;
|
}
|
|
|
/// <summary>
|
/// 获取所有有效流程类型
|
/// </summary>
|
/// <returns></returns>
|
public List<WfNeeddeelDTO> GetListTracking(string RunProcessId = "", string step = "")
|
{
|
|
|
var listRole = _context.WfNeeddeels.Where(r => r.RecStatus == "A").ToList();
|
|
if (!string.IsNullOrEmpty(RunProcessId) && !string.IsNullOrEmpty(step))
|
{
|
listRole = listRole.Where(x => x.RunProcessId == RunProcessId && x.Step == step).ToList();
|
}
|
|
var list = _mapper.Map<List<WfNeeddeelDTO>>(listRole);
|
return list;
|
}
|
}
|
}
|