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/DMDeviceMaintenancePlan")] public class DMDeviceMaintenancePlanController : AuthorizeApiController { IFMNotificationTaskService NotificationTaskService { get; set; } public DMDeviceMaintenancePlanController(IFMNotificationTaskService notificationTaskService) { NotificationTaskService = notificationTaskService; } /// /// 设备设施维保计划 修改 /// /// /// [HttpPost, Route("FullUpdate")] public JsonActionResult FullUpdate([FromBody] T_DM_DEVICE_MAINTENANCE_PLAN entity) { return SafeExecute(() => { var Files = entity.Nav_Files; entity.Nav_Files = null; var FilesPlan = entity.Nav_FilesPlan; entity.Nav_FilesPlan = null; var ListUser = entity.Nav_ListUser; entity.Nav_ListUser = null; if (!entity.DEVICEBASE_ID.HasValue) { throw new Exception("请选择设备设施!"); } if (string.IsNullOrEmpty(entity.POSITION)) { throw new Exception("请填写位置!"); } if (string.IsNullOrEmpty(entity.CONTENT)) { throw new Exception("请填写维保内容!"); } else if (entity.CONTENT.Length > 500) { throw new Exception("维保内容不能超过500字符!"); } List listTask = null; if (entity.STATUS_APPROVE != PFStandardStatus.Draft) { if (ListUser == null || !ListUser.Any()) { throw new Exception("请选择计划检查人员!"); } else if (ListUser.Count() < 2) { throw new Exception("计划检查人员最少2人!"); } #region 周期提示 string Msg = string.Empty; switch (entity.PLANCHECKFREQUENCY) { case BSPLANCHECKFREQUENCYEnum.None: Msg = "请选频率"; break; //case BSPLANCHECKFREQUENCYEnum.OneTime: case BSPLANCHECKFREQUENCYEnum.Year: case BSPLANCHECKFREQUENCYEnum.HalfYear: if (string.IsNullOrEmpty(entity.RUNDATA)) { Msg = "请选择触发日期"; } break; case BSPLANCHECKFREQUENCYEnum.Date: if (entity.RUNSETTIME == DateTime.MinValue) { Msg = "请选择执行时间"; } break; case BSPLANCHECKFREQUENCYEnum.Week: if (!entity.WEEKDATA.HasValue) { Msg = "请选择星期"; } break; case BSPLANCHECKFREQUENCYEnum.Month: case BSPLANCHECKFREQUENCYEnum.Quarter: if (!entity.DATA.HasValue) { Msg = "请选择日"; } break; default: break; } if (!string.IsNullOrEmpty(Msg)) { throw new Exception(Msg); } #endregion List UserId = new List(); List userName = new List(); //var listUserID = ListUser.Select(e => e.USER_ID); //var listUser = GetEntities(e => listUserID.Contains(e.ID), null, null); foreach (var item in ListUser) { if (item.IS_DELETED) { continue; } UserId.Add(item.USER_ID); userName.Add(item.Nav_User.NAME); } listTask = NotificationTaskService.InsertUserNoticeTaskModels("设备设施维保计划确认", entity.ID, entity.ORG_ID, UserId, userName, DateTime.Now, DateTime.Now.AddDays(1), 1, "DM008_SHOWPRINT"); } int RowIndex = 0;//第一个 计划检查人员 为记录人 foreach (var item in ListUser) { if (item.IS_DELETED) { continue; } if (RowIndex == 0) { item.ISMAIN = true; } item.Nav_User = null; RowIndex++; } this.UnifiedCommit(() => { if (entity != null) UpdateEntityNoCommit(entity); if (Files != null && Files.Any())//维保工作方案 BantchSaveEntityNoCommit(Files); if (FilesPlan != null && FilesPlan.Any())//维保工作方案 BantchSaveEntityNoCommit(FilesPlan); if (ListUser != null && ListUser.Any())//维保工作方案 BantchSaveEntityNoCommit(ListUser); if (listTask != null && listTask.Any())//维保工作方案 BantchSaveEntityNoCommit(listTask); }); 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.PLAN_ID == guid); if (Check == null) { this.UnifiedCommit(() => { if (task != null) UpdateEntityNoCommit(task); }); } 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.PLAN_ID == guid && !e.ISCHECK); T_DM_DEVICE_MAINTENANCE_PLAN plan = null; if (UnCheck == null) { plan = GetEntity(e => e.ID == guid); plan.STATUS_APPROVE = PFStandardStatus.Archived; } //还有别人未 确认 this.UnifiedCommit(() => { if (task != null) UpdateEntityNoCommit(task); if (Check != null) UpdateEntityNoCommit(Check); if (plan != null)//状态修改 UpdateEntityNoCommit(plan); }); } return true; }); } } }