using APT.BaseData.Domain.ApiModel.Platform; using APT.BaseData.Domain.Entities.FM; using APT.BaseData.Domain.Enums; using APT.BaseData.Domain.IServices.BI; using APT.Infrastructure.Api; 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; using APT.MS.Domain.Enums.SK; using APT.SC.WebApi.Controllers.Api.BIController; using APT.Utility; using log4net.Core; using Microsoft.AspNetCore.Mvc; using NPOI.OpenXmlFormats.Shared; using NPOI.POIFS.Properties; using NPOI.SS.Formula.Functions; using Org.BouncyCastle.Utilities; using System; using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Linq; namespace APT.SC.WebApi.Controllers.Api.BI { /// /// 首页图表 /// [Route("api/BI/BIHome")] public class BIHomeController : AuthorizeApiController { IBIHomeService BIHomeService { get; set; } public BIHomeController(IBIHomeService biHomeService) { BIHomeService = biHomeService; } /// /// 查询所有数据 /// /// 过滤实体 /// [HttpPost, Route("GetHomeInfo1")] public JsonActionResult GetHomeInfo1([FromBody] KeywordFilter filter) { return SafeExecute(() => { //全部 改成 看自己 所在组织 //安环 取公司 //班组 取 车间 HomeResult result = new HomeResult(); List listDep = new List(); DateTime dtNow = DateTime.Now; Guid? depID = APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID; if (!depID.HasValue) { return result; } var depLogin = GetEntity(APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID.Value); ////FMDepartmentType 部门=0, 车间=1, 班组=2, 公司=3 //if (depLogin.DEPARTMENT_TYPE == 20) //{ // //班组级 因数据少不好看 显示车间信息(功能需求变更) // listDep = GetEntities(e => e.PARENT_ID.HasValue && e.PARENT_ID.Value == depLogin.PARENT_ID, null, null).ToList(); //} //else //{ // listDep = GetEntities(e => e.PARENT_ID.HasValue && e.PARENT_ID.Value == depID, null, null).ToList(); //} if (depLogin.DEPARTMENT_TYPE == 20) { //班组级 因数据少不好看 显示车间信息(功能需求变更) listDep = GetEntities(e => e.ID == depLogin.PARENT_ID.Value, null, null).ToList(); } else { if (depLogin.DEPARTMENT_STATUS == 2)//安环 看公司级 { listDep.Add(GetEntity(e => e.DEPARTMENT_TYPE == 5 && !e.IS_DELETED)); } else { listDep.Add(depLogin); } } if (!listDep.Any()) { return result; } #region //隐患原因 List listReasonT = BIHomeService.GetHomeReasons(filter.OrgId, listDep).ToList(); List listReason = new List(); int reasonMax = listReasonT.Max(e => e.NUMS); //List listEnumVal = new List { 5, 10, 15, 20 }; List LISTNAME = new List();// { "按时整改隐患", "超期整改隐患", "未整改隐患", "隐患整改率" }; HomeRISKREASON model = null; List LISVALUE = null; for (int i = 0; i < listReasonT.Count; i++) { if (i == 0 || listReasonT[i].DEPARTMENT_ID != listReasonT[i - 1].DEPARTMENT_ID) { model = new HomeRISKREASON(); model.DEPARTMENTNAME = listReasonT[i].DEPARTMENTNAME; model.YEAR = listReasonT[i].YEAR; model.SOURCENAME = listReasonT[i].SOURCENAME; LISVALUE = new List(); } LISVALUE.Add(listReasonT[i].COUNT); if (LISTNAME.Count < reasonMax) { LISTNAME.Add(listReasonT[i].SOURCENAME); } if (listReasonT[i].NUMS == 1) { model.NAME1 = listReasonT[i].SOURCENAME; model.COUNT1 = listReasonT[i].COUNT; } if (listReasonT[i].NUMS == 2) { model.NAME2 = listReasonT[i].SOURCENAME; model.COUNT2 = listReasonT[i].COUNT; } if (listReasonT[i].NUMS == 3) { model.NAME3 = listReasonT[i].SOURCENAME; model.COUNT3 = listReasonT[i].COUNT; } if (listReasonT[i].NUMS == 4) { model.NAME4 = listReasonT[i].SOURCENAME; model.COUNT4 = listReasonT[i].COUNT; } if (listReasonT[i].NUMS == 5) { model.NAME5 = listReasonT[i].SOURCENAME; model.COUNT5 = listReasonT[i].COUNT; } if (reasonMax == listReasonT[i].NUMS) { model.LISVALUE = LISVALUE; model.LISTNAME = LISTNAME; listReason.Add(model); } } result.ListR = listReason; #endregion #region //月度 隐患整改情况 //List listLoginDep = new List(); //if (APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID.HasValue) //{ // listLoginDep.Add(depLogin); //} //else //{ // //公司级 // //listLoginDep = listDep; // listLoginDep = GetEntities(e => e.DEPARTMENT_TYPE == 5 && !e.IS_DELETED && e.ENABLE_STATUS == 0, null, null).ToList(); //} //List listCorrectT = BIHomeService.GetHomeCorrect(filter.OrgId, listLoginDep).ToList(); //月度 整改情况 //公司/部门/车间 显示本组织 的数据 //班组 显示 车间的数据 //List listDepC = new List(); //if (depLogin.DEPARTMENT_TYPE == 20) //{ // //depLogin // listDepC.Add(GetEntity(e => e.ID == depLogin.PARENT_ID.Value)); //} //else //{ // if (depLogin.DEPARTMENT_STATUS == 2)//安环 看公司级 // { // listDepC.Add(GetEntity(e => e.DEPARTMENT_TYPE == 5 && !e.IS_DELETED)); // } // else // { // listDepC.Add(depLogin); // } //} //List listCorrectT = BIHomeService.GetHomeCorrect(filter.OrgId, listDepC).ToList(); ////List listCorrectT = BIHomeService.GetHomeCorrect(filter.OrgId, listDep).ToList(); List listCorrectT = BIHomeService.GetHomeCorrect(filter.OrgId, listDep).ToList(); 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() + "月"; List listC = new List(); HomeCorrect modelC = null; for (int i = 0; i < listCorrectT.Count; i++) { if (i == 0 || listCorrectT[i].DEPARTMENT_ID != listCorrectT[i - 1].DEPARTMENT_ID || listCorrectT[i].SOURCEVAL != listCorrectT[i - 1].SOURCEVAL) { modelC = new HomeCorrect(); modelC.DEPARTMENTNAME = listCorrectT[i].DEPARTMENTNAME; modelC.DEPARTMENT_ID = listCorrectT[i].DEPARTMENT_ID; modelC.SOURCENAME = listCorrectT[i].SOURCENAME; modelC.YEAR = listCorrectT[i].YEAR; modelC.NAME = NameMonth; Val = ""; } if (listCorrectT[i].MONTH == 1) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M1 = listCorrectT[i].PERCENT.ToString("0.00"); } else { modelC.M1 = listCorrectT[i].COUNT.ToString(); } Val += modelC.M1 + ","; } if (listCorrectT[i].MONTH == 2) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M2 = listCorrectT[i].PERCENT.ToString("0.00"); } else { modelC.M2 = listCorrectT[i].COUNT.ToString(); } Val += modelC.M2 + ","; } if (listCorrectT[i].MONTH == 3) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M3 = listCorrectT[i].PERCENT.ToString("0.00"); } else { modelC.M3 = listCorrectT[i].COUNT.ToString(); } Val += modelC.M3 + ","; } if (listCorrectT[i].MONTH == 4) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M4 = listCorrectT[i].PERCENT.ToString("0.00"); } else { modelC.M4 = listCorrectT[i].COUNT.ToString(); } Val += modelC.M4 + ","; } if (listCorrectT[i].MONTH == 5) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M5 = listCorrectT[i].PERCENT.ToString("0.00"); } else { modelC.M5 = listCorrectT[i].COUNT.ToString(); } Val += modelC.M5 + ","; } if (listCorrectT[i].MONTH == 6) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M6 = listCorrectT[i].PERCENT.ToString("0.00"); } else { modelC.M6 = listCorrectT[i].COUNT.ToString(); } Val += modelC.M6 + ","; } if (listCorrectT[i].MONTH == 7) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M7 = listCorrectT[i].PERCENT.ToString("0.00"); } else { modelC.M7 = listCorrectT[i].COUNT.ToString(); } Val += modelC.M7 + ","; } if (listCorrectT[i].MONTH == 8) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M8 = listCorrectT[i].PERCENT.ToString("0.00"); } else { modelC.M8 = listCorrectT[i].COUNT.ToString(); } Val += modelC.M8 + ","; } if (listCorrectT[i].MONTH == 9) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M9 = listCorrectT[i].PERCENT.ToString("0.00"); } else { modelC.M9 = listCorrectT[i].COUNT.ToString(); } Val += modelC.M9 + ","; } if (listCorrectT[i].MONTH == 10) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M10 = listCorrectT[i].PERCENT.ToString("0.00"); } else { modelC.M10 = listCorrectT[i].COUNT.ToString(); } Val += modelC.M10 + ","; } if (listCorrectT[i].MONTH == 11) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M11 = listCorrectT[i].PERCENT.ToString("0.00"); } else { modelC.M11 = listCorrectT[i].COUNT.ToString(); } Val += modelC.M11 + ","; } if (listCorrectT[i].MONTH == 12) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M12 = listCorrectT[i].PERCENT.ToString("0.00"); } else { modelC.M12 = listCorrectT[i].COUNT.ToString(); } Val += modelC.M12 + ","; } if (listCorrectT[i].MONTH == dtNow.Month) { modelC.Val = Val.Substring(0, Val.Length - 1); listC.Add(modelC); } } result.ListC = listC; #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 (listDep1MineType != null && listDep1MineType.Any()) { List ListSafeCheckYearMonth = new List(); int befoMonth = 12; List ListSafeCheckYearMonthT = BIHomeService.GetHomeCheckCountMonth(filter.OrgId, listDep1MineType.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_ENUMS_ID == enums.ID, null, null); if (listTypeMine != null && listTypeMine.Any()) { var listMineCheckTypeID = listTypeMine.Where(e => e.CHECK_TYPE_ID.HasValue).Select(e => e.CHECK_TYPE_ID.Value); for (int i = 0; i < listCheckTypeIDT.Count; i++) { if (!listMineCheckTypeID.Contains(listCheckTypeIDT[i])) { listCheckTypeIDT.RemoveAt(i); i--; } } } } var listCheckType = GetEntities(e => listCheckTypeIDT.Contains(e.ID), null, null).OrderBy(e => e.PARENT_ID).ThenBy(e => e.NUM).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) { if (IDZH == Guid.Empty) { IDZH = listCheckType[i].PARENT_ID.Value; 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 return result; }); } /// /// 查询所有数据 /// /// 过滤实体 /// [HttpPost, Route("GetHomeInfoOld")] public JsonActionResult GetHomeInfoOld([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 redisCode = string.Format(RedisCacheKey.HomeResult, APT.Infrastructure.Api.AppContext.CurrentSession.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.ListR != 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.DEPARTMENT_TYPE == 10, null, null);//部门就可以了 因为都相向 统计了 #endregion if (listDep1MineType == null || !listDep1MineType.Any()) { return result; } List listDep = new List(); listDep = listDep1MineType.ToList(); #region //月度 隐患整改情况 List listCorrectT = BIHomeService.GetHomeCorrect(filter.OrgId, listDep).ToList(); 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 modelCorr = listCorrectT.Where(e => e.YEAR == dtNow.Year && e.MONTH == dtNow.Month); if (modelCorr == null) { isNormal = false; } #region 组织合并 #region 新版 有组织合并 if (listCorrectT != null && listCorrectT.Any()) { var depID = listCorrectT[0].DEPARTMENT_ID; for (int i = 0; i < listCorrectT.Count; i++) { if (depID != listCorrectT[i].DEPARTMENT_ID) { continue; } //else if(listC.) { } //处理此信息 var Temp = listCorrectT.Where(e => e.YEAR == listCorrectT[i].YEAR && e.MONTH == listCorrectT[i].MONTH && e.SOURCEVAL == listCorrectT[i].SOURCEVAL); if (i == 0 || listCorrectT[i].SOURCEVAL != listCorrectT[i - 1].SOURCEVAL) { if (!isNormal && !string.IsNullOrEmpty(Val) && modelC != null) { modelC.Val = Val + "0"; listC.Add(modelC); } modelC = new HomeCorrect(); modelC.DEPARTMENTNAME = listCorrectT[i].DEPARTMENTNAME; modelC.DEPARTMENT_ID = listCorrectT[i].DEPARTMENT_ID; modelC.SOURCENAME = listCorrectT[i].SOURCENAME; modelC.YEAR = listCorrectT[i].YEAR; modelC.NAME = NameMonth; Val = ""; } if (listCorrectT[i].MONTH == 1) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M1 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00");//listCorrectT[i].PERCENT } else { modelC.M1 = Temp.Sum(e => e.COUNT).ToString();//listCorrectT[i].COUNT } Val += modelC.M1 + ","; } if (listCorrectT[i].MONTH == 2) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M2 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00"); } else { modelC.M2 = Temp.Sum(e => e.COUNT).ToString(); } Val += modelC.M2 + ","; } if (listCorrectT[i].MONTH == 3) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M3 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00"); } else { modelC.M3 = Temp.Sum(e => e.COUNT).ToString(); } Val += modelC.M3 + ","; } if (listCorrectT[i].MONTH == 4) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M4 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00"); } else { modelC.M4 = Temp.Sum(e => e.COUNT).ToString(); } Val += modelC.M4 + ","; } if (listCorrectT[i].MONTH == 5) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M5 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00"); } else { modelC.M5 = Temp.Sum(e => e.COUNT).ToString(); } Val += modelC.M5 + ","; } if (listCorrectT[i].MONTH == 6) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M6 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00"); } else { modelC.M6 = Temp.Sum(e => e.COUNT).ToString(); } Val += modelC.M6 + ","; } if (listCorrectT[i].MONTH == 7) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M7 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00"); } else { modelC.M7 = Temp.Sum(e => e.COUNT).ToString(); } Val += modelC.M7 + ","; } if (listCorrectT[i].MONTH == 8) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M8 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00"); } else { modelC.M8 = Temp.Sum(e => e.COUNT).ToString(); } Val += modelC.M8 + ","; } if (listCorrectT[i].MONTH == 9) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M9 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00"); } else { modelC.M9 = Temp.Sum(e => e.COUNT).ToString(); } Val += modelC.M9 + ","; } if (listCorrectT[i].MONTH == 10) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M10 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00"); } else { modelC.M10 = Temp.Sum(e => e.COUNT).ToString(); } Val += modelC.M10 + ","; } if (listCorrectT[i].MONTH == 11) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M11 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00"); } else { modelC.M11 = Temp.Sum(e => e.COUNT).ToString(); } Val += modelC.M11 + ","; } if (listCorrectT[i].MONTH == 12) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M12 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00"); } else { modelC.M12 = Temp.Sum(e => e.COUNT).ToString(); } Val += modelC.M12 + ","; } if (isNormal && listCorrectT[i].MONTH == dtNow.Month && listCorrectT[i].YEAR == dtNow.Year) { //有当月数据 是当前月的时候 放入数据 modelC.Val = Val.Substring(0, Val.Length - 1); listC.Add(modelC); } } result.ListC = listC; } else { result.ListC = listC; } #endregion #region 旧版 //for (int i = 0; i < listCorrectT.Count; i++) //{ // if (i == 0 || listCorrectT[i].DEPARTMENT_ID != listCorrectT[i - 1].DEPARTMENT_ID || listCorrectT[i].SOURCEVAL != listCorrectT[i - 1].SOURCEVAL) // { // if (!isNormal && !string.IsNullOrEmpty(Val) && modelC != null) // { // modelC.Val = Val + "0"; // listC.Add(modelC); // } // modelC = new HomeCorrect(); // modelC.DEPARTMENTNAME = listCorrectT[i].DEPARTMENTNAME; // modelC.DEPARTMENT_ID = listCorrectT[i].DEPARTMENT_ID; // modelC.SOURCENAME = listCorrectT[i].SOURCENAME; // modelC.YEAR = listCorrectT[i].YEAR; // modelC.NAME = NameMonth; // Val = ""; // } // //处理此信息 // var Temp = listCorrectT.Where(e => e.YEAR == listCorrectT[i].YEAR && e.MONTH == listCorrectT[i].MONTH && e.SOURCEVAL == listCorrectT[i].SOURCEVAL); // if (listCorrectT[i].MONTH == 1) // { // if (listCorrectT[i].SOURCEVAL == 20) // { // modelC.M1 = listCorrectT[i].PERCENT.ToString("0.00"); // } // else // { // modelC.M1 = listCorrectT[i].COUNT.ToString(); // } // Val += modelC.M1 + ","; // } // if (listCorrectT[i].MONTH == 2) // { // if (listCorrectT[i].SOURCEVAL == 20) // { // modelC.M2 = listCorrectT[i].PERCENT.ToString("0.00"); // } // else // { // modelC.M2 = listCorrectT[i].COUNT.ToString(); // } // Val += modelC.M2 + ","; // } // if (listCorrectT[i].MONTH == 3) // { // if (listCorrectT[i].SOURCEVAL == 20) // { // modelC.M3 = listCorrectT[i].PERCENT.ToString("0.00"); // } // else // { // modelC.M3 = listCorrectT[i].COUNT.ToString(); // } // Val += modelC.M3 + ","; // } // if (listCorrectT[i].MONTH == 4) // { // if (listCorrectT[i].SOURCEVAL == 20) // { // modelC.M4 = listCorrectT[i].PERCENT.ToString("0.00"); // } // else // { // modelC.M4 = listCorrectT[i].COUNT.ToString(); // } // Val += modelC.M4 + ","; // } // if (listCorrectT[i].MONTH == 5) // { // if (listCorrectT[i].SOURCEVAL == 20) // { // modelC.M5 = listCorrectT[i].PERCENT.ToString("0.00"); // } // else // { // modelC.M5 = listCorrectT[i].COUNT.ToString(); // } // Val += modelC.M5 + ","; // } // if (listCorrectT[i].MONTH == 6) // { // if (listCorrectT[i].SOURCEVAL == 20) // { // modelC.M6 = listCorrectT[i].PERCENT.ToString("0.00"); // } // else // { // modelC.M6 = listCorrectT[i].COUNT.ToString(); // } // Val += modelC.M6 + ","; // } // if (listCorrectT[i].MONTH == 7) // { // if (listCorrectT[i].SOURCEVAL == 20) // { // modelC.M7 = listCorrectT[i].PERCENT.ToString("0.00"); // } // else // { // modelC.M7 = listCorrectT[i].COUNT.ToString(); // } // Val += modelC.M7 + ","; // } // if (listCorrectT[i].MONTH == 8) // { // if (listCorrectT[i].SOURCEVAL == 20) // { // modelC.M8 = listCorrectT[i].PERCENT.ToString("0.00"); // } // else // { // modelC.M8 = listCorrectT[i].COUNT.ToString(); // } // Val += modelC.M8 + ","; // } // if (listCorrectT[i].MONTH == 9) // { // if (listCorrectT[i].SOURCEVAL == 20) // { // modelC.M9 = listCorrectT[i].PERCENT.ToString("0.00"); // } // else // { // modelC.M9 = listCorrectT[i].COUNT.ToString(); // } // Val += modelC.M9 + ","; // } // if (listCorrectT[i].MONTH == 10) // { // if (listCorrectT[i].SOURCEVAL == 20) // { // modelC.M10 = listCorrectT[i].PERCENT.ToString("0.00"); // } // else // { // modelC.M10 = listCorrectT[i].COUNT.ToString(); // } // Val += modelC.M10 + ","; // } // if (listCorrectT[i].MONTH == 11) // { // if (listCorrectT[i].SOURCEVAL == 20) // { // modelC.M11 = listCorrectT[i].PERCENT.ToString("0.00"); // } // else // { // modelC.M11 = listCorrectT[i].COUNT.ToString(); // } // Val += modelC.M11 + ","; // } // if (listCorrectT[i].MONTH == 12) // { // if (listCorrectT[i].SOURCEVAL == 20) // { // modelC.M12 = listCorrectT[i].PERCENT.ToString("0.00"); // } // else // { // modelC.M12 = listCorrectT[i].COUNT.ToString(); // } // Val += modelC.M12 + ","; // } // if (isNormal && listCorrectT[i].MONTH == dtNow.Month && listCorrectT[i].YEAR == dtNow.Year) // { // //有当月数据 是当前月的时候 放入数据 // modelC.Val = Val.Substring(0, Val.Length - 1); // listC.Add(modelC); // } //} //result.ListC = listC; #endregion #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; }); } /// /// 查询所有数据 /// /// 过滤实体 /// [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(-5); 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 = currentTime; } 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 ?"100":((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 = "100"; 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 月度 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 checkNotices = GetEntities(e => e.APPLY_DEPARTMENT_ID.HasValue && e.CREATE_TIME.HasValue && e.CREATE_TIME.Value.Year == dtNow.Year && e.Nav_CheckType!=null && !e.Nav_CheckType.NAME.Contains("岗位排查"), newFilter); var checkIds = checkNotices.Select(t => t.CHECK_TYPE_ID).Distinct().ToList(); //var loginDepart = this.GetEntity(t => t.ID == APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID); var listCheckType = GetEntities(e => checkIds.Contains(e.ID), null, "Nav_ProductionUnit").OrderBy(t => t.PRODUCTION_UNIT_ID).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].Nav_ProductionUnit?.NAME + listCheckType[i].NAME); } } //IEnumerable listPerChearch = null; //IEnumerable listPerChearchPer = null; //var beginTime = Convert.ToDateTime(dtNow.Year + "-01-01 00:00:00"); //var endTime = Convert.ToDateTime(dtNow.Year + "-12-31 23:59:59"); 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 = currentTime; } if (i.Date >= dtNow.Date) { monthEnd = dtNow; } var listPerChearch = checkNotices.Where(t => t.CREATE_TIME >= monthStart && t.CREATE_TIME <= monthEnd).ToList(); HomeSafeCheckCountMonth modelper = new HomeSafeCheckCountMonth(); modelper.Total = listPerChearch.Count(); modelper.listSOURCENAME = listCheckTypeNAME; modelper.YEAR = monthStart.Year; modelper.MONTH = monthStart.Month; List listListCount = new List(); for (int j = 0; j < listCheckTypeID.Count; j++) { //if (listCheckTypeID[j] != IDZH) //{ var listPerChearchPer = listPerChearch.Where(e => e.CHECK_TYPE_ID == 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.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) /// /// 过滤实体 /// [HttpPost, Route("GetHomeDetailMonthCheckTypeOld")] public JsonActionResult GetHomeDetailMonthCheckTypeOld([FromBody] KeywordFilter filter) { return SafeExecute(() => { //按生产单元 获取数据 HomeDetailSafeCheckCountMonth result = new HomeDetailSafeCheckCountMonth(); //if (string.IsNullOrEmpty(filter.Keyword)) //{ // return result; //} //int MineType = int.Parse(filter.Keyword); BaseFilter filterD = new BaseFilter(); filterD.SelectField = new List { "ID", "NAME", "DEPARTMENT_TYPE", "PARENT_ID" }; var listDep1MineType = GetEntities(t => (t.DEPARTMENT_TYPE == 15 || t.DEPARTMENT_TYPE == 20), filterD, null); //FMDepartmentType 部门=0, 车间=1, 班组=2, 公司=3 if (listDep1MineType == null || !listDep1MineType.Any()) { return result; } List listDepIDCJ = listDep1MineType.Where(e => e.DEPARTMENT_TYPE == 15).Select(e => e.ID).ToList();//车间ID 用于 统计 每个月各类型的检查数量 DateTime dtNow = DateTime.Now; List listDepCJ = new List(); List listDepBZ = new List(); listDepCJ = listDep1MineType.Where(e => e.DEPARTMENT_TYPE == 15).OrderBy(e => e.NUM).ToList(); listDepBZ = listDep1MineType.Where(e => e.DEPARTMENT_TYPE == 20).OrderBy(e => e.NUM).ToList(); //T_FM_ENUMS enums = null; var loginDepart = this.GetEntity(t => t.ID == APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID); #region 月度 12 个月 安全检查、检查类型 数量 if (listDepCJ == null || listDepCJ.Count < 1 || listDepBZ == null || listDepBZ.Count < 1) { ////深度查找 部门 MineType 只能存一个值 //enums = GetEntity(e => e.VALUE == MineType && e.CODE == "BSMineTypeEnum"); //if (enums == null) //{ // throw new Exception("获取生产类型失败"); //} //var listDepID = GetEntities(e => e.ENUMS_ID == enums.ID, null, null).Select(e => e.DEPARTMENT_ID); //if (listDepID != null && listDepID.Any()) if (loginDepart != null) { listDep1MineType = GetEntities(t => t.PRODUCTION_UNIT_ID == loginDepart.PRODUCTION_UNIT_ID && (t.DEPARTMENT_TYPE == 15 || t.DEPARTMENT_TYPE == 20), filterD, null); if (listDep1MineType != null && listDep1MineType.Any()) { listDepCJ = listDep1MineType.Where(e => e.DEPARTMENT_TYPE == 15).ToList(); listDepBZ = listDep1MineType.Where(e => e.DEPARTMENT_TYPE == 20).ToList(); } } } if (listDepCJ == null || listDepCJ.Count < 1 || listDepBZ == null || listDepBZ.Count < 1) { throw new Exception("获取生产单元组织信息失败!"); } List ListSafeCheckYearMonth = new List(); int befoMonth = 11;//计算 12 个月 就是提前 11个月 List ListSafeCheckYearMonthT = BIHomeService.GetHomeCheckCountMonth(filter.OrgId, listDep1MineType.ToList(), befoMonth).ToList(); var listCheckTypeIDT = ListSafeCheckYearMonthT.Select(e => e.SOURCEID).Distinct().ToList(); //if (enums == null) //{ // enums = GetEntity(e => e.VALUE == MineType && e.CODE == "BSMineTypeEnum"); //} //if (enums != null) //{ // var listTypeMine = GetEntities(e => e.MINETYPE_ENUMS_ID == enums.ID, null, null); // if (listTypeMine != null && listTypeMine.Any()) // { // var listMineCheckTypeID = listTypeMine.Where(e => e.CHECK_TYPE_ID.HasValue).Select(e => e.CHECK_TYPE_ID.Value); // for (int i = 0; i < listCheckTypeIDT.Count; i++) // { // if (!listMineCheckTypeID.Contains(listCheckTypeIDT[i])) // { // listCheckTypeIDT.RemoveAt(i); // i--; // } // } // } //} var listCheckType = GetEntities(e => true, null, null).ToList(); if (loginDepart != null) { listCheckType = listCheckType.Where(t => t.PRODUCTION_UNIT_ID == loginDepart.PRODUCTION_UNIT_ID).ToList(); } //var listCheckType = GetEntities(e => listCheckTypeIDT.Contains(e.ID), null, null).OrderBy(e => e.PARENT_ID).ThenBy(e => e.NUM).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) //{ // if (IDZH == Guid.Empty) // { // IDZH = listCheckType[i].PARENT_ID.Value; // 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; 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 && listDepIDCJ.Contains(e.DEPARTMENT_ID));//只统计到车间 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); } #endregion result.ListSafeCheckYearMonth = ListSafeCheckYearMonth.OrderBy(e => e.YEAR).ThenBy(e => e.MONTH).ToList(); #region 表数据 List listCheckDepCountCJ = new List(); List listCheckDepCountBZ = new List(); List listCheckTypeCount = null; DetailSafeCheckCountDepartment modelCountDep = null; int checkTypeCount = listCheckTypeID.Count; foreach (var item in listDepCJ) { modelCountDep = new DetailSafeCheckCountDepartment(); modelCountDep.listName = listCheckTypeNAME; modelCountDep.PARENT_ID = item.PARENT_ID.Value; modelCountDep.Department_ID = item.ID; modelCountDep.NUM = item.NUM; modelCountDep.RowCount = listDepBZ.Where(e => e.PARENT_ID.HasValue && e.PARENT_ID.Value == item.ID).Count(); modelCountDep.DepartmentName = item.NAME; modelCountDep.DepartmentType = item.DEPARTMENT_TYPE; listCheckTypeCount = new List(); for (int i = 0; i < checkTypeCount; i++) { listCheckTypeCount.Add(ListSafeCheckYearMonthT.Where(e => e.SOURCEID == listCheckTypeID[i] && e.DEPARTMENT_ID == item.ID).Sum(e => e.COUNT)); } modelCountDep.listCount = listCheckTypeCount; listCheckDepCountCJ.Add(modelCountDep); } foreach (var item in listDepBZ) { modelCountDep = new DetailSafeCheckCountDepartment(); modelCountDep.listName = listCheckTypeNAME; modelCountDep.PARENT_ID = item.PARENT_ID.Value; modelCountDep.Department_ID = item.ID; modelCountDep.NUM = item.NUM; modelCountDep.RowCount = 1; modelCountDep.DepartmentName = item.NAME; modelCountDep.DepartmentType = item.DEPARTMENT_TYPE; listCheckTypeCount = new List(); for (int i = 0; i < checkTypeCount; i++) { listCheckTypeCount.Add(ListSafeCheckYearMonthT.Where(e => e.SOURCEID == listCheckTypeID[i] && e.DEPARTMENT_ID == item.ID).Sum(e => e.COUNT)); } modelCountDep.listCount = listCheckTypeCount; listCheckDepCountBZ.Add(modelCountDep); } //result.ListSafeCheckCountDepartmentBZ = listCheckDepCountBZ; foreach (var item in listCheckDepCountCJ) { item.listChild = listCheckDepCountBZ.Where(e => e.PARENT_ID == item.Department_ID).OrderBy(e => e.NUM).ToList(); } #endregion //result.ListSafeCheckCountDepartment = listCheckDepCountCJ; //取明细 List ListSafeCheckYearMonthLast = new List(); int allIndex = 0; foreach (var item in listCheckDepCountCJ) { foreach (var itemC in item.listChild) { allIndex++; itemC.NUM = allIndex; itemC.Parent = item; ListSafeCheckYearMonthLast.Add(itemC); } } result.ListSafeCheckCountDepartment = ListSafeCheckYearMonthLast; return result; }); } /// /// 月度隐患整改情况(BI055HomeDetail) /// /// 过滤实体 /// [HttpPost, Route("GetHomeDetailMonthRiskOld")] public JsonActionResult GetHomeDetailMonthRiskOld([FromBody] KeywordFilter filter) { return SafeExecute(() => { //按生产单元 获取数据 HomeDetailRiskCountMonth result = new HomeDetailRiskCountMonth(); //if (string.IsNullOrEmpty(filter.Keyword)) //{ // return result; //} //int MineType = int.Parse(filter.Keyword); BaseFilter filterD = new BaseFilter(); filterD.SelectField = new List { "ID", "NAME", "DEPARTMENT_TYPE", "PARENT_ID" }; ///部门 //var listDep1MineTypeSum = GetEntities(t => t.MineType.HasValue && t.MineType == MineType && t.DEPARTMENT_TYPE == 10, filterD, null); ///车间 班组 var listDep1MineType = GetEntities(t => (t.DEPARTMENT_TYPE == 15 || t.DEPARTMENT_TYPE == 20 || t.DEPARTMENT_TYPE == 10), filterD, null); //FMDepartmentType 部门=0, 车间=1, 班组=2, 公司=3 if (listDep1MineType == null || !listDep1MineType.Any()) { return result; } DateTime dtNow = DateTime.Now; List listDepCJ = new List(); List listDepBZ = new List(); listDepCJ = listDep1MineType.Where(e => e.DEPARTMENT_TYPE == 15).OrderBy(e => e.NUM).ToList(); listDepBZ = listDep1MineType.Where(e => e.DEPARTMENT_TYPE == 20).OrderBy(e => e.NUM).ToList(); #region //月度 隐患整改情况 int MonthBefo = 11;//计算12个月 就是提前 11个月 List listCorrectT = BIHomeService.GetHomeCorrect(filter.OrgId, listDep1MineType.ToList(), MonthBefo).ToList(); 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 = String.Empty; for (int i = MonthBefo; i > -1; i--) { NameMonth += dtNow.AddMonths(-1 * i).ToString("yy-MM") + ","; } NameMonth = NameMonth.Substring(0, NameMonth.Length - 1); List listC = new List(); HomeCorrect modelC = null; bool isNormal = true;//数据是否正常 var modelCorr = listCorrectT.Where(e => e.YEAR == dtNow.Year && e.MONTH == dtNow.Month); if (modelCorr == null) { isNormal = false; } #region 组织合并 #region 新版 有组织合并 var listDepID = listDep1MineType.Where(e => e.DEPARTMENT_TYPE == 10).Select(e => e.ID); var depID = listCorrectT.FirstOrDefault(e => listDepID.Contains(e.DEPARTMENT_ID))?.DEPARTMENT_ID; if (depID == null) { return result; } for (int i = 0; i < listCorrectT.Count; i++) { if (depID != listCorrectT[i].DEPARTMENT_ID) { continue; } //else if(listC.) { } //处理此信息 var Temp = listCorrectT.Where(e => e.YEAR == listCorrectT[i].YEAR && e.MONTH == listCorrectT[i].MONTH && e.SOURCEVAL == listCorrectT[i].SOURCEVAL && listDepID.Contains(e.DEPARTMENT_ID)); //var listDepID = listDep1MineType.Where(e => e.DEPARTMENT_TYPE == 10).Select(e => e.ID);//部门ID //result.ListC = listC.Where(e => listDepID.Contains(e.DEPARTMENT_ID)).ToList(); if (i == 0 || listCorrectT[i].SOURCEVAL != listCorrectT[i - 1].SOURCEVAL) { if (!isNormal && !string.IsNullOrEmpty(Val) && modelC != null) { modelC.Val = Val + "0"; listC.Add(modelC); } modelC = new HomeCorrect(); modelC.DEPARTMENTNAME = listCorrectT[i].DEPARTMENTNAME; modelC.DEPARTMENT_ID = listCorrectT[i].DEPARTMENT_ID; modelC.SOURCENAME = listCorrectT[i].SOURCENAME; modelC.YEAR = listCorrectT[i].YEAR; modelC.NAME = NameMonth; Val = ""; } if (listCorrectT[i].MONTH == 1) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M1 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00");//listCorrectT[i].PERCENT } else { modelC.M1 = Temp.Sum(e => e.COUNT).ToString();//listCorrectT[i].COUNT } Val += modelC.M1 + ","; } if (listCorrectT[i].MONTH == 2) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M2 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00"); } else { modelC.M2 = Temp.Sum(e => e.COUNT).ToString(); } Val += modelC.M2 + ","; } if (listCorrectT[i].MONTH == 3) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M3 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00"); } else { modelC.M3 = Temp.Sum(e => e.COUNT).ToString(); } Val += modelC.M3 + ","; } if (listCorrectT[i].MONTH == 4) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M4 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00"); } else { modelC.M4 = Temp.Sum(e => e.COUNT).ToString(); } Val += modelC.M4 + ","; } if (listCorrectT[i].MONTH == 5) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M5 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00"); } else { modelC.M5 = Temp.Sum(e => e.COUNT).ToString(); } Val += modelC.M5 + ","; } if (listCorrectT[i].MONTH == 6) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M6 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00"); } else { modelC.M6 = Temp.Sum(e => e.COUNT).ToString(); } Val += modelC.M6 + ","; } if (listCorrectT[i].MONTH == 7) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M7 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00"); } else { modelC.M7 = Temp.Sum(e => e.COUNT).ToString(); } Val += modelC.M7 + ","; } if (listCorrectT[i].MONTH == 8) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M8 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00"); } else { modelC.M8 = Temp.Sum(e => e.COUNT).ToString(); } Val += modelC.M8 + ","; } if (listCorrectT[i].MONTH == 9) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M9 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00"); } else { modelC.M9 = Temp.Sum(e => e.COUNT).ToString(); } Val += modelC.M9 + ","; } if (listCorrectT[i].MONTH == 10) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M10 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00"); } else { modelC.M10 = Temp.Sum(e => e.COUNT).ToString(); } Val += modelC.M10 + ","; } if (listCorrectT[i].MONTH == 11) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M11 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00"); } else { modelC.M11 = Temp.Sum(e => e.COUNT).ToString(); } Val += modelC.M11 + ","; } if (listCorrectT[i].MONTH == 12) { if (listCorrectT[i].SOURCEVAL == 20) { modelC.M12 = ((decimal)1.0 * Temp.Sum(e => e.PERCENT) / Temp.Count()).ToString("0.00"); } else { modelC.M12 = Temp.Sum(e => e.COUNT).ToString(); } Val += modelC.M12 + ","; } if (isNormal && listCorrectT[i].MONTH == dtNow.Month && listCorrectT[i].YEAR == dtNow.Year) { //有当月数据 是当前月的时候 放入数据 modelC.Val = Val.Substring(0, Val.Length - 1); listC.Add(modelC); } } result.ListC = listC; #endregion #endregion //var listDepID = listDep1MineType.Where(e => e.DEPARTMENT_TYPE == 10).Select(e => e.ID);//部门ID //result.ListC = listC.Where(e => listDepID.Contains(e.DEPARTMENT_ID)).ToList(); #endregion #region 子表信息 //BSCorrectType List enums = DataHelper.GetEnum("BSCorrectType"); List listName = new List(); List listVal = new List(); foreach (var item in enums) { listVal.Add(item.ID); listName.Add(item.NAME); } List listCheckDepCountCJ = new List(); List listCheckDepCountBZ = new List(); List listCheckTypeCount = null; DetailSafeCheckCountDepartment modelCountDep = null; int checkTypeCount = listVal.Count; int Percent = 3;//第4项 是辈分比 int All = 0; foreach (var item in listDepCJ) { modelCountDep = new DetailSafeCheckCountDepartment(); modelCountDep.listName = listName; modelCountDep.PARENT_ID = item.PARENT_ID.Value; modelCountDep.Department_ID = item.ID; modelCountDep.NUM = item.NUM; modelCountDep.RowCount = listDepBZ.Where(e => e.PARENT_ID.HasValue && e.PARENT_ID.Value == item.ID).Count(); modelCountDep.DepartmentName = item.NAME; modelCountDep.DepartmentType = item.DEPARTMENT_TYPE; listCheckTypeCount = new List(); for (int i = 0; i < checkTypeCount; i++) { if (Percent == i) { All = listCheckTypeCount[0] + listCheckTypeCount[1] + listCheckTypeCount[2]; if (All == 0) { listCheckTypeCount.Add(10000); } else { listCheckTypeCount.Add((int)(10000 * (listCheckTypeCount[0] + listCheckTypeCount[1]) / All)); } } else { listCheckTypeCount.Add(listCorrectT.Where(e => e.SOURCEVAL == listVal[i] && e.DEPARTMENT_ID == item.ID).Sum(e => e.COUNT)); } } modelCountDep.listCount = listCheckTypeCount; listCheckDepCountCJ.Add(modelCountDep); } foreach (var item in listDepBZ) { modelCountDep = new DetailSafeCheckCountDepartment(); modelCountDep.listName = listName; modelCountDep.PARENT_ID = item.PARENT_ID.Value; modelCountDep.Department_ID = item.ID; modelCountDep.NUM = item.NUM; modelCountDep.RowCount = 1; modelCountDep.DepartmentName = item.NAME; modelCountDep.DepartmentType = item.DEPARTMENT_TYPE; listCheckTypeCount = new List(); for (int i = 0; i < checkTypeCount; i++) { if (Percent == i) { All = listCheckTypeCount[0] + listCheckTypeCount[1] + listCheckTypeCount[2]; if (All == 0) { listCheckTypeCount.Add(10000); } else { listCheckTypeCount.Add((int)(10000 * (listCheckTypeCount[0] + listCheckTypeCount[1]) / All)); } } else { listCheckTypeCount.Add(listCorrectT.Where(e => e.SOURCEVAL == listVal[i] && e.DEPARTMENT_ID == item.ID).Sum(e => e.COUNT)); } } modelCountDep.listCount = listCheckTypeCount; listCheckDepCountBZ.Add(modelCountDep); } foreach (var item in listCheckDepCountCJ) { item.listChild = listCheckDepCountBZ.Where(e => e.PARENT_ID == item.Department_ID).OrderBy(e => e.NUM).ToList(); } //result.ListSafeCheckYearMonth = listCheckDepCountCJ; //取明细 List ListSafeCheckYearMonth = new List(); int allIndex = 0; foreach (var item in listCheckDepCountCJ) { foreach (var itemC in item.listChild) { allIndex++; itemC.NUM = allIndex; itemC.Parent = item; ListSafeCheckYearMonth.Add(itemC); } } result.ListSafeCheckYearMonth = ListSafeCheckYearMonth; #endregion return result; }); } /// /// 首页 安全检查次数统计明细(BI054HomeDetail) /// /// 过滤实体 /// [HttpPost, Route("GetHomeDetailMonthCheckType")] public JsonActionResult GetHomeDetailMonthCheckType([FromBody] KeywordFilter filter) { return SafeExecute(() => { //按生产单元 获取数据 HomeDetailSafeCheckCountMonth result = new HomeDetailSafeCheckCountMonth(); //if (string.IsNullOrEmpty(filter.Keyword)) //{ // return result; //} //int MineType = int.Parse(filter.Keyword); var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId; BaseFilter filterD = new BaseFilter(orgId); filterD.SelectField = new List { "ID", "NAME", "DEPARTMENT_TYPE", "PARENT_ID","NUM", "DEPARTMENT_STATUS" }; var listDep1MineType = GetEntities(t => t.ENABLE_STATUS == 0 && t.CATEGORY == FMCATEGORY.ACTURE, filterD, null); //FMDepartmentType 部门=0, 车间=1, 班组=2, 公司=3 if (listDep1MineType == null || !listDep1MineType.Any()) { return result; } //List listDepIDCJ = listDep1MineType.Where(e => e.DEPARTMENT_TYPE == 15).Select(e => e.ID).ToList();//车间ID 用于 统计 每个月各类型的检查数量 DateTime dtNow = DateTime.Now; List listDepCJ = new List(); List listDepBZ = new List(); //List listDepBM = new List(); //listDepBM = listDep1MineType.Where(e => e.DEPARTMENT_TYPE == 10 || e.DEPARTMENT_STATUS == 2).OrderBy(e => e.NUM).ToList(); listDepCJ = listDep1MineType.Where(e => e.DEPARTMENT_TYPE == 10 || e.DEPARTMENT_STATUS == 2).OrderBy(e => e.NUM).ToList(); listDepBZ = listDep1MineType.Where(e => e.DEPARTMENT_TYPE == 15 ||e.DEPARTMENT_TYPE == 20).OrderBy(t => t.DEPARTMENT_TYPE).ThenBy(e => e.NUM).ToList(); //T_FM_ENUMS enums = null; var loginDepart = this.GetEntity(t => t.ID == APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID); #region 月度 12 个月 安全检查、检查类型 数量 //if (listDepCJ == null || listDepCJ.Count < 1 || listDepBZ == null || listDepBZ.Count < 1) //{ // ////深度查找 部门 MineType 只能存一个值 // //enums = GetEntity(e => e.VALUE == MineType && e.CODE == "BSMineTypeEnum"); // //if (enums == null) // //{ // // throw new Exception("获取生产类型失败"); // //} // //var listDepID = GetEntities(e => e.ENUMS_ID == enums.ID, null, null).Select(e => e.DEPARTMENT_ID); // //if (listDepID != null && listDepID.Any()) // if (loginDepart != null) // { // listDep1MineType = GetEntities(t => t.PRODUCTION_UNIT_ID == loginDepart.PRODUCTION_UNIT_ID && (t.DEPARTMENT_TYPE == 15 || t.DEPARTMENT_TYPE == 20), filterD, null); // if (listDep1MineType != null && listDep1MineType.Any()) // { // listDepCJ = listDep1MineType.Where(e => e.DEPARTMENT_TYPE == 15).ToList(); // listDepBZ = listDep1MineType.Where(e => e.DEPARTMENT_TYPE == 20).ToList(); // } // } //} //if (listDepCJ == null || listDepCJ.Count < 1 || listDepBZ == null || listDepBZ.Count < 1) //{ // throw new Exception("获取生产单元组织信息失败!"); //} var newFilter = new BaseFilter(orgId); newFilter.IgnoreDataRule = true; var startTime = dtNow.AddMonths(-11); var checkNotices = GetEntities(e => e.APPLY_DEPARTMENT_ID.HasValue && e.CREATE_TIME.HasValue && e.CREATE_TIME >= startTime && e.Nav_CheckType!=null && !e.Nav_CheckType.NAME.Contains("岗位排查"), newFilter); var noticeIds = checkNotices.Select(t => t.ID).ToList(); var checkRecords = GetEntities(e => e.SECURITY_INSPECTION_NOTICE_ID.HasValue && noticeIds.Contains((Guid)e.SECURITY_INSPECTION_NOTICE_ID), newFilter); var currentTime = Convert.ToDateTime(startTime.Year + "-" + startTime.Month + "-01 00:00:00"); List ListSafeCheckYearMonth = new List(); //int befoMonth = 11;//计算 12 个月 就是提前 11个月 //List ListSafeCheckYearMonthT = BIHomeService.GetHomeCheckCountMonth(filter.OrgId, listDep1MineType.ToList(), befoMonth).ToList(); var listCheckTypeIDT = checkNotices.Select(e => e.CHECK_TYPE_ID).Distinct().ToList(); //if (enums == null) //{ // enums = GetEntity(e => e.VALUE == MineType && e.CODE == "BSMineTypeEnum"); //} //if (enums != null) //{ // var listTypeMine = GetEntities(e => e.MINETYPE_ENUMS_ID == enums.ID, null, null); // if (listTypeMine != null && listTypeMine.Any()) // { // var listMineCheckTypeID = listTypeMine.Where(e => e.CHECK_TYPE_ID.HasValue).Select(e => e.CHECK_TYPE_ID.Value); // for (int i = 0; i < listCheckTypeIDT.Count; i++) // { // if (!listMineCheckTypeID.Contains(listCheckTypeIDT[i])) // { // listCheckTypeIDT.RemoveAt(i); // i--; // } // } // } //} var listCheckType = GetEntities(e => listCheckTypeIDT.Contains(e.ID), null, "Nav_ProductionUnit").OrderBy(t=>t.PRODUCTION_UNIT_ID).ToList(); //if (loginDepart != null) //{ // listCheckType = listCheckType.Where(t => t.PRODUCTION_UNIT_ID == loginDepart.PRODUCTION_UNIT_ID).ToList(); //} //var listCheckType = GetEntities(e => listCheckTypeIDT.Contains(e.ID), null, null).OrderBy(e => e.PARENT_ID).ThenBy(e => e.NUM).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) //{ // if (IDZH == Guid.Empty) // { // IDZH = listCheckType[i].PARENT_ID.Value; // 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].Nav_ProductionUnit?.NAME+listCheckType[i].NAME); } } //int year = DateTime.Now.Year; //int Month = DateTime.Now.Month; //DateTime dtTemp = DateTime.Now; //IEnumerable listPerChearch = null; //IEnumerable listPerChearchPer = null; 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 = currentTime; } if (i.Date >= dtNow.Date) { monthEnd = dtNow; } var listPerChearch = checkNotices.Where(t => t.CREATE_TIME >= monthStart && t.CREATE_TIME <= monthEnd); HomeSafeCheckCountMonth modelper = new HomeSafeCheckCountMonth(); modelper.Total = listPerChearch.Count(); modelper.listSOURCENAME = listCheckTypeNAME; modelper.YEAR = monthStart.Year; modelper.MONTH = monthStart.Month; List listListCount = new List(); for (int j = 0; j < listCheckTypeID.Count; j++) { //if (listCheckTypeID[j] != IDZH) //{ var listPerChearchPer = listPerChearch.Where(e => e.CHECK_TYPE_ID == listCheckTypeID[j]);//各个检查 if (listPerChearchPer == null || !listPerChearchPer.Any()) { listListCount.Add(0); } else { listListCount.Add(listPerChearchPer.Count()); } } modelper.listListCount = listListCount; ListSafeCheckYearMonth.Add(modelper); } #endregion result.ListSafeCheckYearMonth = ListSafeCheckYearMonth.OrderBy(e => e.YEAR).ThenBy(e => e.MONTH).ToList(); #region 表数据 List listCheckDepCountCJ = new List(); List listCheckDepCountBZ = new List(); List listName = new List() { "计划检查次数", "实际检查次数" }; List listCheckTypeCount = null; DetailSafeCheckCountDepartment modelCountDep = null; int checkTypeCount = listCheckTypeID.Count; //foreach (var item in listDepBM) //{ // var parentIds = listDepCJ.Where(e => e.PARENT_ID.HasValue && e.PARENT_ID.Value == item.ID).Select(t => t.ID).ToList(); // var bzIds = listDepBZ.Where(e => e.PARENT_ID.HasValue && parentIds.Contains(e.PARENT_ID.Value)).Select(t => t.ID).ToList(); // var alls = checkNotices.Where(t => t.APPLY_DEPARTMENT_ID == item.ID || parentIds.Contains((Guid)t.APPLY_DEPARTMENT_ID) || bzIds.Contains((Guid)t.APPLY_DEPARTMENT_ID)).ToList(); // if (alls.Count() > 0) // { // modelCountDep = new DetailSafeCheckCountDepartment(); // modelCountDep.listName = listName; // modelCountDep.PARENT_ID = item.PARENT_ID.Value; // modelCountDep.Department_ID = item.ID; // modelCountDep.NUM = item.NUM; // //modelCountDep.RowCount = listDepBZ.Where(e => e.PARENT_ID.HasValue && e.PARENT_ID.Value == item.ID).Count(); // modelCountDep.DepartmentName = item.NAME; // modelCountDep.DepartmentType = item.DEPARTMENT_TYPE; // listCheckTypeCount = new List(); // var count = alls.Count(); // listCheckTypeCount.Add(count); // var ids = alls.Select(t => t.ID).ToList(); // var countAct = checkRecords.Count(t => ids.Contains((Guid)t.SECURITY_INSPECTION_NOTICE_ID)); // listCheckTypeCount.Add(countAct); // modelCountDep.listCount = listCheckTypeCount; // listCheckDepCountCJ.Add(modelCountDep); // } //} foreach (var item in listDepCJ) { List parentIds = new List(); parentIds.Add(item.ID); List allIds = new List(); GetDepartmentIds(orgId.Value, parentIds, ref allIds); //var parentIdsx = listDep1MineType.Where(e => allIds.Contains(e.ID) && e.ID != item.ID).Select(t => t.ID).ToList(); var alls = checkNotices.Where(t =>t.APPLY_DEPARTMENT_ID == item.ID || allIds.Contains((Guid)t.APPLY_DEPARTMENT_ID)).ToList(); if (alls.Count() > 0) { //var idsx=alls.Where(e => e.APPLY_DEPARTMENT_ID != item.ID).Select(m => m.APPLY_DEPARTMENT_ID).Distinct().ToList(); modelCountDep = new DetailSafeCheckCountDepartment(); modelCountDep.listName = listName; modelCountDep.PARENT_ID = item.PARENT_ID.Value; modelCountDep.Department_ID = item.ID; modelCountDep.NUM = item.NUM; //modelCountDep.listChild = listDep1MineType.Where(e=>idsx.Contains(e.ID)).OrderBy(e => e.NUM).ToList(); //modelCountDep.RowCount = modelCountDep.listChild.Count(); //modelCountDep.RowCount = listDepBZ.Where(e => e.PARENT_ID.HasValue && e.PARENT_ID.Value == item.ID).Count(); modelCountDep.DepartmentName = item.NAME; modelCountDep.DepartmentType = item.DEPARTMENT_TYPE; listCheckTypeCount = new List(); var count = alls.Count(); listCheckTypeCount.Add(count); var ids = alls.Select(t => t.ID).ToList(); var countAct = checkRecords.Count(t => ids.Contains((Guid)t.SECURITY_INSPECTION_NOTICE_ID)); listCheckTypeCount.Add(countAct); modelCountDep.listCount = listCheckTypeCount; listCheckDepCountCJ.Add(modelCountDep); } } foreach (var item in listDepBZ) { var alls = checkNotices.Where(t => t.APPLY_DEPARTMENT_ID == item.ID).ToList(); var count = alls.Count(); if (count > 0) { modelCountDep = new DetailSafeCheckCountDepartment(); modelCountDep.listName = listName; modelCountDep.PARENT_ID = item.PARENT_ID.Value; modelCountDep.Department_ID = item.ID; modelCountDep.NUM = item.NUM; modelCountDep.RowCount = 1; modelCountDep.DepartmentName = item.NAME; modelCountDep.DepartmentType = item.DEPARTMENT_TYPE; listCheckTypeCount = new List(); listCheckTypeCount.Add(count); var ids = alls.Select(t => t.ID).ToList(); var countAct = checkRecords.Count(t => ids.Contains((Guid)t.SECURITY_INSPECTION_NOTICE_ID)); listCheckTypeCount.Add(countAct); modelCountDep.listCount = listCheckTypeCount; listCheckDepCountBZ.Add(modelCountDep); } } //result.ListSafeCheckCountDepartmentBZ = listCheckDepCountBZ; foreach (var item in listCheckDepCountCJ) { //if (item.DepartmentType == 10) //{ // var cjList = listCheckDepCountCJ.Where(e => e.PARENT_ID == item.Department_ID).OrderBy(e => e.NUM).ToList(); // var cjIds = listCheckDepCountCJ.Where(e => e.PARENT_ID == item.Department_ID).Select(e => e.Department_ID).ToList(); // var bzList = listCheckDepCountBZ.Where(e => cjIds.Contains(e.PARENT_ID)).OrderBy(e => e.NUM).ToList(); // cjList.AddRange(bzList); // item.listChild = cjList.ToList(); // item.RowCount = item.listChild.Count(); //} //if (item.DepartmentType == 15) var parentIds = listDepBZ.Where(e => e.PARENT_ID == item.Department_ID).Select(t => t.ID); var classIds = listDepBZ.Where(e => e.PARENT_ID!=null &&parentIds.Contains((Guid)e.PARENT_ID)).Select(t => t.ID); item.listChild = listCheckDepCountBZ.Where(e => e.Department_ID!=null && (classIds.Contains((Guid)e.Department_ID) || parentIds.Contains(e.Department_ID))).OrderBy(e => e.DepartmentType).ThenBy(t=>t.NUM).ToList(); item.RowCount = item.listChild.Count(); } #endregion //result.ListSafeCheckCountDepartment = listCheckDepCountCJ; //取明细 List ListSafeCheckYearMonthLast = new List(); int allIndex = 0; foreach (var item in listCheckDepCountCJ) { if (item.listChild.Count() == 0) { allIndex++; item.NUM = allIndex; item.Parent = item; ListSafeCheckYearMonthLast.Add(item); } else { foreach (var itemC in item.listChild) { allIndex++; itemC.NUM = allIndex; itemC.Parent = item; ListSafeCheckYearMonthLast.Add(itemC); } } } result.ListSafeCheckCountDepartment = ListSafeCheckYearMonthLast; return result; }); } /// /// 月度隐患整改情况(BI055HomeDetail) /// /// 过滤实体 /// [HttpPost, Route("GetHomeDetailMonthRisk")] public JsonActionResult GetHomeDetailMonthRisk([FromBody] KeywordFilter filter) { return SafeExecute(() => { //按生产单元 获取数据 HomeDetailRiskCountMonth result = new HomeDetailRiskCountMonth(); //if (string.IsNullOrEmpty(filter.Keyword)) //{ // return result; //} //int MineType = int.Parse(filter.Keyword); var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId; BaseFilter filterD = new BaseFilter(orgId); filterD.SelectField = new List { "ID", "NAME", "DEPARTMENT_TYPE", "PARENT_ID", "NUM" , "DEPARTMENT_STATUS" }; ///部门 //var listDep1MineTypeSum = GetEntities(t => t.MineType.HasValue && t.MineType == MineType && t.DEPARTMENT_TYPE == 10, filterD, null); ///车间 班组 var listDep1MineType = GetEntities(t => t.ENABLE_STATUS == 0, filterD, null); //FMDepartmentType 部门=0, 车间=1, 班组=2, 公司=3 if (listDep1MineType == null || !listDep1MineType.Any()) { return result; } DateTime dtNow = DateTime.Now; List listDepCJ = new List(); List listDepBZ = new List(); listDepCJ = listDep1MineType.Where(e => e.DEPARTMENT_TYPE == 10 || e.DEPARTMENT_STATUS==2).OrderBy(e => e.NUM).ToList(); listDepBZ = listDep1MineType.Where(e => e.DEPARTMENT_TYPE == 15 || e.DEPARTMENT_TYPE == 20).OrderBy(t=>t.DEPARTMENT_TYPE).ThenBy(e => e.NUM).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 startTime = dtNow.AddMonths(-11); var hiddens = GetEntities(e => e.APPLY_DEPARTMENT_ID.HasValue && e.CREATE_TIME.HasValue && e.CREATE_TIME >= startTime, newFilter); 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 = currentTime; } 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 ? "100" : ((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 = "100"; 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 子表信息 //BSCorrectType //List enums = DataHelper.GetEnum("BSCorrectType"); List listName = new List() { "按时整改隐患", "超期整改隐患", "未整改隐患", "隐患整改率" }; //List listVal = new List(); //foreach (var item in enums) //{ // listVal.Add(item.ID); // listName.Add(item.NAME); //} List listCheckDepCountCJ = new List(); List listCheckDepCountBZ = new List(); List listCheckTypeCount = null; DetailSafeCheckCountDepartment modelCountDep = null; //int checkTypeCount = listVal.Count; int Percent = 3;//第4项 是辈分比 int All = 0; foreach (var item in listDepCJ) { List parentIds = new List(); parentIds.Add(item.ID); List allIds = new List(); GetDepartmentIds(orgId.Value, parentIds, ref allIds); //var parentIdsx = listDep1MineType.Where(e => allIds.Contains(e.ID) && e.ID != item.ID).Select(t => t.ID).ToList(); var alls = hiddens.Where(t => t.APPLY_DEPARTMENT_ID == item.ID || allIds.Contains((Guid)t.APPLY_DEPARTMENT_ID)).ToList(); //var classIds = listDepBZ.Where(e => e.PARENT_ID.HasValue && e.PARENT_ID.Value == item.ID).Select(t => t.ID); //var alls = hiddens.Where(t => t.APPLY_DEPARTMENT_ID == item.ID || classIds.Contains((Guid)t.APPLY_DEPARTMENT_ID)); if (alls.Count() > 0) { modelCountDep = new DetailSafeCheckCountDepartment(); modelCountDep.listName = listName; modelCountDep.PARENT_ID = item.PARENT_ID.Value; modelCountDep.Department_ID = item.ID; modelCountDep.NUM = item.NUM; //modelCountDep.RowCount = listDepBZ.Where(e => e.PARENT_ID.HasValue && e.PARENT_ID.Value == item.ID).Count(); modelCountDep.DepartmentName = item.NAME; modelCountDep.DepartmentType = item.DEPARTMENT_TYPE; listCheckTypeCount = new List(); modelCountDep.TotalCount = alls.Count(); var onTimes = alls.Where(t => t.STATUS == BaseData.Domain.Enums.PF.PFStandardStatus.Archived && t.COMPLETE_DATE <= t.RECITIFY_TIME); if (onTimes.Any()) { listCheckTypeCount.Add(onTimes.Count()); } else { listCheckTypeCount.Add(0); } modelCountDep.OnCount = onTimes.Count(); var overTimes = alls.Where(t => t.STATUS == BaseData.Domain.Enums.PF.PFStandardStatus.Archived && t.COMPLETE_DATE > t.RECITIFY_TIME); if (overTimes.Any()) { listCheckTypeCount.Add(overTimes.Count()); } else { listCheckTypeCount.Add(0); } modelCountDep.OverCount = overTimes.Count(); var noTimes = alls.Where(t => t.STATUS != BaseData.Domain.Enums.PF.PFStandardStatus.Archived); if (noTimes.Any()) { listCheckTypeCount.Add(noTimes.Count()); } else { listCheckTypeCount.Add(0); } modelCountDep.NoCount = noTimes.Count(); if (alls.Any()) { var val = onTimes.Count() + overTimes.Count(); var count = alls.Count(); var rate = count == 0 ? 0 : (int)(10000.00 * val / count); listCheckTypeCount.Add(rate); } else { listCheckTypeCount.Add(10000); } modelCountDep.listCount = listCheckTypeCount; listCheckDepCountCJ.Add(modelCountDep); } } //listCheckDepCountCJ = listCheckDepCountCJ.Where(t => t.TotalCount != 0).ToList(); //var departIds = listCheckDepCountCJ.Select(t => t.Department_ID).Distinct().ToList(); //listDepBZ = listDepBZ.Where(t => t.PARENT_ID != null && departIds.Contains((Guid)t.PARENT_ID)).ToList(); foreach (var item in listDepBZ) { var alls = hiddens.Where(t => t.APPLY_DEPARTMENT_ID == item.ID); if (alls.Count() > 0) { modelCountDep = new DetailSafeCheckCountDepartment(); modelCountDep.listName = listName; modelCountDep.PARENT_ID = item.PARENT_ID.Value; modelCountDep.Department_ID = item.ID; modelCountDep.NUM = item.NUM; modelCountDep.RowCount = 1; modelCountDep.DepartmentName = item.NAME; modelCountDep.DepartmentType = item.DEPARTMENT_TYPE; listCheckTypeCount = new List(); modelCountDep.TotalCount = alls.Count(); var onTimes = alls.Where(t => t.STATUS == BaseData.Domain.Enums.PF.PFStandardStatus.Archived && t.COMPLETE_DATE <= t.RECITIFY_TIME); if (onTimes.Any()) { listCheckTypeCount.Add(onTimes.Count()); } else { listCheckTypeCount.Add(0); } modelCountDep.OnCount = onTimes.Count(); var overTimes = alls.Where(t => t.STATUS == BaseData.Domain.Enums.PF.PFStandardStatus.Archived && t.COMPLETE_DATE > t.RECITIFY_TIME); if (overTimes.Any()) { listCheckTypeCount.Add(overTimes.Count()); } else { listCheckTypeCount.Add(0); } modelCountDep.OverCount = overTimes.Count(); var noTimes = alls.Where(t => t.STATUS != BaseData.Domain.Enums.PF.PFStandardStatus.Archived); if (noTimes.Any()) { listCheckTypeCount.Add(noTimes.Count()); } else { listCheckTypeCount.Add(0); } modelCountDep.NoCount = noTimes.Count(); if (alls.Any()) { var val = onTimes.Count() + overTimes.Count(); var count = alls.Count(); var rate = count == 0 ? 0 : (int)(10000.00 * val / count); listCheckTypeCount.Add(rate); } else { listCheckTypeCount.Add(10000); } modelCountDep.listCount = listCheckTypeCount; listCheckDepCountBZ.Add(modelCountDep); } } //listCheckDepCountBZ = listCheckDepCountBZ.Where(t => t.TotalCount != 0).ToList(); foreach (var item in listCheckDepCountCJ) { var parentIds = listDepBZ.Where(e => e.PARENT_ID == item.Department_ID).Select(t => t.ID); var classIds = listDepBZ.Where(e => e.PARENT_ID != null && parentIds.Contains((Guid)e.PARENT_ID)).Select(t => t.ID); item.listChild = listCheckDepCountBZ.Where(e => e.Department_ID != null && (classIds.Contains((Guid)e.Department_ID) || parentIds.Contains(e.Department_ID))).OrderBy(e => e.DepartmentType).ThenBy(t => t.NUM).ToList(); item.RowCount = item.listChild.Count(); //var parentIds = listCheckDepCountBZ.Where(e => e.PARENT_ID == item.Department_ID).Select(t => t.Department_ID); //item.listChild = listCheckDepCountBZ.Where(e => e.PARENT_ID == item.Department_ID || parentIds.Contains(e.PARENT_ID)).OrderBy(t=>t.DepartmentType).ThenBy(e => e.NUM).ToList(); //item.RowCount = item.listChild.Count(); } //result.ListSafeCheckYearMonth = listCheckDepCountCJ; //取明细 List ListSafeCheckYearMonth = new List(); int allIndex = 0; foreach (var item in listCheckDepCountCJ) { foreach (var itemC in item.listChild) { allIndex++; itemC.NUM = allIndex; itemC.Parent = item; ListSafeCheckYearMonth.Add(itemC); } } result.ListSafeCheckYearMonth = ListSafeCheckYearMonth; #endregion return result; }); } /// /// 风险等级占比 /// /// 过滤实体 /// [HttpPost, Route("GetHomeRiskLevel")] public JsonActionResult> GetHomeRiskLevel([FromBody] KeywordFilter filter) { return SafeExecute(() => { List result = new List(); BaseFilter baseFilter = new BaseFilter(filter.GetOrgId()); baseFilter.SelectField = new string[] { "EVALUATE_LEVEL" }; var evaluateRisks = GetEntities(t => t.EVALUATE_LEVEL != null && t.ENABLE_STATUS == 0, baseFilter).OrderBy(i => i.EVALUATE_LEVEL).ToList(); var distinctLevelTypes = evaluateRisks.GroupBy(m => new { m.EVALUATE_LEVEL }).Select(group => new { group.Key.EVALUATE_LEVEL, count = group.Count() }).ToList(); int i = 1; foreach (var item in distinctLevelTypes) { T_FM_RISK_LEVEL_PROPORTION riskLevelProportion = new T_FM_RISK_LEVEL_PROPORTION(); riskLevelProportion.COUNT = item.count; riskLevelProportion.NUM = i; riskLevelProportion.RISK_LEVEL = item.EVALUATE_LEVEL.GetDescription(); riskLevelProportion.ORG_ID = filter.GetOrgId(); result.Add(riskLevelProportion); i++; } return result; }); } /// /// 返回所有下级部门节点 /// /// /// /// public void GetDepartmentIds(Guid orgId, List listDepIDInt, ref List departmentIdPs) { var listDep = GetEntities(e => !e.IS_DELETED && e.PARENT_ID.HasValue && listDepIDInt.Contains(e.PARENT_ID.Value), new BaseFilter(orgId)); if (listDep != null && listDep.Any()) { listDepIDInt = listDep.Select(e => e.ID).ToList(); departmentIdPs.AddRange(listDepIDInt); GetDepartmentIds(orgId, listDepIDInt, ref departmentIdPs); } } } /// /// 隐患原因 数据 /// public class HomeRISKREASON { /// /// 年 /// public int YEAR { get; set; } /// /// 组织ID /// public Guid DEPARTMENT_ID { get; set; } /// /// 组织ID /// public string DEPARTMENTNAME { get; set; } /// /// 类型 /// public string SOURCENAME { get; set; } /// /// 隐患原因 /// public List LISTNAME { get; set; } /// /// 隐患原因数量 /// public List LISVALUE { get; set; } /// /// 数据源排序 /// public int NUMS { get; set; } /// /// 数据1 /// public int COUNT1 { get; set; } /// /// 名称1 /// public string NAME1 { get; set; } /// /// 数据2 /// public int COUNT2 { get; set; } /// /// 名称2 /// public string NAME2 { get; set; } /// /// 数据3 /// public int COUNT3 { get; set; } /// /// 名称3 /// public string NAME3 { get; set; } /// /// 数据4 /// public int COUNT4 { get; set; } /// /// 名称4 /// public string NAME4 { get; set; } /// /// 数据5 /// public int COUNT5 { get; set; } /// /// 名称5 /// public string NAME5 { get; set; } } /// /// 整改情况 /// public class HomeCorrect { /// /// 年 /// public int YEAR { get; set; } /// /// 月 /// public int MONTH { get; set; } /// /// 组织ID /// public Guid DEPARTMENT_ID { get; set; } /// /// 组织ID /// public string DEPARTMENTNAME { get; set; } /// /// 类型 /// public string SOURCENAME { get; set; } /// /// 1月 /// public string M1 { get; set; } /// /// 1月 /// public string M2 { get; set; } /// /// 1月 /// public string M3 { get; set; } /// /// 1月 /// public string M4 { get; set; } /// /// 1月 /// public string M5 { get; set; } /// /// 1月 /// public string M6 { get; set; } /// /// 1月 /// public string M7 { get; set; } /// /// 1月 /// public string M8 { get; set; } /// /// 1月 /// public string M9 { get; set; } /// /// 1月 /// public string M10 { get; set; } /// /// 1月 /// public string M11 { get; set; } /// /// 1月 /// public string M12 { get; set; } public string Val { get; set; } public string NAME { get; set; } } /// /// 组织 年度 隐患整改情况 /// public class HomeCorrectYear { /// /// 年 /// public int YEAR { get; set; } /// /// 组织ID /// public Guid DEPARTMENT_ID { get; set; } /// /// 组织名称 /// public string DEPARTMENTNAME { get; set; } /// /// 按时整改 /// public int CountIn { get; set; } /// /// 超时整改 /// public int CountOut { get; set; } /// /// 未整改 /// public int CountNot { get; set; } /// /// 未整改 /// public int Count { get; set; } } /// /// 安全检查 月度 检查类型 数量 /// public class HomeSafeCheckCountMonth { /// /// 年 /// public int YEAR { get; set; } /// /// 月 /// public int MONTH { get; set; } /// /// 总数 /// public int Total { get; set; } public List listListCount { get; set; } public List listSOURCENAME { get; set; } } /// /// 首页数据组合 Redis /// public class HomeResultMineType { /// /// 生产单元 Key1 /// public int MineType { get; set; } /// /// 时间 Key2 根据2个key 获取与更新 /// public string yyyyMMddHH { get; set; } /// /// 存储信息 /// public HomeResult result { get; set; } } /// /// 首页数据组合 /// public class HomeResult { /// /// 隐患原因 /// public List ListR { get; set; } /// /// 月度隐患整改情况 /// public List ListC { get; set; } /// /// 年度隐患整改情况 /// public List ListCYear { get; set; } /// /// 安全检查 月度 数量 /// public List ListSafeCheckYearMonth { get; set; } } /// /// 组织 安全检查类型 对应次数 /// public class DetailSafeCheckCountDepartment { /// /// 组织名称 /// public string DepartmentName { get; set; } /// /// 父级ID /// public Guid PARENT_ID { get; set; } /// /// 部门ID /// public Guid Department_ID { get; set; } /// /// 排序 /// public int NUM { get; set; } /// /// 组织类型 /// public int DepartmentType { get; set; } /// /// 数据占行数(班组为1 车间为下一级班组数量) /// public int RowCount { get; set; } = 1; /// /// 数量集合(每次传参 集合顺序一致) /// public List listCount { get; set; } /// /// 隐患整改率(月度隐患整改情况明细 专属) /// public decimal Percent { get; set; } /// /// 名称集合 (每次传参 集合顺序一致) /// public List listName { get; set; } /// /// 子信息 /// public List listChild { get; set; } /// /// 父项 /// public DetailSafeCheckCountDepartment Parent { get; set; } /// /// 总数 /// public int TotalCount { get; set; } /// /// 总数 /// public int OnCount { get; set; } /// /// 总数 /// public int OverCount { get; set; } /// /// 总数 /// public int NoCount { get; set; } } /// /// 安全检查次数统计 /// public class HomeDetailSafeCheckCountMonth { /// /// 安全检查 月度 数量 /// public List ListSafeCheckYearMonth { get; set; } /// /// 每个组织 每种检查 对应次数 /// public List ListSafeCheckCountDepartment { get; set; } } /// /// 安全检查次数统计 /// public class HomeDetailRiskCountMonth { /// /// 月度隐患整改情况 /// public List ListC { get; set; } /// /// 安全检查 月度 数量 /// public List ListSafeCheckYearMonth { get; set; } } }