tangxu
2023-03-20 3bf8bf5179de8b83bbd6ad997e82d98302abd1c3
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using IStation.Model.Api;
using AutoMapper;
using IStation.WebApi.Models;
using IStation.Untity;
using Microsoft.Web.Http;
 
namespace IStation.WebApi.Controllers
{
    /// <summary>
    /// 管路标准api
    /// </summary>
    [RoutePrefix("v1/Standard/PipeLine")]
    [ApiVersion("v1")]
    public class PipeLine_StandardController : ApiController
    {
 
        /// <summary>
        /// 通过 BelongType 和 BelongID 获取管路信息
        /// </summary>
        [Route("GetByBelongTypeAndBelongID")]
        [HttpGet]
        public Result GetByBelongTypeAndBelongID(long CorpID, string BelongType, long BelongID)
        {
            if (CorpID < 1)
            {
                return new Result(Code.Alert, "CorpID 参数错误");
            }
            if (string.IsNullOrEmpty(BelongType))
            {
                return new Result(Code.Alert, "BelongType 参数错误");
            }
            if (BelongID < 1)
            {
                return new Result(Code.Alert, "BelongID 参数错误");
            }
 
            var cacheKey = $"Standard_PipeLine_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 ViewModel.PipeLine(x)).ToList();
                return vm_cache_list;
            }, CacheHelper.CacheLevel4);
 
            return new Result<List<ViewModel.PipeLine>>(vm_list);
        }
 
        /// <summary>
        /// 通过 BelongType 和 BelongID 获取能效管路信息
        /// </summary>
        [Route("GetEtaByBelongTypeAndBelongID")]
        [HttpGet]
        public Result GetEtaByBelongTypeAndBelongID(long CorpID, string BelongType, long BelongID)
        {
            if (CorpID < 1)
            {
                return new Result(Code.Alert, "CorpID 参数错误");
            }
            if (string.IsNullOrEmpty(BelongType))
            {
                return new Result(Code.Alert, "BelongType 参数错误");
            }
            if (BelongID < 1)
            {
                return new Result(Code.Alert, "BelongID 参数错误");
            }
 
            var cacheKey = $"Standard_PipeLine_GetEtaByBelongTypeAndBelongID_{CorpID}_{BelongType}_{BelongID}";
            var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
            {
                var pipe_list = new Service.PipeLine().GetEtaByBelongTypeAndBelongID(CorpID, BelongType, BelongID);
                if (pipe_list == null || pipe_list.Count < 1)
                    return default;
                var vm_cache_list = pipe_list.Select(x => new ViewModel.PipeLine(x)).ToList();
                return vm_cache_list;
            }, CacheHelper.CacheLevel4);
 
            return new Result<List<ViewModel.PipeLine>>(vm_list);
        }
 
        /// <summary>
        /// 通过 BelongType 和 BelongID 获取拓展泵性能曲线列表
        /// </summary>
        [Route("GetExPumpFeatCurveListByBelongTypeAndBelongID")]
        [HttpGet]
        public Result GetExPumpFeatCurveListByBelongTypeAndBelongID(long CorpID, string BelongType, long BelongID)
        {
            if (CorpID < 1)
            {
                return new Result(Code.Alert, "CorpID 参数错误");
            }
            if (string.IsNullOrEmpty(BelongType))
            {
                return new Result(Code.Alert, "BelongType 参数错误");
            }
            if (BelongID < 1)
            {
                return new Result(Code.Alert, "BelongID 参数错误");
            }
 
            var cacheKey = $"Standard_PipeLine_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 == IStation.PipeLine.机泵).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<ViewModel.PipeLineExPumpFeatCurve>();
                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.ObjectType == IStation.ObjectType.Product_设备);
                    if (binding == null)
                        continue;
                    var pump = service_product.GetChildPumpByEnginePumpID(binding.CorpID, binding.ObjectID);
                    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 ViewModel.PipeLineExPumpFeatCurve(pipe_engine_pump, pump, property_list, curve);
                    vm_cache_list.Add(vm_cache);
                }
                return vm_cache_list;
            }, CacheHelper.CacheLevel3);
 
            return new Result<List<ViewModel.PipeLineExPumpFeatCurve>>(vm_list);
        }
 
        /// <summary>
        /// 通过 CorpID 获取机泵业务树
        /// </summary>
        [Route("GetEnginePumpLogicTreeByCorpID")]
        [HttpGet]
        public Result GetEnginePumpLogicTreeByCorpID(long CorpID)
        {
            if (CorpID < 1)
            {
                return new Result(Code.Alert, "CorpID 参数错误");
            }
            var cacheKey = $"Standard_PipeLine_GetEnginePumpLogicTreeByCorpID_{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.LogicCatalog.eUseStatus.Enable).ToList();
                if (catalog_list.Count < 1)
                {
                    return default;
                }
 
                #endregion
 
                #region 获取业务清单列表
 
 
                var vm_cache_list = new List<ViewModel.LogicCatalogExLogicalTreeItems>();
                var service_logic_tree = new Service.LogicTree();
                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<ViewModel.LogicalTreeItem>();
                    if (logic_tree_list != null || logic_tree_list.Count > 0)
                    {
                        foreach (var logic_tree in logic_tree_list)
                        {
                            var vm_logic_tree = new ViewModel.LogicTree(logic_tree);
                            var vm_logic_tree_item = new ViewModel.LogicalTreeItem();
                            vm_logic_tree_item.ID = $"{IStation.ObjectType.Logic_业务清单}_{vm_logic_tree.ID}";
                            if (vm_logic_tree.ParentID < 1)
                            {
                                vm_logic_tree_item.ParentID = string.Empty;
                            }
                            else
                            {
                                vm_logic_tree_item.ParentID = $"{IStation.ObjectType.Logic_业务清单}_{vm_logic_tree.ParentID}";
                            }
 
                            vm_logic_tree_item.LogicalID = vm_logic_tree.ID;
                            vm_logic_tree_item.LogicalType = IStation.ObjectType.Logic_业务清单;
                            vm_logic_tree_item.LogicalName = vm_logic_tree.ObjectName;
                            vm_logic_tree_item.LogicalModel = vm_logic_tree;
                            vm_logic_tree_item.Children = new List<ViewModel.LogicalTreeItem>();
 
                            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 (vm_logic_tree.ObjectType == IStation.ObjectType.Station_泵站)
                            {
                                var pipe_list = service_pipe.GetEnginePumpListByBelongTypeAndBelongID(vm_logic_tree.CorpID,vm_logic_tree.ObjectType,vm_logic_tree.ObjectID);
                                if (pipe_list != null && pipe_list.Count > 0)
                                {
                                    foreach (var pipe in pipe_list)
                                    {
                                        var vm_pipe = new ViewModel.LogicalTreeItem();
                                        vm_pipe.ID = $"{IStation.ObjectType.PipeLine_管路}_{pipe.ID}";
                                        vm_pipe.ParentID = vm_logic_tree_item.ID;
                                        vm_pipe.LogicalID = pipe.ID;
                                        vm_pipe.LogicalType = IStation.ObjectType.PipeLine_管路;
                                        vm_pipe.LogicalName = pipe.Name;
                                        vm_pipe.LogicalModel = new ViewModel.PipeLine(pipe);
                                        vm_pipe.Children = new List<ViewModel.LogicalTreeItem>();
                                        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 ViewModel.LogicCatalogExLogicalTreeItems(catalog, vm_logic_tree_item_list));
                }
 
                #endregion
 
                return vm_cache_list;
 
 
            }, CacheHelper.CacheLevel3);
            return new Result<List<ViewModel.LogicCatalogExLogicalTreeItems>>(vm_list);
        }
 
        /// <summary>
        /// 通过 CorpID 获取机泵逻辑树
        /// </summary>
        [Route("GetEnginePumpLogicalTreeByCorpID")]
        [HttpGet]
        public Result GetEnginePumpLogicalTreeByCorpID(long CorpID)
        {
            if (CorpID < 1)
            {
                return new Result(Code.Alert, "CorpID 参数错误");
            }
            var cacheKey = $"Standard_PipeLine_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.LogicCatalog.eUseStatus.Enable).ToList();
                if (catalog_list.Count < 1)
                {
                    return default;
                }
 
                #endregion
 
                #region 获取业务清单列表
 
 
                var vm_cache_list = new List<ViewModel.LogicCatalogExLogicalTreeItems>();
                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<ViewModel.LogicalTreeItem>();
                    if (logic_tree_list != null || logic_tree_list.Count > 0)
                    {
                        foreach (var logic_tree in logic_tree_list)
                        {
                            var vm_logic_tree_item = new ViewModel.LogicalTreeItem();
                            vm_logic_tree_item.ID = $"{IStation.ObjectType.Logic_业务清单}_{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 = $"{IStation.ObjectType.Logic_业务清单}_{parentId}";
                            }
 
                            vm_logic_tree_item.LogicalID = logic_tree.ObjectID;
                            vm_logic_tree_item.LogicalType = logic_tree.ObjectType;
                            vm_logic_tree_item.LogicalName = logic_tree.ObjectName;
                            if (logic_tree.ObjectType == IStation.ObjectType.Logic_业务区域)
                            {
                                var logic_area = service_logic_area.GetByID(logic_tree.CorpID,logic_tree.ObjectID);
                                vm_logic_tree_item.LogicalModel = new ViewModel.LogicArea(logic_area);
                            }
                            else if (logic_tree.ObjectType == IStation.ObjectType.Station_泵站)
                            {
                                var station = service_station.GetByID(logic_tree.CorpID,logic_tree.ObjectID);
                                vm_logic_tree_item.LogicalModel = new ViewModel.Station(station);
                            }
                            vm_logic_tree_item.Children = new List<ViewModel.LogicalTreeItem>();
 
                            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.ObjectType == IStation.ObjectType.Station_泵站)
                            {
                                var pipe_list = service_pipe.GetEnginePumpListByBelongTypeAndBelongID(logic_tree.CorpID, logic_tree.ObjectType, logic_tree.ObjectID);
                                if (pipe_list != null && pipe_list.Count > 0)
                                {
                                    foreach (var pipe in pipe_list)
                                    {
                                        var vm_pipe = new ViewModel.LogicalTreeItem();
                                        vm_pipe.ID = $"{IStation.ObjectType.PipeLine_管路}_{pipe.ID}";
                                        vm_pipe.ParentID = vm_logic_tree_item.ID;
                                        vm_pipe.LogicalID = pipe.ID;
                                        vm_pipe.LogicalType = IStation.ObjectType.PipeLine_管路;
                                        vm_pipe.LogicalName = pipe.Name;
                                        vm_pipe.LogicalModel = new ViewModel.PipeLine(pipe);
                                        vm_pipe.Children = new List<ViewModel.LogicalTreeItem>();
                                        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 ViewModel.LogicCatalogExLogicalTreeItems(catalog, vm_logic_tree_item_list));
                }
 
                #endregion
 
                return vm_cache_list;
 
 
            }, CacheHelper.CacheLevel3);
            return new Result<List<ViewModel.LogicCatalogExLogicalTreeItems>>(vm_list);
        }
 
    }
}