using APT.BaseData.Domain.Entities; using APT.BaseData.Domain.Entities.FM; using APT.BaseData.Domain.Enums.PF; using APT.BaseData.Domain.IServices; using APT.BaseData.Domain.IServices.FM; using APT.Infrastructure.Core; using APT.MS.Domain.Entities.DM; using APT.MS.Domain.Enums; using APT.Utility; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; namespace APT.SC.WebApi.Controllers.Api.DM { [Route("api/DM/DMDeviceCheck")] public class DMDeviceCheckController : AuthorizeApiController { IFMNotificationTaskService NotificationTaskService { get; set; } public DMDeviceCheckController(IFMNotificationTaskService notificationTaskService) { NotificationTaskService = notificationTaskService; } /// /// 设备设施维保计划 修改 /// /// /// [HttpPost, Route("FullUpdate")] public JsonActionResult FullUpdate([FromBody] T_DM_DEVICE_CHECK entity) { return SafeExecute(() => { var ListDetail = entity.Nav_ListDetail; entity.Nav_ListDetail = null; T_FM_NOTIFICATION_TASK taskEnd = null; List listTaskCheck = null; var files = entity.Nav_Files; entity.Nav_Files = null; if (ListDetail == null) { throw new Exception(entity.CHECKTYPE.GetDescription() + "明细不能未空!"); } if (entity.STATUS != PFStandardStatus.Draft) { int RowIndex = 1; foreach (var item in ListDetail) { if (item.CHECK_VALUE == null) { throw new Exception("请选择行:" + RowIndex + "检查结论!"); } //else if ((item.CHECK_VALUE.Value == CheckResult.CheckWork || item.CHECK_VALUE.Value == CheckResult.CheckStop) && string.IsNullOrEmpty(item.DESCRIPTION)) else if (item.CHECK_VALUE.Value == CheckResult.NotOK && string.IsNullOrEmpty(item.DESCRIPTION)) { throw new Exception("请填写子表行:【" + RowIndex + "】的问题描述!"); } RowIndex++; } if (entity.TaskID != Guid.Empty) { //taskEnd = NotificationTaskService.GetEntityTask(entity.TaskID, "DM010_SHOWPRINT"); taskEnd = NotificationTaskService.GetEntityTask(entity.TaskID, (entity.CHECKTYPE == CheckType.CheckCircuit ? "DM032_SHOWPRINT" : "DM010_SHOWPRINT")); } //给其他人 发送待办 确认 var listUser = GetEntities(e => e.CHECK_ID == entity.ID && !e.ISMAIN, null, "Nav_User"); if (listUser == null || !listUser.Any()) { //没有 别的检查人 entity.STATUS = PFStandardStatus.Archived; } else { List UserId = new List(); List userName = new List(); foreach (var item in listUser) { UserId.Add(item.USER_ID); userName.Add(item.Nav_User.NAME); } //listTaskCheck = NotificationTaskService.InsertUserNoticeTaskModels((entity.CHECKTYPE == CheckType.CheckCircuit ? "设备巡检" : "设备点检") + "确认" + (entity.CREATE_TIME.HasValue ? entity.CREATE_TIME.Value.ToString("MMdd") : ""), entity.ID, entity.ORG_ID, UserId, userName, DateTime.Now, DateTime.Now.AddDays(1), 1, "DM010_SHOWPRINT"); listTaskCheck = NotificationTaskService.InsertUserNoticeTaskModels((entity.CHECKTYPE == CheckType.CheckCircuit ? "设备设施巡检" : "设备设施点检") + "确认" + (entity.CREATE_TIME.HasValue ? entity.CREATE_TIME.Value.ToString("MMdd") : ""), entity.ID, entity.ORG_ID, UserId, userName, DateTime.Now, DateTime.Now.AddDays(1), 1, (entity.CHECKTYPE == CheckType.CheckCircuit ? "DM032_SHOWPRINT" : "DM010_SHOWPRINT")); } } this.UnifiedCommit(() => { if (entity != null) UpdateEntityNoCommit(entity); if (files != null) BantchSaveEntityNoCommit(files); if (taskEnd != null)//结束待办 UpdateEntityNoCommit(taskEnd); if (ListDetail != null && ListDetail.Any())//检查明细 BantchSaveEntityNoCommit(ListDetail); if (listTaskCheck != null && listTaskCheck.Any())//检查明细 BantchSaveEntityNoCommit(listTaskCheck); }); return true; }); } /// /// 点检人 确认 /// [HttpPost, Route("Check")] public JsonActionResult Check([FromBody] KeywordFilter filter) { return SafeExecute(() => { if (string.IsNullOrEmpty(filter.Keyword) || string.IsNullOrEmpty(filter.Parameter1)) { throw new Exception("传参有误!"); } var guid = new Guid(filter.Keyword); var taskID = new Guid(filter.Parameter1); if (guid == Guid.Empty || taskID == Guid.Empty) { throw new Exception("传参有误!"); } var task = NotificationTaskService.GetEntityTask(taskID); var loginID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID; var Check = GetEntity(e => e.USER_ID == loginID && e.CHECK_ID == guid, "Nav_Check"); if (Check == null) { var DeviceCheck = GetEntity(e => e.ID == guid); DeviceCheck.STATUS = PFStandardStatus.Archived;//状态修改 //记录人 上级 确认 this.UnifiedCommit(() => { if (task != null) UpdateEntityNoCommit(task); if (DeviceCheck != null) UpdateEntityNoCommit(DeviceCheck); }); } else if (Check.ISCHECK) { this.UnifiedCommit(() => { if (task != null) UpdateEntityNoCommit(task); }); throw new Exception("您已审阅,无需再次操作!"); } else { Check.ISCHECK = true; var UnCheck = GetEntity(e => e.USER_ID != loginID && e.CHECK_ID == guid && !e.ISCHECK); T_FM_NOTIFICATION_TASK taskMaster = null; if (UnCheck == null) { //最后一个确认 记录人的 上级 确认 Guid UserId = Guid.Empty; string userName = string.Empty; Guid DEPID = Guid.Empty; var CheckMain = GetEntity(e => e.CHECK_ID == guid && e.ISMAIN, "Nav_User.Nav_Department"); if (CheckMain.Nav_User.Nav_Department.USER_ID != CheckMain.USER_ID) { if (CheckMain.Nav_User.Nav_Department.USER_ID.HasValue) { UserId = CheckMain.Nav_User.Nav_Department.USER_ID.Value; } else { DEPID = CheckMain.Nav_User.DEPARTMENT_ID.Value; } } else { var dep = GetEntity(CheckMain.Nav_User.Nav_Department.PARENT_ID.Value); if (dep.USER_ID.HasValue) { UserId = dep.USER_ID.Value; } else { DEPID = dep.ID; } } if (UserId != Guid.Empty) { userName = GetEntity(UserId).NAME; } else { //先不管 } if (UserId != Guid.Empty) { if (UserId == loginID) { //自己就是 填表人的 上级 不发送待办 } else { taskMaster = NotificationTaskService.InsertUserNoticeTaskModel((Check.Nav_Check.CHECKTYPE == CheckType.CheckCircuit ? "设备巡检" : "设备点检") + "确认", CheckMain.CHECK_ID, CheckMain.ORG_ID, UserId, userName, DateTime.Now, DateTime.Now.AddDays(1), 1, (Check.Nav_Check.CHECKTYPE == CheckType.CheckCircuit ? "DM032_SHOWPRINT" : "DM010_SHOWPRINT")); } } } //还有别人未 确认 this.UnifiedCommit(() => { if (task != null) UpdateEntityNoCommit(task); if (Check != null) UpdateEntityNoCommit(Check); if (taskMaster != null) UpdateEntityNoCommit(taskMaster); }); } return true; }); } /// /// 排序分页查询数据 /// /// 分页过滤实体 /// [HttpPost, Route("OrderPagedSuit")] public PagedActionResult OrderPaged([FromBody] KeywordPageFilter pageFilter) { return SafeGetPagedData(delegate (PagedActionResult result) { if (!string.IsNullOrEmpty(pageFilter.MenuParameter) && pageFilter.MenuParameter.Contains("=")) { var listParm = pageFilter.MenuParameter.Split("="); pageFilter.FilterGroup.Rules.Add(new FilterRule() { Field = listParm[0], Value = listParm[1] }); } PagedActionResult orderPageEntities = GetOrderPageEntities(null, pageFilter, null); result.Data = orderPageEntities.Data; result.TotalCount = orderPageEntities.TotalCount; }); } /// /// 获得单条实体数据 /// /// 过滤实体 /// [HttpPost, Route("GetSuit")] public JsonActionResult GetSuit([FromBody] KeywordFilter filter) { return SafeExecute(() => { var result = GetEntity(null, filter, null); if (result.Nav_ListUser != null && result.Nav_ListUser.Any()) { result.Nav_ListUser = result.Nav_ListUser.OrderByDescending(e => e.ISMAIN).ToList(); } return result; }); } } }