From 23f6326b8df32975df95099c9b3d9c958c8c2459 Mon Sep 17 00:00:00 2001 From: lixiaojun <1287241240@qq.com> Date: 星期三, 12 四月 2023 13:34:35 +0800 Subject: [PATCH] 优化调度 --- Application/IStation.Application.OpenApi/shys/plan/PlanAna_ShysController.cs | 254 +++++++++++++++++++++++++++++--------------------- 1 files changed, 149 insertions(+), 105 deletions(-) diff --git a/Application/IStation.Application.OpenApi/shys/plan/PlanAna_ShysController.cs b/Application/IStation.Application.OpenApi/shys/plan/PlanAna_ShysController.cs index 6822e92..472772b 100644 --- a/Application/IStation.Application.OpenApi/shys/plan/PlanAna_ShysController.cs +++ b/Application/IStation.Application.OpenApi/shys/plan/PlanAna_ShysController.cs @@ -9,6 +9,8 @@ using Microsoft.AspNetCore.Authorization; using IStation.Calculation; using IStation.Dto; +using System.Collections.Generic; +using Mapster; namespace IStation.Application { @@ -56,21 +58,45 @@ [HttpGet] public List<PlanAnaDto> Calculate_debug() { - var path = @"D:\WorkData\IStation\result_1021.json"; + var path = @"D:\WorkData\IStation\result_20221114.json"; if (!System.IO.File.Exists(path)) return null; - + var responseText = System.IO.File.ReadAllText(path);//(娴嬭瘯鐢ㄧ殑) var planDataList = JsonHelper.Json2Object<List<PlanAnaData>>(responseText); - return CalculateCore(planDataList); + + var ret = CalculateCore(planDataList ); + + return ret; } - + + + /// <summary> + /// 璁$畻-Web + /// </summary> + [AllowAnonymous] + [NonUnify] + [Route("Calculate@Web")] + [HttpPost] + public List<PlanAnaDto> Calculate_Web([Required] List<PlanAnaData> list) + { + if (list == null || list.Count < 1) + { + LogHelper.Error("涓婃捣鍘熸按鑳借�楄鍒掑垎鏋愯绠楁帴鍙e叆鍙備负绌�"); + return default; + } + + var ret = CalculateCore(list); + return ret; + } + + #region 鍒嗘瀽鏍稿績 + /// <summary> /// 鍒嗘瀽鏍稿績 /// </summary> - /// <param name="planDataList"></param> - /// <returns></returns> - private List<PlanAnaDto> CalculateCore(List<PlanAnaData> planDataList) + /// <param name="planDataList"></param> + private List<PlanAnaDto> CalculateCore(List<PlanAnaData> planDataList) { if (planDataList == null || planDataList.Count < 1) { @@ -85,115 +111,133 @@ var sg_factoryIds = planDataList.SelectMany(x => x.datas).Select(x => x.factory).Distinct().ToList(); var vmList = new List<PlanAnaDto>(); + + foreach (var sg_factoryId in sg_factoryIds) { - //鎵惧埌鐩稿叧娉电珯锛屽苟杩涜璁$畻 - var stationInfo = ShysPlanHelper.GetStationInfo(sg_factoryId); - if (stationInfo == null) + string error_info; + var vmItem = Ana(planDataList, sg_factoryId, out error_info); + if (vmItem != null) { - // LogHelper.Error("鏈壘鍒癷d:{factoryId},瀵瑰簲鐨勬车绔�"); - continue; + vmList.Add(vmItem); } - - var stationId = stationInfo.ID; - var station = new Service.Station().GetByID(_corpId, stationId); - if (station == null) + else { - LogHelper.Error($"涓婃捣鍘熸按鑳借�楄鍒掑垎鏋愯绠椾腑锛� 娉电珯id:{stationId}, 鏁版嵁搴撲腑鏈壘鍒版娉电珯"); - continue; + vmList.Add(new PlanAnaDto() { factory = sg_factoryId, name = "", error = error_info }); } - var calculator = stationInfo.Calculator; - if (calculator == null) - { - LogHelper.Error($"涓婃捣鍘熸按鑳借�楄鍒掑垎鏋愯绠椾腑锛� 娉电珯id:{stationId}, 鏈瀯寤鸿绠楀櫒"); - continue; - } - calculator.SetStationID(4, stationInfo.ID);//璁剧疆ID - - //鏋勯�犺绠楀叆鍙� - var sumRecordList = new List<MonthSumRecord>(); - foreach (var planData in planDataList) - { - var sumRecord = new MonthSumRecord(); - sumRecord.Month = planData.timeflag; - sumRecord.HourRecords = new List<HourSumRecord>(); - var factoryData = planData.datas.Find(t => t.factory == sg_factoryId); - for (int i = 0; i <= 23; i++) - { - var hourSumRecord = new HourSumRecord(); - hourSumRecord.Hour = i; - hourSumRecord.Records = new List<Dto.MonitorRecord4SG>(); - if (factoryData.scada != null && factoryData.scada.Count > 0) - { - foreach (var scadaItem in factoryData.scada) - { - var scadaRecord = new Dto.MonitorRecord4SG(); - scadaRecord.MonitorTag = scadaItem.tagname ; - var ff = scadaItem.values.Find(t => t.GetHour() == i ); - if(ff == null) - { - if (calculator.Is娑蹭綅Monitor(scadaItem.tagname)) - { - scadaRecord.RecordValue = 0; - } - else - { - LogHelper.Error($"涓婃捣鍘熸按鑳借�楄鍒掑垎鏋愯绠椾腑锛� 娉电珯id:{stationId}, {scadaItem.tagname} 鏃堕棿鐐箋i}, 鏈壘鍒版暟鎹�"); - return default; - } - - } - else - { - scadaRecord.RecordValue = ff.value; - } - - hourSumRecord.Records.Add(scadaRecord); - } - } - sumRecord.HourRecords.Add(hourSumRecord); - } - sumRecordList.Add(sumRecord); - } - - string error_info=""; - var resultList = calculator.Calc(station, sg_factoryId, sumRecordList, out error_info); - if (resultList == null || resultList.Count() < 1) - { - LogHelper.Error($"涓婃捣鍘熸按鑳借�楄鍒掑垎鏋愯绠椾腑锛屾车绔欏悕绉�:{station.Name} 娉电珯id:{stationId},璁$畻閿欒,鍘熷洜鏄�:{error_info}" ); - continue; - } - - //鐢熸垚杩斿洖缁撴灉 - var vmItem = new PlanAnaDto(); - vmItem.factory = sg_factoryId; - vmItem.name = station.Name; - vmItem.values = new List<List<double>>(); - for (int i = 1; i <= 12; i++) - { - var result = resultList.Find(t => t.Month == i); - if (result == null) - { - vmItem.values.Add(new List<double>() { 0, 0, 0 }); - } - else - { - vmItem.values.Add(new List<double>() { result.Qt, result.Dt, result.WP }); - } - } - vmList.Add(vmItem); } return vmList; } + private PlanAnaDto Ana(List<PlanAnaData> planDataList, int sg_factoryId, out string error_info) + { + //鎵惧埌鐩稿叧娉电珯锛屽苟杩涜璁$畻 + var stationInfo = ShysPlanHelper.GetStationInfo(sg_factoryId); + if (stationInfo == null) + { + error_info = "鏈壘鍒癷d:{factoryId},瀵瑰簲鐨勬车绔�"; + return null; + } + + var stationId = stationInfo.ID; + var station = new Service.Station().GetByID(_corpId, stationId); + if (station == null) + { + error_info = $"娉电珯id:{stationId}, 鏁版嵁搴撲腑鏈壘鍒版娉电珯"; + return null; + } + var calculator = stationInfo.Calculator; + if (calculator == null) + { + error_info = $"娉电珯id:{stationId}, 鏈瀯寤鸿绠楀櫒"; + return null; + } + calculator.SetStationID(_corpId, stationInfo.ID);//璁剧疆ID + + //鏋勯�犺绠楀叆鍙� + var sumRecordList = new List<MonthSumRecord>(); + foreach (var planData in planDataList) + { + var sumRecord = new MonthSumRecord(); + sumRecord.Month = planData.timeflag; + sumRecord.HourRecords = new List<HourSumRecord>(); + var factoryData = planData.datas.Find(t => t.factory == sg_factoryId); + for (int i = 0; i <= 23; i++) + { + var hourSumRecord = new HourSumRecord(); + hourSumRecord.Hour = i; + hourSumRecord.Records = new List<Dto.MonitorRecord4SG>(); + if (factoryData.scada != null && factoryData.scada.Count > 0) + { + foreach (var scadaItem in factoryData.scada) + { + var scadaRecord = new Dto.MonitorRecord4SG(); + scadaRecord.MonitorTag = scadaItem.tagname; + var ff = scadaItem.values.Find(t => t.GetHour() == i); + if (ff == null) + { + if (calculator.IsIgnoreAble(scadaItem.tagname)) + { + scadaRecord.RecordValue = 0; + } + //else if (calculator.Is娑蹭綅Monitor(scadaItem.tagname)) + //{ + // scadaRecord.RecordValue = 0; + //} + else + { + error_info = $"factoryId:{sg_factoryId}, 娉电珯id:{stationId}, 娴嬭瘯tag:{scadaItem.tagname} ,娴嬬偣鍚嶇О{calculator.GetMonitorNameByTag(scadaItem.tagname)},鏃堕棿鐐箋i}, 鏈壘鍒板搴旀暟鎹�"; + return null; + } + } + else + { + scadaRecord.RecordValue = calculator.CorrectMonitorValue(scadaItem.tagname, ff.value); + } + + hourSumRecord.Records.Add(scadaRecord); + } + } + sumRecord.HourRecords.Add(hourSumRecord); + } + sumRecordList.Add(sumRecord); + } + + string ana_error_info = ""; + var resultList = calculator.Calc(station, sg_factoryId, sumRecordList, out ana_error_info); + if (resultList == null || resultList.Count() < 1) + { + error_info = $"娉电珯鍚嶇О:{station.Name} 娉电珯id:{stationId},鍘熷洜鏄�:{ana_error_info}"; + LogHelper.Error("涓婃捣鍘熸按鑳借�楄鍒掑垎鏋愯绠椾腑 factoryId:{sg_factoryId},锛�" + error_info); + return null; + } + + //鐢熸垚杩斿洖缁撴灉 + var vmItem = new PlanAnaDto(); + vmItem.factory = sg_factoryId; + vmItem.name = station.Name; + vmItem.values = new List<List<double>>(); + vmItem.valueinfo = new List<string>(); + for (int i = 1; i <= 12; i++) + { + var result = resultList.Find(t => t.Month == i); + if (result == null) + { + vmItem.values.Add(new List<double>() { 0, 0, 0 }); + vmItem.valueinfo.Add("鏁版嵁涓虹┖"); + } + else + { + vmItem.values.Add(new List<double>() { result.Qt, result.Dt, result.WP }); + vmItem.valueinfo.Add(result.Info); + } + } + error_info = null; + return vmItem; + } - - - - - - - + #endregion + } } \ No newline at end of file -- Gitblit v1.9.3