using System; using System.Collections.Generic; using System.Linq; namespace BLL { /// /// 安全问题分析 /// public static class ProblemAnalysisService { #region AnalysisColumn /// /// 统计列 /// public class AnalysisColumn { /// /// ID /// public string ID { get; set; } /// /// 名称 /// public string Name { get; set; } /// /// 编号 /// public string Code { get; set; } /// /// 问题数量 /// public int AllCount { get; set; } = 0; /// /// 已整改 /// public int OkCount { get; set; } = 0; /// /// 未整改 /// public int UnCount { get; set; } = 0; /// /// 次数 /// public int NumberV { get; set; } = 0; /// /// 整改率 /// public string Rate { get; set; } } #endregion #region 安全巡检 /// /// 安全巡检 /// public static IQueryable getHazardRegisterLists = from x in Funs.DB.HSSE_Hazard_HazardRegister where x.States != Const.State_4 && x.ProjectId != Const.Project_TestProjectId && x.ProjectId != null select x; /// /// HSE日常检查问题分析 /// /// /// /// /// /// public static List getDailyProblemData(string type, string projectId, DateTime? startTime, DateTime? endTime) { var getDatas = getHazardRegisterLists; List returnLists = new List(); if (getDatas.Count() > 0) { if (!string.IsNullOrEmpty(projectId) && projectId != Const._Null) { getDatas = getDatas.Where(x => x.ProjectId == projectId); } if (startTime.HasValue) { getDatas = getDatas.Where(x => x.CheckTime >= startTime); } if (endTime.HasValue) { getDatas = getDatas.Where(x => x.CheckTime <= endTime); } int AllPCout, okPCount = 0; string rate = string.Empty; if (type == "0") ///按项目 { var getProjects = getDatas.Select(x => x.ProjectId).Distinct(); if (!string.IsNullOrEmpty(projectId) && projectId != Const._Null) { getProjects = getProjects.Where(x => x == projectId); } foreach (var item in getProjects) { var getPRegisters = getDatas.Where(x => x.ProjectId == item); AllPCout = getPRegisters.Count(); if (AllPCout > 0) { okPCount = getPRegisters.Where(x => x.States == Const.State_3).Count(); rate = Math.Round(okPCount * 1.0 / AllPCout * 100, 1).ToString() + "%"; AnalysisColumn newItem = new AnalysisColumn { ID = SQLHelper.GetNewID(), AllCount = AllPCout, OkCount = okPCount, UnCount = AllPCout - okPCount, Rate = rate }; var getProject = ProjectService.GetProjectByProjectId(item); if (getProject != null) { newItem.Code = getProject.ProjectCode; newItem.Name = getProject.ProjectName; } else { newItem.Name = "其他"; } returnLists.Add(newItem); } } } else if (type == "5") ///按项目 { var getUnits = getDatas.Select(x => x.ResponsibleUnit).Distinct(); foreach (var item in getUnits) { var getURegisters = getDatas.Where(x => x.ResponsibleUnit == item); AllPCout = getURegisters.Count(); if (AllPCout > 0) { okPCount = getURegisters.Where(x => x.States == Const.State_3).Count(); rate = Math.Round(okPCount * 1.0 / AllPCout * 100, 1).ToString() + "%"; AnalysisColumn newItem = new AnalysisColumn { ID = SQLHelper.GetNewID(), AllCount = AllPCout, OkCount = okPCount, UnCount = AllPCout - okPCount, Rate = rate }; var getUnit = UnitService.GetUnitByUnitId(item); if (getUnit != null) { newItem.Code = getUnit.UnitCode; newItem.Name = getUnit.UnitName; } else { newItem.Name = "其他"; } returnLists.Add(newItem); } } } else { var getTypes = from x in Funs.DB.HSSE_Hazard_HazardRegisterTypes where x.HazardRegisterType == type orderby x.TypeCode select x; foreach (var item in getTypes) { AnalysisColumn newItem = new AnalysisColumn { ID = SQLHelper.GetNewID(), Name = item.RegisterTypesName, Code = item.TypeCode, }; IQueryable getTRegisters = null; if (type == "1") { getTRegisters = getDatas.Where(x => x.RegisterTypesId == item.RegisterTypesId); } else if (type == "2") { getTRegisters = getDatas.Where(x => x.RegisterTypes2Id == item.RegisterTypesId); } else if (type == "3") { getTRegisters = getDatas.Where(x => x.RegisterTypes3Id == item.RegisterTypesId); } else if (type == "4") { getTRegisters = getDatas.Where(x => x.RegisterTypes4Id == item.RegisterTypesId); } AllPCout = getTRegisters.Count(); if (AllPCout > 0) { okPCount = getTRegisters.Where(x => x.States == Const.State_3).Count(); rate = Math.Round(okPCount * 1.0 / AllPCout * 100, 1).ToString() + "%"; newItem.AllCount = AllPCout; newItem.OkCount = okPCount; newItem.UnCount = AllPCout - okPCount; newItem.Rate = rate; } returnLists.Add(newItem); } IQueryable getTRegistersOther = null; if (type == "1") { getTRegistersOther = getDatas.Where(x => x.RegisterTypesId == null || x.RegisterTypesId == ""); } else if (type == "2") { getTRegistersOther = getDatas.Where(x => x.RegisterTypes2Id == null || x.RegisterTypes2Id == ""); } else if (type == "3") { getTRegistersOther = getDatas.Where(x => x.RegisterTypes3Id == null || x.RegisterTypes3Id == ""); } else if (type == "4") { getTRegistersOther = getDatas.Where(x => x.RegisterTypes4Id == null || x.RegisterTypes4Id == ""); } if (getTRegistersOther != null) { int oAllPCout = getTRegistersOther.Count(); if (oAllPCout > 0) { int ookPCount = getTRegistersOther.Where(x => x.States == Const.State_3).Count(); string orate = Math.Round(ookPCount * 1.0 / oAllPCout * 100, 1).ToString() + "%"; AnalysisColumn newOherItem = new AnalysisColumn { ID = SQLHelper.GetNewID(), Code = "99", Name = "其他", AllCount = oAllPCout, OkCount = ookPCount, UnCount = oAllPCout - ookPCount, Rate = orate }; returnLists.Add(newOherItem); } } } } return returnLists; } #endregion #region 隐患整改单 /// /// 隐患整改单 /// public static IQueryable getRectifyNoticesLists = from x in Funs.DB.Check_RectifyNotices where x.States != Const.State_0 && x.States != null && x.ProjectId != Const.Project_TestProjectId && x.ProjectId != null select x; /// /// 隐患整改检查问题分析 /// /// /// /// /// /// public static List getRectifyProblemData(string type, string projectId, DateTime? startTime, DateTime? endTime) { var getDatas = getRectifyNoticesLists; List returnLists = new List(); if (getDatas.Count() > 0) { if (!string.IsNullOrEmpty(projectId) && projectId != Const._Null) { getDatas = getDatas.Where(x => x.ProjectId == projectId); } if (startTime.HasValue) { getDatas = getDatas.Where(x => x.CheckedDate >= startTime); } if (endTime.HasValue) { getDatas = getDatas.Where(x => x.CheckedDate <= endTime); } int AllPCout, okPCount = 0; string rate = string.Empty; if (type == "0") ///按项目 { var getProjects = getDatas.Select(x => x.ProjectId).Distinct(); if (!string.IsNullOrEmpty(projectId) && projectId != Const._Null) { getProjects = getProjects.Where(x => x == projectId); } foreach (var item in getProjects) { var getPRectifys = getDatas.Where(x => x.ProjectId == item); AllPCout = getPRectifys.Count(); if (AllPCout > 0) { okPCount = getPRectifys.Where(x => x.States == Const.State_5).Count(); rate = Math.Round(okPCount * 1.0 / AllPCout * 100, 1).ToString() + "%"; AnalysisColumn newItem = new AnalysisColumn { ID = SQLHelper.GetNewID(), AllCount = AllPCout, OkCount = okPCount, UnCount = AllPCout - okPCount, Rate = rate }; var getProject = ProjectService.GetProjectByProjectId(item); if (getProject != null) { newItem.Code = getProject.ProjectCode; newItem.Name = getProject.ProjectName; } else { newItem.Name = "其他"; } returnLists.Add(newItem); } } } else if (type == "2") ///按单位 { var getUnits = getDatas.Select(x => x.UnitId).Distinct(); foreach (var item in getUnits) { var getURectifys = getDatas.Where(x => x.UnitId == item); AllPCout = getURectifys.Count(); if (AllPCout > 0) { okPCount = getURectifys.Where(x => x.States == Const.State_5).Count(); rate = Math.Round(okPCount * 1.0 / AllPCout * 100, 1).ToString() + "%"; AnalysisColumn newItem = new AnalysisColumn { ID = SQLHelper.GetNewID(), AllCount = AllPCout, OkCount = okPCount, UnCount = AllPCout - okPCount, Rate = rate }; var getUnit = UnitService.GetUnitByUnitId(item); if (getUnit != null) { newItem.Code = getUnit.UnitCode; newItem.Name = getUnit.UnitName; } else { newItem.Name = "其他"; } returnLists.Add(newItem); } } } else { var getTypes = DropListService.GetHiddenHazardType(); foreach (var item in getTypes) { AnalysisColumn newItem = new AnalysisColumn { ID = SQLHelper.GetNewID(), Name = item.Text, Code = item.Value, }; var getTRegisters = getDatas.Where(x => x.HiddenHazardType == item.Value); AllPCout = getTRegisters.Count(); if (AllPCout > 0) { okPCount = getTRegisters.Where(x => x.States == Const.State_5).Count(); rate = Math.Round(okPCount * 1.0 / AllPCout * 100, 1).ToString() + "%"; newItem.AllCount = AllPCout; newItem.OkCount = okPCount; newItem.UnCount = AllPCout - okPCount; newItem.Rate = rate; } returnLists.Add(newItem); } var getTRegistersOther = getDatas.Where(x => x.HiddenHazardType == null || x.HiddenHazardType == ""); int oAllPCout = getTRegistersOther.Count(); if (oAllPCout > 0) { int ookPCount = getTRegistersOther.Where(x => x.States == Const.State_3).Count(); string orate = Math.Round(ookPCount * 1.0 / oAllPCout * 100, 1).ToString() + "%"; AnalysisColumn newOherItem = new AnalysisColumn { ID = SQLHelper.GetNewID(), Name = "其他", AllCount = oAllPCout, OkCount = ookPCount, UnCount = oAllPCout - ookPCount, Rate = orate }; returnLists.Add(newOherItem); } } } return returnLists; } #endregion #region 教育培训统计 /// /// 教育培训 /// public static IQueryable getTrainRecordLists = from x in Funs.DB.EduTrain_TrainRecord where x.ProjectId != Const.Project_TestProjectId && x.ProjectId != null select x; /// /// 教育培训明细 /// public static IQueryable getTrainRecordDetailLists = from x in Funs.DB.EduTrain_TrainRecordDetail select x; /// /// 教育培训统计 /// /// /// public static List getTrainRecordData(string type, string projectId, string trainTypeId, DateTime? startTime, DateTime? endTime) { var getTrainRecordDatas = getTrainRecordLists; List returnLists = new List(); if (getTrainRecordDatas.Count() > 0) { if (!string.IsNullOrEmpty(projectId) && projectId != Const._Null) { getTrainRecordDatas = getTrainRecordDatas.Where(x => x.ProjectId == projectId); } if (!string.IsNullOrEmpty(trainTypeId) && trainTypeId != Const._Null) { getTrainRecordDatas = getTrainRecordDatas.Where(x => x.TrainTypeId == trainTypeId); } if (startTime.HasValue) { getTrainRecordDatas = getTrainRecordDatas.Where(x => x.TrainStartDate >= startTime); } if (endTime.HasValue) { getTrainRecordDatas = getTrainRecordDatas.Where(x => x.TrainStartDate <= endTime); } int AllPCout, okPCount, NumberV = 0; string rate = string.Empty; if (type == "0") ///按项目 { var getProjects = getTrainRecordDatas.Select(x => x.ProjectId).Distinct(); if (!string.IsNullOrEmpty(projectId) && projectId != Const._Null) { getProjects = getProjects.Where(x => x == projectId); } foreach (var item in getProjects) { var getPTrainRecords = getTrainRecordDatas.Where(x => x.ProjectId == item); NumberV = getPTrainRecords.Count(); if (NumberV > 0) { AnalysisColumn newItem = new AnalysisColumn { ID = SQLHelper.GetNewID(), NumberV = NumberV, }; var getDetailDatas = from x in getTrainRecordDetailLists join y in getPTrainRecords on x.TrainingId equals y.TrainingId select x; AllPCout = getDetailDatas.Count(); if (AllPCout > 0) { okPCount = getDetailDatas.Where(x => x.CheckResult == true).Count(); rate = Math.Round(okPCount * 1.0 / AllPCout * 100, 1).ToString() + "%"; newItem.AllCount = AllPCout; newItem.OkCount = okPCount; newItem.UnCount = AllPCout - okPCount; newItem.Rate = rate; } var getProject = ProjectService.GetProjectByProjectId(item); if (getProject != null) { newItem.Code = getProject.ProjectCode; newItem.Name = getProject.ProjectName; } else { newItem.Name = "其他"; } returnLists.Add(newItem); } } } //else if (type == "2") ///按单位 //{ // var getUnits = getTrainRecordDatas.Select(x => x.UnitIds).Distinct(); // if (getUnits.Count() > 0) // { // var getUnitIds = Funs.GetStrListByList(getUnits.ToList()); // var getIdList = Funs.GetStrListByStr(getUnitIds, ',').Distinct(); // foreach (var item in getIdList) // { // var getUTrainRecords = getTrainRecordDatas.Where(x => x.UnitIds.Contains(item)); // NumberV = getUTrainRecords.Count(); // if (NumberV > 0) // { // AnalysisColumn newItem = new AnalysisColumn // { // ID = SQLHelper.GetNewID(), // NumberV = NumberV, // }; // var getDetailDatas = from x in getTrainRecordDetailLists // join y in getUTrainRecords on x.TrainingId equals y.TrainingId // join z in db.SitePerson_Person on x.PersonId equals z.PersonId // where z.UnitId == item // select x; // AllPCout = getDetailDatas.Count(); // if (AllPCout > 0) // { // okPCount = getDetailDatas.Where(x => x.CheckResult == true).Count(); // rate = Math.Round(okPCount * 1.0 / AllPCout * 100, 1).ToString() + "%"; // newItem.AllCount = AllPCout; // newItem.OkCount = okPCount; // newItem.UnCount = AllPCout - okPCount; // newItem.Rate = rate; // } // var getUnit = UnitService.GetUnitByUnitId(item); // if (getUnit != null) // { // newItem.Code = getUnit.UnitCode; // newItem.Name = getUnit.UnitName; // } // else // { // newItem.Name = "其他"; // } // returnLists.Add(newItem); // } // } // } //} else { var getTypes = TrainTypeService.GetTrainTypeList(); foreach (var item in getTypes) { AnalysisColumn newItem = new AnalysisColumn { ID = SQLHelper.GetNewID(), Name = item.TrainTypeName, Code = item.TrainTypeCode, }; var getTTrainRecord = getTrainRecordDatas.Where(x => x.TrainTypeId == item.TrainTypeId); NumberV = getTTrainRecord.Count(); if (NumberV > 0) { newItem.NumberV = NumberV; var getDetailDatas = from x in getTrainRecordDetailLists join y in getTTrainRecord on x.TrainingId equals y.TrainingId select x; AllPCout = getDetailDatas.Count(); if (AllPCout > 0) { okPCount = getDetailDatas.Where(x => x.CheckResult == true).Count(); rate = Math.Round(okPCount * 1.0 / AllPCout * 100, 1).ToString() + "%"; newItem.AllCount = AllPCout; newItem.OkCount = okPCount; newItem.UnCount = AllPCout - okPCount; newItem.Rate = rate; } returnLists.Add(newItem); } } var getTTrainRecordOther = getTrainRecordDatas.Where(x => x.TrainTypeId == null || x.TrainTypeId == ""); int oNumberV = getTTrainRecordOther.Count(); if (oNumberV > 0) { var getDetailDatas = from x in getTrainRecordDetailLists join y in getTTrainRecordOther on x.TrainingId equals y.TrainingId select x; int oAllPCout = getDetailDatas.Count(); if (oAllPCout > 0) { int ookPCount = getDetailDatas.Where(x => x.CheckResult == true).Count(); string orate = Math.Round(ookPCount * 1.0 / oAllPCout * 100, 1).ToString() + "%"; AnalysisColumn newOherItem = new AnalysisColumn { ID = SQLHelper.GetNewID(), Name = "/", NumberV = oNumberV, AllCount = oAllPCout, OkCount = oAllPCout, UnCount = oAllPCout - ookPCount, Rate = orate }; returnLists.Add(newOherItem); } } } } return returnLists; } #endregion } }