mh_jy_safe/APT.MicroApi/APT.SC.WebApi/Controllers/Api/PRController/ChangeIdentifyEvaluationControllercs.cs

211 lines
11 KiB
C#
Raw Permalink Normal View History

2025-08-25 09:56:57 +08:00
using APT.BaseData.Domain.Entities;
using APT.BaseData.Domain.Entities.FM;
using APT.BaseData.Domain.Enums.PF;
using APT.BaseData.Domain.IServices;
using APT.BaseData.Domain.IServices.FM;
using APT.BaseData.Services.Services.FM;
using APT.Infrastructure.Core;
using APT.MS.Domain.Entities.HM;
using APT.MS.Domain.Entities.SC;
using APT.MS.Domain.Entities.SC.PR;
using APT.MS.Domain.Entities.SC.SC;
using APT.MS.Domain.Enums;
using APT.Utility;
using InfluxData.Net.InfluxDb.Models.Responses;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
namespace APT.SC.WebApi.Controllers.Api.PRController
{
/// <summary>
/// 变化识别评估表
/// </summary>
[Route("api/PR/PRChangeIdentifyEvaluation")]
public partial class ChangeIdentifyEvaluationController : AuthorizeApiController<T_PR_CHANGE_IDENTIFY_EVALUATION>
{
IPFCodeRuleService CodeRuleService { get; set; }
IFMNotificationTaskService NotificationTaskService { get; set; }
IFMFlowPermitService MFlowPermitService { get; set; }
IPFApproveCallBackService ApproveCallBackService { get; set; }
IFMDepartmentService DepartmentService { get; set; }
/// <summary>
/// 变化识别评估表
/// </summary>
/// <param name="notificationTaskService"></param>
public ChangeIdentifyEvaluationController(IPFCodeRuleService codeRuleService, IFMNotificationTaskService notificationTaskService, IFMFlowPermitService mFlowPermitService, IPFApproveCallBackService approveCallBackService, IFMDepartmentService departmentService)
{
CodeRuleService = codeRuleService;
NotificationTaskService = notificationTaskService;
MFlowPermitService = mFlowPermitService;
ApproveCallBackService = approveCallBackService;
DepartmentService = departmentService;
}
/// <summary>
/// 新增/编辑
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
[HttpPost, Route("FullUpdate")]
public JsonActionResult<bool> FullUpdate([FromBody] T_PR_CHANGE_IDENTIFY_EVALUATION entity)
{
return SafeExecute(() =>
{
if (entity.STATUS == PFStandardStatus.Sign && entity.Nav_Tasks.Count() == 0)
{
throw new Exception("执行任务和落实人员必须填写");
}
entity.STATUS = PFStandardStatus.Draft;
entity.TIME = DateTime.Now;
var loginUserId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
if (entity.TaskID != Guid.Empty)
{
var currTask = GetEntity<T_FM_NOTIFICATION_TASK>(t => t.ID == entity.TaskID);
if (currTask != null)
{
loginUserId = currTask.USER_ID;
}
}
if (entity.USER_ID == null)
entity.USER_ID = loginUserId;
var user = this.GetEntity<T_FM_USER>(t => t.ID == entity.USER_ID && t.ENABLE_STATUS == 0, "Nav_Department");
entity.DEPARTMENT_ID = user?.DEPARTMENT_ID;
var types = entity.Nav_Types == null?null: entity.Nav_Types.Where(t => !t.IS_DELETED).ToList();
var tasks = entity.Nav_Tasks == null?null: entity.Nav_Tasks.Where(t => !t.IS_DELETED).ToList();
T_HM_RISK_TASK risk = null;
T_SC_MT_MEETING_BEGIN modelBegin = null;
T_FM_NOTIFICATION_TASK task = null;
List<T_FM_NOTIFICATION_TASK> notices = new List<T_FM_NOTIFICATION_TASK>();
List<T_PR_CHANGE_TASK_IMPLEMENT> implements = new List<T_PR_CHANGE_TASK_IMPLEMENT>();
if (types != null && types.Any())
{
types.ForEach(t =>
{
t.ORG_ID = entity.ORG_ID; t.CHANGE_IDENTIFY_EVALUATION_ID = entity.ID;
t.Nav_Type = null;
});
}
if (tasks != null && tasks.Any())
{
tasks.ForEach(t =>
{
t.ORG_ID = entity.ORG_ID; t.CHANGE_IDENTIFY_EVALUATION_ID = entity.ID;
t.Nav_Task = null;t.Nav_User = null;
});
}
if (entity.PUBLISH != null && entity.PUBLISH.Equals("SaveAndNotify"))
{
entity.STATUS = PFStandardStatus.Sign;
if (tasks != null && tasks.Any())
{
entity.STATUS = PFStandardStatus.Archived;
var userIds = tasks.Select(t => t.USER_ID).Distinct().ToList();
var users = this.GetEntities<T_FM_USER>(t => userIds.Contains(t.ID) && t.ENABLE_STATUS == 0, new BaseFilter(entity.ORG_ID), "Nav_Department");
var taskTemp = tasks.GroupBy(t => new { t.USER_ID, t.TASK_ID }).ToList();
foreach (var temp in taskTemp)
{
var userInfo = users.FirstOrDefault(t => t.ID == temp.Key.USER_ID);
T_PR_CHANGE_TASK_IMPLEMENT implement = new T_PR_CHANGE_TASK_IMPLEMENT();
implement.ORG_ID = userInfo.ORG_ID;
implement.TIME = DateTime.Now;
implement.USER_ID = temp.Key.USER_ID;
implement.TASK_ID = temp.Key.TASK_ID;
implement.DEPARTMENT_ID = userInfo?.Nav_Department.ID;
implement.STATUS = PFStandardStatus.Draft;
implement.CHANGE_IDENTIFY_EVALUATION_ID = entity.ID;
implements.Add(implement);
notices.Add(NotificationTaskService.InsertUserNoticeTaskModel("变化管理任务落实表", implement.ID, entity.ORG_ID, userInfo.ID, userInfo.NAME, DateTime.Now,
DateTime.Now.AddDays(7), (int)FMNoticeTypeEnum., "PR026"));
}
}
else
{
//notices.Add(NotificationTaskService.InsertUserNoticeTaskModel("变化识别评估表(变化带来的风险)", entity.ID, entity.ORG_ID, loginUserId.Value, user.NAME, DateTime.Now,
// DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum.消息, "PR023"));
risk = new T_HM_RISK_TASK();
risk.ORG_ID = entity.ORG_ID;
risk.STATUS = FOPreMeetingStatusEnum.稿;
risk.INITIATING_DEPARTMENT = entity.DEPARTMENT_ID;
risk.LIABLE_USER_ID = entity.USER_ID;
risk.START_TIME = DateTime.Now;
risk.END_TIME = DateTime.Now;
risk.CHANGE_IDENTIFY_EVALUATION_ID = entity.ID;
var requst = this.GetEntity<T_HM_REQUEST>(t => true);
risk.REQUEST_ID = requst?.ID;
notices.Add(NotificationTaskService.InsertUserNoticeTaskModel("风险辨识任务(变化识别评估表)", risk.ID, entity.ORG_ID, loginUserId.Value, user.NAME, DateTime.Now,
DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum., "HM062"));
modelBegin = new T_SC_MT_MEETING_BEGIN();
modelBegin.ID = Guid.NewGuid();
modelBegin.ORG_ID = entity.ORG_ID;
modelBegin.SOURCETYPE = SOURCETYPE.PR023ToMeet;
modelBegin.TABLENAME = "T_PR_CHANGE_IDENTIFY_EVALUATION";
modelBegin.DATA_ID = entity.ID;
modelBegin.ISBEGIN = false;
modelBegin.USER_ID = (Guid)loginUserId;
modelBegin.CREATE_TIME = DateTime.Now;
modelBegin.CREATER_ID = loginUserId;
//notices.Add(NotificationTaskService.InsertUserNoticeTaskModel("安全生产方针讨论会议(变化识别评估表)", modelBegin.ID, entity.ORG_ID, loginUserId.Value, user.NAME, DateTime.Now,
// DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum.消息, "SC032"));
var dep = DepartmentService.GetDEPARTMENTLevel(entity.DEPARTMENT_ID.Value);
if (dep != null)
{
var department = this.GetEntity<T_FM_DEPARTMENT>(t => t.ID == dep.ID && t.USER_ID.HasValue, "Nav_User");
if (department != null)
{
notices.Add(NotificationTaskService.InsertUserNoticeTaskModel("变化识别评估表(变化执行后任务)", entity.ID, entity.ORG_ID, department.USER_ID.Value, department.Nav_User.NAME, DateTime.Now,
DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum., "PR024"));
}
else
throw new Exception("请先到组织架构配置部门级负责人");
}
}
if (entity.TaskID != Guid.Empty)
{
task = NotificationTaskService.GetEntityTask(entity.TaskID, "PR023_SHOWPRINT");
if (!task.SOURCE_DATA_ID.HasValue)
task.SOURCE_DATA_ID = entity.ID;
}
}
entity.Nav_Types = null;
entity.Nav_Tasks = null;
entity.Nav_Department = null;
entity.Nav_User = null;
UnifiedCommit(() =>
{
if (entity != null)
this.UpdateEntityNoCommit(entity);
if (types != null && types.Any())
this.BantchSaveEntityNoCommit(types);
if (risk != null)
this.UpdateEntityNoCommit(risk);
if (modelBegin != null)
this.UpdateEntityNoCommit(modelBegin);
if (notices != null && notices.Any())
this.BantchSaveEntityNoCommit(notices);
if (task != null)
this.UpdateEntityNoCommit(task);
if (tasks != null && tasks.Any())
this.BantchSaveEntityNoCommit(tasks);
if (implements != null && implements.Any())
this.BantchSaveEntityNoCommit(implements);
});
return true;
});
}
/// <summary>
/// 自动生成CODE
/// </summary>
/// <param name="filter"></param>
[HttpPost, Route("GetFileCode")]
public JsonActionResult<string> GetFileCode([FromBody] KeywordFilter filter)
{
return SafeExecute<string>(() =>
{
var fileCode = DateTime.Now.Year.ToString().PadLeft(4, '0') + DateTime.Now.Month.ToString().PadLeft(2, '0') + DateTime.Now.Day.ToString().PadLeft(2, '0') + new Random().Next().ToString();
return fileCode;
});
}
}
}