using APT.BaseData.Domain.Entities; using APT.BaseData.Domain.Enums.PF; using APT.BaseData.Domain.IServices.FM; using APT.BaseData.Domain.IServices; using APT.Infrastructure.Core; using APT.MS.Domain.Entities.DM; using APT.Utility; using Microsoft.AspNetCore.Mvc; using System; using System.Linq; using NPOI.SS.Formula.Functions; using APT.BaseData.Domain.Entities.FM; namespace APT.SC.WebApi.Controllers.Api.DM { [Route("api/DM/DMDeviceRepair")] public class DeviceRepairController : AuthorizeApiController { IFMNotificationTaskService NotificationTaskService { get; set; } public DeviceRepairController(IFMNotificationTaskService notificationTaskService) { NotificationTaskService = notificationTaskService; } /// /// 更新 /// /// /// [HttpPost, Route("FullUpdate")] public JsonActionResult FullUpdate([FromBody] T_DM_DEVICE_REPAIR entity) { return SafeExecute(() => { var files = entity.Nav_Files; entity.Nav_Files = null; if (entity.CODE == null) { entity.CODE = DateTime.Now.ToString("yyyyMMddHHmmss"); } if (entity.USER_ID == null || entity.USER_ID == Guid.Empty) { entity.USER_ID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID; } if (entity.REPAIR_TIME == DateTime.Parse("0001-01-01 00:00:00")) { entity.REPAIR_TIME = DateTime.Now; } if(entity.STATUS== PFStandardStatus.Archived) { throw new Exception("已归档不能编辑"); } T_FM_NOTIFICATION_TASK sendNotice = null; T_FM_NOTIFICATION_TASK finishNotice = null; T_DM_DEVICE_OVERHAUL overhaul= null; if (entity.PUBLISH != null && entity.PUBLISH.Equals("SaveAndNotify")) { if (entity.STATUS == PFStandardStatus.Draft) { entity.STATUS = PFStandardStatus.Sign; sendNotice = NotificationTaskService.InsertUserNoticeTaskModel("设备设施故障报修-" + entity.MACHINE_NAME, entity.ID, entity.ORG_ID, (Guid)entity.REPAIR_CHARGE_USER_ID, GetEntity(entity.REPAIR_CHARGE_USER_ID.Value).NAME, DateTime.Now, DateTime.Now.AddDays(1), 0, "DM020"); } else if (entity.STATUS == PFStandardStatus.Sign) { entity.STATUS = PFStandardStatus.Archived; finishNotice = NotificationTaskService.FOGetTaskFinishModel(entity.TaskID,entity.ID, "DM020_SHOWPRINT"); overhaul=new T_DM_DEVICE_OVERHAUL { ID= Guid.NewGuid(), OVERHAUL_TIME=DateTime.Now, CODE= DateTime.Now.ToString("yyyyMMddHHmmss"), USER_ID=entity.REPAIR_USER_ID, DEVICE_BASE_ID=entity.DEVICE_BASE_ID, MACHINE_NAME=entity.MACHINE_NAME, SPEC= entity.SPEC, MACHINE_CODE=entity.MACHINE_CODE, POSITION= entity.POSITION, MALFUCTION=entity.DESCRPTION, REPAIR_ID=entity.ID, ORG_ID=entity.ORG_ID, IS_HELP=entity.IS_HELP, }; if (entity.IS_HELP == true) { sendNotice = NotificationTaskService.InsertUserNoticeTaskModel("设备设施检修记录-"+entity.MACHINE_NAME, overhaul.ID, entity.ORG_ID, (Guid)entity.REPAIR_CHARGE_USER_ID, GetEntity(entity.REPAIR_CHARGE_USER_ID.Value).NAME, DateTime.Now, DateTime.Now.AddDays(1), 0, "DM022"); } else { sendNotice = NotificationTaskService.InsertUserNoticeTaskModel("设备设施检修记录-" + entity.MACHINE_NAME, overhaul.ID, entity.ORG_ID, (Guid)entity.REPAIR_USER_ID, GetEntity(entity.REPAIR_USER_ID.Value).NAME, DateTime.Now, DateTime.Now.AddDays(1), 0, "DM022"); } } } UnifiedCommit(() => { UpdateEntityNoCommit(entity); if (files != null && files.Any()) BantchSaveEntityNoCommit(files); if (sendNotice != null) AddEntityNoCommit(sendNotice); if (finishNotice != null) UpdateEntityNoCommit(finishNotice); if (overhaul != null) AddEntityNoCommit(overhaul); }); return true; }); } } }