lixiaojun
2022-09-02 d5a3d08601fa59498edc092cec23c7ca166a0d15
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
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>
    /// PipeLine
    /// </summary>
    [Route("Main/PipeLine/Logic")]
    [ApiDescriptionSettings("Main", Name = "管路", Order = 599)]
    public class PipeLine_LogicController : IDynamicApiController
    {
 
        /// <summary>
        /// 通过 BelongType 和 BelongID 获取管路信息(业务)
        /// </summary>
        [Route("GetByBelongTypeAndBelongID@V1.0")]
        [HttpGet]
        public List<PipeLineLogicDto> GetByBelongTypeAndBelongID([FromQuery][Required] BelongUnderCorpInput input)
        {
            var corpId = input.CorpID;
            var belongType = input.BelongType;
            var belongId = input.BelongID;
 
            var cacheKey = $"Main_PipeLine_Logic_GetByBelongTypeAndBelongID_{corpId}_{belongType}_{belongId}";
            var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
            {
                var pipe_list = new Service.PipeLine().GetByBelongTypeAndBelongID(corpId, belongType, belongId);
                if (pipe_list == null || pipe_list.Count < 1)
                    return default;
                var vm_cache_list = pipe_list.Select(x => new PipeLineLogicDto(x)).ToList();
                return vm_cache_list;
            }, CacheHelper.CacheLevel4);
            return vm_list;
        }
 
        /// <summary>
        /// 通过 BelongType 和 BelongID 获取能效管路信息(业务)
        /// </summary>
        [Route("GetEtaByBelongTypeAndBelongID@V1.0")]
        [HttpGet]
        public List<PipeLineLogicDto> GetEtaByBelongTypeAndBelongID([FromQuery][Required] BelongUnderCorpInput input)
        {
            var corpId = input.CorpID;
            var belongType = input.BelongType;
            var belongId = input.BelongID;
 
            var cacheKey = $"Main_PipeLine_Logic_GetEtaByBelongTypeAndBelongID_{corpId}_{belongType}_{belongId}";
            var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
            {
                var pipe_list = new Service.PipeLine().GetEtaListByBelongTypeAndBelongID(corpId, belongType, belongId);
                if (pipe_list == null || pipe_list.Count < 1)
                    return default;
                var vm_cache_list = pipe_list.Select(x => new PipeLineLogicDto(x)).ToList();
                return vm_cache_list;
            }, CacheHelper.CacheLevel4);
            return vm_list;
        }
 
        /// <summary>
        /// 通过 BelongType 和 BelongID 获取拓展泵性能曲线列表(业务)
        /// </summary>
        [Route("GetExPumpFeatCurveListByBelongTypeAndBelongID@V1.0")]
        [HttpGet]
        public List<PipeLineExPumpFeatCurveLogicDto> GetExPumpFeatCurveListByBelongTypeAndBelongID([FromQuery][Required] BelongUnderCorpInput input)
        {
            var corpId = input.CorpID;
            var belongType = input.BelongType;
            var belongId = input.BelongID;
 
            var cacheKey = $"Main_PipeLine_Logic_GetExPumpFeatCurveListByBelongTypeAndBelongID_{corpId}_{belongType}_{belongId}";
            var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
            {
                var pipe_list = new Service.PipeLine().GetByBelongTypeAndBelongID(corpId, belongType, belongId);
                if (pipe_list == null || pipe_list.Count < 1)
                    return default;
                var pipe_engine_pump_list = pipe_list.Where(x => x.Catalog == PipeLine.EnginePump).OrderBy(x => x.SerialNO).ToList();
                if (pipe_engine_pump_list.Count < 1)
                    return default;
                var service_binding = new Service.PipeLineBinding();
                var service_product = new Service.Product();
                var service_property = new Service.ProductTypePropertyGroup();
                var service_curve = new Service.PumpCurveExMapping();
                var vm_cache_list = new List<PipeLineExPumpFeatCurveLogicDto>();
                foreach (var pipe_engine_pump in pipe_engine_pump_list)
                {
                    var binding_list = service_binding.GetUseByPipeLineID(pipe_engine_pump.CorpID, pipe_engine_pump.ID);
                    if (binding_list == null || binding_list.Count < 1)
                        continue;
                    var binding = binding_list.Find(x => x.BindingType == IStation.ObjectType.Product);
                    if (binding == null)
                        continue;
                    var pump = service_product.GetChildPumpByEnginePumpID(binding.CorpID, binding.BindingID);
                    if (pump == null)
                        continue;
                    var property_list = service_property.GetExItemsByProductTypeID(pump.CorpID, pump.ProductTypeID);
                    var curve = service_curve.GetDefaultWorkingByPumpID(pump.CorpID, pump.ID);
                    if (curve == null)
                        continue;
                    var vm_cache = new PipeLineExPumpFeatCurveLogicDto(pipe_engine_pump, pump, property_list, curve);
                    vm_cache_list.Add(vm_cache);
                }
                return vm_cache_list;
            }, CacheHelper.CacheLevel3);
 
            return vm_list;
        }
 
        /// <summary>
        /// 通过 CorpID 获取机泵逻辑树(业务)
        /// </summary>
        [Route("GetEnginePumpLogicalTreeByCorpID@V1.0")]
        [HttpGet]
        public List<LogicCatalogExLogicalTreeItemsLogicDto> GetEnginePumpLogicalTreeByCorpID([FromQuery][Required] CorpIDInput input)
        {
            var corpId = input.CorpID;
            var cacheKey = $"Main_PipeLine_Logic_GetEnginePumpLogicalTreeByCorpID_{corpId}";
            var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
            {
 
                #region 获取业务类别列表
 
                var service_logic_catalog = new Service.LogicCatalog();
                var catalog_list = service_logic_catalog.GetByCorpID(corpId);
                if (catalog_list == null || catalog_list.Count < 1)
                {
                    return default;
                }
                catalog_list = catalog_list.Where(x => x.UseStatus == Model.eUseStatus.Enable).ToList();
                if (catalog_list.Count < 1)
                {
                    return default;
                }
 
                #endregion
 
                #region 获取业务清单列表
 
 
                var vm_cache_list = new List<LogicCatalogExLogicalTreeItemsLogicDto>();
                var service_logic_tree = new Service.LogicTree();
                var service_logic_area = new Service.LogicArea();
                var service_station = new Service.Station();
                var service_pipe = new Service.PipeLine();
 
                foreach (var catalog in catalog_list)
                {
                    var logic_tree_list = service_logic_tree.GetExByCatalogID(corpId, catalog.ID);
                    var vm_logic_tree_item_list = new List<LogicalTreeItemDto>();
                    if (logic_tree_list != null || logic_tree_list.Count > 0)
                    {
                        foreach (var logic_tree in logic_tree_list)
                        {
                            var vm_logic_tree_item = new LogicalTreeItemDto();
                            vm_logic_tree_item.ID = $"{ObjectType.LogicTree}_{logic_tree.ID}";
                            var parentId = TreeParentIdsHelper.GetLastParentID(logic_tree.ParentIds);
                            if (parentId < 1)
                            {
                                vm_logic_tree_item.ParentID = string.Empty;
                            }
                            else
                            {
                                vm_logic_tree_item.ParentID = $"{ObjectType.LogicTree}_{parentId}";
                            }
 
                            vm_logic_tree_item.LogicalID = logic_tree.LogicID;
                            vm_logic_tree_item.LogicalType = logic_tree.LogicType;
                            vm_logic_tree_item.LogicalName = logic_tree.LogicName;
                            if (logic_tree.LogicType == ObjectType.LogicArea)
                            {
                                var logic_area = service_logic_area.GetByID(logic_tree.CorpID, logic_tree.LogicID);
                                vm_logic_tree_item.LogicalModel = new LogicAreaLogicDto(logic_area);
                            }
                            else if (logic_tree.LogicType == ObjectType.Station)
                            {
                                var station = service_station.GetByID(logic_tree.CorpID, logic_tree.LogicID);
                                vm_logic_tree_item.LogicalModel = new StationLogicDto(station);
                            }
                            vm_logic_tree_item.Children = new List<LogicalTreeItemDto>();
 
                            var vm_logic_tree_parent_item = vm_logic_tree_item_list.Find(t => t.ID == vm_logic_tree_item.ParentID);
                            if (vm_logic_tree_parent_item != null)
                            {
                                vm_logic_tree_parent_item.Children.Add(vm_logic_tree_item);
                            }
                            vm_logic_tree_item_list.Add(vm_logic_tree_item);
 
                            if (logic_tree.LogicType == ObjectType.Station)
                            {
                                var pipe_list = service_pipe.GetEnginePumpListByBelongTypeAndBelongID(logic_tree.CorpID, logic_tree.LogicType, logic_tree.LogicID);
                                if (pipe_list != null && pipe_list.Count > 0)
                                {
                                    foreach (var pipe in pipe_list)
                                    {
                                        var vm_pipe = new LogicalTreeItemDto();
                                        vm_pipe.ID = $"{ObjectType.PipeLine}_{pipe.ID}";
                                        vm_pipe.ParentID = vm_logic_tree_item.ID;
                                        vm_pipe.LogicalID = pipe.ID;
                                        vm_pipe.LogicalType = ObjectType.PipeLine;
                                        vm_pipe.LogicalName = pipe.Name;
                                        vm_pipe.LogicalModel = new PipeLineLogicDto(pipe);
                                        vm_pipe.Children = new List<LogicalTreeItemDto>();
                                        vm_logic_tree_item.Children.Add(vm_pipe);
                                    }
                                }
                            }
 
                        }
                        vm_logic_tree_item_list = vm_logic_tree_item_list.Where(t => string.IsNullOrEmpty(t.ParentID)).ToList();
                    }
                    vm_cache_list.Add(new LogicCatalogExLogicalTreeItemsLogicDto(catalog, vm_logic_tree_item_list));
                }
 
                #endregion
 
                return vm_cache_list;
 
 
            }, CacheHelper.CacheLevel3);
            return vm_list;
        }
 
        /// <summary>
        /// 通过 ID 获取泵频率曲线(业务)
        /// </summary>
        [Route("GetPumpHZCurveByID@V1.0")]
        [HttpGet]
        public PumpHZCurveLogicDto GetPumpHZCurveByID
            (
                [Required,Range(1,long.MaxValue,ErrorMessage ="CorpID 必须大于0")]
                long CorpID,
                [Required,Range(1,long.MaxValue,ErrorMessage ="ID 必须大于0")]
                long ID,
                [Required]
                double HZ
            )
        {
 
            var binding_list = new Service.PipeLineBinding().GetUseByPipeLineID(CorpID, ID);
            if (binding_list == null || binding_list.Count < 1)
            {
                return default;
            }
            var binding = binding_list.Find(x => x.BindingType == ObjectType.Product);
            if (binding == null)
            {
                return default;
            }
            var pump = new Service.Product().GetChildPumpByEnginePumpID(binding.CorpID, binding.BindingID);
            if (pump == null)
            {
                return default;
            }
            var curve = new Service.PumpCurveExMapping().GetDefaultWorkingByPumpID(pump.CorpID, pump.ID);
            if (curve == null)
            {
                return default;
            }
 
            var vm = new PumpHZCurveLogicDto();
            if (HZ > 49.5)
            {
                if (curve.CurveInfo != null && curve.CurveInfo.CurveQH != null)
                {
                    vm.PointQH = curve.CurveInfo.CurveQH.GetFitPoints(20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
                    if (curve.CurveInfo.CurveQP != null)
                    {
                        vm.PointQP = curve.CurveInfo.CurveQP.GetFitPoints(20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
                    }
                }
            }
            else
            {
                if (curve.CurveInfo != null)
                {
                    vm.PointQH = curve.CalcuCurveQhByHz(HZ).GetFitPoints(20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
                    vm.PointQP = curve.CalcuCurveQpByHz(HZ).GetFitPoints(20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
                }
            }
            return vm;
        }
 
 
        /// <summary>
        /// 计算并联曲线(业务)
        /// </summary>
        [Route("CalculatePumpParallelCurve@V1.0")]
        [HttpPost]
        public PumpParallelCurveLogicDto CalculatePumpParallelCurve([Required] PipeLineParallelCurveInput input)
        {
 
            var service_pipe = new Service.PipeLine();
            var service_binding = new Service.PipeLineBinding();
            var service_product = new Service.Product();
            var service_curve = new Service.PumpCurveExMapping();
 
            var curve_qh_list = new List<Model.CurveExpress>();
            var curve_qp_list = new List<Model.CurveExpress>();
            var h_min = double.MinValue;
            var h_max = double.MaxValue;
 
            foreach (var item in input.Items)
            {
                var pipe = service_pipe.GetByID(input.CorpID, item.ID);
                if (pipe == null)
                    continue;
                var binding_list = service_binding.GetUseByPipeLineID(input.CorpID, item.ID);
                if (binding_list == null || binding_list.Count < 1)
                    continue;
                var binding = binding_list.Find(x => x.BindingType == ObjectType.Product);
                if (binding == null)
                    continue;
                var pump = service_product.GetChildPumpByEnginePumpID(binding.CorpID, binding.BindingID);
                if (pump == null)
                    continue;
                var curve = service_curve.GetDefaultWorkingByPumpID(pump.CorpID, pump.ID);
                if (curve == null)
                    continue;
 
                if (item.HZ > 49.5)
                {
                    if (curve.CurveInfo != null && curve.CurveInfo.CurveQH != null)
                    {
                        curve_qh_list.Add(curve.CurveInfo.CurveQH);
                        if (curve.CurveInfo.CurveQP != null)
                        {
                            curve_qp_list.Add(curve.CurveInfo.CurveQP);
                        }
                    }
                }
                else
                {
                    var curve_qh = curve.CalcuCurveQhByHz(item.HZ);
                    if (curve_qh != null)
                    {
                        curve_qh_list.Add(curve_qh);
                        var curve_qp = curve.CalcuCurveQpByHz(item.HZ);
                        if (curve_qp != null)
                        {
                            curve_qp_list.Add(curve_qp);
                        }
                    }
                }
 
                var curve_qh_last = curve_qh_list.LastOrDefault();
                if (curve_qh_last != null)
                {
                    var curve_qh_first_point = curve_qh_last.GetFirstFitPoint();
                    h_max = Math.Min(h_max, curve_qh_first_point.Y);
                    var curve_qh_last_point = curve_qh_last.GetLastFitPoint();
                    h_min = Math.Max(h_min, curve_qh_last_point.Y);
                }
            }
 
            if (curve_qh_list.Count < 2)
            {
                throw new Exception("NULL1");
            }
            if (h_max < h_min)
            {
                throw new Exception("NULL2");
            }
 
            double space_h = (h_max - h_min) / 19;
            var points_qh_parallel = new List<Model.CurvePoint>();
            var points_qp_parallel = new List<Model.CurvePoint>();
 
            for (var h = h_min; h <= h_max; h = h + space_h)
            {
                double total_flow = 0;
                double total_power = 0;
 
                for (int j = 0; j < curve_qh_list.Count; j++)
                {
                    var curve_qh = curve_qh_list[j];
                    var curve_qp = curve_qp_list[j];
                    var pts = Model.FitCurveHelper.GetInterPointX(curve_qh, h);
                    if (pts != null && pts.Count > 0)
                    {
                        var q = pts.Last().X;
                        total_flow += q;
                        total_power += curve_qp.GetFitPointY(q);
                    }
                }
                points_qh_parallel.Add(new Model.CurvePoint(total_flow, h));
                points_qp_parallel.Add(new Model.CurvePoint(total_flow, total_power));
            }
 
            var vm = new PumpParallelCurveLogicDto();
            vm.PointQH = Model.FitCurveHelper.GetFitPoints(points_qh_parallel, 20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
            vm.PointQP = Model.FitCurveHelper.GetFitPoints(points_qp_parallel, 20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
            return vm;
 
        }
 
        /// <summary>
        /// 计算并联曲线(包含单泵曲线)(业务)
        /// </summary>
        [Route("CalculatePipeLineParallelEx@V1.0")]
        [HttpPost]
        public List<PumpParallelCurveExLogicDto> CalculatePumpParallelCurveEx([Required] PipeLineParallelCurveInput input)
        {
 
            var service_pipe = new Service.PipeLine();
            var service_binding = new Service.PipeLineBinding();
            var service_product = new Service.Product();
            var service_curve = new Service.PumpCurveExMapping();
            var vm_list = new List<PumpParallelCurveExLogicDto>();
 
            var curve_qh_list = new List<Model.CurveExpress>();
            var curve_qp_list = new List<Model.CurveExpress>();
            var h_min = double.MinValue;
            var h_max = double.MaxValue;
 
            foreach (var item in input.Items)
            {
                var pipe = service_pipe.GetByID(input.CorpID, item.ID);
                if (pipe == null)
                    continue;
                var binding_list = service_binding.GetUseByPipeLineID(input.CorpID, item.ID);
                if (binding_list == null || binding_list.Count < 1)
                    continue;
                var binding = binding_list.Find(x => x.BindingType == ObjectType.Product);
                if (binding == null)
                    continue;
                var pump = service_product.GetChildPumpByEnginePumpID(binding.CorpID, binding.BindingID);
                if (pump == null)
                    continue;
                var curve = service_curve.GetDefaultWorkingByPumpID(pump.CorpID, pump.ID);
                if (curve == null)
                    continue;
 
                if (item.HZ > 49.5)
                {
                    if (curve.CurveInfo != null && curve.CurveInfo.CurveQH != null)
                    {
                        curve_qh_list.Add(curve.CurveInfo.CurveQH);
                        if (curve.CurveInfo.CurveQP != null)
                        {
                            curve_qp_list.Add(curve.CurveInfo.CurveQP);
                        }
                    }
                }
                else
                {
                    var curve_qh = curve.CalcuCurveQhByHz(item.HZ);
                    if (curve_qh != null)
                    {
                        curve_qh_list.Add(curve_qh);
                        var curve_qp = curve.CalcuCurveQpByHz(item.HZ);
                        if (curve_qp != null)
                        {
                            curve_qp_list.Add(curve_qp);
                        }
                    }
                }
 
                var curve_qh_last = curve_qh_list.LastOrDefault();
                if (curve_qh_last != null)
                {
                    var curve_qh_first_point = curve_qh_last.GetFirstFitPoint();
                    h_max = Math.Min(h_max, curve_qh_first_point.Y);
                    var curve_qh_last_point = curve_qh_last.GetLastFitPoint();
                    h_min = Math.Max(h_min, curve_qh_last_point.Y);
                }
                var vm_parallel_curve = new PumpParallelCurveExLogicDto();
                vm_parallel_curve.Type = 0;
                vm_parallel_curve.Name = pipe.Name;
                vm_parallel_curve.PointQH = curve_qh_list.LastOrDefault()?.GetFitPoints(20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
                vm_parallel_curve.PointQP = curve_qp_list.LastOrDefault()?.GetFitPoints(20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
                vm_list.Add(vm_parallel_curve);
            }
 
            if (curve_qh_list.Count < 2)
            {
                throw new Exception("NULL1");
            }
            if (h_max < h_min)
            {
                throw new Exception("NULL2");
            }
 
            double space_h = (h_max - h_min) / 19;
            var points_qh_parallel = new List<Model.CurvePoint>();
            var points_qp_parallel = new List<Model.CurvePoint>();
 
            for (var h = h_min; h <= h_max; h = h + space_h)
            {
                double total_flow = 0;
                double total_power = 0;
 
                for (int j = 0; j < curve_qh_list.Count; j++)
                {
                    var curve_qh = curve_qh_list[j];
                    var curve_qp = curve_qp_list[j];
                    var pts = Model.FitCurveHelper.GetInterPointX(curve_qh, h);
                    if (pts != null && pts.Count > 0)
                    {
                        var q = pts.Last().X;
                        total_flow += q;
                        total_power += curve_qp.GetFitPointY(q);
                    }
                }
                points_qh_parallel.Add(new Model.CurvePoint(total_flow, h));
                points_qp_parallel.Add(new Model.CurvePoint(total_flow, total_power));
            }
 
            var vm = new PumpParallelCurveExLogicDto();
            vm.Type = 1;
            vm.Name = "并联曲线";
            vm.PointQH = Model.FitCurveHelper.GetFitPoints(points_qh_parallel, 20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
            vm.PointQP = Model.FitCurveHelper.GetFitPoints(points_qp_parallel, 20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
            vm_list.Insert(0, vm);
            return vm_list;
        }
 
    }
}