using APT.BaseData.Domain.Entities.FM; using APT.BaseData.Domain.Entities; using APT.BaseData.Domain.Enums.PF; using APT.BaseData.Domain.Enums; using APT.BaseData.Services.DomainServices; using APT.Infrastructure.Core; using APT.MS.Domain.Entities.HM; using APT.MS.Domain.Entities.SC.PE; using APT.MS.Domain.Entities.SC.PM; using APT.MS.Domain.Enums; using APT.Utility; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using System.Linq; using System; using APT.BaseData.Domain.IServices; using APT.BaseData.Domain.IServices.FM; using APT.BaseData.Services.Services.FM; namespace APT.SC.WebApi.Controllers.Api.PEController { /// /// 安全标准化内部评价计划录入表 /// [Route("api/PE/PESafetyEvaluationPlan")] public partial class SafetyEvaluationPlanController : AuthorizeApiController { IPFCodeRuleService CodeRuleService { get; set; } IFMFlowPermitService MFlowPermitService { get; set; } IPFApproveCallBackService ApproveCallBackService { get; set; } public SafetyEvaluationPlanController(IPFCodeRuleService codeRuleService, IFMFlowPermitService mFlowPermitService, IPFApproveCallBackService approveCallBackService) { CodeRuleService = codeRuleService; MFlowPermitService = mFlowPermitService; ApproveCallBackService = approveCallBackService; } /// /// 根据生产单元带出考评项目 /// /// /// [HttpPost, Route("GetEvaluationPlanDetail")] public JsonActionResult GetEvaluationPlanDetail([FromBody] KeywordFilter filter) { return SafeExecute(() => { var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId; T_PE_SAFETY_EVALUATION_PLAN main = new T_PE_SAFETY_EVALUATION_PLAN(); List detailList = new List(); //传入的识别表CODE不为空 if (!string.IsNullOrEmpty(filter.Keyword)) { var evaluationItem = GetEntities(t => t.PARENT_ID == Guid.Parse(filter.Keyword),new BaseFilter(orgId)); if (evaluationItem != null && evaluationItem.Any()) { var methods = this.GetEntities(t => !t.IS_DELETED, new BaseFilter(orgId)); evaluationItem.ForEach(t => { T_PE_SAFETY_EVALUATION_PLAN_DETAIL detail = new T_PE_SAFETY_EVALUATION_PLAN_DETAIL(); List methodList = new List(); detail.STANDARDIZED_ID = t.ID; detail.Nav_StandardName = t; detail.NUM = t.NUM; if (methods != null && methods.Any()) { methods.ForEach(t2 => { T_PE_SAFETY_EVALUATION_PLAN_METHOD method = new T_PE_SAFETY_EVALUATION_PLAN_METHOD(); method.ORG_ID = orgId; method.EVALUATION_PLAN_DETAIL_ID = detail.ID; method.METHOD_ID = t2.ID; method.Nav_Method = t2; methodList.Add(method); }); } detail.Nav_EvaluationMethod = methodList; detailList.Add(detail); }); } } main.Nav_Details = detailList.OrderBy(t=>t.NUM).ToList(); return main; }); } /// /// 新增/编辑 /// /// /// [HttpPost, Route("FullUpdate")] public JsonActionResult FullUpdate([FromBody] T_PE_SAFETY_EVALUATION_PLAN entity) { return SafeExecute(() => { var details = entity.Nav_Details.Where(t=>!t.IS_DELETED); entity.STATUS = PFStandardStatus.Draft; entity.DEPARTMENT_ID = APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID; if (entity.START_TIME <= DateTime.Now) throw new Exception("评价开始时间必须大于当前时间"); List evaluationUser = new List(); List evaluationMethod = new List(); if (details != null && details.Any()) { details.ForEach(t => { t.ORG_ID = entity.ORG_ID; t.SAFETY_EVALUATION_PLAN_ID = entity.ID; if (t.Nav_EvaluationUser != null && t.Nav_EvaluationUser.Any()) { var i = 1; t.Nav_EvaluationUser.ForEach(t1 => { if (!t1.IS_DELETED) { t1.ORG_ID = entity.ORG_ID; t1.EVALUATION_PLAN_DETAIL_ID = t.ID; t1.ROW_NO = i; evaluationUser.Add(t1); i++; } }); t.Nav_EvaluationUser = null; } if (t.Nav_EvaluationMethod != null && t.Nav_EvaluationMethod.Any()) { t.Nav_EvaluationMethod.ForEach(t2 => { t2.ORG_ID = entity.ORG_ID; t2.EVALUATION_PLAN_DETAIL_ID = t.ID; evaluationMethod.Add(t2); }); t.Nav_EvaluationMethod = null; } }); } var detailIds = details.Select(t => t.ID).ToList(); var deleteUserIds=this.GetEntities(t=> detailIds.Contains(t.EVALUATION_PLAN_DETAIL_ID),new BaseFilter(entity.ORG_ID)).Select(t => t.ID).ToList(); var deleteMethodIds = this.GetEntities(t => detailIds.Contains(t.EVALUATION_PLAN_DETAIL_ID), new BaseFilter(entity.ORG_ID)).Select(t => t.ID).ToList(); if (entity.PUBLISH != null && entity.PUBLISH.Equals("SaveAndNotify")) { entity.STATUS = PFStandardStatus.Approving; entity.Nav_Details = null; //取审批流水码 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[] { ',' }); MFlowPermitService.InsertApprove(serialCode[0], "PE027", "", entity.ID, "PE027_SHOWPRINT", entity.TaskID, true, () => { if (entity != null) this.UpdateEntityNoCommit(entity); if (details != null && details.Any()) this.BantchSaveEntityNoCommit(details); if (deleteUserIds != null && deleteUserIds.Any()) this.BantchDeleteEntityNoCommit(deleteUserIds); if (deleteMethodIds != null && deleteMethodIds.Any()) this.BantchDeleteEntityNoCommit(deleteMethodIds); if (evaluationUser != null && evaluationUser.Any()) this.BantchSaveEntityNoCommit(evaluationUser); if (evaluationMethod != null && evaluationMethod.Any()) this.BantchSaveEntityNoCommit(evaluationMethod); }, null, null, null, null, null, "PE027_SHOWPRINT", null); return true; } entity.Nav_Details = null; UnifiedCommit(() => { if (entity != null) this.UpdateEntityNoCommit(entity); if (details != null && details.Any()) this.BantchSaveEntityNoCommit(details); if (deleteUserIds != null && deleteUserIds.Any()) this.BantchDeleteEntityNoCommit(deleteUserIds); if (deleteMethodIds != null && deleteMethodIds.Any()) this.BantchDeleteEntityNoCommit(deleteMethodIds); if (evaluationUser != null && evaluationUser.Any()) this.BantchSaveEntityNoCommit(evaluationUser); if (evaluationMethod != null && evaluationMethod.Any()) this.BantchSaveEntityNoCommit(evaluationMethod); }); return true; }); } /// /// 获取 /// /// /// [HttpPost, Route("GetEdit")] public JsonActionResult GetEdit([FromBody] KeywordFilter filter) { return SafeExecute(() => { var id = filter.FilterGroup.Rules.FirstOrDefault(t => t.Field == "ID").Value.ToString(); if (string.IsNullOrEmpty(id)) this.ThrowError("030017"); var result = this.GetEntity(id, new string[] {"Nav_ProductionUnit", "Nav_Details","Nav_Details.Nav_StandardName","Nav_Details.Nav_EvaluationUser","Nav_Details.Nav_EvaluationUser.Nav_User", "Nav_Details.Nav_EvaluationMethod","Nav_Details.Nav_EvaluationMethod.Nav_Method"}); if (result != null && result.Nav_Details != null && result.Nav_Details.Any()) { result.Nav_Details.ForEach(t => { if (t.Nav_EvaluationUser != null && t.Nav_EvaluationUser.Any()) t.Nav_EvaluationUser = t.Nav_EvaluationUser.OrderBy(m => m.ROW_NO).ToList(); }); result.Nav_Details = result.Nav_Details.OrderBy(t => t.NUM).ToList(); } return result; }); } /// /// 回调函数 /// /// /// [HttpGet, Route("BackUpdate")] public JsonActionResult BackUpdate(string id) { return SafeExecute(() => { return ApproveCallBackService.CallBack("PE/PESafetyEvaluationPlan/BackUpdate", id); }); } } }