mh_jy_safe/APT.MicroApi/APT.SK.WebApi/Controllers/Api/MajorAccidentHazardManageController.cs
2026-04-08 10:39:01 +08:00

297 lines
16 KiB
C#

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;
using APT.BaseData.Domain.IServices.FM;
using APT.BaseData.Services.DomainServices;
using APT.Infrastructure.Core;
using APT.MS.Domain.Entities.FO;
using APT.MS.Domain.Entities.SK;
using APT.MS.Domain.Enums;
using APT.MS.Domain.Enums.SK;
using APT.Utility;
using InfluxData.Net.InfluxDb.Models.Responses;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
namespace APT.SK.WebApi.Controllers.Api
{
/// <summary>
/// 重大事故隐患治理销号表
/// </summary>
[Route("api/SK/SKMajorAccidentHazardManage")]
public partial class MajorAccidentHazardManageController : AuthorizeApiController<T_SK_MAJOR_ACCIDENT_HAZARD_MANAGE>
{
IPFApproveCallBackService ApproveCallBackService { get; set; }
IFMNotificationTaskService NotificationTaskService { get; set; }
IPFCodeRuleService CodeRuleService { get; set; }
IFMFlowPermitService MFlowPermitService { get; set; }
public MajorAccidentHazardManageController(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_MAJOR_ACCIDENT_HAZARD_MANAGE 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.REVIEW_RESULT == null)
{
throw new Exception("复查结论必须填写!");
}
T_FM_NOTIFICATION_TASK finishNotice = null;
//if (entity.STATUS != PFStandardStatus.Draft && entity.STATUS != PFStandardStatus.Rejected)
//{
// var taskId = entity.TaskID;
// if (taskId == Guid.Empty)
// {
// var taskTemp = GetEntity<T_FM_NOTIFICATION_TASK>(i => i.SOURCE_DATA_ID == entity.ID && i.USER_ID == userId
//&& i.NOTICE_STATUS == FMNoticeStatusEnum.未处理.GetInt() && i.SOURCE_FORMCODE == "SK091");
// if (taskTemp != null)
// {
// taskTemp.NOTICE_STATUS = 1;
// taskTemp.SOURCE_FORMCODE = "SK091_SHOWPRINT";
// finishNotice = taskTemp;
// }
// }
// if (taskId != Guid.Empty)
// {
// finishNotice = NotificationTaskService.FOGetTaskFinishModel(taskId, entity.ID, "SK091_SHOWPRINT");
// }
// UpdateEntity(finishNotice);
// throw new Exception("你已提交,请勿重复提交!");
//}
if (string.IsNullOrEmpty(entity.CODE))
entity.CODE = "YHXH" + DateTime.Now.ToShortDateString().Replace("/", "") + new Random().Next(1, 999);
var users = entity.Nav_Users;
entity.Nav_Users = null;
var files = entity.Nav_Files;
entity.Nav_Files = null;
var userIds = this.GetEntities<T_SK_MAJOR_ACCIDENT_HAZARD_MANAGE_USER>(t => t.MAJOR_ACCIDENT_HAZARD_MANAGE_ID == entity.ID, new BaseFilter(entity.ORG_ID)).Select(m => m.ID).ToList();
var userList = new List<T_SK_MAJOR_ACCIDENT_HAZARD_MANAGE_USER>();
var fileIds = this.GetEntities<T_SK_MAJOR_ACCIDENT_HAZARD_MANAGE_FILE>(t => t.MAJOR_ACCIDENT_HAZARD_MANAGE_ID == entity.ID, new BaseFilter(entity.ORG_ID)).Select(m => m.ID).ToList();
var fileList = new List<T_SK_MAJOR_ACCIDENT_HAZARD_MANAGE_FILE>();
if (users != null && users.Any())
{
foreach (var user in users.Where(t=>!t.IS_DELETED))
{
T_SK_MAJOR_ACCIDENT_HAZARD_MANAGE_USER item = new T_SK_MAJOR_ACCIDENT_HAZARD_MANAGE_USER();
item.ORG_ID = entity.ORG_ID;
item.MAJOR_ACCIDENT_HAZARD_MANAGE_ID = entity.ID;
item.USER_ID = user.USER_ID;
userList.Add(item);
}
}
if (files != null && files.Any())
{
foreach (var file in files.Where(t => !t.IS_DELETED))
{
T_SK_MAJOR_ACCIDENT_HAZARD_MANAGE_FILE item = new T_SK_MAJOR_ACCIDENT_HAZARD_MANAGE_FILE();
item.ORG_ID = entity.ORG_ID;
item.MAJOR_ACCIDENT_HAZARD_MANAGE_ID = entity.ID;
item.IMG_FILE_ID = file.IMG_FILE_ID;
fileList.Add(item);
}
}
List<T_FM_NOTIFICATION_TASK> notices = new List<T_FM_NOTIFICATION_TASK>();
T_FM_NOTIFICATION_TASK task = null;
T_SK_HIDDEN_DANGER_RECTIFY_RECORD record = null;
var recordFileIds = new List<Guid>();
if (entity.PUBLISH != null && entity.PUBLISH.Equals("SaveAndNotify"))
{
//同意销号触发审批
if (entity.REVIEW_RESULT == SKReviewResultEnum.OK)
{
//触发审批
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], "SK080", "", entity.ID, "SK080_SHOWPRINT", entity.TaskID, true, () =>
{
if (userIds != null && userIds.Any())
this.BantchDeleteEntityNoCommit<T_SK_MAJOR_ACCIDENT_HAZARD_MANAGE_USER>(userIds);
if (fileIds != null && fileIds.Any())
this.BantchDeleteEntityNoCommit<T_SK_MAJOR_ACCIDENT_HAZARD_MANAGE_FILE>(fileIds);
if (entity != null)
UpdateEntityNoCommit(entity);
if (userList != null && userList.Any())
BantchSaveEntityNoCommit(userList);
if (fileList != null && fileList.Any())
BantchSaveEntityNoCommit(fileList);
}, null, null, null, null, null, "SK080_SHOWPRINT", null);
return true;
}
else
{
//置为驳回
entity.STATUS = PFStandardStatus.Rejected;
//隐患整改记录从“归档”状况转为“驳回”(原来的内容带过去,驳回意见显示:不同意销号,请重新整改!),(整改后重新走责任人确认、验收人验收和审批流,归档后再触发销号表)
record = this.GetEntity<T_SK_HIDDEN_DANGER_RECTIFY_RECORD>(t => t.ID == entity.HIDDEN_DANGER_RECTIFY_RECORD_ID);
if (record != null)
{
record.STATUS = PFStandardStatus.Rejected;
record.ACCEPT_DATE = null;
record.ACCEPT_OPINION = null;
record.ACCEPT_USER_ID = null;
record.RECTIFICATION_DESCRIPTION = null;
record.RECTIFICATION_MONEY = null;
record.COMPLETE_DATE = null;
recordFileIds = this.GetEntities<T_SK_HIDDEN_DANGER_RECTIFY_RECORD_PHOTOB>(t => t.HIDDEN_DANGER_RECTIFY_RECORD_ID == record.ID, new BaseFilter(entity.ORG_ID)).Select(m => m.ID).ToList();
if (record.IMPLEMENT_USER_ID != null)
{
var user = this.GetEntity<T_FM_USER>(t => t.ID == record.IMPLEMENT_USER_ID);
if (user!=null)
{
//同时触发给整改落实人重新整改
var sendNotice = NotificationTaskService.InsertUserNoticeTaskModel("隐患整改记录表" + record.CODE+"不同意销号,点击重新整改", record.ID, record.ORG_ID, user.ID, user.NAME, DateTime.Now,
DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum., "SK022");
notices.Add(sendNotice);
}
}
if (record.RECITIFY_USER_ID != null)
{
var user = this.GetEntity<T_FM_USER>(t => t.ID == record.RECITIFY_USER_ID);
if (user != null)
{
//并发送今日提醒给整改责任人“隐患整改记录表单编号为***,经重大事故隐患治理复查不同意销号,请监督重新整改!”
var sendNotice = NotificationTaskService.InsertUserNoticeTaskModel("隐患整改记录表单编号为"+ record.CODE +",经重大事故隐患治理复查不同意销号,请监督重新整改!", record.ID, record.ORG_ID, user.ID, user.NAME, DateTime.Now,
DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum., "PF135");
notices.Add(sendNotice);
}
}
}
}
if (entity.TaskID != Guid.Empty)
{
task = NotificationTaskService.GetTaskFinishModel(entity.TaskID);
task.SOURCE_FORMCODE = "SK080_SHOWPRINT";
}
}
this.UnifiedCommit(() =>
{
if (userIds != null && userIds.Any())
this.BantchDeleteEntityNoCommit<T_SK_MAJOR_ACCIDENT_HAZARD_MANAGE_USER>(userIds);
if (fileIds != null && fileIds.Any())
this.BantchDeleteEntityNoCommit<T_SK_MAJOR_ACCIDENT_HAZARD_MANAGE_FILE>(fileIds);
if (task != null)
UpdateEntityNoCommit(task);
if (entity != null)
UpdateEntityNoCommit(entity);
if (userList != null && userList.Any())
BantchSaveEntityNoCommit(userList);
if (fileList != null && fileList.Any())
BantchSaveEntityNoCommit(fileList);
if (notices != null && notices.Any())
BantchSaveEntityNoCommit(notices);
if (record != null)
UpdateEntityNoCommit(record);
if (recordFileIds != null && recordFileIds.Any())
this.BantchDeleteEntityNoCommit<T_SK_HIDDEN_DANGER_RECTIFY_RECORD_PHOTOB>(recordFileIds);
});
return true;
});
}
/// <summary>
/// 获得单条实体数据
/// </summary>
/// <param name="filter">过滤实体</param>
/// <returns></returns>
[HttpPost, Route("SKGet")]
public JsonActionResult<T_SK_MAJOR_ACCIDENT_HAZARD_MANAGE> 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;
var result = this.GetEntity<T_SK_MAJOR_ACCIDENT_HAZARD_MANAGE>(id, new string[] { "Nav_ApplyUser", "Nav_ChargeUser", "Nav_ApplyDepartment", "Nav_RectifyRecord.Nav_ProductionUnit",
"Nav_RectifyRecord.Nav_RiskArea", "Nav_RectifyRecord.Nav_RectifyPhotoas.Nav_ImgFile","Nav_RectifyRecord.Nav_RectifyPhotobs.Nav_ImgFile",
"Nav_Users.Nav_User","Nav_MonitorDepart", "Nav_Files.Nav_ImgFile"});
if (result != null && 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/SKMajorAccidentHazardManage/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_MAJOR_ACCIDENT_HAZARD_MANAGE>(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., "SK080");
}
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;
});
}
}
}