using APT.BaseData.Domain.Entities; using APT.BaseData.Domain.Entities.FM; using APT.BaseData.Domain.Enums; using APT.BaseData.Domain.Enums.PF; using APT.BaseData.Domain.IServices; using APT.BaseData.Domain.IServices.AE; using APT.BaseData.Domain.IServices.FM; using APT.BaseData.Services.DomainServices; using APT.BaseData.Services.Services.FM; using APT.Infrastructure.Core; using APT.MS.Domain.Entities.DM; using APT.MS.Domain.Enums; using APT.Utility; using ICSharpCode.SharpZipLib.Core; 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 { IPFCodeRuleService CodeRuleService { get; set; } IFMNotificationTaskService NotificationTaskService { get; set; } IFMFlowPermitService MFlowPermitService { get; set; } IPFApproveCallBackService ApproveCallBackService { get; set; } public DMDeviceMaintenancePlanController(IPFCodeRuleService codeRuleService, IFMNotificationTaskService notificationTaskService, IFMFlowPermitService mFlowPermitService, IPFApproveCallBackService approveCallBackService) { CodeRuleService = codeRuleService; NotificationTaskService = notificationTaskService; MFlowPermitService = mFlowPermitService; ApproveCallBackService = approveCallBackService; } /// /// 设备设施维保计划 修改 /// /// /// [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 details = entity.Nav_PlanDetails; entity.Nav_PlanDetails = null; T_FM_NOTIFICATION_TASK listTask = null; var another = new List(); var loginUserId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID; if (entity.TaskID != Guid.Empty) { var currTask = GetEntity(t => t.ID == entity.TaskID); if (currTask != null) { loginUserId = currTask.USER_ID; } } entity.USER_ID = loginUserId; entity.DEPARTMENT_ID = this.GetEntity(t => t.ENABLE_STATUS == 0 && t.ID == (Guid)loginUserId)?.DEPARTMENT_ID; if (details != null && details.Any()) { var item = details.FirstOrDefault(t => t.RUNSETTIME == DateTime.Parse("0001-01-01 00:00:00")); if (item != null) throw new Exception("开始时间不能是0001-01-01 00:00:00,请重新选择时间!"); details.ForEach(t => { t.DEPARTMENT_ID = entity.DEPARTMENT_ID; }); } if (entity.STATUS_APPROVE != PFStandardStatus.Draft) { //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); //} entity.STATUS_APPROVE = PFStandardStatus.Archived; //把其他人得待办置为已办 another = this.GetEntities(t => t.NOTICE_STATUS == 0 && t.SOURCE_DATA_ID == entity.ID && t.USER_ID != entity.USER_ID, new BaseFilter(entity.ORG_ID)).ToList(); if (another != null && another.Any()) { another.ForEach(t => { t.NOTICE_STATUS = 1; t.SOURCE_FORMCODE = "DM008_SHOWPRINT"; }); } //所有计划表都完成后汇总触发审批 var plans = this.GetEntities(t => t.SYNC_ID == entity.SYNC_ID,new BaseFilter(entity.ORG_ID)); var plan = plans.FirstOrDefault(t=>t.ID != entity.ID && t.STATUS_APPROVE == PFStandardStatus.Draft); if (plan == null) { var userId = this.GetEntity(t => t.NAME == "设备设施管理员")?.USER_ID; if (userId != null) { var user = this.GetEntity(t => t.ENABLE_STATUS == 0 && t.ID == userId); if (user != null) { entity.STATUS_APPROVE = PFStandardStatus.Approving; //取审批流水码 var sysFilter = new SystemCodeFilter(); sysFilter.CodeType = (int)PFCodeRuleType.审批流编码; sysFilter.Count = 1; sysFilter.OrgId = entity.ORG_ID; var codes = CodeRuleService.NewGenSerial(sysFilter); var serialCode = codes.Split(new char[] { ',' }); //if (entity.SYNC_ID == null || plans.Count() == 1) //{ // entity.SYNC_ID = entity.ID; //} MFlowPermitService.InsertApprove(serialCode[0], "DM008", "",entity.ID, "DM008_SHOWSUMMARY", entity.TaskID, true, () => { if (entity != null) UpdateEntityNoCommit(entity); if (Files != null && Files.Any())//维保工作方案 BantchSaveEntityNoCommit(Files); if (details != null && details.Any()) BantchSaveEntityNoCommit(details); if (another != null && another.Any()) BantchSaveEntityNoCommit(another); }, null, user.ID, null, null, null, "DM008_SHOWSUMMARY", null); return true; } } } if (entity.TaskID != Guid.Empty) { listTask = NotificationTaskService.GetTaskFinishModel(entity.TaskID); listTask.SOURCE_FORMCODE = "DM008_SHOWPRINT"; } } this.UnifiedCommit(() => { if (entity != null) UpdateEntityNoCommit(entity); if (Files != null && Files.Any())//维保工作方案 BantchSaveEntityNoCommit(Files); if (details != null && details.Any()) BantchSaveEntityNoCommit(details); if (listTask != null)//维保工作方案 UpdateEntityNoCommit(listTask); if (another != null && another.Any()) BantchSaveEntityNoCommit(another); }); return true; }); } /// /// 获得单条实体数据 /// /// 过滤实体 /// [HttpPost, Route("GetAll")] public JsonActionResult GetAll([FromBody] KeywordFilter filter) { return SafeExecute(() => { T_DM_DEVICE_MAINTENANCE_PLAN plan = new T_DM_DEVICE_MAINTENANCE_PLAN(); List details = new List(); List files = new List(); var id = filter.FilterGroup.Rules.FirstOrDefault(t => t.Field == "ID").Value.ToString(); if (string.IsNullOrEmpty(id)) throw new Exception("ID未获取到,请联系管理员"); var planTemp = GetEntity(id, "Nav_Department", "Nav_User"); if (planTemp != null && planTemp.SYNC_ID != null) { var baseFilter = new BaseFilter(filter.GetOrgId()); baseFilter.IgnoreDataRule = true; baseFilter.SelectField = new string[] { "NAME", "MineType", "YEARPLAN", "DEPARTMENT_ID", "USER_ID", "SYNC_ID", "ID", "Nav_Department", "Nav_User", "Nav_PlanDetails", "Nav_PlanDetails.SPEC", "Nav_PlanDetails.POSITION", "Nav_PlanDetails.CONTENTS", "Nav_PlanDetails.RUNSETTIME", "Nav_PlanDetails.PLANCHECKFREQUENCY", "Nav_PlanDetails.Nav_DeviceBase", "Nav_PlanDetails.Nav_Department", "Nav_PlanDetails.Nav_User", "Nav_Files.Nav_ImgFile.FILE_NAME", "Nav_Files.Nav_ImgFile.FILE_ID", "Nav_Files.Nav_ImgFile.FILE_PATH", "Nav_Files.Nav_ImgFile.Nav_File" }; //baseFilter.Include = new string[] { "Nav_Department", "Nav_User", "Nav_PlanDetails", "Nav_PlanDetails.Nav_DeviceBase", "Nav_PlanDetails.Nav_Department", "Nav_PlanDetails.Nav_User", "Nav_Files.Nav_ImgFile.Nav_File" }; var plans = GetEntities(t => t.SYNC_ID == planTemp.SYNC_ID, baseFilter); if (plans != null && plans.Any()) { foreach (var item in plans) { if (item.Nav_PlanDetails != null) details.AddRange(item.Nav_PlanDetails); if (item.Nav_Files != null) files.AddRange(item.Nav_Files); } plan = planTemp; plan.Nav_PlanDetails = details; plan.Nav_Files = files; } } return plan; }); } /// /// 回调函数 /// /// /// [HttpPost, Route("BackUpdateNew")] public JsonActionResult BackUpdateNew([FromBody] T_PF_APPROVE entity) { return SafeExecute(() => { return ApproveCallBackService.CallBackNew("DM/DMDeviceMaintenancePlan/BackUpdateNew", entity); }); } /// /// 点检人 确认 /// //[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; // }); //} } }