diff --git a/APT.BaseData.Services/Services/PF/PFApproveCallBackService.cs b/APT.BaseData.Services/Services/PF/PFApproveCallBackService.cs index ff69111..cf3a806 100644 --- a/APT.BaseData.Services/Services/PF/PFApproveCallBackService.cs +++ b/APT.BaseData.Services/Services/PF/PFApproveCallBackService.cs @@ -13456,7 +13456,7 @@ namespace APT.BaseData.Services.DomainServices var details = GetEntities(i => identityIds.Contains(i.RISK_IDENTIFY_ID), new BaseFilter(filter.OrgId)).ToList(); var identityDetailIds = details.Select(t => t.ID).ToList(); var identityDetailMes = GetEntities(i => identityDetailIds.Contains(i.RISK_IDENTIFY_DETAIL_ID), new BaseFilter(filter.OrgId)).ToList(); - var detailList = details.GroupBy(m => new { m.AREA_ID, m.PRODUCTION_UNIT_ID, m.RISK_NAME, m.RISK_DESCRIPTION, m.TYPE_ID, m.ENABLE_STATUS }).Select(g => g.FirstOrDefault()); + var detailList = details.OrderByDescending(t => t.ENABLE_STATUS).GroupBy(m => new { m.AREA_ID, m.PRODUCTION_UNIT_ID, m.RISK_NAME, m.RISK_DESCRIPTION, m.TYPE_ID, m.ENABLE_STATUS }).Select(g => g.FirstOrDefault()); if (detailList.Any()) { foreach (var item in detailList) @@ -13862,7 +13862,7 @@ namespace APT.BaseData.Services.DomainServices var resultDetailDepts = GetEntities(i => resultDetailIds.Contains(i.RISK_IDENTIFY_RESULT_DETAIL_ID), new BaseFilter(filter.OrgId)).ToList(); var resultDetailDeptIds = resultDetailDepts.Select(t => t.ID).ToList(); var resultDetailDeptPosts = GetEntities(i => resultDetailDeptIds.Contains(i.RISK_IDENTIFY_DETAIL_RESULT_POST_ID), new BaseFilter(filter.OrgId)).ToList(); - var detailList = details.GroupBy(m => new { m.AREA_ID, m.PRODUCTION_UNIT_ID, m.RISK_NAME, m.RISK_DESCRIPTION, m.TYPE_ID, m.ENABLE_STATUS }).Select(g => g.FirstOrDefault()); + var detailList = details.OrderByDescending(t=>t.ENABLE_STATUS).GroupBy(m => new { m.AREA_ID, m.PRODUCTION_UNIT_ID, m.RISK_NAME, m.RISK_DESCRIPTION, m.TYPE_ID, m.ENABLE_STATUS }).Select(g => g.FirstOrDefault()); if (detailList.Any()) { foreach (var de in detailList) @@ -14610,7 +14610,7 @@ namespace APT.BaseData.Services.DomainServices var detailMes = this.GetEntities(t => detailIds.Contains(t.RISK_EVALUATION_DETAIL_ID), new BaseFilter(entity.ORG_ID)); //var detailDeparts = this.GetEntities(t => detailIds.Contains(t.RISK_EVALUATION_DETAIL_ID), new BaseFilter(entity.ORG_ID)); var detailPosts = this.GetEntities(t => detailIds.Contains(t.RISK_EVALUATION_DETAIL_ID), new BaseFilter(entity.ORG_ID), "Nav_PostDetails"); - var detailList = details.GroupBy(m => new { m.AREA_ID, m.PRODUCTION_UNIT_ID, m.RISK_NAME, m.RISK_DESCRIPTION, m.TYPE_ID }).Select(g => g.FirstOrDefault()); + var detailList = details.OrderByDescending(t=>t.ENABLE_STATUS).GroupBy(m => new { m.AREA_ID, m.PRODUCTION_UNIT_ID, m.RISK_NAME, m.RISK_DESCRIPTION, m.TYPE_ID,m.ENABLE_STATUS }).Select(g => g.FirstOrDefault()); if (detailList.Any()) { foreach (var de in detailList) @@ -14807,7 +14807,7 @@ namespace APT.BaseData.Services.DomainServices if(approveTemp.Nav_ApproveTempDetails.Count() == 0) { result.STATUS = PFStandardStatus.Archived; - var resultDetailTemps = resultDetails.Where(t => (t.MARK == SKMarkEnum.Add && t.ENABLE_STATUS == SKEnableStatusEnum.Yes) || (t.MARK != SKMarkEnum.Add)).ToList(); + var resultDetailTemps = resultDetails.Where(t => t.MARK != SKMarkEnum.Auto).ToList(); if (user != null && resultDetailTemps != null && resultDetailTemps.Any()) { var productionIds = resultDetailTemps.Where(t => t.PRODUCTION_UNIT_ID != null).Select(m=>m.PRODUCTION_UNIT_ID).Distinct().ToList(); @@ -15149,7 +15149,7 @@ namespace APT.BaseData.Services.DomainServices List douContentPosts = new List(); //List douContentDepartPosts = new List(); List douContentHiddenss = new List(); - var entityDetails = sumDetails.Where(t => (t.MARK == SKMarkEnum.Add && t.ENABLE_STATUS == SKEnableStatusEnum.Yes) || (t.MARK != SKMarkEnum.Add)).ToList(); + var entityDetails = sumDetails.Where(t => t.MARK != SKMarkEnum.Auto).ToList(); if (entity.APPLY_USER_ID != null && entityDetails != null && entityDetails.Any()) { var sumDetailIds = entityDetails.Select(t => t.ID).ToList(); 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 9714447..91a92b1 100644 --- a/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIHomeController.cs +++ b/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIHomeController.cs @@ -1,2137 +1,2137 @@ -using APT.BaseData.Domain.ApiModel.Platform; -using APT.BaseData.Domain.Entities.FM; -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.SK; -using APT.Utility; -using log4net.Core; -using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -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; - }); +using APT.BaseData.Domain.ApiModel.Platform; +using APT.BaseData.Domain.Entities.FM; +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.SK; +using APT.Utility; +using log4net.Core; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +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("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 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.CATEGORY == BaseData.Domain.Enums.FMCATEGORY.ACTURE && t.ENABLE_STATUS == 0, null, null); - - #endregion - - if (listDep1MineType == null || !listDep1MineType.Any()) - { - return result; - } - - List listDep = new List(); - listDep = listDep1MineType.ToList(); - - - #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 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.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 || ((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) - /// - /// 过滤实体 - /// - [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); - - 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 == 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; - - #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()) - { - listDep1MineType = GetEntities(t => listDepID.Contains(t.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 => 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("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); - - 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.MineType.HasValue && t.MineType == MineType && (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 - - #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 = ""; - // } - // 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); - // } - //} - - #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; - }); + + /// + /// 查询所有数据 + /// + /// 过滤实体 + /// + [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 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.MineType.HasValue && t.MineType == MineType && t.DEPARTMENT_TYPE == 10, null, null);//部门就可以了 因为都相向 统计了 + + #endregion + + if (listDep1MineType == null || !listDep1MineType.Any()) + { + return result; + } + + List listDep = new List(); + listDep = listDep1MineType.ToList(); + + + #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 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_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 || ((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("GetHomeRiskLevel")] - public JsonActionResult> GetHomeRiskLevel([FromBody] KeywordFilter filter) - { - return SafeExecute(() => - { - + + /// + /// 首页 安全检查次数统计明细(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); + + 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 == 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; + + #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()) + { + listDep1MineType = GetEntities(t => listDepID.Contains(t.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 => 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("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); + + 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.MineType.HasValue && t.MineType == MineType && (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 + + #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 = ""; + // } + // 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); + // } + //} + + #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; + }); + } + /// + /// 风险等级占比 + /// + /// 过滤实体 + /// + [HttpPost, Route("GetHomeRiskLevel")] + public JsonActionResult> GetHomeRiskLevel([FromBody] KeywordFilter filter) + { + return SafeExecute(() => + { + List result = new List(); - BaseFilter baseFilter = new BaseFilter(filter.GetOrgId()); + 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(); @@ -2146,404 +2146,404 @@ namespace APT.SC.WebApi.Controllers.Api.BI result.Add(riskLevelProportion); i++; } - return result; - }); - } - } - - /// - /// 隐患原因 数据 - /// - 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 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; } - } + return result; + }); + } + } + + /// + /// 隐患原因 数据 + /// + 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 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; } + } } \ No newline at end of file