using Microsoft.AspNetCore.Mvc; using System.Net; using System.Net.Http.Headers; using Microsoft.Extensions.Hosting.Internal; using Microsoft.AspNetCore.Http.Extensions; using IStation.Untity; using Furion.DynamicApiController; using System.ComponentModel.DataAnnotations; using Mapster; namespace IStation.Application { /// /// EtaAnalyKpi /// [Route("Eta/Analy/Kpi")] [ApiDescriptionSettings("Eta", Name = "能效KPI分析", Order = 800)] public class EtaAnalyKpi_Controller : IDynamicApiController { /// /// 获取业务区域能效指标 /// [Route("GetLogicAreaEtaKpi@V1.0")] [HttpGet] public EtaKpi GetLogicAreaEtaKpi([FromQuery][Required] LogicAreaIDUnderCorpInput input) { #region 入参 var corpId = input.CorpID; var logicAreaId = input.LogicAreaID; #endregion #region 时间 var last_year = DateTime.Now.AddYears(-1).Year;//去年 var this_year = DateTime.Now.Year;//今年 var last_month_day = DateTime.Now.AddMonths(-1);//上个月的同一天 var today = DateTime.Today;//今天 #endregion #region 数据 var eta_standard_coal = new Service.ParasConfigure().GetByType(corpId, Configure.Paras_StandardCoal);//标准煤系数 var eta_standard_list = new Service.EtaStandardConfigure().GetByCorpID(corpId);//能效标准项列表 var service_eta = new Service.EtaLogicRealRecord(); var eta_yestoday_record_list = service_eta.GetByObjectOfDay(corpId, ObjectType.LogicArea, logicAreaId, DateTime.Today.AddDays(-1)); //昨天的所有能效记录 var eta_this_record_list = service_eta.GetByObjectOfDay(corpId, ObjectType.LogicArea, logicAreaId, DateTime.Today);//当天所有能效记录 var eta_last_record = eta_this_record_list?.LastOrDefault();//最近一次能效记录 var service_eta_sum = new Service.EtaSumLogicRecord(); var eta_sum_month_last_record_list = service_eta_sum.GetMonthByObjectOfYear(corpId, ObjectType.LogicArea, logicAreaId, last_year);//去年的能效月汇总记录 var eta_sum_month_this_record_list = service_eta_sum.GetMonthByObjectOfYear(corpId, ObjectType.LogicArea, logicAreaId, this_year);//今年的能效月汇总记录 var eta_sum_day_last_record_list = service_eta_sum.GetDayByObjectOfYM(corpId, ObjectType.LogicArea, logicAreaId, last_month_day.Year, last_month_day.Month);//上月的能效日汇总记录 var eta_sum_day_this_record_list = service_eta_sum.GetDayByObjectOfYM(corpId, ObjectType.LogicArea, logicAreaId, today.Year, today.Month);//当月的能效日汇总记录 #endregion var vm = new EtaKpi(); #region Kpi指标项 vm.Items = new List(); #region 瞬时流量 var vm_item_q = new EtaKpiItem(); vm_item_q.Name = "瞬时流量"; vm_item_q.Unit = "m³/h"; vm_item_q.Value = string.Empty; if (eta_last_record != null) { if (eta_last_record.Qa != null) { vm_item_q.Value = Math.Round(eta_last_record.Qa.Value, 2).ToString(); } } vm.Items.Add(vm_item_q); #endregion #region 功率 var vm_item_p = new EtaKpiItem(); vm_item_p.Name = "瞬时功率"; vm_item_p.Unit = "kW"; vm_item_p.Value = string.Empty; if (eta_last_record != null) { if (eta_last_record.Pa != null) { vm_item_p.Value = Math.Round(eta_last_record.Pa.Value, 2).ToString(); } } vm.Items.Add(vm_item_p); #endregion #region 千吨能耗 var vm_item_wp = new EtaKpiItem(); vm_item_wp.Name = "千吨能耗"; vm_item_wp.Unit = "kW·h/km³"; vm_item_wp.Value = string.Empty; if (eta_last_record != null) { if (eta_last_record.WPa != null) { vm_item_wp.Value = Math.Round(eta_last_record.WPa.Value, 2).ToString(); } } vm.Items.Add(vm_item_wp); #endregion #region 单位能耗 var vm_item_uwp = new EtaKpiItem(); vm_item_uwp.Name = "单位能耗"; vm_item_uwp.Unit = "kW·h/km³/m"; vm_item_uwp.Value = string.Empty; if (eta_last_record != null) { if (eta_last_record.UWPa != null) { vm_item_uwp.Value = Math.Round(eta_last_record.UWPa.Value, 2).ToString(); } } vm.Items.Add(vm_item_uwp); #endregion #region 标准煤 var vm_item_coal = new EtaKpiItem(); vm_item_coal.Name = "标准煤"; vm_item_coal.Unit = "吨"; vm_item_coal.Value = string.Empty; if (eta_this_record_list != null && eta_this_record_list.Count > 0) { var eta_pa_record_list = eta_this_record_list?.Where(x => x.Pa != null).ToList(); if (eta_pa_record_list != null && eta_pa_record_list.Count > 0) { var standard_coal = 2.7978; if (eta_standard_coal != null) { standard_coal = double.Parse(eta_standard_coal.Value); } var run_coal = eta_pa_record_list.Sum(x => x.Pa.Value * x.Duration / 3600f); var run_coalStandard = ((run_coal / 10000f) * standard_coal); if (run_coalStandard > 1) { vm_item_coal.Value = run_coalStandard.ToString("0.00"); } else { vm_item_coal.Value = run_coalStandard.ToString("0.0000"); } } } vm.Items.Add(vm_item_coal); //算出今日的总用电量 value_coal ((value_coal / 10000f) * 2.7978).ToString("0.000000"); #endregion #endregion #region 效率区间比 vm.RatioItems = new List(); if (eta_this_record_list != null && eta_this_record_list.Count > 0) { var eta_this_ea_record_list = eta_this_record_list.Where(x => x.Ea != null).ToList(); if (eta_this_ea_record_list != null && eta_this_ea_record_list.Count > 0) { if (eta_standard_list != null && eta_standard_list.Count > 0) { foreach (var item in eta_standard_list) { var vm_ratio_item = new EtaKpiRatioItem(); vm_ratio_item.Name = $"{item.LowerLimit}%-{item.UpperLimit}%"; vm_ratio_item.Value = 0; var eta_ea_item_record_list = eta_this_ea_record_list.Where(x => x.Ea.Value >= item.LowerLimit && x.Ea.Value < item.UpperLimit).ToList(); if (eta_ea_item_record_list.Count > 0) { vm_ratio_item.Value = eta_ea_item_record_list.Sum(x => x.Duration); } vm.RatioItems.Add(vm_ratio_item); } } } } #endregion #region 能效指标 if (eta_last_record != null) { if (eta_last_record.Ea != null) { vm.Value = Math.Round(eta_last_record.Ea.Value, 2); } } #endregion #region 年度量 vm.YearItems = new List(); #region 用电量 var year_item_ed = new EtaKpiYearItem(); year_item_ed.Name = "用电量"; year_item_ed.Unit = "度"; year_item_ed.LastYearRecords = new List(); for (int i = 1; i <= 12; i++) { var record = new EtaKpiYearItemRecord(); record.Month = i; record.Value = 0; var last_year_month_sum_record = eta_sum_month_last_record_list?.Find(x => x.DataMonth == i); if (last_year_month_sum_record != null) { record.Value = Math.Round(last_year_month_sum_record.Dt, 1); } year_item_ed.LastYearRecords.Add(record); } year_item_ed.ThisYearRecords = new List(); for (int i = 1; i < DateTime.Now.Month; i++) { var record = new EtaKpiYearItemRecord(); record.Month = i; record.Value = 0; var this_year_month_sum_record = eta_sum_month_this_record_list?.Find(x => x.DataMonth == i); if (this_year_month_sum_record != null) { record.Value = Math.Round(this_year_month_sum_record.Dt, 1); } year_item_ed.ThisYearRecords.Add(record); } vm.YearItems.Add(year_item_ed); #endregion #region 供水量 var year_item_ws = new EtaKpiYearItem(); year_item_ws.Name = "供水量"; year_item_ws.Unit = "吨"; vm.YearItems.Add(year_item_ws); year_item_ws.LastYearRecords = new List(); for (int i = 1; i <= 12; i++) { var record = new EtaKpiYearItemRecord(); record.Month = i; record.Value = 0; var last_year_month_sum_record = eta_sum_month_last_record_list?.Find(x => x.DataMonth == i); if (last_year_month_sum_record != null) { record.Value = Math.Round(last_year_month_sum_record.Qt, 1); } year_item_ws.LastYearRecords.Add(record); } year_item_ws.ThisYearRecords = new List(); for (int i = 1; i < DateTime.Now.Month; i++) { var record = new EtaKpiYearItemRecord(); record.Month = i; record.Value = 0; var this_year_month_sum_record = eta_sum_month_this_record_list?.Find(x => x.DataMonth == i); if (this_year_month_sum_record != null) { record.Value = Math.Round(this_year_month_sum_record.Qt, 1); } year_item_ws.ThisYearRecords.Add(record); } #endregion #endregion #region 月度量 vm.MonthItems = new List(); #region 用电量 var month_item_ed = new EtaKpiMonthItem(); month_item_ed.Name = "用电量"; month_item_ed.Unit = "度"; vm.MonthItems.Add(month_item_ed); month_item_ed.LastMonthRecords = new List(); for (int i = 0; i < DateTime.DaysInMonth(last_month_day.Year, last_month_day.Month); i++) { var record = new EtaKpiMonthItemRecord(); record.Day = i + 1; record.Value = 0; var last_month_day_sum_record = eta_sum_day_last_record_list?.Find(x => x.DataDay.Day == i + 1); if (last_month_day_sum_record != null) { record.Value = Math.Round(last_month_day_sum_record.Dt, 1); } month_item_ed.LastMonthRecords.Add(record); } month_item_ed.ThisMonthRecords = new List(); for (int i = 1; i < today.Day; i++) { var record = new EtaKpiMonthItemRecord(); record.Day = i; record.Value = 0; var this_month_day_sum_record = eta_sum_day_this_record_list?.Find(x => x.DataDay.Day == i); if (this_month_day_sum_record != null) { record.Value = Math.Round(this_month_day_sum_record.Dt, 1); } month_item_ed.ThisMonthRecords.Add(record); } #endregion #region 供水量 var month_item_ws = new EtaKpiMonthItem(); month_item_ws.Name = "供水量"; month_item_ws.Unit = "吨"; vm.MonthItems.Add(month_item_ws); month_item_ws.LastMonthRecords = new List(); for (int i = 0; i < DateTime.DaysInMonth(last_month_day.Year, last_month_day.Month); i++) { var record = new EtaKpiMonthItemRecord(); record.Day = i + 1; record.Value = 0; var last_month_day_sum_record = eta_sum_day_last_record_list?.Find(x => x.DataDay.Day == i + 1); if (last_month_day_sum_record != null) { record.Value = Math.Round(last_month_day_sum_record.Qt, 1); } month_item_ws.LastMonthRecords.Add(record); } month_item_ws.ThisMonthRecords = new List(); for (int i = 1; i < DateTime.Now.Day; i++) { var record = new EtaKpiMonthItemRecord(); record.Day = i; record.Value = 0; var this_month_day_sum_record = eta_sum_day_this_record_list?.Find(x => x.DataDay.Day == i); if (this_month_day_sum_record != null) { record.Value = Math.Round(this_month_day_sum_record.Qt, 1); } month_item_ws.ThisMonthRecords.Add(record); } #endregion #endregion #region 实时量 vm.RealItems = new List(); #region 瞬时流量 var vm_real_item_q = new EtaKpiRealItem(); vm_real_item_q.Name = "瞬时流量"; vm_real_item_q.Unit = "m³/h"; vm_real_item_q.LastRealRecords = new List(); vm_real_item_q.ThisRealRecords = new List(); vm.RealItems.Add(vm_real_item_q); #endregion #region 功率 var vm_real_item_p = new EtaKpiRealItem(); vm_real_item_p.Name = "瞬时功率"; vm_real_item_p.Unit = "kW"; vm_real_item_p.LastRealRecords = new List(); vm_real_item_p.ThisRealRecords = new List(); vm.RealItems.Add(vm_real_item_p); #endregion #region 效率 var vm_real_item_e = new EtaKpiRealItem(); vm_real_item_e.Name = "效率"; vm_real_item_e.Unit = "%"; vm_real_item_e.LastRealRecords = new List(); vm_real_item_e.ThisRealRecords = new List(); vm.RealItems.Add(vm_real_item_e); #endregion #region 千吨能耗 var vm_real_item_wp = new EtaKpiRealItem(); vm_real_item_wp.Name = "千吨能耗"; vm_real_item_wp.Unit = "kW·h/km³"; vm_real_item_wp.LastRealRecords = new List(); vm_real_item_wp.ThisRealRecords = new List(); vm.RealItems.Add(vm_real_item_wp); #endregion #region 单位能耗 var vm_real_item_uwp = new EtaKpiRealItem(); vm_real_item_uwp.Name = "单位能耗"; vm_real_item_uwp.Unit = "kW·h/km³/m"; vm_real_item_uwp.LastRealRecords = new List(); vm_real_item_uwp.ThisRealRecords = new List(); vm.RealItems.Add(vm_real_item_uwp); #endregion #region 记录 //昨日记录 if (eta_yestoday_record_list != null && eta_yestoday_record_list.Count > 0) { for (DateTime i = DateTime.Today.AddDays(-1).Date; i < DateTime.Today.Date; i = i.AddSeconds(120)) { var last_real_record = eta_yestoday_record_list.Find(t => t.DataTime >= i && t.DataTime < i.AddSeconds(120)); if (last_real_record != null) { //瞬时流量 var vm_real_item_record_q = new EtaKpiRealItemRecord(); vm_real_item_record_q.Time = i.ToString("HH:mm:ss"); vm_real_item_record_q.Value = last_real_record.Qa; vm_real_item_q.LastRealRecords.Add(vm_real_item_record_q); //功率 var vm_real_item_record_p = new EtaKpiRealItemRecord(); vm_real_item_record_p.Time = i.ToString("HH:mm:ss"); vm_real_item_record_p.Value = last_real_record.Pa; vm_real_item_p.LastRealRecords.Add(vm_real_item_record_p); //效率 var vm_real_item_record_e = new EtaKpiRealItemRecord(); vm_real_item_record_e.Time = i.ToString("HH:mm:ss"); vm_real_item_record_e.Value = last_real_record.Ea; vm_real_item_e.LastRealRecords.Add(vm_real_item_record_e); //千吨能耗 var vm_real_item_record_wp = new EtaKpiRealItemRecord(); vm_real_item_record_wp.Time = i.ToString("HH:mm:ss"); vm_real_item_record_wp.Value = last_real_record.WPa; vm_real_item_wp.LastRealRecords.Add(vm_real_item_record_wp); //单位能耗 var vm_real_item_record_uwp = new EtaKpiRealItemRecord(); vm_real_item_record_uwp.Time = i.ToString("HH:mm:ss"); vm_real_item_record_uwp.Value = last_real_record.UWPa; vm_real_item_uwp.LastRealRecords.Add(vm_real_item_record_uwp); } } } //今日记录 if (eta_this_record_list != null && eta_this_record_list.Count > 0) { for (DateTime i = DateTime.Today.Date; i < DateTime.Now; i = i.AddSeconds(120)) { var this_real_record = eta_this_record_list.Find(t => t.DataTime >= i && t.DataTime < i.AddSeconds(120)); if (this_real_record != null) { //瞬时流量 var vm_real_item_record_q = new EtaKpiRealItemRecord(); vm_real_item_record_q.Time = i.ToString("HH:mm:ss"); vm_real_item_record_q.Value = this_real_record.Qa; vm_real_item_q.ThisRealRecords.Add(vm_real_item_record_q); //功率 var vm_real_item_record_p = new EtaKpiRealItemRecord(); vm_real_item_record_p.Time = i.ToString("HH:mm:ss"); vm_real_item_record_p.Value = this_real_record.Pa; vm_real_item_p.ThisRealRecords.Add(vm_real_item_record_p); //效率 var vm_real_item_record_e = new EtaKpiRealItemRecord(); vm_real_item_record_e.Time = i.ToString("HH:mm:ss"); vm_real_item_record_e.Value = this_real_record.Ea; vm_real_item_e.ThisRealRecords.Add(vm_real_item_record_e); //千吨能耗 var vm_real_item_record_wp = new EtaKpiRealItemRecord(); vm_real_item_record_wp.Time = i.ToString("HH:mm:ss"); vm_real_item_record_wp.Value = this_real_record.WPa; vm_real_item_wp.ThisRealRecords.Add(vm_real_item_record_wp); //单位能耗 var vm_real_item_record_uwp = new EtaKpiRealItemRecord(); vm_real_item_record_uwp.Time = i.ToString("HH:mm:ss"); vm_real_item_record_uwp.Value = this_real_record.UWPa; vm_real_item_uwp.ThisRealRecords.Add(vm_real_item_record_uwp); } } } #endregion #endregion #region 错误信息 if (eta_last_record != null) { var stationIds = eta_last_record.GetStatioinIds(); if (stationIds != null && stationIds.Count > 0) { if (!string.IsNullOrEmpty(eta_last_record.AnalyInfo)) { var stations = new Service.Station().GetByIds(corpId, stationIds); foreach (var item in stations) { vm.ErrorMessage += item.Name + "/"; } vm.ErrorMessage = vm.ErrorMessage.Substring(0, vm.ErrorMessage.Length - 1) + "测点异常!"; } } } #endregion #region 备注信息 var logicArea = new Service.LogicArea().GetByID(corpId, logicAreaId); vm.Description = logicArea.Description; #endregion return vm; } /// /// 获取泵站能效指标 /// [Route("GetStationEtaKpi@V1.0")] [HttpGet] public EtaKpi GetStationEtaKpi([FromQuery][Required] StationIDUnderCorpInput input) { #region 入参 var corpId = input.CorpID; var stationId = input.StationID; #endregion #region 时间 var last_year = DateTime.Now.AddYears(-1).Year;//去年 var this_year = DateTime.Now.Year;//今年 var last_month_day = DateTime.Now.AddMonths(-1);//上个月的同一天 var today = DateTime.Today;//今天 #endregion #region 数据 var eta_standard_coal = new Service.ParasConfigure().GetByType(corpId, Configure.Paras_StandardCoal);//标准煤系数 var eta_standard_list = new Service.EtaStandardConfigure().GetByCorpID(corpId);//能效标准项列表 var pipe_line_list = new Service.PipeLine().GetByBelongTypeAndBelongID(corpId,ObjectType.Station,stationId); pipe_line_list = pipe_line_list?.Where(x => x.Catalog == PipeLine.EnginePump && x.SerialNO != null).OrderBy(x => x.SerialNO).ToList();//机泵管路列表 var service_eta = new Service.EtaMultiRealRecord(); var eta_yestoday_record_list = service_eta.GetByObjectOfDay(corpId, ObjectType.Station, stationId, DateTime.Today.AddDays(-1)); //昨天的所有能效记录 var eta_this_record_list = service_eta.GetByObjectOfDay(corpId, ObjectType.Station, stationId, DateTime.Today);//当天所有能效记录 var eta_this_run_record_list = eta_this_record_list?.Where(x => x.RunningCount > 0).ToList();//当天所有开机能效记录 var eta_last_record = eta_this_record_list?.LastOrDefault();//最近一次能效记录 var service_eta_sum = new Service.EtaSumMultiRecord(); var eta_sum_month_last_record_list = service_eta_sum.GetMonthByObjectOfYear(corpId,ObjectType.Station, stationId, last_year);//去年的能效月汇总记录 var eta_sum_month_this_record_list = service_eta_sum.GetMonthByObjectOfYear(corpId, ObjectType.Station, stationId, this_year);//今年的能效月汇总记录 var eta_sum_day_last_record_list = service_eta_sum.GetDayByObjectOfYM(corpId, ObjectType.Station, stationId, last_month_day.Year, last_month_day.Month);//上月的能效日汇总记录 var eta_sum_day_this_record_list = service_eta_sum.GetDayByObjectOfYM(corpId, ObjectType.Station, stationId, today.Year, today.Month);//当月的能效日汇总记录 #endregion var vm = new EtaKpi(); #region Kpi指标项 vm.Items = new List(); #region 瞬时流量 var vm_item_q = new EtaKpiItem(); vm_item_q.Name = "瞬时流量"; vm_item_q.Unit = "m³/h"; vm_item_q.Value = string.Empty; if (eta_last_record != null) { if (eta_last_record.Qa != null) { vm_item_q.Value = Math.Round(eta_last_record.Qa.Value, 2).ToString(); } } vm.Items.Add(vm_item_q); #endregion #region 功率 var vm_item_p = new EtaKpiItem(); vm_item_p.Name = "瞬时功率"; vm_item_p.Unit = "kW"; vm_item_p.Value = string.Empty; if (eta_last_record != null) { if (eta_last_record.Pa != null) { vm_item_p.Value = Math.Round(eta_last_record.Pa.Value, 2).ToString(); } } vm.Items.Add(vm_item_p); #endregion #region 千吨能耗 var vm_item_wp = new EtaKpiItem(); vm_item_wp.Name = "千吨能耗"; vm_item_wp.Unit = "kW·h/km³"; vm_item_wp.Value = string.Empty; if (eta_last_record != null) { if (eta_last_record.WPa != null) { vm_item_wp.Value = Math.Round(eta_last_record.WPa.Value, 2).ToString(); } } vm.Items.Add(vm_item_wp); #endregion #region 单位能耗 var vm_item_uwp = new EtaKpiItem(); vm_item_uwp.Name = "单位能耗"; vm_item_uwp.Unit = "kW·h/km³/m"; vm_item_uwp.Value = string.Empty; if (eta_last_record != null) { if (eta_last_record.UWPa != null) { vm_item_uwp.Value = Math.Round(eta_last_record.UWPa.Value, 2).ToString(); } } vm.Items.Add(vm_item_uwp); #endregion #region 开机台数 var vm_item_run = new EtaKpiItem(); vm_item_run.Name = "开机台数"; vm_item_run.Unit = ""; vm_item_run.Value = string.Empty; if (pipe_line_list != null && pipe_line_list.Count > 0) { if (eta_last_record != null) { vm_item_run.Value = $"{eta_last_record.RunningCount}/{pipe_line_list.Count}"; } } vm.Items.Add(vm_item_run); #endregion #region 标准煤 var vm_item_coal = new EtaKpiItem(); vm_item_coal.Name = "标准煤"; vm_item_coal.Unit = "吨"; vm_item_coal.Value = string.Empty; if (eta_this_run_record_list != null && eta_this_run_record_list.Count > 0) { var eta_run_pa_record_list = eta_this_run_record_list?.Where(x => x.Pa != null).ToList(); if (eta_run_pa_record_list != null && eta_run_pa_record_list.Count > 0) { var standard_coal = 2.7978; if (eta_standard_coal != null) { standard_coal = double.Parse(eta_standard_coal.Value); } var run_coal = eta_run_pa_record_list.Sum(x => x.Pa.Value * x.Duration / 3600f); var run_coalStandard = ((run_coal / 10000f) * standard_coal); if (run_coalStandard > 1) { vm_item_coal.Value = run_coalStandard.ToString("0.00"); } else { vm_item_coal.Value = run_coalStandard.ToString("0.0000"); } } } vm.Items.Add(vm_item_coal); //算出今日的总用电量 value_coal ((value_coal / 10000f) * 2.7978).ToString("0.000000"); #endregion #endregion #region 效率区间比 vm.RatioItems = new List(); if (eta_this_run_record_list != null && eta_this_run_record_list.Count > 0) { var eta_this_run_ea_record_list = eta_this_run_record_list.Where(x => x.Ea != null).ToList(); if (eta_this_run_ea_record_list != null && eta_this_run_ea_record_list.Count > 0) { if (eta_standard_list != null && eta_standard_list.Count > 0) { foreach (var item in eta_standard_list) { var vm_ratio_item = new EtaKpiRatioItem(); vm_ratio_item.Name = $"{item.LowerLimit}%-{item.UpperLimit}%"; vm_ratio_item.Value = 0; var eta_run_ea_item_record_list = eta_this_run_ea_record_list.Where(x => x.Ea.Value >= item.LowerLimit && x.Ea.Value < item.UpperLimit).ToList(); if (eta_run_ea_item_record_list.Count > 0) { vm_ratio_item.Value = eta_run_ea_item_record_list.Sum(x => x.Duration); } vm.RatioItems.Add(vm_ratio_item); } } } } #endregion #region 能效指标 if (eta_last_record != null) { if (eta_last_record.Ea != null) { vm.Value = Math.Round(eta_last_record.Ea.Value, 2); } } #endregion #region 年度量 vm.YearItems = new List(); #region 用电量 var year_item_ed = new EtaKpiYearItem(); year_item_ed.Name = "用电量"; year_item_ed.Unit = "度"; year_item_ed.LastYearRecords = new List(); for (int i = 1; i <= 12; i++) { var record = new EtaKpiYearItemRecord(); record.Month = i; record.Value = 0; var last_year_month_sum_record = eta_sum_month_last_record_list?.Find(x => x.DataMonth == i); if (last_year_month_sum_record != null) { record.Value = Math.Round(last_year_month_sum_record.Dt, 1); } year_item_ed.LastYearRecords.Add(record); } year_item_ed.ThisYearRecords = new List(); for (int i = 1; i < DateTime.Now.Month; i++) { var record = new EtaKpiYearItemRecord(); record.Month = i; record.Value = 0; var this_year_month_sum_record = eta_sum_month_this_record_list?.Find(x => x.DataMonth == i); if (this_year_month_sum_record != null) { record.Value = Math.Round(this_year_month_sum_record.Dt, 1); } year_item_ed.ThisYearRecords.Add(record); } vm.YearItems.Add(year_item_ed); #endregion #region 供水量 var year_item_ws = new EtaKpiYearItem(); year_item_ws.Name = "供水量"; year_item_ws.Unit = "吨"; vm.YearItems.Add(year_item_ws); year_item_ws.LastYearRecords = new List(); for (int i = 1; i <= 12; i++) { var record = new EtaKpiYearItemRecord(); record.Month = i; record.Value = 0; var last_year_month_sum_record = eta_sum_month_last_record_list?.Find(x => x.DataMonth == i); if (last_year_month_sum_record != null) { record.Value = Math.Round(last_year_month_sum_record.Qt, 1); } year_item_ws.LastYearRecords.Add(record); } year_item_ws.ThisYearRecords = new List(); for (int i = 1; i < DateTime.Now.Month; i++) { var record = new EtaKpiYearItemRecord(); record.Month = i; record.Value = 0; var this_year_month_sum_record = eta_sum_month_this_record_list?.Find(x => x.DataMonth == i); if (this_year_month_sum_record != null) { record.Value = Math.Round(this_year_month_sum_record.Qt, 1); } year_item_ws.ThisYearRecords.Add(record); } #endregion #endregion #region 月度量 vm.MonthItems = new List(); #region 用电量 var month_item_ed = new EtaKpiMonthItem(); month_item_ed.Name = "用电量"; month_item_ed.Unit = "度"; vm.MonthItems.Add(month_item_ed); month_item_ed.LastMonthRecords = new List(); for (int i = 0; i < DateTime.DaysInMonth(last_month_day.Year, last_month_day.Month); i++) { var record = new EtaKpiMonthItemRecord(); record.Day = i + 1; record.Value = 0; var last_month_day_sum_record = eta_sum_day_last_record_list?.Find(x => x.DataDay.Day == i + 1); if (last_month_day_sum_record != null) { record.Value = Math.Round(last_month_day_sum_record.Dt, 1); } month_item_ed.LastMonthRecords.Add(record); } month_item_ed.ThisMonthRecords = new List(); for (int i = 1; i < today.Day; i++) { var record = new EtaKpiMonthItemRecord(); record.Day = i; record.Value = 0; var this_month_day_sum_record = eta_sum_day_this_record_list?.Find(x => x.DataDay.Day == i); if (this_month_day_sum_record != null) { record.Value = Math.Round(this_month_day_sum_record.Dt, 1); } month_item_ed.ThisMonthRecords.Add(record); } #endregion #region 供水量 var month_item_ws = new EtaKpiMonthItem(); month_item_ws.Name = "供水量"; month_item_ws.Unit = "吨"; vm.MonthItems.Add(month_item_ws); month_item_ws.LastMonthRecords = new List(); for (int i = 0; i < DateTime.DaysInMonth(last_month_day.Year, last_month_day.Month); i++) { var record = new EtaKpiMonthItemRecord(); record.Day = i + 1; record.Value = 0; var last_month_day_sum_record = eta_sum_day_last_record_list?.Find(x => x.DataDay.Day == i + 1); if (last_month_day_sum_record != null) { record.Value = Math.Round(last_month_day_sum_record.Qt, 1); } month_item_ws.LastMonthRecords.Add(record); } month_item_ws.ThisMonthRecords = new List(); for (int i = 1; i < DateTime.Now.Day; i++) { var record = new EtaKpiMonthItemRecord(); record.Day = i; record.Value = 0; var this_month_day_sum_record = eta_sum_day_this_record_list?.Find(x => x.DataDay.Day == i); if (this_month_day_sum_record != null) { record.Value = Math.Round(this_month_day_sum_record.Qt, 1); } month_item_ws.ThisMonthRecords.Add(record); } #endregion #endregion #region 实时量 vm.RealItems = new List(); #region 瞬时流量 var vm_real_item_q = new EtaKpiRealItem(); vm_real_item_q.Name = "瞬时流量"; vm_real_item_q.Unit = "m³/h"; vm_real_item_q.LastRealRecords = new List(); vm_real_item_q.ThisRealRecords = new List(); vm.RealItems.Add(vm_real_item_q); #endregion #region 功率 var vm_real_item_p = new EtaKpiRealItem(); vm_real_item_p.Name = "瞬时功率"; vm_real_item_p.Unit = "kW"; vm_real_item_p.LastRealRecords = new List(); vm_real_item_p.ThisRealRecords = new List(); vm.RealItems.Add(vm_real_item_p); #endregion #region 效率 var vm_real_item_e = new EtaKpiRealItem(); vm_real_item_e.Name = "效率"; vm_real_item_e.Unit = "%"; vm_real_item_e.LastRealRecords = new List(); vm_real_item_e.ThisRealRecords = new List(); vm.RealItems.Add(vm_real_item_e); #endregion #region 千吨能耗 var vm_real_item_wp = new EtaKpiRealItem(); vm_real_item_wp.Name = "千吨能耗"; vm_real_item_wp.Unit = "kW·h/km³"; vm_real_item_wp.LastRealRecords = new List(); vm_real_item_wp.ThisRealRecords = new List(); vm.RealItems.Add(vm_real_item_wp); #endregion #region 单位能耗 var vm_real_item_uwp = new EtaKpiRealItem(); vm_real_item_uwp.Name = "单位能耗"; vm_real_item_uwp.Unit = "kW·h/km³/m"; vm_real_item_uwp.LastRealRecords = new List(); vm_real_item_uwp.ThisRealRecords = new List(); vm.RealItems.Add(vm_real_item_uwp); #endregion #region 记录 //昨日记录 if (eta_yestoday_record_list != null && eta_yestoday_record_list.Count > 0) { for (DateTime i = DateTime.Today.AddDays(-1).Date; i < DateTime.Today.Date; i = i.AddSeconds(120)) { var last_real_record = eta_yestoday_record_list.Find(t => t.DataTime >= i && t.DataTime < i.AddSeconds(120)); if (last_real_record != null) { //瞬时流量 var vm_real_item_record_q = new EtaKpiRealItemRecord(); vm_real_item_record_q.Time = i.ToString("HH:mm:ss"); vm_real_item_record_q.Value = last_real_record.Qa; vm_real_item_q.LastRealRecords.Add(vm_real_item_record_q); //功率 var vm_real_item_record_p = new EtaKpiRealItemRecord(); vm_real_item_record_p.Time = i.ToString("HH:mm:ss"); vm_real_item_record_p.Value = last_real_record.Pa; vm_real_item_p.LastRealRecords.Add(vm_real_item_record_p); //效率 var vm_real_item_record_e = new EtaKpiRealItemRecord(); vm_real_item_record_e.Time = i.ToString("HH:mm:ss"); vm_real_item_record_e.Value = last_real_record.Ea; vm_real_item_e.LastRealRecords.Add(vm_real_item_record_e); //千吨能耗 var vm_real_item_record_wp = new EtaKpiRealItemRecord(); vm_real_item_record_wp.Time = i.ToString("HH:mm:ss"); vm_real_item_record_wp.Value = last_real_record.WPa; vm_real_item_wp.LastRealRecords.Add(vm_real_item_record_wp); //单位能耗 var vm_real_item_record_uwp = new EtaKpiRealItemRecord(); vm_real_item_record_uwp.Time = i.ToString("HH:mm:ss"); vm_real_item_record_uwp.Value = last_real_record.UWPa; vm_real_item_uwp.LastRealRecords.Add(vm_real_item_record_uwp); if (last_real_record.RunningCount > 0) { var tool_tip_list = new List(); for (int j = 0; j < pipe_line_list.Count; j++) { if (last_real_record.RunningFlag[j] == RunStatus.Run) { var tool_tip = pipe_line_list[j].Name+" "+last_real_record.HZa[j].ToString()+"Hz"; tool_tip_list.Add(tool_tip); } } vm_real_item_record_q.ToolTips = tool_tip_list; vm_real_item_record_p.ToolTips = tool_tip_list; vm_real_item_record_e.ToolTips = tool_tip_list; vm_real_item_record_wp.ToolTips = tool_tip_list; vm_real_item_record_uwp.ToolTips = tool_tip_list; } } } } //今日记录 if (eta_this_record_list != null && eta_this_record_list.Count > 0) { for (DateTime i = DateTime.Today.Date; i < DateTime.Now; i = i.AddSeconds(120)) { var this_real_record = eta_this_record_list.Find(t => t.DataTime >= i && t.DataTime < i.AddSeconds(120)); if (this_real_record != null) { //瞬时流量 var vm_real_item_record_q = new EtaKpiRealItemRecord(); vm_real_item_record_q.Time = i.ToString("HH:mm:ss"); vm_real_item_record_q.Value = this_real_record.Qa; vm_real_item_q.ThisRealRecords.Add(vm_real_item_record_q); //功率 var vm_real_item_record_p = new EtaKpiRealItemRecord(); vm_real_item_record_p.Time = i.ToString("HH:mm:ss"); vm_real_item_record_p.Value = this_real_record.Pa; vm_real_item_p.ThisRealRecords.Add(vm_real_item_record_p); //效率 var vm_real_item_record_e = new EtaKpiRealItemRecord(); vm_real_item_record_e.Time = i.ToString("HH:mm:ss"); vm_real_item_record_e.Value = this_real_record.Ea; vm_real_item_e.ThisRealRecords.Add(vm_real_item_record_e); //千吨能耗 var vm_real_item_record_wp = new EtaKpiRealItemRecord(); vm_real_item_record_wp.Time = i.ToString("HH:mm:ss"); vm_real_item_record_wp.Value = this_real_record.WPa; vm_real_item_wp.ThisRealRecords.Add(vm_real_item_record_wp); //单位能耗 var vm_real_item_record_uwp = new EtaKpiRealItemRecord(); vm_real_item_record_uwp.Time = i.ToString("HH:mm:ss"); vm_real_item_record_uwp.Value = this_real_record.UWPa; vm_real_item_uwp.ThisRealRecords.Add(vm_real_item_record_uwp); if (this_real_record.RunningCount > 0) { var tool_tip_list = new List(); for (int j = 0; j < pipe_line_list.Count; j++) { if (this_real_record.RunningFlag[j] == RunStatus.Run) { var tool_tip = pipe_line_list[j].Name + " " + this_real_record.HZa[j].ToString() + "Hz"; tool_tip_list.Add(tool_tip); } } vm_real_item_record_q.ToolTips = tool_tip_list; vm_real_item_record_p.ToolTips = tool_tip_list; vm_real_item_record_e.ToolTips = tool_tip_list; vm_real_item_record_wp.ToolTips = tool_tip_list; vm_real_item_record_uwp.ToolTips = tool_tip_list; } } } } #endregion #endregion #region 错误信息 if (eta_last_record != null) { if (!string.IsNullOrEmpty(eta_last_record.AnalyInfo)) { vm.ErrorMessage += eta_last_record.GetAnaInfoCN(); var pumpIds = eta_last_record.GetPumpIds(); if (pumpIds != null && pumpIds.Count > 0) { var pumps = new Service.Product().GetByIds(corpId, pumpIds); foreach (var item in pumps) { vm.ErrorMessage += item.Name + "/"; } vm.ErrorMessage = vm.ErrorMessage.Substring(0, vm.ErrorMessage.Length - 1) + "测点异常!"; } } } #endregion #region 备注信息 var station = new Service.LogicArea().GetByID(corpId, stationId); vm.Description = station.Description; #endregion return vm; } /// /// 获取机泵能效指标 /// [Route("GetEnginePumpEtaApi@V1.0")] [HttpGet] public EtaKpi GetEnginePumpEtaApi([FromQuery][Required] PipeLineIDUnderCorpInput input) { #region 入参 var corpId = input.CorpID; var pipeLineId = input.PipeLineID; #endregion #region 时间 var last_year = DateTime.Now.AddYears(-1).Year;//去年 var this_year = DateTime.Now.Year;//今年 var last_month_day = DateTime.Now.AddMonths(-1);//上个月的同一天 var today = DateTime.Today;//今天 #endregion #region 数据 var eta_standard_coal = new Service.ParasConfigure().GetByType(corpId,Configure.Paras_StandardCoal);//标准煤系数 LogHelper.Info("标准煤系数 通过"); var eta_standard_list = new Service.EtaStandardConfigure().GetByCorpID(corpId);//能效标准项列表 LogHelper.Info("能效标准项列表 通过"); var service_eta = new Service.EtaSingleRealRecord(); var eta_yestoday_record_list = service_eta.GetByObjectOfDay(corpId, ObjectType.PipeLine, pipeLineId, DateTime.Today.AddDays(-1));//昨天的所有能效记录 var eta_record_list = service_eta.GetByObjectOfDay(corpId, ObjectType.PipeLine, pipeLineId, DateTime.Today);//当天所有能效记录 var eta_run_record_list = eta_record_list?.Where(x => x.RSa > 0).ToList();//当天所有开机能效记录 var eta_last_record = eta_record_list?.LastOrDefault();//最近一次能效记录 LogHelper.Info("EtaLogicRealRecord 通过"); var service_eta_sum = new Service.EtaSumSingleRecord(); var eta_sum_month_last_record_list = service_eta_sum.GetMonthByObjectOfYear(corpId, ObjectType.PipeLine, pipeLineId, last_year);//去年的能效月汇总记录 var eta_sum_month_this_record_list = service_eta_sum.GetMonthByObjectOfYear(corpId, ObjectType.PipeLine, pipeLineId, this_year);//今年的能效月汇总记录 LogHelper.Info("EtaSumSingleMonthRecord 通过"); var eta_sum_day_last_record_list = service_eta_sum.GetDayByObjectOfYM(corpId, ObjectType.PipeLine, pipeLineId, last_month_day.Year, last_month_day.Month);//上月的能效日汇总记录 var eta_sum_day_this_record_list = service_eta_sum.GetDayByObjectOfYM(corpId, ObjectType.PipeLine, pipeLineId, today.Year, today.Month);//当月的能效日汇总记录 LogHelper.Info("EtaSumSingleDayRecord 通过"); #endregion var vm = new EtaKpi(); #region Kpi指标项 vm.Items = new List(); #region 瞬时流量 var vm_item_q = new EtaKpiItem(); vm_item_q.Name = "瞬时流量"; vm_item_q.Unit = "m³/h"; vm_item_q.Value = string.Empty; if (eta_last_record != null) { if (eta_last_record.Qa != null) { vm_item_q.Value = Math.Round(eta_last_record.Qa.Value, 2).ToString(); } } vm.Items.Add(vm_item_q); #endregion #region 功率 var vm_item_p = new EtaKpiItem(); vm_item_p.Name = "瞬时功率"; vm_item_p.Unit = "kW"; vm_item_p.Value = string.Empty; if (eta_last_record != null) { if (eta_last_record.Pa != null) { vm_item_p.Value = Math.Round(eta_last_record.Pa.Value, 2).ToString(); } } vm.Items.Add(vm_item_p); #endregion #region 千吨能耗 var vm_item_wp = new EtaKpiItem(); vm_item_wp.Name = "千吨能耗"; vm_item_wp.Unit = "kW·h/km³"; vm_item_wp.Value = string.Empty; if (eta_last_record != null) { if (eta_last_record.WPa != null) { vm_item_wp.Value = Math.Round(eta_last_record.WPa.Value, 2).ToString(); } } vm.Items.Add(vm_item_wp); #endregion #region 单位能耗 var vm_item_uwp = new EtaKpiItem(); vm_item_uwp.Name = "单位能耗"; vm_item_uwp.Unit = "kW·h/km³/m"; vm_item_uwp.Value = string.Empty; if (eta_last_record != null) { if (eta_last_record.UWPa != null) { vm_item_uwp.Value = Math.Round(eta_last_record.UWPa.Value, 2).ToString(); } } vm.Items.Add(vm_item_uwp); #endregion #region 运行时间 var vm_item_run = new EtaKpiItem(); vm_item_run.Name = "运行时间"; vm_item_run.Unit = "h"; vm_item_run.Value = string.Empty; if (eta_run_record_list != null && eta_run_record_list.Count > 0) { var run_time = eta_run_record_list.Sum(x => x.Duration); vm_item_run.Value = Math.Round(run_time / 3600f, 2).ToString(); } vm.Items.Add(vm_item_run); #endregion #region 标准煤 var vm_item_coal = new EtaKpiItem(); vm_item_coal.Name = "标准煤"; vm_item_coal.Unit = "吨"; vm_item_coal.Value = string.Empty; if (eta_run_record_list != null && eta_run_record_list.Count > 0) { var eta_run_pa_record_list = eta_run_record_list?.Where(x => x.Pa != null).ToList(); if (eta_run_pa_record_list != null && eta_run_pa_record_list.Count > 0) { var standard_coal = 2.7978; if (eta_standard_coal != null) { standard_coal = double.Parse(eta_standard_coal.Value); } var run_coal = eta_run_pa_record_list.Sum(x => x.Pa.Value * x.Duration / 3600f); var run_coalStandard = ((run_coal / 10000f) * standard_coal); if (run_coalStandard > 1) { vm_item_coal.Value = run_coalStandard.ToString("0.00"); } else { vm_item_coal.Value = run_coalStandard.ToString("0.0000"); } } } vm.Items.Add(vm_item_coal); //算出今日的总用电量 value_coal ((value_coal / 10000f) * 2.7978).ToString("0.000000"); #endregion #endregion #region 效率运行比 vm.RatioItems = new List(); if (eta_run_record_list != null && eta_run_record_list.Count > 0) { var eta_run_ea_record_list = eta_run_record_list.Where(x => x.Ea != null).ToList(); if (eta_run_ea_record_list != null && eta_run_ea_record_list.Count > 0) { if (eta_standard_list != null && eta_standard_list.Count > 0) { foreach (var item in eta_standard_list) { var vm_ratio_item = new EtaKpiRatioItem(); vm_ratio_item.Name = $"{item.LowerLimit}%-{item.UpperLimit}%"; vm_ratio_item.Value = 0; var eta_run_ea_item_record_list = eta_run_ea_record_list.Where(x => x.Ea.Value >= item.LowerLimit && x.Ea.Value < item.UpperLimit).ToList(); if (eta_run_ea_item_record_list.Count > 0) { vm_ratio_item.Value = eta_run_ea_item_record_list.Sum(x => x.Duration); } vm.RatioItems.Add(vm_ratio_item); } } } } #endregion #region 能效指标 if (eta_last_record != null) { if (eta_last_record.Ea != null) { vm.Value = Math.Round(eta_last_record.Ea.Value, 2); } } #endregion #region 年度量 vm.YearItems = new List(); #region 用电量 var year_item_ed = new EtaKpiYearItem(); year_item_ed.Name = "用电量"; year_item_ed.Unit = "度"; year_item_ed.LastYearRecords = new List(); for (int i = 1; i <= 12; i++) { var record = new EtaKpiYearItemRecord(); record.Month = i; record.Value = 0; var last_year_month_sum_record = eta_sum_month_last_record_list?.Find(x => x.DataMonth == i); if (last_year_month_sum_record != null) { record.Value = Math.Round(last_year_month_sum_record.Dt, 1); } year_item_ed.LastYearRecords.Add(record); } year_item_ed.ThisYearRecords = new List(); for (int i = 1; i < DateTime.Now.Month; i++) { var record = new EtaKpiYearItemRecord(); record.Month = i; record.Value = 0; var this_year_month_sum_record = eta_sum_month_this_record_list?.Find(x => x.DataMonth == i); if (this_year_month_sum_record != null) { record.Value = Math.Round(this_year_month_sum_record.Dt, 1); } year_item_ed.ThisYearRecords.Add(record); } vm.YearItems.Add(year_item_ed); #endregion #region 供水量 var year_item_ws = new EtaKpiYearItem(); year_item_ws.Name = "供水量"; year_item_ws.Unit = "吨"; vm.YearItems.Add(year_item_ws); year_item_ws.LastYearRecords = new List(); for (int i = 1; i <= 12; i++) { var record = new EtaKpiYearItemRecord(); record.Month = i; record.Value = 0; var last_year_month_sum_record = eta_sum_month_last_record_list?.Find(x => x.DataMonth == i); if (last_year_month_sum_record != null) { record.Value = Math.Round(last_year_month_sum_record.Qt, 1); } year_item_ws.LastYearRecords.Add(record); } year_item_ws.ThisYearRecords = new List(); for (int i = 1; i < DateTime.Now.Month; i++) { var record = new EtaKpiYearItemRecord(); record.Month = i; record.Value = 0; var this_year_month_sum_record = eta_sum_month_this_record_list?.Find(x => x.DataMonth == i); if (this_year_month_sum_record != null) { record.Value = Math.Round(this_year_month_sum_record.Qt, 1); } year_item_ws.ThisYearRecords.Add(record); } #endregion #region 运行时间 var year_item_run = new EtaKpiYearItem(); year_item_run.Name = "运行时间"; year_item_run.Unit = "h"; year_item_run.LastYearRecords = new List(); for (int i = 1; i <= 12; i++) { var record = new EtaKpiYearItemRecord(); record.Month = i; record.Value = 0; var last_year_month_sum_record = eta_sum_month_last_record_list?.Find(x => x.DataMonth == i); if (last_year_month_sum_record != null) { record.Value = Math.Round(last_year_month_sum_record.RunTime / 3600f, 1); } year_item_run.LastYearRecords.Add(record); } year_item_run.ThisYearRecords = new List(); for (int i = 1; i < DateTime.Now.Month; i++) { var record = new EtaKpiYearItemRecord(); record.Month = i; record.Value = 0; var this_year_month_sum_record = eta_sum_month_this_record_list?.Find(x => x.DataMonth == i); if (this_year_month_sum_record != null) { record.Value = Math.Round(this_year_month_sum_record.RunTime / 3600f, 1); } year_item_run.ThisYearRecords.Add(record); } vm.YearItems.Add(year_item_run); #endregion #endregion #region 月度量 vm.MonthItems = new List(); #region 用电量 var month_item_ed = new EtaKpiMonthItem(); month_item_ed.Name = "用电量"; month_item_ed.Unit = "度"; vm.MonthItems.Add(month_item_ed); month_item_ed.LastMonthRecords = new List(); for (int i = 0; i < DateTime.DaysInMonth(last_month_day.Year, last_month_day.Month); i++) { var record = new EtaKpiMonthItemRecord(); record.Day = i + 1; record.Value = 0; var last_month_day_sum_record = eta_sum_day_last_record_list?.Find(x => x.DataDay.Day == i + 1); if (last_month_day_sum_record != null) { record.Value = Math.Round(last_month_day_sum_record.Dt, 1); } month_item_ed.LastMonthRecords.Add(record); } month_item_ed.ThisMonthRecords = new List(); for (int i = 1; i < today.Day; i++) { var record = new EtaKpiMonthItemRecord(); record.Day = i; record.Value = 0; var this_month_day_sum_record = eta_sum_day_this_record_list?.Find(x => x.DataDay.Day == i); if (this_month_day_sum_record != null) { record.Value = Math.Round(this_month_day_sum_record.Dt, 1); } month_item_ed.ThisMonthRecords.Add(record); } #endregion #region 供水量 var month_item_ws = new EtaKpiMonthItem(); month_item_ws.Name = "供水量"; month_item_ws.Unit = "吨"; vm.MonthItems.Add(month_item_ws); month_item_ws.LastMonthRecords = new List(); for (int i = 0; i < DateTime.DaysInMonth(last_month_day.Year, last_month_day.Month); i++) { var record = new EtaKpiMonthItemRecord(); record.Day = i + 1; record.Value = 0; var last_month_day_sum_record = eta_sum_day_last_record_list?.Find(x => x.DataDay.Day == i + 1); if (last_month_day_sum_record != null) { record.Value = Math.Round(last_month_day_sum_record.Qt, 1); } month_item_ws.LastMonthRecords.Add(record); } month_item_ws.ThisMonthRecords = new List(); for (int i = 1; i < DateTime.Now.Day; i++) { var record = new EtaKpiMonthItemRecord(); record.Day = i; record.Value = 0; var this_month_day_sum_record = eta_sum_day_this_record_list?.Find(x => x.DataDay.Day == i); if (this_month_day_sum_record != null) { record.Value = Math.Round(this_month_day_sum_record.Qt, 1); } month_item_ws.ThisMonthRecords.Add(record); } #endregion #region 运行时间 var month_item_run = new EtaKpiMonthItem(); month_item_run.Name = "运行时间"; month_item_run.Unit = "h"; month_item_run.LastMonthRecords = new List(); for (int i = 0; i < DateTime.DaysInMonth(last_month_day.Year, last_month_day.Month); i++) { var record = new EtaKpiMonthItemRecord(); record.Day = i + 1; record.Value = 0; var last_month_day_sum_record = eta_sum_day_last_record_list?.Find(x => x.DataDay.Day == i + 1); if (last_month_day_sum_record != null) { record.Value = Math.Round(last_month_day_sum_record.RunTime / 3600f, 1); } month_item_run.LastMonthRecords.Add(record); } month_item_run.ThisMonthRecords = new List(); for (int i = 1; i < today.Day; i++) { var record = new EtaKpiMonthItemRecord(); record.Day = i; record.Value = 0; var this_month_day_sum_record = eta_sum_day_this_record_list?.Find(x => x.DataDay.Day == i); if (this_month_day_sum_record != null) { record.Value = Math.Round(this_month_day_sum_record.RunTime / 3600f, 1); } month_item_run.ThisMonthRecords.Add(record); } vm.MonthItems.Add(month_item_run); #endregion #endregion #region 实时量 vm.RealItems = new List(); #region 瞬时流量 var vm_real_item_q = new EtaKpiRealItem(); vm_real_item_q.Name = "瞬时流量"; vm_real_item_q.Unit = "m³/h"; vm_real_item_q.LastRealRecords = new List(); vm_real_item_q.ThisRealRecords = new List(); vm.RealItems.Add(vm_real_item_q); #endregion #region 功率 var vm_real_item_p = new EtaKpiRealItem(); vm_real_item_p.Name = "瞬时功率"; vm_real_item_p.Unit = "kW"; vm_real_item_p.LastRealRecords = new List(); vm_real_item_p.ThisRealRecords = new List(); vm.RealItems.Add(vm_real_item_p); #endregion #region 效率 var vm_real_item_e = new EtaKpiRealItem(); vm_real_item_e.Name = "效率"; vm_real_item_e.Unit = "%"; vm_real_item_e.LastRealRecords = new List(); vm_real_item_e.ThisRealRecords = new List(); vm.RealItems.Add(vm_real_item_e); #endregion #region 千吨能耗 var vm_real_item_wp = new EtaKpiRealItem(); vm_real_item_wp.Name = "千吨能耗"; vm_real_item_wp.Unit = "kW·h/km³"; vm_real_item_wp.LastRealRecords = new List(); vm_real_item_wp.ThisRealRecords = new List(); vm.RealItems.Add(vm_real_item_wp); #endregion #region 单位能耗 var vm_real_item_uwp = new EtaKpiRealItem(); vm_real_item_uwp.Name = "单位能耗"; vm_real_item_uwp.Unit = "kW·h/km³/m"; vm_real_item_uwp.LastRealRecords = new List(); vm_real_item_uwp.ThisRealRecords = new List(); vm.RealItems.Add(vm_real_item_uwp); #endregion #region 记录 //昨日记录 if (eta_yestoday_record_list != null && eta_yestoday_record_list.Count > 0) { for (DateTime i = DateTime.Today.AddDays(-1).Date; i < DateTime.Today.Date; i = i.AddSeconds(120)) { var last_real_record = eta_yestoday_record_list.Find(t => t.DataTime >= i && t.DataTime < i.AddSeconds(120)); if (last_real_record != null) { //瞬时流量 var vm_real_item_record_q = new EtaKpiRealItemRecord(); vm_real_item_record_q.Time = i.ToString("HH:mm:ss"); vm_real_item_record_q.Value = last_real_record.Qa; vm_real_item_q.LastRealRecords.Add(vm_real_item_record_q); //功率 var vm_real_item_record_p = new EtaKpiRealItemRecord(); vm_real_item_record_p.Time = i.ToString("HH:mm:ss"); vm_real_item_record_p.Value = last_real_record.Pa; vm_real_item_p.LastRealRecords.Add(vm_real_item_record_p); //效率 var vm_real_item_record_e = new EtaKpiRealItemRecord(); vm_real_item_record_e.Time = i.ToString("HH:mm:ss"); vm_real_item_record_e.Value = last_real_record.Ea; vm_real_item_e.LastRealRecords.Add(vm_real_item_record_e); //千吨能耗 var vm_real_item_record_wp = new EtaKpiRealItemRecord(); vm_real_item_record_wp.Time = i.ToString("HH:mm:ss"); vm_real_item_record_wp.Value = last_real_record.WPa; vm_real_item_wp.LastRealRecords.Add(vm_real_item_record_wp); //单位能耗 var vm_real_item_record_uwp = new EtaKpiRealItemRecord(); vm_real_item_record_uwp.Time = i.ToString("HH:mm:ss"); vm_real_item_record_uwp.Value = last_real_record.UWPa; vm_real_item_uwp.LastRealRecords.Add(vm_real_item_record_uwp); } } } //今日记录 if (eta_record_list != null && eta_record_list.Count > 0) { for (DateTime i = DateTime.Today.Date; i < DateTime.Now; i = i.AddSeconds(120)) { var this_real_record = eta_record_list.Find(t => t.DataTime >= i && t.DataTime < i.AddSeconds(120)); if (this_real_record != null) { //瞬时流量 var vm_real_item_record_q = new EtaKpiRealItemRecord(); vm_real_item_record_q.Time = i.ToString("HH:mm:ss"); vm_real_item_record_q.Value = this_real_record.Qa; vm_real_item_q.ThisRealRecords.Add(vm_real_item_record_q); //功率 var vm_real_item_record_p = new EtaKpiRealItemRecord(); vm_real_item_record_p.Time = i.ToString("HH:mm:ss"); vm_real_item_record_p.Value = this_real_record.Pa; vm_real_item_p.ThisRealRecords.Add(vm_real_item_record_p); //效率 var vm_real_item_record_e = new EtaKpiRealItemRecord(); vm_real_item_record_e.Time = i.ToString("HH:mm:ss"); vm_real_item_record_e.Value = this_real_record.Ea; vm_real_item_e.ThisRealRecords.Add(vm_real_item_record_e); //千吨能耗 var vm_real_item_record_wp = new EtaKpiRealItemRecord(); vm_real_item_record_wp.Time = i.ToString("HH:mm:ss"); vm_real_item_record_wp.Value = this_real_record.WPa; vm_real_item_wp.ThisRealRecords.Add(vm_real_item_record_wp); //单位能耗 var vm_real_item_record_uwp = new EtaKpiRealItemRecord(); vm_real_item_record_uwp.Time = i.ToString("HH:mm:ss"); vm_real_item_record_uwp.Value = this_real_record.UWPa; vm_real_item_uwp.ThisRealRecords.Add(vm_real_item_record_uwp); } } } #endregion #endregion #region 错误信息 if (eta_last_record != null) { vm.ErrorMessage = eta_last_record.GetAnaInfoCN(); } #endregion #region 备注信息 var pipeLineBinding = new Service.PipeLineBinding().GetUseByPipeLineID(corpId,pipeLineId); if (pipeLineBinding!=null&&pipeLineBinding.Count>0) { var first = pipeLineBinding.First(); var product = new Service.Product().GetByID(corpId, first.BindingID); vm.Description = product?.Description; } #endregion return vm; } } }