From c08d233e5133f0e1925945c6d95b433d6428c0d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E7=BE=8E=E8=8D=A3?= <10755671+mei-rong-he@user.noreply.gitee.com> Date: Thu, 2 Jul 2026 18:08:40 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9A=90=E6=82=A3=E6=95=B4=E6=94=B9=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Api/BIController/BIHomeController.cs | 439 +++++++++++++++++- 1 file changed, 436 insertions(+), 3 deletions(-) diff --git a/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIHomeController.cs b/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIHomeController.cs index 642d884..901a822 100644 --- a/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIHomeController.cs +++ b/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIHomeController.cs @@ -7,11 +7,14 @@ using APT.Infrastructure.Api.Redis; using APT.Infrastructure.Core; using APT.MS.Domain.Entities.BI; using APT.MS.Domain.Entities.HM; +using APT.MS.Domain.Entities.SC.BI; using APT.MS.Domain.Entities.SK; using APT.MS.Domain.Enums.SK; +using APT.SC.WebApi.Controllers.Api.BIController; using APT.Utility; using log4net.Core; using Microsoft.AspNetCore.Mvc; +using Org.BouncyCastle.Utilities; using System; using System.Collections.Generic; using System.Linq; @@ -546,8 +549,8 @@ namespace APT.SC.WebApi.Controllers.Api.BI /// /// 过滤实体 /// - [HttpPost, Route("GetHomeInfo")] - public JsonActionResult GetHomeInfo([FromBody] KeywordFilter filter) + [HttpPost, Route("GetHomeInfoOld")] + public JsonActionResult GetHomeInfoOld([FromBody] KeywordFilter filter) { return SafeExecute(() => { @@ -1231,7 +1234,437 @@ namespace APT.SC.WebApi.Controllers.Api.BI return result; }); } - + + /// + /// 查询所有数据 + /// + /// 过滤实体 + /// + [HttpPost, Route("GetHomeInfo")] + public JsonActionResult GetHomeInfo([FromBody] KeywordFilter filter) + { + return SafeExecute(() => + { + //按生产单元 获取数据 + HomeResult result = new HomeResult(); + //if (string.IsNullOrEmpty(filter.Keyword)) + //{ + // return result; + //} + //int MineType = int.Parse(filter.Keyword); + + + //根据 日期 yyyyMMddHH MineType 获取信息 Redis信息 + //如果是有效的直接返回 否则更新 + var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId; + var redisCode = string.Format(RedisCacheKey.HomeResult, orgId); + DateTime dtNow = DateTime.Now; + + + #region 判断 从Redis中获取数据 有就直接返回到前端 没有就按原来的进行搜索 最后再判断存入Redis中 + + bool isRedisConfig = true; + var redisConfig = APT.Infrastructure.Api.ConfigurationManager.AppSettings["RedisFormConfig"]; + List listHomeRedis = null; + if (!string.IsNullOrEmpty(redisConfig)) + isRedisConfig = bool.Parse(redisConfig); + + if (isRedisConfig && CsRedisManager.KeyExists(redisCode)) + listHomeRedis = CsRedisManager.StringGet>(redisCode); + + if (listHomeRedis != null && listHomeRedis.Count() > 0) + { + foreach (var item in listHomeRedis) + { + //if (item.MineType == MineType) + { + if (dtNow.ToString("yyyyMMddHH") == item.yyyyMMddHH) + { + result = item.result; + } + else + { + listHomeRedis.Remove(item);//Key不匹配 过期数据删除 + } + break; + } + } + } + + //redis获取到了数据 + //if (result != null && (result.ListC != null || result.ListCYear != null || result.ListSafeCheckYearMonth != null)) + //{ + // return result; + //} + + #endregion + + #region Collection was modified, enumeration operation may not execute(foreach) 不要 SelectField 看看结果 如果继续报错 返回来 + //TODO wyw SelectField + + //BaseFilter filterD = new BaseFilter(); + //filterD.SelectField = new List { "ID", "NAME", "DEPARTMENT_TYPE", "PARENT_ID", "MineType" }; + //var listDep1MineType = GetEntities(t => t.MineType.HasValue && t.MineType == MineType && t.DEPARTMENT_TYPE == 10, filterD, null);//部门就可以了 因为都相向 统计了 + + var listDep1MineType = GetEntities(t => t.ENABLE_STATUS == 0, null, null);//部门就可以了 因为都相向 统计了 + + #endregion + + if (listDep1MineType == null || !listDep1MineType.Any()) + { + return result; + } + + List listDep = new List(); + listDep = listDep1MineType.ToList(); + + + #region //月度 隐患整改情况 + string Val = string.Empty;// 0 ,1,2,3 + //string NameMonth = dtNow.AddMonths(-5).Month.ToString() + "月," + dtNow.AddMonths(-4).Month.ToString() + "月," + dtNow.AddMonths(-3).Month.ToString() + "月," + dtNow.AddMonths(-2).Month.ToString() + "月," + dtNow.AddMonths(-1).Month.ToString() + "月," + dtNow.Month.ToString() + "月"; + string NameMonth = dtNow.AddMonths(-5).ToString("yyyy-MM") + "," + dtNow.AddMonths(-4).ToString("yyyy-MM") + "," + dtNow.AddMonths(-3).ToString("yyyy-MM") + "," + dtNow.AddMonths(-2).ToString("yyyy-MM") + "," + dtNow.AddMonths(-1).ToString("yyyy-MM") + "," + dtNow.ToString("yyyy-MM"); + List listC = new List(); + //HomeCorrect modelC = null; + bool isNormal = true;//数据是否正常 + var newFilter = new BaseFilter(orgId); + newFilter.IgnoreDataRule = true; + var hiddens = GetEntities(e => e.APPLY_DEPARTMENT_ID.HasValue && e.CREATE_TIME.HasValue && e.CREATE_TIME.Value.Year == dtNow.Year, newFilter); + + var startTime = dtNow.AddMonths(-6); + var currentTime = Convert.ToDateTime(startTime.Year + "-" + startTime.Month + "-01 00:00:00"); + //var groupDepart = hiddens.GroupBy(t => t.APPLY_DEPARTMENT_ID); + //if (groupDepart.Any()) + { + //foreach (var item in groupDepart) + { + for (DateTime i = currentTime; i <= dtNow; i = i.AddMonths(1)) + { + var monthStart = Convert.ToDateTime(i.Year + "-" + i.Month + "-01 00:00:00"); + var monthEnd = Convert.ToDateTime(monthStart.AddMonths(1).AddDays(-1).ToString().Replace("0:00:00", "23:59:59")); + if (i.Date <= startTime.Date) + { + monthStart = startTime; + } + if (i.Date >= dtNow.Date) + { + monthEnd = dtNow; + } + var alls = hiddens.Where(t => t.CREATE_TIME >= monthStart && t.CREATE_TIME <= monthEnd); + var onTimes = alls.Where(t => t.STATUS == BaseData.Domain.Enums.PF.PFStandardStatus.Archived && t.COMPLETE_DATE <= t.RECITIFY_TIME); + if (onTimes.Any()) + { + HomeCorrect modelC = new HomeCorrect(); + modelC.Val = onTimes.Count().ToString(); + modelC.SOURCENAME = "按时整改隐患"; + //modelC.DEPARTMENT_ID = (Guid)item.Key; + //modelC.DEPARTMENTNAME = listDep.FirstOrDefault(t => t.ID == item.Key)?.NAME; + modelC.YEAR = monthStart.Year; + modelC.NAME = monthStart.ToString("yyyy-MM"); + listC.Add(modelC); + } + else + { + HomeCorrect modelC = new HomeCorrect(); + modelC.Val = "0"; + modelC.SOURCENAME = "按时整改隐患"; + //modelC.DEPARTMENT_ID = (Guid)item.Key; + //modelC.DEPARTMENTNAME = listDep.FirstOrDefault(t => t.ID == item.Key)?.NAME; + modelC.YEAR = monthStart.Year; + modelC.NAME = monthStart.ToString("yyyy-MM"); + listC.Add(modelC); + } + var overTimes = alls.Where(t => t.STATUS == BaseData.Domain.Enums.PF.PFStandardStatus.Archived && t.COMPLETE_DATE > t.RECITIFY_TIME); + if (overTimes.Any()) + { + HomeCorrect modelC = new HomeCorrect(); + modelC.Val = overTimes.Count().ToString(); + modelC.SOURCENAME = "超期整改隐患"; + //modelC.DEPARTMENT_ID = (Guid)item.Key; + //modelC.DEPARTMENTNAME = listDep.FirstOrDefault(t => t.ID == item.Key)?.NAME; + modelC.YEAR = monthStart.Year; + modelC.NAME = monthStart.ToString("yyyy-MM"); + listC.Add(modelC); + } + else + { + HomeCorrect modelC = new HomeCorrect(); + modelC.Val = "0"; + modelC.SOURCENAME = "超期整改隐患"; + //modelC.DEPARTMENT_ID = (Guid)item.Key; + //modelC.DEPARTMENTNAME = listDep.FirstOrDefault(t => t.ID == item.Key)?.NAME; + modelC.YEAR = monthStart.Year; + modelC.NAME = monthStart.ToString("yyyy-MM"); + listC.Add(modelC); + } + var noTimes = alls.Where(t => t.STATUS != BaseData.Domain.Enums.PF.PFStandardStatus.Archived); + if (noTimes.Any()) + { + HomeCorrect modelC = new HomeCorrect(); + modelC.Val = noTimes.Count().ToString(); + modelC.SOURCENAME = "未整改隐患"; + //modelC.DEPARTMENT_ID = (Guid)item.Key; + //modelC.DEPARTMENTNAME = listDep.FirstOrDefault(t => t.ID == item.Key)?.NAME; + modelC.YEAR = monthStart.Year; + modelC.NAME = monthStart.ToString("yyyy-MM"); + listC.Add(modelC); + } + else + { + HomeCorrect modelC = new HomeCorrect(); + modelC.Val = "0"; + modelC.SOURCENAME = "未整改隐患"; + //modelC.DEPARTMENT_ID = (Guid)item.Key; + //modelC.DEPARTMENTNAME = listDep.FirstOrDefault(t => t.ID == item.Key)?.NAME; + modelC.YEAR = monthStart.Year; + modelC.NAME = monthStart.ToString("yyyy-MM"); + listC.Add(modelC); + } + if (alls.Any()) + { + var val = onTimes.Count() + overTimes.Count(); + var count = alls.Count(); + HomeCorrect modelC = new HomeCorrect(); + modelC.Val = count == 0 ?"0":((decimal)Math.Round(100.00 * val / count, 2)).ToString(); + modelC.SOURCENAME = "隐患整改率"; + //modelC.DEPARTMENT_ID = (Guid)item.Key; + //modelC.DEPARTMENTNAME = listDep.FirstOrDefault(t => t.ID == item.Key)?.NAME; + modelC.YEAR = monthStart.Year; + modelC.NAME = monthStart.ToString("yyyy-MM"); + listC.Add(modelC); + } + else + { + HomeCorrect modelC = new HomeCorrect(); + modelC.Val = "0"; + modelC.SOURCENAME = "隐患整改率"; + //modelC.DEPARTMENT_ID = (Guid)item.Key; + //modelC.DEPARTMENTNAME = listDep.FirstOrDefault(t => t.ID == item.Key)?.NAME; + modelC.YEAR = monthStart.Year; + modelC.NAME = monthStart.ToString("yyyy-MM"); + listC.Add(modelC); + } + } + } + } + List listC2 = new List(); + if (listC.Any()) + { + var groupList = listC.GroupBy(t => new { t.SOURCENAME }); + if (groupList.Any()) + { + foreach (var item in groupList) + { + var vals = listC.Where(t => t.SOURCENAME == item.Key.SOURCENAME).OrderBy(m => m.NAME).Select(n => n.Val).ToList(); + var names = listC.Where(t => t.SOURCENAME == item.Key.SOURCENAME).OrderBy(m => m.NAME).Select(n => n.NAME).ToList(); + HomeCorrect modelC = new HomeCorrect(); + modelC.Val = string.Join(",", vals); + modelC.SOURCENAME = item.Key.SOURCENAME; + //modelC.DEPARTMENT_ID = item.Key.DEPARTMENT_ID; + //modelC.DEPARTMENTNAME = listDep.FirstOrDefault(t => t.ID == item.Key.DEPARTMENT_ID)?.NAME; + modelC.YEAR = dtNow.Year; + modelC.NAME = string.Join(",", names); + listC2.Add(modelC); + } + } + } + + result.ListC = listC2; + + #region 组织合并 + + + #endregion + + + + #endregion + + #region 年度 各下属组织 隐患整改情况 + + List listReasonYearT = BIHomeService.GetHomeCorrectYear(filter.OrgId, listDep).ToList(); + List ListCYear = new List(); + HomeCorrectYear modelCY = null; + int CountYearT = listReasonYearT.Count; + for (int i = 0; i < CountYearT; i++) + { + if (i == 0 || listReasonYearT[i].DEPARTMENT_ID != listReasonYearT[i - 1].DEPARTMENT_ID) + { + modelCY = new HomeCorrectYear(); + modelCY.DEPARTMENTNAME = listReasonYearT[i].DEPARTMENTNAME; + modelCY.DEPARTMENT_ID = listReasonYearT[i].DEPARTMENT_ID; + modelCY.YEAR = listReasonYearT[i].YEAR; + } + + // 按时整改隐患 5 超期整改隐患 10 未整改隐患 15 + if (listReasonYearT[i].SOURCEVAL == 5) + { + modelCY.CountIn += listReasonYearT[i].COUNT; + } + else if (listReasonYearT[i].SOURCEVAL == 10) + { + modelCY.CountOut += listReasonYearT[i].COUNT; + } + else if (listReasonYearT[i].SOURCEVAL == 15) + { + modelCY.CountNot += listReasonYearT[i].COUNT; + } + + if (i == CountYearT - 1 || listReasonYearT[i].DEPARTMENT_ID != listReasonYearT[i + 1].DEPARTMENT_ID) + { + modelCY.Count = modelCY.CountIn + modelCY.CountOut + modelCY.CountNot; + ListCYear.Add(modelCY); + } + } + + result.ListCYear = ListCYear; + + #endregion + + + #region 月度 6 个月 安全检查、检查类型 数量 + + //按生产单元 获取 + + //if (!string.IsNullOrEmpty(filter.Keyword)) + { + //int MineType = int.Parse(filter.Keyword.ToString()); + //BaseFilter filterD = new BaseFilter(); + //filterD.SelectField = new List { "ID", "NAME", "DEPARTMENT_TYPE", "PARENT_ID" }; + + //var listDep1MineType = GetEntities(t => t.MineType.HasValue && t.MineType == MineType && t.DEPARTMENT_TYPE == 10, filterD, null);//部门就可以了 因为都相向 统计了 + if (listDep != null && listDep.Any()) + { + List ListSafeCheckYearMonth = new List(); + int befoMonth = 12; + List ListSafeCheckYearMonthT = BIHomeService.GetHomeCheckCountMonth(filter.OrgId, listDep.ToList(), befoMonth).ToList(); + //var listCheckTypeIDT = ListSafeCheckYearMonthT.Select(e => e.SOURCEID).Distinct().ToList(); + + //var enums = GetEntity(e => e.VALUE == MineType && e.CODE == "BSMineTypeEnum"); + //if (enums != null) + //{ + // var listTypeMine = GetEntities(e => e.MineType == (SKProductionUnit)MineType, null, null); + // if (listTypeMine != null && listTypeMine.Any()) + // { + // var listMineCheckTypeID = listTypeMine.Select(e => e.ID); + // for (int i = 0; i < listCheckTypeIDT.Count; i++) + // { + // if (!listMineCheckTypeID.Contains(listCheckTypeIDT[i])) + // { + // listCheckTypeIDT.RemoveAt(i); + // i--; + // } + // } + // } + //} + var checkIds = ListSafeCheckYearMonthT.Select(t => t.SOURCEID).Distinct().ToList(); + var loginDepart = this.GetEntity(t => t.ID == APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID); + var listCheckType = GetEntities(e => checkIds.Contains(e.ID), null, null).ToList(); + if (loginDepart != null) + { + listCheckType = listCheckType.Where(t => t.PRODUCTION_UNIT_ID == loginDepart.PRODUCTION_UNIT_ID).ToList(); + } + List listCheckTypeID = new List(); + List listCheckTypeNAME = new List(); + + //Guid IDZH = Guid.Empty;//综合检查(只有一个) + //List listGUID = new List();//综合检查子集 + for (int i = 0; i < listCheckType.Count; i++) + { + //if (listCheckType[i].PARENT_ID.HasValue || ((IDZH != Guid.Empty && IDZH == listCheckType[i].ID) || listCheckType[i].NAME == "综合检查")) + //{ + // if (IDZH == Guid.Empty) + // { + // IDZH = listCheckType[i].PARENT_ID.HasValue ? listCheckType[i].PARENT_ID.Value : listCheckType[i].ID; + // listCheckTypeID.Add(IDZH); + // var checkTypeP = GetEntity(IDZH); + // listCheckTypeNAME.Add(checkTypeP.NAME); + // } + // listGUID.Add(listCheckType[i].ID); + //} + //else + { + listCheckTypeID.Add(listCheckType[i].ID); + listCheckTypeNAME.Add(listCheckType[i].NAME); + } + } + + int year = DateTime.Now.Year; + int Month = DateTime.Now.Month; + DateTime dtTemp = DateTime.Now; + IEnumerable listPerChearch = null; + IEnumerable listPerChearchPer = null; + + //List listListCount = null; + for (int i = 0; i < befoMonth; i++) + { + dtTemp = dtNow.AddMonths(-1 * i); + year = dtTemp.Year; + Month = dtTemp.Month; + listPerChearch = ListSafeCheckYearMonthT.Where(e => e.YEAR == year && e.MONTH == Month); + HomeSafeCheckCountMonth modelper = new HomeSafeCheckCountMonth(); + modelper.Total = listPerChearch.Count(); + modelper.listSOURCENAME = listCheckTypeNAME; + modelper.YEAR = year; + modelper.MONTH = Month; + List listListCount = new List(); + + for (int j = 0; j < listCheckTypeID.Count; j++) + { + //if (listCheckTypeID[j] != IDZH) + { + listPerChearchPer = listPerChearch.Where(e => e.YEAR == year && e.MONTH == Month && e.SOURCEID == listCheckTypeID[j]);//各个检查 + } + //else + //{ + // listPerChearchPer = listPerChearch.Where(e => e.YEAR == year && e.MONTH == Month && listGUID.Contains(e.SOURCEID));//综合检查 + //} + + if (listPerChearchPer == null || !listPerChearchPer.Any()) + { + listListCount.Add(0); + } + else + { + listListCount.Add(listPerChearchPer.Sum(e => e.COUNT)); + } + } + modelper.listListCount = listListCount; + ListSafeCheckYearMonth.Add(modelper); + } + result.ListSafeCheckYearMonth = ListSafeCheckYearMonth.OrderBy(e => e.YEAR).ThenBy(e => e.MONTH).ToList(); + } + } + + + #endregion + + + #region 搜索结果 判断存入Redis中 + + //if (isRedisConfig) + //{ + // try + // { + // if (listHomeRedis == null) + // listHomeRedis = new List(); + + // listHomeRedis.Add(new HomeResultMineType() + // { + // //MineType = MineType, + // yyyyMMddHH = dtNow.ToString("yyyyMMddHH"), + // result = result + // }); + + // CsRedisManager.StringSet>(redisCode, listHomeRedis); + // } + // catch { } + //} + + #endregion + + return result; + }); + } /// /// 首页 安全检查次数统计明细(BI054HomeDetail) ///