241 lines
12 KiB
C#
241 lines
12 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// 安全标准化内部评价计划录入表
|
|
/// </summary>
|
|
[Route("api/PE/PESafetyEvaluationPlan")]
|
|
public partial class SafetyEvaluationPlanController : AuthorizeApiController<T_PE_SAFETY_EVALUATION_PLAN>
|
|
{
|
|
IPFCodeRuleService CodeRuleService { get; set; }
|
|
IFMFlowPermitService MFlowPermitService { get; set; }
|
|
IPFApproveCallBackService ApproveCallBackService { get; set; }
|
|
IFMNotificationTaskService NotificationTaskService { get; set; }
|
|
public SafetyEvaluationPlanController(IPFCodeRuleService codeRuleService, IFMFlowPermitService mFlowPermitService, IPFApproveCallBackService approveCallBackService, IFMNotificationTaskService notificationTaskService)
|
|
{
|
|
CodeRuleService = codeRuleService;
|
|
MFlowPermitService = mFlowPermitService;
|
|
ApproveCallBackService = approveCallBackService;
|
|
NotificationTaskService = notificationTaskService;
|
|
}
|
|
/// <summary>
|
|
/// 根据生产单元带出考评项目
|
|
/// </summary>
|
|
/// <param name="filter"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("GetEvaluationPlanDetail")]
|
|
public JsonActionResult<T_PE_SAFETY_EVALUATION_PLAN> 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<T_PE_SAFETY_EVALUATION_PLAN_DETAIL> detailList = new List<T_PE_SAFETY_EVALUATION_PLAN_DETAIL>();
|
|
//传入的识别表CODE不为空
|
|
if (!string.IsNullOrEmpty(filter.Keyword))
|
|
{
|
|
var evaluationItem = GetEntities<T_PE_STANDARDIZED_SCORE_IMPORT>(t => t.PARENT_ID == Guid.Parse(filter.Keyword), new BaseFilter(orgId));
|
|
if (evaluationItem != null && evaluationItem.Any())
|
|
{
|
|
var methods = this.GetEntities<T_PE_EVALUATION_METHOD>(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<T_PE_SAFETY_EVALUATION_PLAN_METHOD> methodList = new List<T_PE_SAFETY_EVALUATION_PLAN_METHOD>();
|
|
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;
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 新增/编辑
|
|
/// </summary>
|
|
/// <param name="entity"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("FullUpdate")]
|
|
public JsonActionResult<bool> FullUpdate([FromBody] T_PE_SAFETY_EVALUATION_PLAN entity)
|
|
{
|
|
return SafeExecute(() =>
|
|
{
|
|
var details = entity.Nav_Details;
|
|
entity.STATUS = PFStandardStatus.Draft;
|
|
entity.DEPARTMENT_ID = APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID;
|
|
if (entity.START_TIME <= DateTime.Now)
|
|
throw new Exception("评价开始时间必须大于当前时间");
|
|
List<T_PE_SAFETY_EVALUATION_PLAN_USER> evaluationUser = new List<T_PE_SAFETY_EVALUATION_PLAN_USER>();
|
|
List<T_PE_SAFETY_EVALUATION_PLAN_METHOD> evaluationMethod = new List<T_PE_SAFETY_EVALUATION_PLAN_METHOD>();
|
|
if (details != null && details.Any())
|
|
{
|
|
details.Where(t => !t.IS_DELETED).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_PE_SAFETY_EVALUATION_PLAN_USER>(t => detailIds.Contains(t.EVALUATION_PLAN_DETAIL_ID), new BaseFilter(entity.ORG_ID)).Select(t => t.ID).ToList();
|
|
var deleteMethodIds = this.GetEntities<T_PE_SAFETY_EVALUATION_PLAN_METHOD>(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[] { ',' });
|
|
|
|
T_FM_NOTIFICATION_TASK taskEnd = null;
|
|
if (entity.TaskID != Guid.Empty)
|
|
{
|
|
taskEnd = NotificationTaskService.GetEntityTask(entity.TaskID, "PE027_SHOWPRINT");
|
|
if (!taskEnd.SOURCE_DATA_ID.HasValue)
|
|
{
|
|
taskEnd.SOURCE_DATA_ID = entity.ID;
|
|
}
|
|
}
|
|
|
|
MFlowPermitService.InsertApprove(serialCode[0], "PE027", "", entity.ID, "PE027_SHOWPRINT", null, true, () =>
|
|
{
|
|
if (entity != null)
|
|
this.UpdateEntityNoCommit(entity);
|
|
if (taskEnd != null)
|
|
this.UpdateEntityNoCommit(taskEnd);
|
|
if (details != null && details.Any())
|
|
this.BantchSaveEntityNoCommit(details);
|
|
if (deleteUserIds != null && deleteUserIds.Any())
|
|
this.BantchDeleteEntityNoCommit<T_PE_SAFETY_EVALUATION_PLAN_USER>(deleteUserIds);
|
|
if (deleteMethodIds != null && deleteMethodIds.Any())
|
|
this.BantchDeleteEntityNoCommit<T_PE_SAFETY_EVALUATION_PLAN_METHOD>(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<T_PE_SAFETY_EVALUATION_PLAN_USER>(deleteUserIds);
|
|
if (deleteMethodIds != null && deleteMethodIds.Any())
|
|
this.BantchDeleteEntityNoCommit<T_PE_SAFETY_EVALUATION_PLAN_METHOD>(deleteMethodIds);
|
|
if (evaluationUser != null && evaluationUser.Any())
|
|
this.BantchSaveEntityNoCommit(evaluationUser);
|
|
if (evaluationMethod != null && evaluationMethod.Any())
|
|
this.BantchSaveEntityNoCommit(evaluationMethod);
|
|
});
|
|
return true;
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 获取
|
|
/// </summary>
|
|
/// <param name="filter"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("GetEdit")]
|
|
public JsonActionResult<T_PE_SAFETY_EVALUATION_PLAN> 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<T_PE_SAFETY_EVALUATION_PLAN>(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;
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 回调函数
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet, Route("BackUpdate")]
|
|
public JsonActionResult<bool> BackUpdate(string id)
|
|
{
|
|
return SafeExecute(() =>
|
|
{
|
|
return ApproveCallBackService.CallBack("PE/PESafetyEvaluationPlan/BackUpdate", id);
|
|
});
|
|
}
|
|
}
|
|
}
|