| | |
| | | using IStation.Calculation; |
| | | using IStation.Dto; |
| | | using System.Collections.Generic; |
| | | using Mapster; |
| | | |
| | | namespace IStation.Application |
| | | { |
| | |
| | | |
| | | 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("上海原水能耗计划分析计算三高返回接口出参为空"); |
| | | return default; |
| | | } |
| | | if (planDataList.Exists(x => x.datas == null || x.datas.Count < 1)) |
| | | { |
| | | { |
| | | LogHelper.Error("上海原水能耗计划分析计算三高返回接口出参格式错误"); |
| | | 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); |
| | | 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("未找到id:{factoryId},对应的泵站"); |
| | | error_info = "未找到id:{factoryId},对应的泵站" ; |
| | | return null; |
| | | } |
| | | |
| | |
| | | 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(_corpId, stationInfo.ID);//设置ID |
| | |
| | | { |
| | | scadaRecord.RecordValue = 0; |
| | | } |
| | | else if (calculator.Is液位Monitor(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; |
| | | } |
| | | } |
| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | vmItem.values.Add(new List<double>() { result.Qt, result.Dt, result.WP }); |
| | | } |
| | | } |
| | | |
| | | error_info = null; |
| | | return vmItem; |
| | | } |
| | | |