325 lines
		
	
	
		
			16 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			325 lines
		
	
	
		
			16 KiB
		
	
	
	
		
			C#
		
	
	
	
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Linq;
 | |
| using System.Text;
 | |
| using System.Threading.Tasks;
 | |
| 
 | |
| namespace BLL
 | |
| {
 | |
|    public static class DataStatisticsService
 | |
|     {
 | |
|         #region 安全检查统计
 | |
|         /// <summary>
 | |
|         ///  安全检查统计
 | |
|         /// </summary>
 | |
|         /// <param name="projectId"></param>
 | |
|         /// <param name="unitId"></param>
 | |
|         /// <param name="startTime"></param>
 | |
|         /// <param name="endTime"></param>
 | |
|         /// <returns></returns>
 | |
|         public static List<Model.ChartAnalysisItem> GetCheckStatistics(string projectId, string unitId, DateTime? startTime, DateTime? endTime)
 | |
|         {
 | |
|             List<Model.ChartAnalysisItem> GetCheckStatistics = new List<Model.ChartAnalysisItem>();
 | |
|             var getProjects = ProjectService.GetProjectWorkList();
 | |
|             if (projectId != Const._Null && !string.IsNullOrEmpty(projectId))
 | |
|             {
 | |
|                 getProjects = getProjects.Where(x => x.ProjectId == projectId).ToList();
 | |
|             }
 | |
|             foreach (var pitem in getProjects)
 | |
|             {
 | |
|                 var getUnits = UnitService.GetUnitByProjectIdList(pitem.ProjectId);
 | |
|                 if (unitId != Const._Null && !string.IsNullOrEmpty(unitId))
 | |
|                 {
 | |
|                     getUnits = getUnits.Where(x => x.UnitId == unitId).ToList();
 | |
|                 }
 | |
|                 foreach (var item in getUnits)
 | |
|                 {
 | |
|                     var getHazardRegister = from x in Funs.DB.HSSE_Hazard_HazardRegister
 | |
|                                             where x.ProjectId == pitem.ProjectId && x.ResponsibleUnit == item.UnitId
 | |
|                                             && (x.States == "1" || x.States == "2" || x.States == "3")
 | |
|                                             select x;
 | |
|                     if (startTime.HasValue)
 | |
|                     {
 | |
|                         getHazardRegister = getHazardRegister.Where(x => x.CheckTime >= startTime);
 | |
|                     }
 | |
|                     if (endTime.HasValue)
 | |
|                     {
 | |
|                         getHazardRegister = getHazardRegister.Where(x => x.CheckTime <= endTime);
 | |
|                     }
 | |
|                     Model.ChartAnalysisItem newItem = new Model.ChartAnalysisItem
 | |
|                     {
 | |
|                         DataId = SQLHelper.GetNewID(),
 | |
|                         DataAllName = pitem.ProjectName,
 | |
|                         DataName = item.UnitName,
 | |
|                     };
 | |
|                     newItem.DataSumCount = getHazardRegister.Count();
 | |
|                     newItem.DataCount1 = getHazardRegister.Where(x => x.States == "1").Count();
 | |
|                     newItem.DataCount2 = getHazardRegister.Where(x => x.States == "2").Count();
 | |
|                     newItem.DataCount3 = getHazardRegister.Where(x => x.States == "3").Count();
 | |
|                     GetCheckStatistics.Add(newItem);
 | |
|                 }
 | |
|             }
 | |
|             return GetCheckStatistics;
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 隐患整改单统计
 | |
|         /// <summary>
 | |
|         ///  隐患整改单统计
 | |
|         /// </summary>
 | |
|         /// <param name="projectId"></param>
 | |
|         /// <param name="unitId"></param>
 | |
|         /// <param name="startTime"></param>
 | |
|         /// <param name="endTime"></param>
 | |
|         /// <returns></returns>
 | |
|         public static List<Model.RecityNoticesItem> RectifyNoticesStatistics(string projectId, string unitId, DateTime? startTime, DateTime? endTime)
 | |
|         {
 | |
|             List<Model.RecityNoticesItem> GetCheckStatistics = new List<Model.RecityNoticesItem>();
 | |
|             var getProjects = ProjectService.GetProjectWorkList();
 | |
|             if (projectId != Const._Null && !string.IsNullOrEmpty(projectId))
 | |
|             {
 | |
|                 getProjects = getProjects.Where(x => x.ProjectId == projectId).ToList();
 | |
|             }
 | |
|             foreach (var pitem in getProjects)
 | |
|             {
 | |
|                 var getUnits = UnitService.GetUnitByProjectIdList(pitem.ProjectId);
 | |
|                 if (unitId != Const._Null && !string.IsNullOrEmpty(unitId))
 | |
|                 {
 | |
|                     getUnits = getUnits.Where(x => x.UnitId == unitId).ToList();
 | |
|                 }
 | |
|                 foreach (var item in getUnits)
 | |
|                 {
 | |
|                     
 | |
|                     Model.RecityNoticesItem newItem = new Model.RecityNoticesItem
 | |
|                     {
 | |
|                         DataId = SQLHelper.GetNewID(),
 | |
|                         DataAllName = pitem.ProjectName,
 | |
|                         DataName = item.UnitName,
 | |
|                     };
 | |
|                     //安全巡检隐患数
 | |
|                     var getHazardRegister = from x in Funs.DB.View_Hazard_HazardRegister
 | |
|                                             where x.ProblemTypes == "1" && x.ProjectId == pitem.ProjectId && x.ResponsibleUnit == item.UnitId
 | |
|                                             select x;
 | |
|                     if (startTime.HasValue)
 | |
|                     {
 | |
|                         getHazardRegister = getHazardRegister.Where(x => x.CheckTime >= startTime);
 | |
|                     }
 | |
|                     if (endTime.HasValue)
 | |
|                     {
 | |
|                         getHazardRegister = getHazardRegister.Where(x => x.CheckTime <= endTime);
 | |
|                     }
 | |
|                     newItem.DataSumCount1 = getHazardRegister.Where(x=>x.Type==0).Count();
 | |
|                     newItem.DataSumCountYzg1 = getHazardRegister.Where(x => x.Type == 0 && x.States == "2").Count();
 | |
|                     newItem.DataSumCountDzg1 = getHazardRegister.Where(x => x.Type == 0 && x.States == "1").Count();
 | |
|                     if (newItem.DataSumCountYzg1 > 0)
 | |
|                     {
 | |
|                         newItem.DataSumCountZgl1 =Math.Round((float)newItem.DataSumCountYzg1 / (float)newItem.DataSumCount1 * 100,2).ToString()+"%";
 | |
|                     }
 | |
|                     else
 | |
|                     {
 | |
|                         newItem.DataSumCountZgl1 ="0%";
 | |
|                     }
 | |
| 
 | |
| 
 | |
|                     //常规巡检隐患数
 | |
|                     newItem.DataSumCount2 = getHazardRegister.Where(x => x.Type == 1).Count();
 | |
|                     newItem.DataSumCountYzg2 = getHazardRegister.Where(x => x.Type == 1 && x.States == "2").Count();
 | |
|                     newItem.DataSumCountDzg2 = getHazardRegister.Where(x => x.Type == 1 && x.States == "1").Count();
 | |
|                     if (newItem.DataSumCountYzg2 > 0)
 | |
|                     {
 | |
|                         newItem.DataSumCountZgl2 = Math.Round((float)newItem.DataSumCountYzg2 / (float)newItem.DataSumCount2 * 100, 2).ToString() + "%";
 | |
|                     }
 | |
|                     else
 | |
|                     {
 | |
|                         newItem.DataSumCountZgl2 = "0%";
 | |
|                     }
 | |
| 
 | |
|                     //专项检查隐患数
 | |
|                     var getCheckSpecial = from x in Funs.DB.Check_CheckSpecialDetail
 | |
|                                           join y in Funs.DB.Check_CheckSpecial on x.CheckSpecialId equals y.CheckSpecialId
 | |
|                                           where x.UnitId == item.UnitId && y.ProjectId == pitem.ProjectId
 | |
|                                           select new { y.CheckTime,x.UnitId,y.ProjectId,x.CompleteStatus };
 | |
|                     if (startTime.HasValue)
 | |
|                     {
 | |
|                         getCheckSpecial = getCheckSpecial.Where(x => x.CheckTime >= startTime);
 | |
|                     }
 | |
|                     if (endTime.HasValue)
 | |
|                     {
 | |
|                         getCheckSpecial = getCheckSpecial.Where(x => x.CheckTime <= endTime);
 | |
|                     }
 | |
|                     newItem.DataSumCount3= getCheckSpecial.Count();
 | |
|                     newItem.DataSumCountYzg3 = getCheckSpecial.Where(x =>x.CompleteStatus == true).Count();
 | |
|                     newItem.DataSumCountDzg3 = getCheckSpecial.Where(x =>x.CompleteStatus == false).Count();
 | |
|                     if (newItem.DataSumCountYzg3 > 0)
 | |
|                     {
 | |
|                         newItem.DataSumCountZgl3 =Math.Round((float)newItem.DataSumCountYzg3 / (float)newItem.DataSumCount3 * 100, 2).ToString() + "%"; ;
 | |
|                     }
 | |
|                     else
 | |
|                     {
 | |
|                         newItem.DataSumCountZgl3 = "0%";
 | |
|                     }
 | |
| 
 | |
|                     //综合检查隐患数
 | |
|                     var getCheckColligation = from x in Funs.DB.Check_CheckColligationDetail
 | |
|                                               join y in Funs.DB.Check_CheckColligation on x.CheckColligationId equals y.CheckColligationId
 | |
|                                               where x.UnitId == item.UnitId && y.ProjectId == pitem.ProjectId
 | |
|                                               select new { y.CheckTime, x.UnitId, y.ProjectId, x.CompleteStatus };
 | |
|                     if (startTime.HasValue)
 | |
|                     {
 | |
|                         getCheckColligation = getCheckColligation.Where(x => x.CheckTime >= startTime);
 | |
|                     }
 | |
|                     if (endTime.HasValue)
 | |
|                     {
 | |
|                         getCheckColligation = getCheckColligation.Where(x => x.CheckTime <= endTime);
 | |
|                     }
 | |
|                     newItem.DataSumCount4 = getCheckColligation.Count();
 | |
|                     newItem.DataSumCountYzg4 = getCheckColligation.Where(x => x.CompleteStatus == true).Count();
 | |
|                     newItem.DataSumCountDzg4 = getCheckColligation.Where(x => x.CompleteStatus == false).Count();
 | |
|                     if (newItem.DataSumCountYzg4 > 0)
 | |
|                     {
 | |
|                         newItem.DataSumCountZgl4 = Math.Round((float)newItem.DataSumCountYzg4 / (float)newItem.DataSumCount4 * 100, 2).ToString();
 | |
|                     }
 | |
|                     else
 | |
|                     {
 | |
|                         newItem.DataSumCountZgl4 = "0%";
 | |
|                     }
 | |
| 
 | |
|                     //var getHazardRegister = from x in Funs.DB.Check_RectifyNotices
 | |
|                     //                        where x.ProjectId == pitem.ProjectId && x.UnitId == item.UnitId
 | |
|                     //                        && x.States != "0"
 | |
|                     //                        select x;
 | |
|                     //if (startTime.HasValue)
 | |
|                     //{
 | |
|                     //    getHazardRegister = getHazardRegister.Where(x => x.CheckedDate >= startTime);
 | |
|                     //}
 | |
|                     //if (endTime.HasValue)
 | |
|                     //{
 | |
|                     //    getHazardRegister = getHazardRegister.Where(x => x.CheckedDate <= endTime);
 | |
|                     //}
 | |
|                     //newItem.DataSumCount = getHazardRegister.Count();
 | |
|                     //newItem.DataCount1 = getHazardRegister.Where(x => x.States == "1").Count();
 | |
|                     //newItem.DataCount2 = getHazardRegister.Where(x => x.States == "2").Count();
 | |
|                     //newItem.DataCount3 = getHazardRegister.Where(x => x.States == "3").Count();
 | |
|                     //newItem.DataCount4 = getHazardRegister.Where(x => x.States == "4").Count();
 | |
|                     //newItem.DataCount5 = getHazardRegister.Where(x => x.States == "5").Count();
 | |
|                     //if (newItem.DataCount2 > 0)
 | |
|                     //{
 | |
|                     //    newItem.DataCountRate = (float)newItem.DataCount5 / (float)newItem.DataCount2 * 100;
 | |
|                     //}
 | |
|                     //else
 | |
|                     //{
 | |
|                     //    newItem.DataCountRate = 0;
 | |
|                     //}
 | |
|                     GetCheckStatistics.Add(newItem);
 | |
|                 }
 | |
|             }
 | |
|             return GetCheckStatistics;
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 安全会议统计
 | |
|         /// <summary>
 | |
|         ///  安全会议统计
 | |
|         /// </summary>
 | |
|         /// <param name="projectId"></param>
 | |
|         /// <param name="unitId"></param>
 | |
|         /// <param name="startTime"></param>
 | |
|         /// <param name="endTime"></param>
 | |
|         /// <returns></returns>
 | |
|         public static List<Model.ChartAnalysisItem> MeetStatistics(string projectId, string unitId, DateTime? startTime, DateTime? endTime)
 | |
|         {
 | |
|             List<Model.ChartAnalysisItem> GetCheckStatistics = new List<Model.ChartAnalysisItem>();
 | |
|             var getProjects = ProjectService.GetProjectWorkList();
 | |
|             if (projectId != Const._Null && !string.IsNullOrEmpty(projectId))
 | |
|             {
 | |
|                 getProjects = getProjects.Where(x => x.ProjectId == projectId).ToList();
 | |
|             }
 | |
|             foreach (var pitem in getProjects)
 | |
|             {
 | |
|                 var getUnits = UnitService.GetUnitByProjectIdList(pitem.ProjectId);
 | |
|                 if (unitId != Const._Null && !string.IsNullOrEmpty(unitId))
 | |
|                 {
 | |
|                     getUnits = getUnits.Where(x => x.UnitId == unitId).ToList();
 | |
|                 }
 | |
|                 foreach (var item in getUnits)
 | |
|                 {
 | |
|                     Model.ChartAnalysisItem newItem = new Model.ChartAnalysisItem
 | |
|                     {
 | |
|                         DataId = SQLHelper.GetNewID(),
 | |
|                         DataAllName = pitem.ProjectName,
 | |
|                         DataName = item.UnitName,
 | |
|                     };
 | |
|                     ///班前会
 | |
|                     var getClassMeeting = from x in Funs.DB.Meeting_ClassMeeting
 | |
|                                           where x.ProjectId == pitem.ProjectId && x.UnitId == item.UnitId
 | |
|                                           select x;
 | |
|                     if (startTime.HasValue)
 | |
|                     {
 | |
|                         getClassMeeting = getClassMeeting.Where(x => x.ClassMeetingDate >= startTime);
 | |
|                     }
 | |
|                     if (endTime.HasValue)
 | |
|                     {
 | |
|                         getClassMeeting = getClassMeeting.Where(x => x.ClassMeetingDate <= endTime);
 | |
|                     }
 | |
|                     ////周例会
 | |
|                     var getWeekMeeting = from x in Funs.DB.Meeting_WeekMeeting
 | |
|                                          where x.ProjectId == pitem.ProjectId && x.UnitId == item.UnitId
 | |
|                                          select x;
 | |
|                     if (startTime.HasValue)
 | |
|                     {
 | |
|                         getWeekMeeting = getWeekMeeting.Where(x => x.WeekMeetingDate >= startTime);
 | |
|                     }
 | |
|                     if (endTime.HasValue)
 | |
|                     {
 | |
|                         getWeekMeeting = getWeekMeeting.Where(x => x.WeekMeetingDate <= endTime);
 | |
|                     }
 | |
|                     ////月例会
 | |
|                     var getMonthMeeting = from x in Funs.DB.Meeting_MonthMeeting
 | |
|                                           where x.ProjectId == pitem.ProjectId && x.UnitId == item.UnitId
 | |
|                                           select x;
 | |
|                     if (startTime.HasValue)
 | |
|                     {
 | |
|                         getMonthMeeting = getMonthMeeting.Where(x => x.MonthMeetingDate >= startTime);
 | |
|                     }
 | |
|                     if (endTime.HasValue)
 | |
|                     {
 | |
|                         getMonthMeeting = getMonthMeeting.Where(x => x.MonthMeetingDate <= endTime);
 | |
|                     }
 | |
|                     ////专题会
 | |
|                     var getSpecialMeeting = from x in Funs.DB.Meeting_SpecialMeeting
 | |
|                                             where x.ProjectId == pitem.ProjectId && x.UnitId == item.UnitId
 | |
|                                             select x;
 | |
|                     if (startTime.HasValue)
 | |
|                     {
 | |
|                         getSpecialMeeting = getSpecialMeeting.Where(x => x.SpecialMeetingDate >= startTime);
 | |
|                     }
 | |
|                     if (endTime.HasValue)
 | |
|                     {
 | |
|                         getSpecialMeeting = getSpecialMeeting.Where(x => x.SpecialMeetingDate <= endTime);
 | |
|                     }
 | |
|                     ////其他会议
 | |
|                     var getAttendMeeting = from x in Funs.DB.Meeting_AttendMeeting
 | |
|                                            where x.ProjectId == pitem.ProjectId && x.UnitId == item.UnitId
 | |
|                                            select x;
 | |
|                     if (startTime.HasValue)
 | |
|                     {
 | |
|                         getAttendMeeting = getAttendMeeting.Where(x => x.AttendMeetingDate >= startTime);
 | |
|                     }
 | |
|                     if (endTime.HasValue)
 | |
|                     {
 | |
|                         getAttendMeeting = getAttendMeeting.Where(x => x.AttendMeetingDate <= endTime);
 | |
|                     }
 | |
|                     newItem.DataCount1 = getClassMeeting.Where(x => x.States == "1").Count();
 | |
|                     newItem.DataCount2 = getWeekMeeting.Where(x => x.States == "2").Count();
 | |
|                     newItem.DataCount3 = getMonthMeeting.Where(x => x.States == "3").Count();
 | |
|                     newItem.DataCount4 = getSpecialMeeting.Where(x => x.States == "4").Count();
 | |
|                     newItem.DataCount5 = getAttendMeeting.Where(x => x.States == "5").Count();
 | |
|                     GetCheckStatistics.Add(newItem);
 | |
|                 }
 | |
|             }
 | |
|             return GetCheckStatistics;
 | |
|         }
 | |
|         #endregion
 | |
|     }
 | |
| }
 |