ningshuxia
2022-11-22 4efe844d9bcc03435cbbeb1aedbda5bf6ebf5912
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
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
{
    /// <summary>
    /// 节能改造
    /// </summary>
    [Route("Eta/Analy/Reform")]
    [ApiDescriptionSettings("Eta", Name = "节能改造", Order = 598)]
    public class EtaAnalyReform_Controller : IDynamicApiController
    {
        /// <summary>
        /// 获取泵站下面机泵(含曲线信息):能效专用
        /// </summary>
        /// <param name="CorpID"></param>
        /// <param name="StationID"></param>
        /// <returns></returns>
        [Route("GetMachineByStationID@V1.0")]
        [HttpGet]
        public List<Dto.MachineBaseItem4Reform> GetMachineByStationID(long CorpID,long StationID)
        {
            if (CorpID < 1)
            {
                throw new Exception("CorpID大于0");
            }
 
            if (StationID < 1)
            {
                throw new Exception("StationID大于0");
            }
 
            var cacheKey = $"MachineList4EnergyAna_{CorpID}_Station_{StationID}";
            var vm_list = MemoryCacheHelper.GetSet<List<Dto.MachineBaseItem4Reform>>(cacheKey, () =>
            {
                List<Dto.MachineBaseItem4Reform> vm_cache_list = new List<Dto.MachineBaseItem4Reform>();
                //获取机泵列表
                var enginePumplist = new Service.Product().GetEnginePumpListByBelongTypeAndBelongID(CorpID,ObjectType.Station,StationID);
                foreach (var enginePump in enginePumplist)
                {
                    var pump = new Service.Product().GetChildPumpByEnginePumpID(CorpID,enginePump.ID);
                    if (pump == null)
                        continue;
                     
                        var curve = new Service.PumpCurveExMapping().GetDefaultWorkingByPumpID(CorpID,pump.ID);
                     
     
                    if (curve == null || curve.CurveInfo == null || curve.CurveInfo.CurveQH == null)
                        continue;
 
                    var vm_cache = new Dto.MachineBaseItem4Reform();
                    //pipe_engine_pump, pump, property_list, curve);
                    vm_cache.MachineID = enginePump.ID;
                    vm_cache.MachineName = enginePump.Name;
 
                    vm_cache.PumpID = pump.ID;
                    vm_cache.CurveID = curve.ID;
 
                    vm_cache.PointsQH = IStation.Model.FitCurveHelper.GetFitPoints(curve.CurveInfo.CurveQH, 12);
                    vm_cache.PointsQE = IStation.Model.FitCurveHelper.GetFitPoints(curve.CurveInfo.CurveQE, 12);
                    vm_cache.PointsQP = IStation.Model.FitCurveHelper.GetFitPoints(curve.CurveInfo.CurveQP, 12);
 
                    if (pump.RatedParas != null)
                    {
                        vm_cache.RatedQ = pump.RatedParas.Q;
                        vm_cache.RatedH = pump.RatedParas.H;
                        vm_cache.RatedE = pump.RatedParas.E;
                        vm_cache.RatedP = pump.RatedParas.P;
 
                        vm_cache.Ratedn = pump.RatedParas.N;
                        vm_cache.IsFrequency = pump.RatedParas.IsFrequency;
                        vm_cache.IsSxp = pump.RatedParas.IsSxp;
                    }
 
                    vm_cache.WorkDayInYear = 200;// 每年工作天数(以后来源数据库)
                    vm_cache.WorkHourInDay = 5;//每天平均工作小时(以后来源数据库)
                    vm_cache.ElectricityFees = 1;//电费 (来源配置)
 
                    vm_cache.CurrentWorkFr = 0; //来源数据库( 最近一次的开机频率)
                    vm_cache.CurrentWorkPtQ = 0; //来源数据库( 最近一次的单泵开机流量)
                    vm_cache.CurrentWorkPtH = 0; //来源数据库( 最近一次的单泵开机扬程)
                    vm_cache.CurrentWorkPtE = 0; //来源数据库( 最近一次的单泵开机效率)
                    vm_cache.CurrentWorkPtP = 0; //来源数据库( 最近一次的单泵开机功率)
 
                    vm_cache_list.Add(vm_cache);
                }
                return vm_cache_list;
            }, 12);
        
            return new List<IStation.Dto.MachineBaseItem4Reform>(vm_list);
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="AnaRequest"></param>
        /// <returns></returns>
        [Route("GetAnaResult@V1.0")]
        [HttpPost]
        public List<Dto.ReformAnaResultItem> GetAnaResult(IStation.Dto.ReformAnaRequest AnaRequest)
        {
            if (AnaRequest == null || AnaRequest.CorpID < 1)
            {
                throw new Exception("CorpID大于0");
            }
            if (AnaRequest.PumpID < 1)
            {
                throw new Exception("MachineID大于0");
            }
            if (AnaRequest.CurveID < 1)
            {
                throw new Exception("CurveID大于0");
            }
            var service_curve = new Service.PumpCurveExMapping();
            var curves = service_curve.GetByCurveID(AnaRequest.CorpID, AnaRequest.CurveID);
            if (curves == null)
            {
                throw new Exception("曲线还未设置"); 
            }
            var curve = curves.Find(x => x.PumpID == AnaRequest.PumpID);
            if (curve == null || curve.CurveInfo == null || curve.CurveInfo.CurveQH == null)
            {
                throw new Exception("曲线还未设置");
            }
 
            var fit_point_h = IStation.Model.FitCurveHelper.GetFitPointY(curve.CurveInfo.CurveQH, AnaRequest.TargetQ);
 
            #region 切割
 
            var result_cut = new Dto.ReformAnaResultItem();
            result_cut.Name = "叶轮切割";
            result_cut.Type = 1;
            result_cut.WorkPointQ = AnaRequest.TargetQ;
            result_cut.WorkPointH = AnaRequest.TargetH;
            result_cut.IsAble = false;
            if (fit_point_h < AnaRequest.TargetH * 1.05)
            {//切割 变频都不行
                result_cut.Note = "当前水泵,无法通过切割的方式,达到理想工况点";
                result_cut.IsAble = false;
            }
            else
            {
                double OriginD2 = 100;//计算的是百分率
                double wrk_d2 = IStation.Common.CutSimuCalculer.GetSimuValue(curve.CurveInfo.CurveQH,
                     new IStation.Model.CurvePoint(AnaRequest.TargetQ, AnaRequest.TargetH), OriginD2, 1.05);
 
                if (wrk_d2 > 30)
                {
                    var CurveExpressQH = IStation.Common.CutSimuCalculer.GetSimuPointQH(curve.CurveInfo.CurveQH, OriginD2, wrk_d2);
                    var CurveExpressQE = IStation.Common.CutSimuCalculer.GetSimuPointQE(curve.CurveInfo.CurveQE, OriginD2, wrk_d2);
                    var CurveExpressQP = IStation.Common.CutSimuCalculer.GetSimuPointQP(curve.CurveInfo.CurveQP, OriginD2, wrk_d2);
 
                    result_cut.PointsQH = IStation.Model.FitCurveHelper.GetFitPoints(CurveExpressQH, 12);
                    result_cut.PointsQE = IStation.Model.FitCurveHelper.GetFitPoints(CurveExpressQE, 12);
                    result_cut.PointsQP = IStation.Model.FitCurveHelper.GetFitPoints(CurveExpressQP, 12);
 
                    result_cut.Note = string.Format("切割率 {0:0.0}% ", (1 - wrk_d2 / OriginD2) * 100);
 
                    result_cut.WorkPointE = Math.Round(IStation.Model.FitCurveHelper.GetFitPointY(CurveExpressQE, result_cut.WorkPointQ), 2);
                    result_cut.WorkPointP = Math.Round(IStation.Model.FitCurveHelper.GetFitPointY(CurveExpressQP, result_cut.WorkPointQ), 1);
 
                    result_cut.IsAble = true;
                    result_cut.PerDayPower = Math.Round(result_cut.WorkPointP.Value * AnaRequest.WorkHourInDay, 0);
                    result_cut.PerYearPower = result_cut.PerDayPower * AnaRequest.WorkDayInYear;
                    result_cut.PerYearCost = result_cut.PerYearPower * AnaRequest.ElectricityFees;
                }
                else
                {
                    result_cut.Note = "当前水泵,无法通过切割的方式,达到理想工况点";
                    result_cut.IsAble = false;
                }
            }
 
 
            #endregion
 
 
            #region 变频      
            var result_speed = new Dto.ReformAnaResultItem();
            result_speed.Name = "电机变频";
            result_speed.WorkPointQ = AnaRequest.TargetQ;
            result_speed.WorkPointH = AnaRequest.TargetH;
            result_speed.IsAble = false;
            result_speed.Type = 2;
            if (fit_point_h < AnaRequest.TargetH * 1.05)
            {//切割 变频都不行
                result_speed.Note = "当前水泵,无法通过变频的方式,达到理想工况点";
                result_speed.IsAble = false;
            }
            else
            {
                double wrk_hz = IStation.Common.SpeedSimuCalculer.GetSimuValue(curve.CurveInfo.CurveQH,
                     new IStation.Model.CurvePoint(AnaRequest.TargetQ, AnaRequest.TargetH), 50, 1.05);
 
                if (wrk_hz > 10)
                {
                    var CurveExpressQH = IStation.Common.SpeedSimuCalculer.GetSimuPointQH(curve.CurveInfo.CurveQH, 50, wrk_hz);
                    var CurveExpressQE = IStation.Common.SpeedSimuCalculer.GetSimuPointQE(curve.CurveInfo.CurveQE, 50, wrk_hz);
                    var CurveExpressQP = IStation.Common.SpeedSimuCalculer.GetSimuPointQP(curve.CurveInfo.CurveQP, 50, wrk_hz);
 
                    result_speed.PointsQH = IStation.Model.FitCurveHelper.GetFitPoints(CurveExpressQH, 12);
                    result_speed.PointsQE = IStation.Model.FitCurveHelper.GetFitPoints(CurveExpressQE, 12);
                    result_speed.PointsQP = IStation.Model.FitCurveHelper.GetFitPoints(CurveExpressQP, 12);
 
                    result_speed.Note = string.Format("变频{0:0.0}HZ ", wrk_hz);
 
                    result_speed.WorkPointE = Math.Round(IStation.Model.FitCurveHelper.GetFitPointY(CurveExpressQE, result_speed.WorkPointQ), 2);
                    result_speed.WorkPointP = Math.Round(IStation.Model.FitCurveHelper.GetFitPointY(CurveExpressQP, result_speed.WorkPointQ), 1);
                    result_speed.IsAble = true;
 
                    result_speed.PerDayPower = Math.Round(result_speed.WorkPointP.Value * AnaRequest.WorkHourInDay, 0);
                    result_speed.PerYearPower = result_speed.PerDayPower * AnaRequest.WorkDayInYear;
                    result_speed.PerYearCost = result_speed.PerYearPower * AnaRequest.ElectricityFees;
                }
                else
                {
                    result_speed.Note = "当前水泵,无法通过变频的方式,达到理想工况点";
                    result_speed.IsAble = false;
                }
            }
 
 
            #endregion
 
 
 
 
            #region 替换
            var service_product = new Service.Product();
            var pump = service_product.GetChildPumpByEnginePumpID(AnaRequest.CorpID, AnaRequest.MachineID);
            if (pump == null)
            {
                throw new Exception("机泵未找到"); 
            }
            IStation.Model.GroupPoint theRepRatedParas = new IStation.Model.GroupPoint();
            theRepRatedParas.Q = AnaRequest.TargetQ;
            theRepRatedParas.H = AnaRequest.TargetH;
            theRepRatedParas.E = 90;
            if (pump.RatedParas.E > 0)
                theRepRatedParas.E = pump.RatedParas.E;
            theRepRatedParas.P = IStation.Common.PumpParaHelper.CalculateP(theRepRatedParas.Q, theRepRatedParas.H, theRepRatedParas.E);
 
 
            List<IStation.Model.CurvePoint> pointsQH_replace = null;
            List<IStation.Model.CurvePoint> pointsQE_replace = null;
            List<IStation.Model.CurvePoint> pointsQP_replace = null;
            List<IStation.Model.CurvePoint> pointsNPSH_replace = null;
 
            double ratedn = 960;
            if (pump.RatedParas.N > 0)
                ratedn = pump.RatedParas.N;
            else
            {
                var motor = service_product.GetChildMotorByEnginePumpID(AnaRequest.CorpID, AnaRequest.MachineID);
                if (motor != null && motor.RatedParas != null && motor.RatedParas.N > 10)
                {
                    ratedn = motor.RatedParas.N;
                }
            }
 
            var RET = IStation.Common.DimensionlessCurvesHelper.CalcPoints(theRepRatedParas, ratedn,
                ref pointsQH_replace, ref pointsQE_replace, ref pointsQP_replace, ref pointsNPSH_replace, pump.RatedParas.IsSxp, 1);
 
 
            var result_replace = new Dto.ReformAnaResultItem();
            result_replace.Name = "换叶轮/换泵";
            result_replace.IsAble = true;
            result_replace.Type = 3;
 
            result_replace.WorkPointQ = AnaRequest.TargetQ;
            result_replace.WorkPointH = AnaRequest.TargetH;
            result_replace.PointsQH = pointsQH_replace;
            result_replace.PointsQE = pointsQE_replace;
            result_replace.PointsQP = pointsQP_replace;
            result_replace.Note = "";
            result_replace.WorkPointE = Math.Round(IStation.Model.FitCurveHelper.GetFitPointY(pointsQE_replace, result_replace.WorkPointQ), 2);
            result_replace.WorkPointP = Math.Round(IStation.Model.FitCurveHelper.GetFitPointY(pointsQP_replace, result_replace.WorkPointQ), 1);
 
 
            result_replace.PerDayPower = Math.Round(result_replace.WorkPointP.Value * AnaRequest.WorkHourInDay, 0);
            result_replace.PerYearPower = result_replace.PerDayPower * AnaRequest.WorkDayInYear;
            result_replace.PerYearCost = result_replace.PerYearPower * AnaRequest.ElectricityFees;
 
            #endregion
 
 
            var vm_list = new List<Dto.ReformAnaResultItem>();
            vm_list.Add(result_cut);
            vm_list.Add(result_speed);
            vm_list.Add(result_replace);
 
            foreach (var vm in vm_list)
            {
                if (vm.IsAble && vm.PerYearPower != null && vm.PerYearCost != null && AnaRequest.CurrentWorkPtP > 0)
                {
                    var CurrentPerDayPower = Math.Round(AnaRequest.CurrentWorkPtP * AnaRequest.WorkHourInDay, 0);
                    var CurrentPerYearPower = CurrentPerDayPower * AnaRequest.WorkDayInYear;
                    var CurrentPerYearCost = CurrentPerYearPower * AnaRequest.ElectricityFees;
 
                    vm.SavePowerNumber = (CurrentPerYearPower - (double)vm.PerYearPower).ToString("N0");
                    vm.SavePowerCost = (CurrentPerYearCost - (double)vm.PerYearCost).ToString("N0");
 
                    vm.PerYearQ = Math.Round(vm.WorkPointQ * AnaRequest.WorkHourInDay * AnaRequest.WorkDayInYear, 0);
                    vm.CostPerM3 = Math.Round((double)vm.PerYearCost * 1000 / (double)vm.PerYearQ, 1).ToString();
                }
                else
                {
                    vm.SavePowerNumber = "-";
                    vm.SavePowerCost = "-";
 
                    vm.PerYearQ = null;
                    vm.CostPerM3 = null;
                }
            }
 
 
            return new List<Dto.ReformAnaResultItem>(vm_list);
        }
 
    }
}