using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using AutoMapper;
|
using DTO;
|
using IServices;
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
using Microsoft.EntityFrameworkCore;
|
using zhengcaioa.Models;
|
|
|
namespace Services
|
{
|
public class AdmDocDocService:IAdmDocDocService
|
{
|
private readonly zhengcaioaContext _context;
|
private readonly IMapper _mapper;
|
public AdmDocDocService(zhengcaioaContext context, IMapper mapper)
|
{
|
_context = context;
|
_mapper = mapper;
|
}
|
public ResultEntity save(AdmDocDocDTO dto)
|
{
|
ResultEntity resultEntity = new ResultEntity();
|
try
|
{
|
var checkUserSn = _context.AdmDocDocs.Where(x => x.DocTitle == dto.DocTitle && x.RecStatus == "A" && x.Id != dto.Id).FirstOrDefault();
|
if (checkUserSn != null && (string.IsNullOrWhiteSpace(dto.Id) || (!string.IsNullOrWhiteSpace(dto.Id) && checkUserSn.Id != dto.Id)))
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "公文标题重复";
|
return resultEntity;
|
}
|
|
var entity = _mapper.Map<AdmDocDoc>(dto);
|
|
|
if (String.IsNullOrEmpty(entity.Id))
|
{
|
entity.Id = Guid.NewGuid().ToString();
|
|
var DocNo = _context.AdmDocDocs.Max(x => x.DocNo);
|
if (string.IsNullOrEmpty(DocNo))
|
{
|
entity.DocNo = 1.ToString().PadLeft(6, '0');
|
}
|
else
|
{
|
entity.DocNo = (int.Parse(DocNo) + 1).ToString().PadLeft(6, '0');
|
}
|
_context.AdmDocDocs.Add(entity);
|
}
|
else
|
{
|
var updateproject = _context.AdmDocDocs.Find(entity.Id);
|
|
updateproject.DocType = entity.DocType;
|
updateproject.DocDept = entity.DocDept;
|
updateproject.DocNo = entity.DocNo;
|
updateproject.DocTitle = entity.DocTitle;
|
updateproject.DocContent = entity.DocContent;
|
updateproject.DocZtc = entity.DocZtc;
|
updateproject.Printtimes = entity.Printtimes;
|
updateproject.DocCsdw = entity.DocCsdw;
|
updateproject.PublishTime = entity.PublishTime;
|
updateproject.PrintStatus = entity.PrintStatus;
|
updateproject.RecStatus = entity.RecStatus;
|
updateproject.Modifier = entity.Modifier;
|
updateproject.Modifytime = entity.Modifytime;
|
|
}
|
|
_context.SaveChanges();
|
resultEntity.ReturnID = entity.Id;
|
resultEntity.Result = true;
|
}
|
catch (Exception ex)
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "保存失败,请联系管理员";
|
|
}
|
return resultEntity;
|
}
|
|
public AdmDocDocDTO Get(string id)
|
{
|
|
var entity = _context.AdmDocDocs.Find(id);
|
|
if (entity.RecStatus != "A")
|
{
|
entity = new AdmDocDoc();
|
}
|
|
var result = _mapper.Map<AdmDocDocDTO>(entity);
|
|
|
return result;
|
}
|
|
public ResultDataEntity<AdmDocDocDTO> SearchByPaging(AdmDocDocDTOSearch searchEntity)
|
{
|
|
|
|
ResultDataEntity<AdmDocDocDTO> data = new ResultDataEntity<AdmDocDocDTO>();
|
List<AdmDocDocDTO> list = new List<AdmDocDocDTO>();
|
|
|
|
|
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 PublishTimestart = DateTime.Now;
|
DateTime PublishTimeend = DateTime.Now;
|
if (!string.IsNullOrWhiteSpace(searchEntity.PublishTime))
|
{
|
string[] PublishTimes = searchEntity.PublishTime.Split("|");
|
DateTime.TryParse(PublishTimes[0], out PublishTimestart);
|
DateTime.TryParse(PublishTimes[1], out PublishTimeend);
|
//PublishTimeend = PublishTimeend.AddDays(1);
|
}
|
|
///AdmDocDocs
|
var query = (from a in _context.AdmDocDocs
|
|
|
join e in listCode.Where(x => x.CodeTable == "system" && x.CodeField == "shifou")
|
on a.PrintStatus equals e.CodeSn
|
into esssss
|
from eee in esssss.DefaultIfEmpty()
|
|
|
|
|
join g in _context.AdmDocBases.Where(x => x.RecStatus == "A")
|
on a.DocType equals g.Id
|
into gsss
|
from ggg in gsss.DefaultIfEmpty()
|
|
|
|
join k in _context.HrDepts.Where(x => x.RecStatus == "A" && x.QiyongStatus == "A")
|
on a.DocDept equals k.Id
|
into ksssss
|
from kkk in ksssss.DefaultIfEmpty()
|
|
where a.RecStatus == "A"
|
&& (string.IsNullOrWhiteSpace(searchEntity.PublishTime) || (a.PublishTime >= PublishTimestart && a.PublishTime <= PublishTimeend))
|
&& (string.IsNullOrWhiteSpace(searchEntity.DocType) || a.DocType == searchEntity.DocType.Trim())
|
&& (string.IsNullOrWhiteSpace(searchEntity.DocDept) || a.DocDept == searchEntity.DocDept.Trim())
|
&& (string.IsNullOrWhiteSpace(searchEntity.DocTitle) || a.DocTitle.Contains(searchEntity.DocTitle.Trim()))
|
&& (string.IsNullOrWhiteSpace(searchEntity.DocNo) || a.DocNo.Contains(searchEntity.DocNo.Trim()))
|
|
|
|
|
|
select new AdmDocDocDTO
|
{
|
Id = a.Id,
|
DocType = a.DocType,
|
PublishTimeName = a.PublishTime.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,
|
PublishTime = a.PublishTime,
|
PrintStatus = a.PrintStatus,
|
PrintStatusName = eee.Comments,
|
Printtimes = a.Printtimes ?? 0,
|
|
|
|
|
|
|
|
|
Creater = a.Creater,
|
Createtime = a.Createtime,
|
|
RecStatus = a.RecStatus,
|
Modifier = a.Modifier,
|
Modifytime = a.Modifytime,
|
|
}
|
).OrderByDescending(x => x.DocNo).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;
|
}
|
|
|
|
|
|
|
/// <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.AdmDocDocs.Find(id);
|
if (model != null)
|
{
|
model.RecStatus = "D";
|
model.Modifier = userid;
|
model.Modifytime = DateTime.Now;
|
_context.SaveChanges();
|
}
|
|
return result;
|
}
|
}
|
}
|