using FineUIPro; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using Model; using Newtonsoft.Json; using static BLL.Project_HJGLData_HJGLService; namespace BLL { public static class Project_SYHSEData_SYHSEService { public static Model.SGGLDB db = Funs.DB; /// /// 实业数据类型 /// public enum SYHSESDateType { /// /// 全部数据 /// All, /// /// 风险管控数据 /// RiskControl, /// /// 重大危险源数据 /// MajorHazardSources, /// /// 基本数据 /// Basic, /// /// 环保数据 /// EnvironmentalData, /// /// 隐患排查治理数据 /// TroubleshootingAndTreatment, /// /// 作业管理数据 /// JobManagementData } #region 获取列表 /// /// 记录数 /// public static int count { get; set; } public static List GetProject_SYHSEData_SYHSEByModle(Model.Project_SYHSEData_SYHSE table) { var q = from x in db.Project_SYHSEData_SYHSE where (string.IsNullOrEmpty(table.Id) || x.Id.Contains(table.Id)) && (string.IsNullOrEmpty(table.ProjectId) || x.Id.Contains(table.ProjectId)) && (string.IsNullOrEmpty(table.UnitId) || x.UnitId.Contains(table.UnitId)) && (string.IsNullOrEmpty(table.CollCropCode) || x.CollCropCode.Contains(table.CollCropCode)) && (string.IsNullOrEmpty(table.UnitName) || x.UnitName.Contains(table.UnitName)) select x ; return q.ToList(); } /// 获取分页列表 /// /// 页码 /// 每页数量 /// public static IEnumerable getListData(Model.Project_SYHSEData_SYHSE table, Grid Grid1) { var q = GetProject_SYHSEData_SYHSEByModle(table); count = q.Count(); if (count == 0) { return null; } //q = SortConditionHelper.SortingAndPaging(q, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize); return from x in q select new { x.Id, x.ProjectId, x.UnitId, x.CollCropCode, x.UnitName, x.ReportDate, x.GeneralRiskNum, x.LowRiskNum, x.MediumRiskNum, x.HighRiskNum, x.GradedResponsiblePersonNum, x.ChargeInsurancePersonNum, x.DesignQuantity, x.RunningCapacity, x.InterlockSettingValue, x.VideoSurveillanceNum, x.TotalWorkinghours, x.SafeWorkinghours, x.LostWorkinghours, x.TotalEnergyConsumption, x.IncomeComprehensiveEnergyConsumption, x.NewWaterConsumption, x.GeneralClosedNum, x.GeneralNotClosedNum, x.MajorClosedNum, x.MajorNotClosedNum, x.HotWorkPermitNum, x.HotWorkClosedNum, x.HighPermitNum, x.HighClosedNum, x.TemporaryElectricityPermitNum, x.TemporaryElectricityClosedNum, x.BlindPlatePermitNum, x.BlindPlateClosedNum, x.GroundbreakingPermitNum, x.GroundbreakingClosedNum, x.OpenCircuitPermitNum, x.OpenCircuitClosedNum, x.HoistingPermitNum, x.HoistingClosedNum, }; } #endregion public static Model.Project_SYHSEData_SYHSE GetProject_SYHSEData_SYHSEById(string Id) { return db.Project_SYHSEData_SYHSE.FirstOrDefault(x => x.Id == Id); } public static void AddProject_SYHSEData_SYHSE(Model.Project_SYHSEData_SYHSE newtable) { using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { Model.Project_SYHSEData_SYHSE table = new Model.Project_SYHSEData_SYHSE { Id = newtable.Id, ProjectId = newtable.ProjectId, UnitId = newtable.UnitId, CollCropCode = newtable.CollCropCode, UnitName = newtable.UnitName, ReportDate = newtable.ReportDate, GeneralRiskNum = newtable.GeneralRiskNum, LowRiskNum = newtable.LowRiskNum, MediumRiskNum = newtable.MediumRiskNum, HighRiskNum = newtable.HighRiskNum, GradedResponsiblePersonNum = newtable.GradedResponsiblePersonNum, ChargeInsurancePersonNum = newtable.ChargeInsurancePersonNum, DesignQuantity = newtable.DesignQuantity, RunningCapacity = newtable.RunningCapacity, InterlockSettingValue = newtable.InterlockSettingValue, VideoSurveillanceNum = newtable.VideoSurveillanceNum, TotalWorkinghours = newtable.TotalWorkinghours, SafeWorkinghours = newtable.SafeWorkinghours, LostWorkinghours = newtable.LostWorkinghours, TotalEnergyConsumption = newtable.TotalEnergyConsumption, IncomeComprehensiveEnergyConsumption = newtable.IncomeComprehensiveEnergyConsumption, NewWaterConsumption = newtable.NewWaterConsumption, GeneralClosedNum = newtable.GeneralClosedNum, GeneralNotClosedNum = newtable.GeneralNotClosedNum, MajorClosedNum = newtable.MajorClosedNum, MajorNotClosedNum = newtable.MajorNotClosedNum, HotWorkPermitNum = newtable.HotWorkPermitNum, HotWorkClosedNum = newtable.HotWorkClosedNum, HighPermitNum = newtable.HighPermitNum, HighClosedNum = newtable.HighClosedNum, TemporaryElectricityPermitNum = newtable.TemporaryElectricityPermitNum, TemporaryElectricityClosedNum = newtable.TemporaryElectricityClosedNum, BlindPlatePermitNum = newtable.BlindPlatePermitNum, BlindPlateClosedNum = newtable.BlindPlateClosedNum, GroundbreakingPermitNum = newtable.GroundbreakingPermitNum, GroundbreakingClosedNum = newtable.GroundbreakingClosedNum, OpenCircuitPermitNum = newtable.OpenCircuitPermitNum, OpenCircuitClosedNum = newtable.OpenCircuitClosedNum, HoistingPermitNum = newtable.HoistingPermitNum, HoistingClosedNum = newtable.HoistingClosedNum, }; db.Project_SYHSEData_SYHSE.InsertOnSubmit(table); db.SubmitChanges(); } } public static void UpdateProject_SYHSEData_SYHSE(Model.Project_SYHSEData_SYHSE newtable) { using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { Model.Project_SYHSEData_SYHSE table = db.Project_SYHSEData_SYHSE.FirstOrDefault(x => x.Id == newtable.Id); if (table != null) { table.Id = newtable.Id; table.ProjectId = newtable.ProjectId; table.UnitId = newtable.UnitId; table.CollCropCode = newtable.CollCropCode; table.UnitName = newtable.UnitName; table.ReportDate = newtable.ReportDate; table.GeneralRiskNum = newtable.GeneralRiskNum; table.LowRiskNum = newtable.LowRiskNum; table.MediumRiskNum = newtable.MediumRiskNum; table.HighRiskNum = newtable.HighRiskNum; table.GradedResponsiblePersonNum = newtable.GradedResponsiblePersonNum; table.ChargeInsurancePersonNum = newtable.ChargeInsurancePersonNum; table.DesignQuantity = newtable.DesignQuantity; table.RunningCapacity = newtable.RunningCapacity; table.InterlockSettingValue = newtable.InterlockSettingValue; table.VideoSurveillanceNum = newtable.VideoSurveillanceNum; table.TotalWorkinghours = newtable.TotalWorkinghours; table.SafeWorkinghours = newtable.SafeWorkinghours; table.LostWorkinghours = newtable.LostWorkinghours; table.TotalEnergyConsumption = newtable.TotalEnergyConsumption; table.IncomeComprehensiveEnergyConsumption = newtable.IncomeComprehensiveEnergyConsumption; table.NewWaterConsumption = newtable.NewWaterConsumption; table.GeneralClosedNum = newtable.GeneralClosedNum; table.GeneralNotClosedNum = newtable.GeneralNotClosedNum; table.MajorClosedNum = newtable.MajorClosedNum; table.MajorNotClosedNum = newtable.MajorNotClosedNum; table.HotWorkPermitNum = newtable.HotWorkPermitNum; table.HotWorkClosedNum = newtable.HotWorkClosedNum; table.HighPermitNum = newtable.HighPermitNum; table.HighClosedNum = newtable.HighClosedNum; table.TemporaryElectricityPermitNum = newtable.TemporaryElectricityPermitNum; table.TemporaryElectricityClosedNum = newtable.TemporaryElectricityClosedNum; table.BlindPlatePermitNum = newtable.BlindPlatePermitNum; table.BlindPlateClosedNum = newtable.BlindPlateClosedNum; table.GroundbreakingPermitNum = newtable.GroundbreakingPermitNum; table.GroundbreakingClosedNum = newtable.GroundbreakingClosedNum; table.OpenCircuitPermitNum = newtable.OpenCircuitPermitNum; table.OpenCircuitClosedNum = newtable.OpenCircuitClosedNum; table.HoistingPermitNum = newtable.HoistingPermitNum; table.HoistingClosedNum = newtable.HoistingClosedNum; db.SubmitChanges(); } } } public static void DeleteProject_SYHSEData_SYHSEById(string Id) { using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { Model.Project_SYHSEData_SYHSE table = db.Project_SYHSEData_SYHSE.FirstOrDefault(x => x.Id == Id); if (table != null) { db.Project_SYHSEData_SYHSE.DeleteOnSubmit(table); db.SubmitChanges(); } } } /// /// 判断当天是否统计过数据 /// /// /// public static bool IsReportByToday(string projectid) { var result = false; var q = (from x in Funs.DB.Project_SYHSEData_SYHSE where x.ReportDate < DateTime.Now.AddDays(1).Date && x.ReportDate >= DateTime.Now.Date && x.ProjectId == projectid select x).ToList(); if (q != null && q.Count > 0) { result = true; } return result; } /// /// 获取当天统计后的数据 /// /// /// public static Model.Project_SYHSEData_SYHSE getTodayProject_SYHSEData_SYHSE(string projectid) { var q = (from x in Funs.DB.Project_SYHSEData_SYHSE where x.ReportDate < DateTime.Now.AddDays(1).Date && x.ReportDate >= DateTime.Now.Date && x.ProjectId == projectid select x).FirstOrDefault(); return q; } /// /// 统计所有在建项目数据 /// public static void StatisticalAllProjectData() { var projectlist = ProjectService.GetProjectWorkList(); foreach (var item in projectlist) { StatisticalData(item.ProjectId, SYHSESDateType.All); } } /// /// 统计数据 /// /// /// public static void StatisticalData(string projectid,SYHSESDateType sYHSESDateType) { string thisUnitId = string.Empty; var thisUnit = CommonService.GetIsThisUnit(); if (thisUnit != null) { thisUnitId = thisUnit.UnitId; } var base_Unit = BLL.UnitService.GetUnitByUnitId(thisUnitId); Model.Project_SYHSEData_SYHSE table = new Model.Project_SYHSEData_SYHSE(); if (IsReportByToday(projectid)) { table = getTodayProject_SYHSEData_SYHSE(projectid); } else { table.Id = SQLHelper.GetNewID(); } table.UnitId = thisUnitId; table.CollCropCode = base_Unit.CollCropCode; table.UnitName = base_Unit.UnitName; table.ProjectId = projectid; table.ReportDate = DateTime.Now.Date; if (sYHSESDateType== SYHSESDateType.RiskControl || sYHSESDateType == SYHSESDateType.All) { table.GeneralRiskNum = GetGeneralRiskNum(projectid); table.LowRiskNum = GetLowRiskNum(projectid); table.MediumRiskNum = GetMediumRiskNum(projectid); table.HighRiskNum = GetHighRiskNum(projectid); } if (sYHSESDateType == SYHSESDateType.MajorHazardSources || sYHSESDateType == SYHSESDateType.All) { table.GradedResponsiblePersonNum = GetGradedResponsiblePersonNum(projectid); table.ChargeInsurancePersonNum = GetChargeInsurancePersonNum(projectid); table.DesignQuantity = GetDesignQuantity(projectid); table.RunningCapacity = GetRunningCapacity(projectid); table.InterlockSettingValue = GetInterlockSettingValue(projectid); table.VideoSurveillanceNum = GetVideoSurveillanceNum(projectid); } if (sYHSESDateType == SYHSESDateType.Basic || sYHSESDateType == SYHSESDateType.All) { table.TotalWorkinghours = GetTotalWorkinghours(projectid); table.SafeWorkinghours = GetSafeWorkinghours(projectid); table.LostWorkinghours = GetLostWorkinghours(projectid); } if (sYHSESDateType == SYHSESDateType.EnvironmentalData || sYHSESDateType == SYHSESDateType.All) { table.TotalEnergyConsumption = GetTotalEnergyConsumption(projectid); table.IncomeComprehensiveEnergyConsumption = GetIncomeComprehensiveEnergyConsumption(projectid); table.NewWaterConsumption = GetNewWaterConsumption(projectid); } if (sYHSESDateType == SYHSESDateType.TroubleshootingAndTreatment || sYHSESDateType == SYHSESDateType.All) { table.GeneralClosedNum = GetGeneralClosedNum(projectid); table.GeneralNotClosedNum = GetGeneralNotClosedNum(projectid); table.MajorClosedNum = GetMajorClosedNum(projectid); table.MajorNotClosedNum = GetMajorNotClosedNum(projectid); } if (sYHSESDateType == SYHSESDateType.JobManagementData || sYHSESDateType == SYHSESDateType.All) { table.HotWorkPermitNum = GetHotWorkPermitNum(projectid); table.HotWorkClosedNum = GetHotWorkClosedNum(projectid); table.HighPermitNum = GetHighPermitNum(projectid); table.HighClosedNum = GetHighClosedNum(projectid); table.TemporaryElectricityPermitNum = GetTemporaryElectricityPermitNum(projectid); table.TemporaryElectricityClosedNum = GetTemporaryElectricityClosedNum(projectid); table.BlindPlatePermitNum = GetBlindPlatePermitNum(projectid); table.BlindPlateClosedNum = GetBlindPlateClosedNum(projectid); table.GroundbreakingPermitNum = GetGroundbreakingPermitNum(projectid); table.GroundbreakingClosedNum = GetGroundbreakingClosedNum(projectid); table.OpenCircuitPermitNum = GetOpenCircuitPermitNum(projectid); table.OpenCircuitClosedNum = GetOpenCircuitClosedNum(projectid); table.HoistingPermitNum = GetHoistingPermitNum(projectid); table.HoistingClosedNum = GetHoistingClosedNum(projectid); } if (IsReportByToday(projectid)) { UpdateProject_SYHSEData_SYHSE(table); } else { AddProject_SYHSEData_SYHSE(table); } SYHSEData_SYHSEService.UpdateTodyData_State(); } /// /// 判断该项目的该日期是否统计数据 /// /// public static bool IsReportByDate(DateTime dateTime, string projectid) { var result = false; var q = (from x in Funs.DB.Project_SYHSEData_SYHSE where x.ReportDate >= dateTime.Date && x.ReportDate < (dateTime.Date.AddDays(1).Date) && x.ProjectId == projectid select x).ToList(); if (q != null && q.Count > 0) { result = true; } return result; } /// /// 获取一般风险数 /// /// public static int GetGeneralRiskNum(string projectid) { int result = 0; return result; } /// /// 获取低风险数 /// /// public static int GetLowRiskNum(string projectid) { int result = 0; return result; } /// /// 获取中风险数 /// /// public static int GetMediumRiskNum(string projectid) { int result = 0; return result; } /// /// 获取高风险数 /// /// public static int GetHighRiskNum(string projectid) { int result = 0; return result; } /// /// 获取分级责任人数 /// /// public static int GetGradedResponsiblePersonNum(string projectid) { int result = 0; return result; } /// /// 获取包保责任人数 /// /// public static int GetChargeInsurancePersonNum(string projectid) { int result = 0; return result; } /// /// 获取设计量 /// /// public static int GetDesignQuantity(string projectid) { int result = 0; return result; } /// /// 获取运行量 /// /// public static int GetRunningCapacity(string projectid) { int result = 0; return result; } /// /// 获取联锁设定值 /// /// public static int GetInterlockSettingValue(string projectid) { int result = 0; return result; } /// /// 获取视频监控数 /// /// public static int GetVideoSurveillanceNum(string projectid) { int result = 0; return result; } /// /// 获取总工时数 /// /// public static int GetTotalWorkinghours(string projectid) { int result = 0; return result; } /// /// 获取安全工时数 /// /// public static int GetSafeWorkinghours(string projectid) { int result = 0; return result; } /// /// 获取损失工时数 /// /// public static int GetLostWorkinghours(string projectid) { int result = 0; return result; } /// /// 获取能耗总量 /// /// public static int GetTotalEnergyConsumption(string projectid) { int result = 0; return result; } /// /// 获取万元营业收入综合能耗 /// /// public static int GetIncomeComprehensiveEnergyConsumption(string projectid) { int result = 0; return result; } /// /// 获取用新水量 /// /// public static int GetNewWaterConsumption(string projectid) { int result = 0; return result; } /// /// 获取一般隐患整改闭环项 /// /// public static int GetGeneralClosedNum(string projectid) { int result = 0; return result; } /// /// 获取一般隐患未整改完成项 /// /// public static int GetGeneralNotClosedNum(string projectid) { int result = 0; return result; } /// /// 获取重大隐患整改闭环项 /// /// public static int GetMajorClosedNum(string projectid) { int result = 0; return result; } /// /// 获取重大隐患未整改完成项 /// /// public static int GetMajorNotClosedNum(string projectid) { int result = 0; return result; } /// /// 获取动火许可项数 /// /// public static int GetHotWorkPermitNum(string projectid) { int result = 0; return result; } /// /// 获取动火关闭项数 /// /// public static int GetHotWorkClosedNum(string projectid) { int result = 0; return result; } /// /// 获取高处许可项数 /// /// public static int GetHighPermitNum(string projectid) { int result = 0; return result; } /// /// 获取高处关闭项数 /// /// public static int GetHighClosedNum(string projectid) { int result = 0; return result; } /// /// 获取临电许可项数 /// /// public static int GetTemporaryElectricityPermitNum(string projectid) { int result = 0; return result; } /// /// 获取临电关闭项数 /// /// public static int GetTemporaryElectricityClosedNum(string projectid) { int result = 0; return result; } /// /// 获取盲板许可项数 /// /// public static int GetBlindPlatePermitNum(string projectid) { int result = 0; return result; } /// /// 获取盲板关闭项数 /// /// public static int GetBlindPlateClosedNum(string projectid) { int result = 0; return result; } /// /// 获取动土许可项数 /// /// public static int GetGroundbreakingPermitNum(string projectid) { int result = 0; return result; } /// /// 获取动土关闭项数 /// /// public static int GetGroundbreakingClosedNum(string projectid) { int result = 0; return result; } /// /// 获取断路许可项数 /// /// public static int GetOpenCircuitPermitNum(string projectid) { int result = 0; return result; } /// /// 获取断路关闭项数 /// /// public static int GetOpenCircuitClosedNum(string projectid) { int result = 0; return result; } /// /// 获取吊装许可项数 /// /// public static int GetHoistingPermitNum(string projectid) { int result = 0; return result; } /// /// 获取吊装关闭项数 /// /// public static int GetHoistingClosedNum(string projectid) { int result = 0; return result; } } }