mh_jy_safe/APT.MicroApi/APT.SC.WebApi/Controllers/Api/PCController/PCInfoController.cs
2025-08-25 09:56:57 +08:00

532 lines
27 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.FM;
using APT.BaseData.Domain.IServices;
using APT.Infrastructure.Core;
using APT.MS.Domain.Entities.SC.PE;
using APT.Utility;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using APT.MS.Domain.Enums;
using APT.MS.Domain.Entities.PC;
using APT.MS.Domain.Entities.HM;
using APT.MS.Domain.Enums.SK;
using APT.MS.Domain.Entities.SK;
using APT.MS.Domain.Entities.FO;
namespace APT.SC.WebApi.Controllers.Api.PCController
{
/// <summary>
/// 纠正与预防措施通知单
/// </summary>
[Route("api/PC/PCInfo")]
public partial class PCInfoController : AuthorizeApiController<T_PC_INFO>
{
IPFCodeRuleService CodeRuleService { get; set; }
IFMNotificationTaskService NotificationTaskService { get; set; }
IFMFlowPermitService MFlowPermitService { get; set; }
IPFApproveCallBackService ApproveCallBackService { get; set; }
/// <summary>
///
/// </summary>
/// <param name="notificationTaskService"></param>
public PCInfoController(IPFCodeRuleService codeRuleService, IFMNotificationTaskService notificationTaskService, IFMFlowPermitService mFlowPermitService, IPFApproveCallBackService approveCallBackService)
{
CodeRuleService = codeRuleService;
NotificationTaskService = notificationTaskService;
MFlowPermitService = mFlowPermitService;
ApproveCallBackService = approveCallBackService;
}
/// <summary>
/// 新增/编辑
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
[HttpPost, Route("FullUpdate")]
public JsonActionResult<bool> FullUpdate([FromBody] T_PC_INFO entity)
{
return SafeExecute(() =>
{
if (entity.Nav_Files == null || !entity.Nav_Files.Any() || entity.Nav_Files.Count() < 1)
{
throw new Exception("请选择背景图");
}
else if (entity.Nav_Files.Count() > 1)
{
var FilesCheck = entity.Nav_Files.Where(e => !e.IS_DELETED);
if (FilesCheck != null && FilesCheck.Any() && FilesCheck.Count() > 1)
{
throw new Exception("背景图只能设置一张");
}
}
var Files = entity.Nav_Files.ToList();
if (string.IsNullOrEmpty(entity.FILE_PATH))
{
entity.FILE_PATH = Files[0].Nav_ImgFile?.FILE_PATH;
}
if (string.IsNullOrEmpty(entity.FILE_PATH))
{
var img = GetEntity<T_PF_IMG_FILE>(Files[0].IMG_FILE_ID, "Nav_File");
entity.FILE_PATH = img.Nav_File.FILE_PATH;
}
entity.Nav_Files = null;
var Colors = entity.Nav_Colors;
entity.Nav_Colors = null;
List<T_PC_INFO_COLOR_POINT> listPoint = new List<T_PC_INFO_COLOR_POINT>();
List<T_PC_INFO_COLOR_AREA> listArea = new List<T_PC_INFO_COLOR_AREA>();
int index = 0;
foreach (var item in Colors)
{
var ColorPoints = item.Nav_ColorPoints;
item.Nav_ColorPoints = null;
if (item.IS_DELETED)
{
foreach (var itemP in ColorPoints)
{
itemP.IS_DELETED = true;
}
listPoint.AddRange(ColorPoints);
continue;
}
index++;
if (item.ISDIY && string.IsNullOrEmpty(item.RGBCOLOR))
{
throw new Exception("手动数据必须选择填充色");
}
var Areas = item.Nav_Areas;//区域 不一定都会绑定 可以直接描点 按手动的来取色
if (Areas != null && Areas.Any() && Areas.Count() > 0)
{
item.Nav_Areas = null;
foreach (var itemA in Areas)
{
itemA.INFO_ID = entity.ID;
}
listArea.AddRange(Areas);
}
else if (!item.ISDIY)
{
throw new Exception("非自定数据必须选择区域!");//根据区域判断等级与颜色
}
//点位必须要有 且坐标顺序 必须连续 不重复
//if (ColorPoints == null || !ColorPoints.Any() || ColorPoints.Count() < 3)
//{
// 升级后别的地方添加
// throw new Exception("坐标点位必须大于2点击最左边[+]进行坐标添点加");
//}
if (ColorPoints != null && ColorPoints.Any() && ColorPoints.Count > 0)
{
if (ColorPoints.Where(e => !e.IS_DELETED).Max(e => e.NUM) != ColorPoints.Where(e => !e.IS_DELETED).Count())
{
throw new Exception("请检查坐标顺序[色块:" + index + "]有序正整数1、2、3...");
}
}
foreach (var itemP in ColorPoints)
{
itemP.INFO_ID = entity.ID;
}
listPoint.AddRange(ColorPoints);
}
UnifiedCommit(() =>
{
if (entity != null)
this.UpdateEntityNoCommit(entity);
if (Files != null && Files.Any())
this.BantchSaveEntityNoCommit(Files);
if (Colors != null && Colors.Any())
this.BantchSaveEntityNoCommit(Colors);
if (listArea != null && listArea.Any())
this.BantchSaveEntityNoCommit(listArea);
if (listPoint != null && listPoint.Any())
this.BantchSaveEntityNoCommit(listPoint);
});
return true;
});
}
/// <summary>
/// 获得单条实体数据 坐标排序
/// </summary>
/// <param name="filter">过滤实体</param>
/// <returns></returns>
[HttpPost, Route("Get")]
public JsonActionResult<T_PC_INFO> Get([FromBody] KeywordFilter filter)
{
return SafeExecute(() =>
{
var result = GetEntity<T_PC_INFO>(null, filter, null);
if (result.Nav_Colors != null && result.Nav_Colors.Any())
{
foreach (var item in result.Nav_Colors)
{
if (item.Nav_ColorPoints != null && item.Nav_ColorPoints.Any())
{
item.Nav_ColorPoints = item.Nav_ColorPoints.OrderBy(e => e.NUM).ToList();
}
}
}
return result;
});
}
/// <summary>
/// 显示信息
/// </summary>
/// <param name="filter">过滤实体</param>
/// <returns></returns>
[HttpPost, Route("EntitiesShow")]
public JsonActionResult<IEnumerable<T_PC_INFO>> EntitiesShow([FromBody] KeywordFilter filter)
{
return SafeExecute(() =>
{
var result = GetEntities<T_PC_INFO>(null, filter, null);
if (result != null && result.Any())
{
var colors = GetEntities<T_PC_COLORSET>(e => !e.IS_DELETED && e.ENABLE_STATUS == FMEnableStatusEnum., null, null).OrderBy(e => e.LEVEL);
if (colors == null || colors.Count() < 1)
{
throw new Exception("请配置四色图颜色信息");
}
List<Guid> listAreaID = new List<Guid>();
foreach (var rp in result)
{
if (rp.Nav_Colors != null && rp.Nav_Colors.Any())
{
rp.Nav_Colors = rp.Nav_Colors.OrderBy(e => e.ZNDEX).ToList();
foreach (var item in rp.Nav_Colors)
{
item.DESCRIBE_TITLE = item.DESCRIBE;
//排序
if (item.Nav_ColorPoints != null && item.Nav_ColorPoints.Any())
{
item.Nav_ColorPoints = item.Nav_ColorPoints.OrderBy(e => e.NUM).ToList();
}
//如果非DIY数据 根据区域去查找隐患 根据隐患信息 判断等级 给颜色赋值 1为高级
//收集区域ID
if (!item.ISDIY && item.Nav_Areas.Any())
{
listAreaID.AddRange(item.Nav_Areas.Select(e => e.AREA_ID));
//colorLevel = 4;
//item.DESCRIBE = "信息描述";
////T_HM_EVALUATE_RISK
}
}
}
}
listAreaID = listAreaID.Distinct().ToList();
//风险等级匹配
if (listAreaID != null && listAreaID.Any() && listAreaID.Count > 0)
{
//--企业库:T_SK_ENTERPRISE_LIBRARY 区域 等级 取最高的
//--工作票:T_FO_CRUCIAL_LICENSE_JOB 区域 等级 取最高的
//--隐患整改记录:T_SK_HIDDEN_DANGER_RECTIFY_RECORD STATUS<30 查数量
#region
BaseFilter filterLib = new BaseFilter(filter.OrgId);
filterLib.SelectField = new string[] { "AREA_ID", "EVALUATE_LEVEL", "IS_DELETED" };
//区域 固有风险
var listLib = GetEntities<T_SK_ENTERPRISE_LIBRARY>(e => !e.IS_DELETED && e.AREA_ID.HasValue && listAreaID.Contains(e.AREA_ID.Value), filterLib, null).GroupBy(e => new { e.AREA_ID, e.EVALUATE_LEVEL }).OrderBy(e => e.Key.AREA_ID).ThenBy(e => e.Key.EVALUATE_LEVEL).ToList();
//工作票 未归档 正在作业 //FOPreMeetingStatusEnum IS_PUBLISH
int PUBLISH = (int)FOPreMeetingStatusEnum.;
DateTime dtNow = DateTime.Now;
BaseFilter filterJob = new BaseFilter(filter.OrgId);
filterJob.SelectField = new string[] { "AREA_ID", "JOB_DATE", "IS_DELETED", "JOB_END_DATE", "IS_PUBLISH", "EVALUATE_LEVEL" };
var JobsNow = GetEntities<T_FO_CRUCIAL_LICENSE_JOB>(e => !e.IS_DELETED && e.AREA_ID.HasValue && listAreaID.Contains(e.AREA_ID.Value) && e.JOB_DATE.HasValue && e.JOB_END_DATE.HasValue && (int)e.IS_PUBLISH < PUBLISH && e.JOB_DATE.Value <= dtNow && dtNow <= e.JOB_END_DATE.Value, filterJob, null);
//隐患整改记录
int STATUSMax = (int)PFStandardStatus.Archived;
BaseFilter filterRec = new BaseFilter(filter.OrgId);
filterRec.SelectField = new string[] { "RISK_AREA_ID", "STATUS", "IS_DELETED", "HIDDEN_LEVEL" };
var listDangerRecord = GetEntities<T_SK_HIDDEN_DANGER_RECTIFY_RECORD>(e => !e.IS_DELETED && e.RISK_AREA_ID.HasValue && ((int)e.STATUS) < STATUSMax, null, null);
//区域 供显示
var listArea = GetEntities<T_SK_RISK_AREA>(e => listAreaID.Contains(e.ID), null, null);
#endregion
IEnumerable<Guid> listAreaIDItem = null;
T_PC_COLORSET colorPer = null;
SKEvaluateLevelEnum? LevelResultEst = null;//高风险等级结果
SKEvaluateLevelEnum? LevelAreaEst = null;//区域固有最高风险等级
SKEvaluateLevelEnum? LevelJobEst = null;//实施工作票最高风险等级
SKEvaluateLevelEnum? LevelDanjerEst = null;//隐患待整改最高风险等级
int CountHightLevel = 0;//重大隐患未整改数量
int CountNotHightLevel = 0;//一般隐患未整改数量
int disIndex = 0;
foreach (var rp in result)
{
if (rp.Nav_Colors == null && !rp.Nav_Colors.Any())
continue;
foreach (var item in rp.Nav_Colors)
{
if (item.ISDIY || !item.Nav_Areas.Any() || item.Nav_Areas.Count < 1)
continue;
LevelResultEst = null;//高风险等级结果
LevelAreaEst = null;//区域固有最高风险等级
LevelJobEst = null;//实施工作票最高风险等级
LevelDanjerEst = null;//隐患待整改最高风险等级
CountHightLevel = 0;//重大隐患未整改数量
CountNotHightLevel = 0;//一般隐患未整改数量
//绑定区域 按实际数据显示信息
listAreaIDItem = item.Nav_Areas.Select(e => e.AREA_ID);
var listAreaItem = listArea.Where(e => listAreaIDItem.Contains(e.ID));
if (listAreaItem.Any() && listAreaItem.Count() > 0)
{
item.DESCRIBE = "区域:" + String.Join('、', listAreaItem.Select(e => e.NAME)) + "<br/>";
}
else
{
item.DESCRIBE = "";
}
#region LevelAreaEst
if (listLib != null && listLib.Any() && listLib.Count() > 0)
{
var ListAreaLib = listLib.Where(e => listAreaIDItem.Contains(e.Key.AREA_ID.Value));
if (ListAreaLib != null && ListAreaLib.Any() && ListAreaLib.Count() > 0)
{
LevelAreaEst = ListAreaLib.OrderBy(e => e.Key.EVALUATE_LEVEL).ToList()[0].Key.EVALUATE_LEVEL;
}
}
#endregion
#region LevelJobEst
if (JobsNow != null && JobsNow.Any() && JobsNow.Count() > 0)
{
var listJobsArea = JobsNow.Where(e => listAreaIDItem.Contains(e.AREA_ID.Value)).OrderBy(e => e.EVALUATE_LEVEL);
if (listJobsArea != null && listJobsArea.Any() && listJobsArea.Count() > 0)
{
LevelJobEst = listJobsArea.OrderBy(e => e.EVALUATE_LEVEL).ToList()[0].EVALUATE_LEVEL;
}
}
#endregion
#region CountHightLevel CountNotHightLevel
CountHightLevel = listDangerRecord.Count(e => e.HIDDEN_LEVEL == SKHiddenLevel.Major && listAreaIDItem.Contains(e.RISK_AREA_ID.Value));
CountNotHightLevel = listDangerRecord.Count(e => e.HIDDEN_LEVEL == SKHiddenLevel.General && listAreaIDItem.Contains(e.RISK_AREA_ID.Value));
#endregion
#region LevelResultEst
foreach (var itemCL in colors)
{
if (LevelAreaEst != null && itemCL.LEVEL == LevelAreaEst)
{
if (LevelResultEst == null)
{
LevelResultEst = itemCL.LEVEL;
}
}
if (LevelJobEst != null && itemCL.LEVEL == LevelJobEst)
{
if (LevelResultEst == null)
{
LevelResultEst = itemCL.LEVEL;
}
}
if ((CountHightLevel > 0 || CountNotHightLevel > 0) && LevelDanjerEst == null)
{
//区域内有待整改隐患 并且 此项未赋值
//有设置 最小值 并且不为0 数量大于/等于 最小值 就是对应数据
if (CountHightLevel > 0 && LevelDanjerEst == null && itemCL.COUNTMIN_HIGH.HasValue && itemCL.COUNTMIN_HIGH.Value != 0 && CountHightLevel >= itemCL.COUNTMIN_HIGH.Value)
{
LevelDanjerEst = itemCL.LEVEL;
}
if (CountNotHightLevel > 0 && LevelDanjerEst == null && itemCL.COUNTMIN_LOW.HasValue && itemCL.COUNTMIN_LOW.Value != 0 && CountNotHightLevel >= itemCL.COUNTMIN_LOW.Value)
{
LevelDanjerEst = itemCL.LEVEL;
}
if (LevelDanjerEst != null && LevelResultEst == null)
{
LevelResultEst = itemCL.LEVEL;
}
}
}
#endregion
#region
if (!LevelResultEst.HasValue)
{
item.RGBCOLOR = "";
item.DESCRIBE += "按四色取值规则未匹配到对应信息";
continue;
}
colorPer = colors.FirstOrDefault(e => e.LEVEL == LevelResultEst);
if (colorPer != null)
{
item.DESCRIBE += colorPer.NAME + "预警依据:<br/>";
item.RGBCOLOR = colorPer.CODE;
}
else
item.RGBCOLOR = "";
disIndex = 0;
//LevelAreaEst = null;//区域固有最高风险等级
//LevelJobEst = null;//实施工作票最高风险等级
//LevelDanjerEst = null;//隐患待整改最高风险等级
//CountHightLevel = 0;//重大隐患未整改数量
//CountNotHightLevel = 0;//一般隐患未整改数量
if (LevelAreaEst != null)
{
disIndex++;
item.DESCRIBE += (disIndex + "、区域固有最高风险等级:" + LevelAreaEst.Value.GetDescription() + "<br/>");
}
if (LevelJobEst != null)
{
disIndex++;
item.DESCRIBE += (disIndex + "、工作票风险等级:" + LevelJobEst.Value.GetDescription() + "<br/>");
}
if (LevelDanjerEst != null)
{
disIndex++;
item.DESCRIBE += (disIndex + "、待整改隐患风险等级:" + LevelJobEst.Value.GetDescription() + (CountHightLevel > 0 ? ("重大隐患" + CountHightLevel + "条") : "") + (CountNotHightLevel > 0 ? "一般隐患" + CountNotHightLevel + "条" : "") + "<br/>");
}
if (!string.IsNullOrEmpty(item.DESCRIBE))
{
item.DESCRIBE_TITLE = item.DESCRIBE.Replace("<br/>", "\n");
}
#endregion
}
}
}
}
return result;
});
}
/// <summary>
/// 更新色块区域
/// </summary>
/// <param name="listPoint">对象实体</param>
/// <returns></returns>
[HttpPost, Route("UpdateColorPoint")]
public JsonActionResult<bool> UpdateColorPoint([FromBody] List<T_PC_INFO_COLOR_POINT> listPoint)
{
return SafeExecute(() =>
{
//List<T_PC_INFO_COLOR_POINT> listPoint = new List<T_PC_INFO_COLOR_POINT>();
if (listPoint == null || listPoint.Count() < 1)
{
throw new Exception("未获取到坐标序列!");
}
var pointCheck = listPoint.Find(e => e.INFO_COLOR_ID == Guid.Empty || e.INFO_ID == Guid.Empty);
if (pointCheck != null || pointCheck.ID == Guid.Empty)
{
throw new Exception("未获取到坐标序列!");
}
Guid INFO_COLOR_ID = listPoint.ToList()[0].INFO_COLOR_ID;
var check = listPoint.Find(e => e.INFO_COLOR_ID != INFO_COLOR_ID);
if (check != null || check.ID != Guid.Empty)
{
throw new Exception("数据有误,每次只能操作一个配置区域!");
}
//删除原有数据 增加新数据
UnifiedCommit(() =>
{
DeleteEntityNoCommit<T_PC_INFO_COLOR_POINT>(e => e.INFO_COLOR_ID == INFO_COLOR_ID);
if (listPoint != null && listPoint.Any())
this.BantchSaveEntityNoCommit(listPoint);
});
return true;
});
}
/// <summary>
/// 更新色块区域
/// </summary>
/// <param name="PointInfo">对象实体</param>
/// <returns></returns>
[HttpPost, Route("UpdateColorPointInfo")]
public JsonActionResult<bool> UpdateColorPoint([FromBody] T_PC_INFO_COLOR PointInfo)
{
return SafeExecute(() =>
{
if (PointInfo.Nav_ColorPoints == null || !PointInfo.Nav_ColorPoints.Any())
{
throw new Exception("未获取到坐标序列!");
}
List<T_PC_INFO_COLOR_POINT> listPoint = PointInfo.Nav_ColorPoints.ToList();
//List<T_PC_INFO_COLOR_POINT> listPoint = new List<T_PC_INFO_COLOR_POINT>();
if (listPoint == null || listPoint.Count() < 1)
{
throw new Exception("未获取到坐标序列!");
}
var pointCheck = listPoint.Find(e => e.INFO_COLOR_ID == Guid.Empty || e.INFO_ID == Guid.Empty);
if (pointCheck != null)
{
throw new Exception("未获取到坐标序列!");
}
Guid INFO_COLOR_ID = listPoint.ToList()[0].INFO_COLOR_ID;
var check = listPoint.Find(e => e.INFO_COLOR_ID != INFO_COLOR_ID);
if (check != null)
{
throw new Exception("数据有误,每次只能操作一个配置区域!");
}
//删除原有数据 增加新数据
UnifiedCommit(() =>
{
DeleteEntityNoCommit<T_PC_INFO_COLOR_POINT>(e => e.INFO_COLOR_ID == INFO_COLOR_ID);
if (listPoint != null && listPoint.Any())
this.BantchSaveEntityNoCommit(listPoint);
});
return true;
});
}
/// <summary>
/// 更新色块区域
/// </summary>
/// <param name="listPoint">对象实体</param>
/// <returns></returns>
[HttpPost, Route("UpdateColor")]
public JsonActionResult<bool> UpdateColorPoint([FromBody] T_PC_INFO_COLOR_POINT Point)
{
return SafeExecute(() =>
{
////List<T_PC_INFO_COLOR_POINT> listPoint = new List<T_PC_INFO_COLOR_POINT>();
//if (listPoint == null || listPoint.Count() < 1)
//{
// throw new Exception("未获取到坐标序列!");
//}
//var pointCheck = listPoint.Find(e => e.INFO_COLOR_ID == Guid.Empty || e.INFO_ID == Guid.Empty);
//if (pointCheck != null || pointCheck.ID == Guid.Empty)
//{
// throw new Exception("未获取到坐标序列!");
//}
//Guid INFO_COLOR_ID = listPoint.ToList()[0].INFO_COLOR_ID;
//var check = listPoint.Find(e => e.INFO_COLOR_ID != INFO_COLOR_ID);
//if (check != null || check.ID != Guid.Empty)
//{
// throw new Exception("数据有误,每次只能操作一个配置区域!");
//}
////删除原有数据 增加新数据
//UnifiedCommit(() =>
//{
// DeleteEntityNoCommit<T_PC_INFO_COLOR_POINT>(e => e.INFO_COLOR_ID == INFO_COLOR_ID);
// if (listPoint != null && listPoint.Any())
// this.BantchSaveEntityNoCommit(listPoint);
//});
return true;
});
}
}
}