From 05f522e321a742f03bf1e3e26edaeb5147da42f4 Mon Sep 17 00:00:00 2001 From: tangxu <76880903@qq.com> Date: 星期三, 02 十一月 2022 16:18:47 +0800 Subject: [PATCH] 解决南汇北 计划计算 --- Application/IStation.Application.OpenApi/shys/plan/PlanAna_ShysController.cs | 64 ++++++++++++++++++++----------- 1 files changed, 41 insertions(+), 23 deletions(-) diff --git a/Application/IStation.Application.OpenApi/shys/plan/PlanAna_ShysController.cs b/Application/IStation.Application.OpenApi/shys/plan/PlanAna_ShysController.cs index 7616b7a..256f1b2 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,68 +58,80 @@ [HttpGet] public List<PlanAnaDto> Calculate_debug() { - var path = @"D:\WorkData\IStation\result_1021.json"; + var path = @"D:\WorkData\IStation\result_1102.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> /// 鍒嗘瀽鏍稿績 /// </summary> /// <param name="planDataList"></param> /// <returns></returns> - private List<PlanAnaDto> CalculateCore(List<PlanAnaData> planDataList) + private List<PlanAnaDto> CalculateCore(List<PlanAnaData> planDataList ) { if (planDataList == null || planDataList.Count < 1) - { + { LogHelper.Error("涓婃捣鍘熸按鑳借�楄鍒掑垎鏋愯绠椾笁楂樿繑鍥炴帴鍙e嚭鍙備负绌�"); return default; } if (planDataList.Exists(x => x.datas == null || x.datas.Count < 1)) - { + { LogHelper.Error("涓婃捣鍘熸按鑳借�楄鍒掑垎鏋愯绠椾笁楂樿繑鍥炴帴鍙e嚭鍙傛牸寮忛敊璇�"); return default; } 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 vmItem = Ana(planDataList, sg_factoryId); - if(vmItem != null) - vmList.Add(vmItem); + string error_info; + var vmItem = Ana(planDataList, sg_factoryId,out error_info); + if (vmItem != null) + { + vmList.Add(vmItem); + } + else + { + vmList.Add(new PlanAnaDto() { factory=sg_factoryId, name="", Error = error_info }); + } } return vmList; } - private PlanAnaDto Ana(List<PlanAnaData> planDataList, int sg_factoryId) + private PlanAnaDto Ana(List<PlanAnaData> planDataList, int sg_factoryId, out string error_info) { //鎵惧埌鐩稿叧娉电珯锛屽苟杩涜璁$畻 var stationInfo = ShysPlanHelper.GetStationInfo(sg_factoryId); if (stationInfo == null) { - // LogHelper.Error("鏈壘鍒癷d:{factoryId},瀵瑰簲鐨勬车绔�"); - return null ; + error_info = "鏈壘鍒癷d:{factoryId},瀵瑰簲鐨勬车绔�" ; + return null; } var stationId = stationInfo.ID; var station = new Service.Station().GetByID(_corpId, stationId); if (station == null) { - LogHelper.Error($"涓婃捣鍘熸按鑳借�楄鍒掑垎鏋愯绠椾腑锛� 娉电珯id:{stationId}, 鏁版嵁搴撲腑鏈壘鍒版娉电珯"); + error_info = $"娉电珯id:{stationId}, 鏁版嵁搴撲腑鏈壘鍒版娉电珯" ; return null; } var calculator = stationInfo.Calculator; if (calculator == null) { - LogHelper.Error($"涓婃捣鍘熸按鑳借�楄鍒掑垎鏋愯绠椾腑锛� 娉电珯id:{stationId}, 鏈瀯寤鸿绠楀櫒"); + error_info = $"娉电珯id:{stationId}, 鏈瀯寤鸿绠楀櫒" ; return null; } - calculator.SetStationID(4, stationInfo.ID);//璁剧疆ID + calculator.SetStationID(_corpId, stationInfo.ID);//璁剧疆ID //鏋勯�犺绠楀叆鍙� var sumRecordList = new List<MonthSumRecord>(); @@ -141,16 +155,19 @@ var ff = scadaItem.values.Find(t => t.GetHour() == i); if (ff == null) { - if (calculator.Is娑蹭綅Monitor(scadaItem.tagname)) + if (calculator.IsIgnoreAble(scadaItem.tagname)) { scadaRecord.RecordValue = 0; } + //else if (calculator.Is娑蹭綅Monitor(scadaItem.tagname)) + //{ + // scadaRecord.RecordValue = 0; + //} else { - LogHelper.Error($"涓婃捣鍘熸按鑳借�楄鍒掑垎鏋愯绠椾腑锛� 娉电珯id:{stationId}, {scadaItem.tagname} 鏃堕棿鐐箋i}, 鏈壘鍒版暟鎹�"); + error_info = $"factoryId:{sg_factoryId}, 娉电珯id:{stationId}, 娴嬭瘯tag:{scadaItem.tagname} ,娴嬬偣鍚嶇О{calculator.GetMonitorNameByTag(scadaItem.tagname)},鏃堕棿鐐箋i}, 鏈壘鍒板搴旀暟鎹�" ; return null; } - } else { @@ -165,11 +182,12 @@ sumRecordList.Add(sumRecord); } - string error_info = ""; - var resultList = calculator.Calc(station, sg_factoryId, sumRecordList, out error_info); + string ana_error_info = ""; + var resultList = calculator.Calc(station, sg_factoryId, sumRecordList, out ana_error_info); if (resultList == null || resultList.Count() < 1) { - LogHelper.Error($"涓婃捣鍘熸按鑳借�楄鍒掑垎鏋愯绠椾腑锛屾车绔欏悕绉�:{station.Name} 娉电珯id:{stationId},璁$畻閿欒,鍘熷洜鏄�:{error_info}"); + error_info = $"娉电珯鍚嶇О:{station.Name} 娉电珯id:{stationId},鍘熷洜鏄�:{ana_error_info}"; + LogHelper.Error("涓婃捣鍘熸按鑳借�楄鍒掑垎鏋愯绠椾腑 factoryId:{sg_factoryId},锛�" + error_info); return null; } @@ -190,7 +208,7 @@ vmItem.values.Add(new List<double>() { result.Qt, result.Dt, result.WP }); } } - + error_info = null; return vmItem; } -- Gitblit v1.9.3