using AutoMapper; using Cksoft.Data; using Cksoft.Data.Repository; using Cksoft.Unity; using DllEapEntity; using DllEapEntity.Dtos; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using System.IO; using System.Linq; using DllEapCommon.NPOI; using DllEapDal.SystemLog; namespace DllEapBll.Controllers { [Route("eap/api/systemupdatelog/[action]")] [ApiController] [Authorize] public class SystemUpdateLogController : ControllerBase { private IMapper _mapper; public SystemUpdateLogController(IMapper mapper) { _mapper = mapper; } /// /// 查看系统更新记录 /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// [HttpGet] public LayuiModel Get(DateTime? start, DateTime? end, string version, string content, string updatetype, string department, string employee, string developer, string result, string te, string remark, int id, int environment = -1, int pageIndex = 1, int pageSize = 20) { using (IDatabase db = DbFactory.Base("eapslave")) { var dal = new SystemUpdateLogDal(db); return dal.Get(start, end, id, environment, version, content, updatetype, department, employee, developer, result, te, remark, pageIndex, pageSize); } } /// /// 增加或修改系统更新记录 /// /// /// [HttpPost] public EapResponse Add(SystemUpdataLogDto systemUpdateLog) { string usercode = Request.Headers["usercode"]; using (IDatabase db = DbFactory.Base("eap")) { var dal = new SystemUpdateLogDal(db); return dal.AddUpdate(systemUpdateLog, usercode); } } /// /// 删除系统更新记录 /// /// /// [HttpPost] public EapResponse Delete(IDictionary filterInfo) { string id = string.Empty; /*string userCode=*/ string usercode = Request.Headers["usercode"]; if (filterInfo.ContainsKey("Id")) { id = filterInfo["Id"]; using (IDatabase db = DbFactory.Base("eap")) { var dal = new SystemUpdateLogDal(db); return dal.Delete(id, usercode); } } else { return new EapResponse() { Code = -1, Msg = "未收到ID,请检查后重试" }; } } /// /// 系统更新记录导出 /// /// /// [HttpPost] public async Task Export(IDictionary filterInfo) { using (IDatabase db = DbFactory.Base("eapslave")) { string version = string.Empty, content = string.Empty, updatetype = string.Empty, department = string.Empty, employee = string.Empty, developer = string.Empty; int environmentint = -1; string result = string.Empty, te = string.Empty, remark = string.Empty; var dal = new SystemUpdateLogDal(db); DateTime end = DateTime.Now, start = end.AddDays(-30); if (filterInfo.ContainsKey("end")) end = Convert.ToDateTime(filterInfo["end"]); if (filterInfo.ContainsKey("start")) start = Convert.ToDateTime(filterInfo["start"]); if (filterInfo.ContainsKey("environmentint")) environmentint = Convert.ToInt32(filterInfo["environmentint"]); if (filterInfo.ContainsKey("version")) version = filterInfo["version"]; if (filterInfo.ContainsKey("content")) content = filterInfo["content"]; if (filterInfo.ContainsKey("updatetype")) updatetype = filterInfo["updatetype"]; if (filterInfo.ContainsKey("department")) department = filterInfo["department"]; if (filterInfo.ContainsKey("employee")) employee = filterInfo["employee"]; if (filterInfo.ContainsKey("developer")) developer = filterInfo["developer"]; if (filterInfo.ContainsKey("result")) result = filterInfo["result"]; if (filterInfo.ContainsKey("te")) te = filterInfo["te"]; if (filterInfo.ContainsKey("remark")) remark = filterInfo["remark"]; int pageIndex = 1, pageSize = 10000; string errorinfo = string.Empty; var dto = dal.Get(start, end, 0, environmentint, version, content, updatetype, department, employee, developer, result, te, remark, pageIndex, pageSize).data.ToList(); var book = DataExportHelper.SULToExcel(dto); MemoryStream ms = new MemoryStream(); ms.Position = 0; book.Write(ms); ms.Dispose(); ms.Close(); await Task.CompletedTask; return File(ms.ToArray(), "application/octet-stream"); } } } }