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.FM; using APT.BaseData.Domain.IServices; using APT.Infrastructure.Core; using APT.MS.Domain.Entities.OG; using APT.MS.Domain.Enums; using APT.Utility; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using APT.MS.Domain.Entities.LR; namespace APT.SC.WebApi.Controllers.Api.OG { [Route("api/OG/OGSafePdtSigned")] public class OGSafePdtSignedController : AuthorizeApiController { IFMNotificationTaskService NotificationTaskService { get; set; } public OGSafePdtSignedController(IFMNotificationTaskService notificationTaskService, IPFCodeRuleService codeRuleService) { NotificationTaskService = notificationTaskService; } /// /// 更新 /// /// /// [HttpPost, Route("FullUpdate")] public JsonActionResult FullUpdate([FromBody] T_OG_SAFE_PDT_SIGNED entity) { return SafeExecute(() => { var Nav_SafePdtSignedPost = entity.Nav_SafePdtSignedPost; entity.Nav_SafePdtSignedPost = null; List notices = new List(); if (entity.PUBLISH != null && entity.PUBLISH.Equals("SaveAndNotify")) { if (entity.STATUS != PFStandardStatus.Draft) { throw new Exception("已发送!"); } entity.STATUS = PFStandardStatus.Sign; entity.ANNUAL = DateTime.Now.Year; var allSendUserTitles = new List(); var allSendDataIds = new List(); var allSendUserIds = new List(); var allSendUserNames = new List(); foreach (var user in Nav_SafePdtSignedPost.Where(t => t.IS_DELETED == false)) { if (user.CHARGE_USER_ID == Guid.Empty || user.CHARGE_USER_ID == null) { throw new Exception("签订人员负责人不能为空!"); } allSendUserTitles.Add(DateTime.Now.ToShortDateString() + "安全生产责任制个人签订表"); allSendDataIds.Add(entity.ID); allSendUserIds.Add(user.ID); allSendUserNames.Add(""); } notices = NotificationTaskService.InsertUserNoticeTaskModels(allSendUserTitles, allSendDataIds, entity.ORG_ID, allSendUserIds, allSendUserNames, DateTime.Now, DateTime.Now.AddDays(7), 1, "OG001_SHOWPRINT"); } UnifiedCommit(() => { UpdateEntityNoCommit(entity); if (Nav_SafePdtSignedPost != null && Nav_SafePdtSignedPost.Any()) BantchSaveEntityNoCommit(Nav_SafePdtSignedPost); if (notices != null && notices.Any()) BantchAddEntityNoCommit(notices); }); return true; }); } /// /// 安环部负责人审阅 /// /// /// [HttpPost, Route("Agree")] public JsonActionResult Agree([FromBody] T_OG_SAFE_PDT_SIGNED entity) { return SafeExecute(() => { var signeds = GetEntities(t => t.TRIGGER_TYPE == OGPersonalSignedTriggerType.任务触发 && t.STATUS == PFStandardStatus.Sign && t.ANNUAL == DateTime.Now.Year, new BaseFilter(entity.ORG_ID)).ToList(); if (signeds == null || signeds.Count == 0) { return true; } var signedPosts = GetEntities(t => t.Nav_SafePdtSigned.TRIGGER_TYPE == OGPersonalSignedTriggerType.任务触发 && t.Nav_SafePdtSigned.STATUS == PFStandardStatus.Sign && t.Nav_SafePdtSigned.ANNUAL == DateTime.Now.Year, new BaseFilter(entity.ORG_ID), new string[] { "Nav_SCPost", "Nav_ChargeUser.Nav_Department" }).ToList(); signeds.ForEach(signed => { signed.STATUS = PFStandardStatus.Archived; }); var finishNotice = NotificationTaskService.FOGetTaskFinishModel(entity.TaskID, entity.ID); var checkList = new List(); var allSendUserTitles = new List(); var allSendDataIds = new List(); var allSendUserIds = new List(); var allSendUserNames = new List(); foreach (var item in signedPosts) { var isExist = checkList.Where(t => t.USER_ID == item.CHARGE_USER_ID); if (!isExist.Any()) { T_OG_SAFE_PDT_ASSESS_PLAN_CHECK check = new T_OG_SAFE_PDT_ASSESS_PLAN_CHECK { ID = Guid.NewGuid(), TIME = DateTime.Now, DEPARTMENT_ID = item.Nav_ChargeUser.DEPARTMENT_ID, USER_ID = item.CHARGE_USER_ID, LEVEL = (FMDepartmentType)item.Nav_ChargeUser.Nav_Department.DEPARTMENT_TYPE, STATUS = PFStandardStatus.Draft, ORG_ID = item.ORG_ID, ANNUAL = DateTime.Now.Year, }; checkList.Add(check); allSendUserTitles.Add("安全生产责任制考核方案审核"); allSendDataIds.Add(check.ID); allSendUserIds.Add((Guid)item.CHARGE_USER_ID); allSendUserNames.Add(item.Nav_ChargeUser.NAME); } } var sendNotices = NotificationTaskService.InsertUserNoticeTaskModels(allSendUserTitles, allSendDataIds, entity.ORG_ID.Value, allSendUserIds, allSendUserNames, DateTime.Now, DateTime.Now.AddDays(1), 1, "OG004"); UnifiedCommit(() => { BantchSaveEntityNoCommit(signeds); if (finishNotice != null) UpdateEntityNoCommit(finishNotice); if (checkList.Any()) BantchSaveEntityNoCommit(checkList); if (sendNotices.Any()) BantchSaveEntityNoCommit(sendNotices); }); return true; }); } public class SafePdtSignedModel { public List Nav_Signed { get; set; } public int SafePdtSignedStatus { get; set; } } /// /// 获得单条实体数据 /// /// 过滤实体 /// [HttpPost, Route("FullGet")] public JsonActionResult FullGet([FromBody] KeywordFilter filter) { JsonActionResult jsonActionResult = new JsonActionResult(); var data = WitEntity(null, filter); if (data.Data == null) { var id = filter.FilterGroup.Rules.FirstOrDefault(t => t.Field == "ID").Value.ToString(); var signpost = GetEntity(id); filter.FilterGroup.Rules.FirstOrDefault(t => t.Field == "ID").Value = signpost.SAFE_PDT_SIGNED_ID; data = WitEntity(null, filter); T_OG_SAFE_PDT_SIGNED model = data.Data; jsonActionResult.Data = model; } else { T_OG_SAFE_PDT_SIGNED model = data.Data; if (model != null && model.Nav_SafePdtSignedPost != null && model.Nav_SafePdtSignedPost.Count() > 0) { var Nav_SafePdtSignedPost = model.Nav_SafePdtSignedPost; var user_id = APT.Infrastructure.Api.AppContext.CurrentSession.UserID; var isChargeUser = Nav_SafePdtSignedPost.FirstOrDefault(t => t.USER_ID == user_id); Guid? charge_user = Guid.Empty; if (isChargeUser == null) { charge_user = user_id; } else { charge_user = isChargeUser.CHARGE_USER_ID; } model.Nav_SafePdtSignedPost = Nav_SafePdtSignedPost.Where(t => t.CHARGE_USER_ID == charge_user).ToList(); } jsonActionResult.Data = model; } return jsonActionResult; } /// /// 责任人签订 /// /// /// [HttpPost, Route("UserAgree")] public JsonActionResult UserAgree([FromBody] T_OG_SAFE_PDT_SIGNED entity) { return SafeExecute(() => { var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId; var userID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID; var baseFilter = new BaseFilter(orgId); baseFilter.Include = new string[] { "Nav_ChargeUser" }; var signedPosts = GetEntities(t => t.SAFE_PDT_SIGNED_ID == entity.ID, baseFilter); var currUser = signedPosts.Where(t => t.USER_ID == userID); T_FM_NOTIFICATION_TASK finishNotice = null; T_FM_NOTIFICATION_TASK sendNotice = null; T_OG_SAFE_PDT_SIGNED signed = null; if (currUser != null && currUser.Any()) { signed = GetEntity(entity.ID); signed.STATUS = PFStandardStatus.Sign; var chargeUser = currUser.FirstOrDefault().CHARGE_USER_ID; if (chargeUser == null) { var tempUser = GetEntity((Guid)currUser.FirstOrDefault().USER_ID); if (tempUser != null) { var tempDepartment = GetEntity((Guid)tempUser.DEPARTMENT_ID); if (tempDepartment != null) { chargeUser = tempDepartment.USER_ID; } } } foreach(var item in currUser) { item.CHARGE_USER_ID= chargeUser; } foreach (var signedPost in currUser) { signedPost.DEAL_STATUS = PdtSignStatus.已签订; signedPost.SIGNED_TIME = DateTime.Now; } var leftuser = signedPosts.Where(t => t.CHARGE_USER_ID == chargeUser && t.DEAL_STATUS == PdtSignStatus.未签订); if (leftuser.Count() == 0) { sendNotice = NotificationTaskService.InsertUserNoticeTaskModel("安全生产责任制签订-负责人签订", entity.ID, orgId, (Guid)chargeUser, "", DateTime.Now, DateTime.Now.AddDays(1), 0, "OG001_SHOWPRINT"); } } if (entity.TaskID != Guid.Empty) { finishNotice = NotificationTaskService.FOGetTaskFinishModel(entity.TaskID, entity.ID); } this.UnifiedCommit(() => { if (finishNotice != null) UpdateEntityNoCommit(finishNotice); if (currUser != null && currUser.Any()) BantchUpdateEntityNoCommit(currUser); if (sendNotice != null) AddEntityNoCommit(sendNotice); if (signed != null) UpdateEntityNoCommit(signed); }); return true; }); } /// /// 负责人签订 /// /// /// [HttpPost, Route("ChargeUserAgree")] public JsonActionResult ChargeUserAgree([FromBody] T_OG_SAFE_PDT_SIGNED entity) { return SafeExecute(() => { var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId; var userID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID; T_FM_NOTIFICATION_TASK finishNotice = null; T_FM_NOTIFICATION_TASK sendNotice = null; T_OG_SAFE_PDT_SIGNED signed = null; var signedPost = GetEntities(t => t.Nav_SafePdtSigned.ANNUAL == DateTime.Now.Year && t.SAFE_PDT_SIGNED_ID == entity.ID && t.CHARGE_USER_ID == userID && t.CHARGE_DEAL_STATUS == PdtSignStatus.未签订, new BaseFilter(orgId)); if (signedPost != null && signedPost.Any()) { foreach (var item in signedPost) { item.CHARGE_DEAL_STATUS = PdtSignStatus.已签订; item.CHARGE_SIGNED_TIME = DateTime.Now; } signed = GetEntity(entity.ID); signed.STATUS = PFStandardStatus.Archived; //20230727去掉审核环节 //var AHUser = GetEntity(t => t.Nav_ApproveRole.NAME == "安环部负责人" && t.ENABLE_STATUS == 0); // sendNotice = NotificationTaskService.InsertUserNoticeTaskModel("安全生产责任制签订-审核", entity.ID, orgId, AHUser.ID, AHUser.NAME, DateTime.Now, DateTime.Now.AddDays(1), 0, "OG001_REPORT"); } if (entity.TaskID != Guid.Empty) { finishNotice = NotificationTaskService.FOGetTaskFinishModel(entity.TaskID, entity.ID); } this.UnifiedCommit(() => { if (finishNotice != null) UpdateEntityNoCommit(finishNotice); if (signedPost != null) BantchUpdateEntityNoCommit(signedPost); if (sendNotice != null) AddEntityNoCommit(sendNotice); if (signed != null) UpdateEntityNoCommit(signed); }); return true; }); } } }