299 lines
15 KiB
C#
299 lines
15 KiB
C#
using APT.BaseData.Domain.IServices.FM;
|
|
using APT.BaseData.Domain.IServices;
|
|
using APT.MS.Domain.Entities.SK;
|
|
using APT.Utility;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using APT.Infrastructure.Core;
|
|
using APT.BaseData.Domain.Entities.FM;
|
|
using APT.BaseData.Domain.Entities;
|
|
using APT.BaseData.Domain.Enums.PF;
|
|
using APT.BaseData.Domain.Enums;
|
|
using APT.MS.Domain.Enums;
|
|
using APT.MS.Domain.Entities.FO;
|
|
using NPOI.SS.Formula.Functions;
|
|
using APT.MS.Domain.Enums.SK;
|
|
using System.Collections.Generic;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace APT.SK.WebApi.Controllers.Api
|
|
{
|
|
/// <summary>
|
|
/// 安全风险辨识表
|
|
/// </summary>
|
|
[Route("api/SK/SKRiskIdentify")]
|
|
public partial class RiskIdentifyController : AuthorizeApiController<T_SK_RISK_IDENTIFY>
|
|
{
|
|
IPFApproveCallBackService ApproveCallBackService { get; set; }
|
|
IFMNotificationTaskService NotificationTaskService { get; set; }
|
|
IPFCodeRuleService CodeRuleService { get; set; }
|
|
IFMFlowPermitService MFlowPermitService { get; set; }
|
|
public RiskIdentifyController(IFMNotificationTaskService notificationTaskService, IFMFlowPermitService mFlowPermitService, IPFCodeRuleService codeRuleService, IPFApproveCallBackService approveCallBackService)
|
|
{
|
|
NotificationTaskService = notificationTaskService;
|
|
MFlowPermitService = mFlowPermitService;
|
|
CodeRuleService = codeRuleService;
|
|
ApproveCallBackService = approveCallBackService;
|
|
}
|
|
[HttpPost, Route("FullUpdate")]
|
|
public JsonActionResult<bool> FullUpdate([FromBody] T_SK_RISK_IDENTIFY entity)
|
|
{
|
|
return SafeExecute<bool>(() =>
|
|
{
|
|
var userId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
|
|
var departId = APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID;
|
|
if (entity.APPLY_USER_ID == null)
|
|
entity.APPLY_USER_ID = userId;
|
|
if (entity.APPLY_DEPARTMENT_ID == null)
|
|
entity.APPLY_DEPARTMENT_ID = departId;
|
|
if (entity.IDENTIFY_EVALUATION_PLAN_ID == null)
|
|
entity.APPLY_DEPARTMENT_ID = this.GetEntity<T_SK_IDENTIFY_EVALUATION_PLAN>(t => t.START_DATE.Value.Date == entity.START_DATE.Value.Date && t.STATUS == PFStandardStatus.Archived && t.ISSEND == true)?.ID;
|
|
var details = entity.Nav_Details;
|
|
entity.Nav_Details = null;
|
|
var requires = entity.Nav_Requires;
|
|
entity.Nav_Requires = null;
|
|
var files = entity.Nav_Files;
|
|
entity.Nav_Files = null;
|
|
entity.ApplyDepartmentName = this.GetEntity<T_FM_DEPARTMENT>(t => t.ID == departId).NAME;
|
|
entity.ApplyPostName = this.GetEntity<T_FM_USER>(t => t.ID == userId, "Nav_Person.Nav_Post")?.Nav_Person?.Nav_Post?.NAME;
|
|
List<Guid> deleteMeasureIds = new List<Guid>();
|
|
List<Guid> deleteDetailIds = new List<Guid>();
|
|
List<T_SK_RISK_IDENTIFY_DETAIL_MEASURE> measureList = new List<T_SK_RISK_IDENTIFY_DETAIL_MEASURE>();
|
|
//更新标识字段
|
|
var record = this.GetEntity<T_SK_RISK_IDENTIFY>(t => t.ID == entity.ID, "Nav_Details");
|
|
if (record != null && record.Nav_Details != null && record.Nav_Details.Any() && details != null && details.Any())
|
|
{
|
|
deleteDetailIds = record.Nav_Details.Select(t => t.ID).ToList();
|
|
deleteMeasureIds = this.GetEntities<T_SK_RISK_IDENTIFY_DETAIL_MEASURE>(t => deleteDetailIds.Contains(t.RISK_IDENTIFY_DETAIL_ID), new BaseFilter(entity.ORG_ID)).Select(t => t.ID).ToList();
|
|
//record.Nav_Details.ForEach(t =>
|
|
//{
|
|
// if (t.Nav_DetailMeasures != null && t.Nav_DetailMeasures.Any())
|
|
// {
|
|
// var tempIds = t.Nav_DetailMeasures.Select(m => m.ID).ToList();
|
|
// deleteMeasureIds.AddRange(tempIds);
|
|
// }
|
|
// deleteDetailIds.Add(t.ID);
|
|
//});
|
|
foreach (var item in details)
|
|
{
|
|
var temp = record.Nav_Details.FirstOrDefault(t => t.PRODUCTION_UNIT_ID == item.PRODUCTION_UNIT_ID && t.AREA_ID == item.AREA_ID && t.TYPE_ID == item.TYPE_ID && t.RISK_NAME == item.RISK_NAME && t.RISK_DESCRIPTION == item.RISK_DESCRIPTION && t.MEASURE == item.MEASURE
|
|
&& t.EMERGENCY == item.EMERGENCY);
|
|
if (temp == null && item.MARK != SKMarkEnum.Add)
|
|
{
|
|
item.MARK = SKMarkEnum.Update;
|
|
}
|
|
}
|
|
}
|
|
if (details != null && details.Any())
|
|
{
|
|
foreach (var item in details)
|
|
{
|
|
item.ORG_ID = entity.ORG_ID;
|
|
item.RISK_IDENTIFY_ID = entity.ID;
|
|
if (item.Nav_DetailMeasures != null && item.Nav_DetailMeasures.Any())
|
|
{
|
|
foreach (var item2 in item.Nav_DetailMeasures)
|
|
{
|
|
item2.ORG_ID = entity.ORG_ID;
|
|
item2.RISK_IDENTIFY_DETAIL_ID = item.ID;
|
|
measureList.Add(item2);
|
|
}
|
|
}
|
|
item.Nav_DetailMeasures = null;
|
|
}
|
|
}
|
|
if (files != null && files.Any())
|
|
{
|
|
foreach (var item in files)
|
|
{
|
|
item.ORG_ID = entity.ORG_ID;
|
|
item.RISK_IDENTIFY_ID = entity.ID;
|
|
item.Nav_ImgFile = null;
|
|
}
|
|
}
|
|
if (requires != null && requires.Any())
|
|
{
|
|
foreach (var item in requires)
|
|
{
|
|
item.ORG_ID = entity.ORG_ID;
|
|
item.RISK_IDENTIFY_ID = entity.ID;
|
|
item.Nav_Require = null;
|
|
}
|
|
}
|
|
List<T_FM_NOTIFICATION_TASK> notices = new List<T_FM_NOTIFICATION_TASK>();
|
|
if (entity.PUBLISH != null && entity.PUBLISH.Equals("SaveAndNotify"))
|
|
{
|
|
var department = this.GetEntity<T_FM_DEPARTMENT>(t => t.ID == entity.APPLY_DEPARTMENT_ID && t.ENABLE_STATUS == 0);
|
|
var param = Enum.GetName(typeof(SKDepartmentTypeEnum), department?.DEPARTMENT_TYPE);
|
|
if (department.PARENT_ID != null && param == "公司级")
|
|
{
|
|
param = "部门级";
|
|
}
|
|
entity.STATUS = 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[] { ',' });
|
|
MFlowPermitService.InsertApprove(serialCode[0], "SK033", param, entity.ID, "SK033_SHOWPRINT", entity.TaskID, true, () =>
|
|
{
|
|
if (deleteMeasureIds != null && deleteMeasureIds.Any())
|
|
this.BantchDeleteEntityNoCommit<T_SK_RISK_IDENTIFY_DETAIL_MEASURE>(deleteMeasureIds);
|
|
if (deleteDetailIds != null && deleteDetailIds.Any())
|
|
this.BantchDeleteEntityNoCommit<T_SK_RISK_IDENTIFY_DETAIL>(deleteDetailIds);
|
|
if (entity != null)
|
|
UpdateEntityNoCommit(entity);
|
|
if (details != null && details.Any())
|
|
BantchSaveEntityNoCommit(details);
|
|
if (files != null && files.Any())
|
|
BantchSaveEntityNoCommit(files);
|
|
if (requires != null && requires.Any())
|
|
BantchSaveEntityNoCommit(requires);
|
|
if (measureList != null && measureList.Any())
|
|
BantchSaveEntityNoCommit(measureList);
|
|
}, null, null, null, null, null, "SK033_SHOWPRINT", null, "安全风险辨识表审批");
|
|
return true;
|
|
}
|
|
this.UnifiedCommit(() =>
|
|
{
|
|
if (deleteMeasureIds != null && deleteMeasureIds.Any())
|
|
this.BantchDeleteEntityNoCommit<T_SK_RISK_IDENTIFY_DETAIL_MEASURE>(deleteMeasureIds);
|
|
if (deleteDetailIds != null && deleteDetailIds.Any())
|
|
this.BantchDeleteEntityNoCommit<T_SK_RISK_IDENTIFY_DETAIL>(deleteDetailIds);
|
|
if (entity != null)
|
|
UpdateEntityNoCommit(entity);
|
|
if (details != null && details.Any())
|
|
BantchSaveEntityNoCommit(details);
|
|
if (files != null && files.Any())
|
|
BantchSaveEntityNoCommit(files);
|
|
if (requires != null && requires.Any())
|
|
BantchSaveEntityNoCommit(requires);
|
|
if (measureList != null && measureList.Any())
|
|
BantchSaveEntityNoCommit(measureList);
|
|
});
|
|
return true;
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 排序分页查询数据
|
|
/// </summary>
|
|
/// <param name="pageFilter">分页过滤实体</param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("SKOrderPaged")]
|
|
public PagedActionResult<T_SK_RISK_IDENTIFY> SKOrderPaged([FromBody] KeywordPageFilter pageFilter)
|
|
{
|
|
var result = WitOrderPaged(null, pageFilter);
|
|
List<T_SK_RISK_IDENTIFY> newData = new List<T_SK_RISK_IDENTIFY>();
|
|
if (result != null && result.Data != null && result.Data.Any())
|
|
{
|
|
var company = result.Data.FirstOrDefault(t => t.Nav_ApplyDepartment != null && t.Nav_ApplyDepartment.DEPARTMENT_TYPE == 3);
|
|
if (company != null)
|
|
{
|
|
newData.Add(company);
|
|
}
|
|
var other = result.Data.Where(t => t.Nav_ApplyDepartment != null && t.Nav_ApplyDepartment.DEPARTMENT_TYPE != 3).OrderBy(n => n.Nav_ApplyDepartment.DEPARTMENT_TYPE).ThenBy(m => m.APPLY_DEPARTMENT_ID).ToList();
|
|
if (other.Any())
|
|
{
|
|
newData.AddRange(other);
|
|
}
|
|
result.Data = newData;
|
|
}
|
|
return result;
|
|
}
|
|
/// <summary>
|
|
/// 获得单条实体数据
|
|
/// </summary>
|
|
/// <param name="filter">过滤实体</param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("SKGet")]
|
|
public JsonActionResult<T_SK_RISK_IDENTIFY> SKGet([FromBody] KeywordFilter filter)
|
|
{
|
|
return SafeExecute(() =>
|
|
{
|
|
var id = filter.FilterGroup.Rules.FirstOrDefault(t => t.Field == "ID").Value.ToString();
|
|
if (string.IsNullOrEmpty(id))
|
|
this.ThrowError("060010");
|
|
filter.IgnoreDataRule = true;
|
|
|
|
KeywordFilter filter2 = new KeywordFilter();
|
|
filter2.IgnoreDataRule = true;
|
|
filter2.IgnoreOrgRule = true;
|
|
filter2.OrgId = null;
|
|
var result = this.GetEntity<T_SK_RISK_IDENTIFY>(e => e.ID == new Guid(id), filter2, new string[] { "Nav_ApplyUser", "Nav_ApplyDepartment","Nav_Require",
|
|
"Nav_Files.Nav_ImgFile","Nav_Requires.Nav_Require"});
|
|
if (result != null)
|
|
{
|
|
var details = this.GetEntities<T_SK_RISK_IDENTIFY_DETAIL>(t => t.RISK_IDENTIFY_ID == result.ID, filter2, "Nav_Area", "Nav_Type", "Nav_RiskName", "Nav_ProductionUnit");
|
|
result.Nav_Details = details.OrderBy(m => m.MineType).ThenBy(t => t.AREA_ID).ThenBy(x => x.TYPE_ID).ToList();
|
|
if (result.STATUS == PFStandardStatus.Rejected)
|
|
{
|
|
result.CONTEXT = ApproveCallBackService.RejectContent(result.ID);
|
|
}
|
|
}
|
|
return result;
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 回调函数
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("BackUpdateNew")]
|
|
public JsonActionResult<bool> BackUpdateNew([FromBody] T_PF_APPROVE entity)
|
|
{
|
|
return SafeExecute(() =>
|
|
{
|
|
return ApproveCallBackService.CallBackNew("SK/SKRiskIdentify/BackUpdateNew", entity);
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 驳回
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("RejectUpdate")]
|
|
public JsonActionResult<bool> RejectUpdate([FromBody] T_PF_APPROVE model)
|
|
{
|
|
return SafeExecute(() =>
|
|
{
|
|
//公共 获取审批流信息
|
|
T_PF_APPROVE modelApp = null;
|
|
List<T_PF_APPROVE_DETAIL> listAppDetail = null;
|
|
T_FM_NOTIFICATION_TASK taskFinish = null;
|
|
string Msg = string.Empty;
|
|
bool ResultGetInfo = ApproveCallBackService.GetApproject(model, ref modelApp, ref listAppDetail, ref taskFinish, ref Msg);
|
|
if (!ResultGetInfo)
|
|
throw new Exception("驳回失败!");
|
|
if (modelApp == null || listAppDetail == null)
|
|
throw new Exception("获取驳回信息失败!");
|
|
var entity = this.GetEntity<T_SK_RISK_IDENTIFY>(model.DATA_ID, new string[] { "Nav_ApplyUser" });
|
|
entity.STATUS = PFStandardStatus.Rejected;
|
|
T_FM_NOTIFICATION_TASK notice = new T_FM_NOTIFICATION_TASK();
|
|
if (entity.APPLY_USER_ID != null)
|
|
{
|
|
//发消息
|
|
notice = NotificationTaskService.InsertUserNoticeTaskModel("安全风险辨识表被驳回", entity.ID, entity.ORG_ID, (Guid)entity.APPLY_USER_ID, entity.Nav_ApplyUser?.NAME, DateTime.Now,
|
|
DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum.消息, "SK033");
|
|
}
|
|
UnifiedCommit(() =>
|
|
{
|
|
if (entity != null)
|
|
this.UpdateEntityNoCommit(entity);
|
|
if (notice != null)
|
|
this.UpdateEntityNoCommit(notice);
|
|
if (modelApp != null)
|
|
UpdateEntityNoCommit(modelApp);
|
|
if (listAppDetail != null && listAppDetail.Count > 0)
|
|
BantchUpdateEntityNoCommit(listAppDetail);
|
|
if (taskFinish != null)
|
|
UpdateEntityNoCommit(taskFinish);
|
|
});
|
|
return true;
|
|
//return ApproveCallBackService.CallReject("HM/HMLicenseAnalysis/RejectUpdate", id);
|
|
});
|
|
}
|
|
}
|
|
}
|