tangxu
2022-11-02 05f522e321a742f03bf1e3e26edaeb5147da42f4
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
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;
using Microsoft.AspNetCore.Http;
using Furion.DependencyInjection;
using Microsoft.AspNetCore.Authorization;
using Furion.DataEncryption;
using Furion.FriendlyException;
 
namespace IStation.Application
{
    /// <summary>
    /// 机泵
    /// </summary>
    [AllowAnonymous]
    [Route("LargeScreen/Demo/EnginePump")]
    [ApiDescriptionSettings("LargeScreen", Name = "Demo(机泵)", Order = 666)]
    public class DemoEnginePump_Controller : IDynamicApiController, ITransient
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
 
        /// <summary>
        /// 
        /// </summary>
        public DemoEnginePump_Controller(IHttpContextAccessor httpContextAccessor)
        {
            _httpContextAccessor = httpContextAccessor; 
        }
 
        /// <summary>
        /// 获取机组主页信息 (左上部分)
        /// </summary>
        /// <param name="ProductID">机组ID</param>
        [Route("GetLeftTopInfo")]
        [HttpGet]
        public DemoEnginePumpLeftTopInfoDto GetLeftTopInfo(long ProductID)
        {
            var pumpInfo = new DemoEnginePumpLeftTopInfoDto();
 
            var r = new Random();
 
            pumpInfo.ID = ProductID;
            pumpInfo.CorpID = 2;
            pumpInfo.Name = "一号机泵";
            pumpInfo.Manufacturer = "KSB";
            pumpInfo.Rated_Q = 80;
            pumpInfo.Unit_Rated_Q = "m³/h";
            pumpInfo.MotorPower = 45;
            pumpInfo.Unit_MotorPower = "Kw";
            pumpInfo.Rated_H = 50;
            pumpInfo.Unit_Rated_H = "m";
            pumpInfo.UWP = r.Next(200, 210);
            pumpInfo.Unit_UWP = "kW/千吨水";
 
            pumpInfo.RunDurationTime = string.Format("{0}小时{1}分钟", r.Next(1, 8), r.Next(1, 55));
            pumpInfo.SafeDurationTime = string.Format("{0}小时 ", r.Next(100, 188) + 1000);
 
            return pumpInfo;
        }
 
 
        /// <summary>
        ///  获取机组供水数据分析数据 (左中部分)
        /// </summary>
        /// <param name="ProductID">机组ID</param>
        /// <param name="StaticType">汇总类型(1按日  2 按周 3 按月 4 按年)</param> 
        [Route("GetLeftMiddleInfo")]
        [HttpGet]
        public DemoEnginePumpLeftMiddleInfoDto GetLeftMiddleInfo(long ProductID, int StaticType)
        {
            var r = new Random();
 
            var info = new DemoEnginePumpLeftMiddleInfoDto();
            info.TotalSupplyWater = r.Next(21500, 22350);
 
 
            List<DemoEnginePumpLeftMiddleItemInfoDto> info_list = new List<DemoEnginePumpLeftMiddleItemInfoDto>();
            if (StaticType == 1 || StaticType <= 0)
            {
                info.CurrentValueLabel = "昨日供水量";
                info.CurrentSupplyWater = r.Next(760, 780);
                for (DateTime day = DateTime.Today.AddMonths(-1); day < DateTime.Today; day = day.AddDays(1))
                {
                    DemoEnginePumpLeftMiddleItemInfoDto item = new DemoEnginePumpLeftMiddleItemInfoDto();
                    item.Label = day.ToString("yyyy-MM-dd");
                    item.SupplyWater = r.Next(60, 80);
                    item.EnergyConsumption = r.Next(80, 95);
                    info_list.Add(item);
                }
                info.Details = info_list;
            }
            else if (StaticType == 3 || StaticType == 2)
            {//2 按周 3 按月
                info.CurrentValueLabel = "本月供水量";
                info.CurrentSupplyWater = r.Next(760, 780) * 20;
 
                for (int month = 1; month < DateTime.Today.Month; month = month + 1)
                {
                    DemoEnginePumpLeftMiddleItemInfoDto item = new DemoEnginePumpLeftMiddleItemInfoDto();
                    item.Label = month.ToString();
                    item.SupplyWater = r.Next(60, 80) * 30;
                    item.EnergyConsumption = r.Next(20, 35) * 30;
                    info_list.Add(item);
                }
                info.Details = info_list;
            }
            else
            {//4 按年
                info.CurrentValueLabel = "今年供水量";
                info.CurrentSupplyWater = r.Next(760, 780) * 300;
 
                for (int year = 1; year < 4; year = year + 1)
                {
                    DemoEnginePumpLeftMiddleItemInfoDto item = new DemoEnginePumpLeftMiddleItemInfoDto();
                    item.Label = (DateTime.Today.Year - 3 + year).ToString();
                    item.SupplyWater = r.Next(60, 80) * 270;
                    item.EnergyConsumption = r.Next(20, 35) * 270;
                    info_list.Add(item);
                }
                info.Details = info_list;
            }
 
            return info;
        }
 
        /// <summary>
        ///  获取机组性能曲线数据  (左下部分)
        /// </summary>
        /// <param name="ProductID">机组ID</param>
        [Route("GetLeftBottomInfo")]
        [HttpGet]
        public DemoEnginePumpLeftBottomInfoDto GetLeftBottomInfo(long ProductID)
        {
            var r = new Random();
 
            var ratedParas = new Model.GroupPoint();
            ratedParas.Q = 1200;
            ratedParas.H = 50;
            ratedParas.E = 88;
            ratedParas.P = Common.PumpParaHelper.CalculateP(ratedParas.Q, ratedParas.H, ratedParas.E);
 
            List<Model.GroupPoint> grp_points = new List<Model.GroupPoint>();
            Common.DimensionlessCurvesHelper.CalcPoints(ratedParas, 1450, ref grp_points, true, 1);
 
            var info = new DemoEnginePumpLeftBottomInfoDto();
            info.CurveInfoQH = (from x in grp_points select new Model.CurvePoint(x.Q, x.H)).ToList();
            info.CurveInfoQE = (from x in grp_points select new Model.CurvePoint(x.Q, x.E)).ToList();
            info.CurveInfoQP = (from x in grp_points select new Model.CurvePoint(x.Q, x.P)).ToList();
 
            info.HistoryRunPointQH = new List<Model.CurvePoint>();
            info.HistoryRunPointQE = new List<Model.CurvePoint>();
            info.HistoryRunPointQP = new List<Model.CurvePoint>();
 
            for (int i = 0; i < 100; i++)
            {
                var q = r.Next(800, 1200) * ratedParas.Q / 1000.0;
                var h = Model.FitCurveHelper.GetFitPointY(info.CurveInfoQH, q) * 0.95;
                var e = Model.FitCurveHelper.GetFitPointY(info.CurveInfoQE, q) * 0.95;
                var p = Common.PumpParaHelper.CalculateP(q, h, e);
 
                info.HistoryRunPointQH.Add(new Model.CurvePoint(q, h));
                info.HistoryRunPointQE.Add(new Model.CurvePoint(q, e));
                info.HistoryRunPointQP.Add(new Model.CurvePoint(q, p));
            }
 
            return info;
        }
 
        /// <summary>
        /// 获取首页报警和信息公告(中间底部)
        /// </summary>
        /// <param name="ProductID">机泵ID</param>
        /// <param name="InfoType">信息类型(1公告信息  2报警信息)</param> 
        [Route("GetCenterBottomInfo")]
        [HttpGet]
        public List<DemoEnginePumpCenterBottomItemInfoDto> GetCenterBottomInfo(long ProductID, int InfoType)
        {
            var r = new Random();
            List<DemoEnginePumpCenterBottomItemInfoDto> info_list = new List<DemoEnginePumpCenterBottomItemInfoDto>();
 
            if (InfoType == 1)
            {
                DemoEnginePumpCenterBottomItemInfoDto item1 = new DemoEnginePumpCenterBottomItemInfoDto();
                item1.Title = "大修";
                item1.UserName = "管理员";
                item1.Content = "2020年8月26日,控江路管道维修抢修完成。";
                info_list.Add(item1);
 
                DemoEnginePumpCenterBottomItemInfoDto item2 = new DemoEnginePumpCenterBottomItemInfoDto();
                item2.Title = "维护";
                item2.UserName = "管理员";
                item2.Content = "2020年9月11日,二号泵电机振动过大,进行大修。";
                info_list.Add(item2);
 
 
                DemoEnginePumpCenterBottomItemInfoDto item3 = new DemoEnginePumpCenterBottomItemInfoDto();
                item3.Title = "故障";
                item3.UserName = "管理员";
                item3.Content = "2020年9月22日,发生振动。";
                info_list.Add(item2);
            }
            else
            {
                DemoEnginePumpCenterBottomItemInfoDto item1 = new DemoEnginePumpCenterBottomItemInfoDto();
                item1.Title = "二号泵";
                item1.UserName = "李三林";
                item1.Content = "2020年9月20日 12时30分,漏水严重。";
                info_list.Add(item1);
 
                DemoEnginePumpCenterBottomItemInfoDto item2 = new DemoEnginePumpCenterBottomItemInfoDto();
                item2.Title = "二号泵";
                item2.UserName = "李三林";
                item2.Content = "2020年9月21日 12时30分,漏水严重。";
                info_list.Add(item2);
 
 
                DemoEnginePumpCenterBottomItemInfoDto item3 = new DemoEnginePumpCenterBottomItemInfoDto();
                item3.Title = "二号泵";
                item3.UserName = "管理员";
                item3.Content = "2020年9月25日 12时30分,电流超标。";
                info_list.Add(item2);
            }
 
 
            return info_list;
        }
 
        /// <summary>
        /// 获取表单状态统计占比(右部上)
        /// </summary>
        /// <param name="ProductID">机泵ID</param>
        /// <param name="StaticType">统计类型(1成本 暂时又有一个) </param> 
        [Route("GetRightTopInfo")]
        [HttpGet]
        public List<DemoEnginePumpRightTopInfoDto> GetRightTopInfo(long ProductID, int StaticType)
        {
            var r = new Random();
            List<DemoEnginePumpRightTopInfoDto> info_list = new List<DemoEnginePumpRightTopInfoDto>();
            int ratio = 1;
 
 
 
            DemoEnginePumpRightTopInfoDto item1 = new DemoEnginePumpRightTopInfoDto();
            item1.Label = "总电费";
            item1.Number = r.Next(1221, 3453) * ratio + 150000;
            info_list.Add(item1);
 
 
            DemoEnginePumpRightTopInfoDto item2 = new DemoEnginePumpRightTopInfoDto();
            item2.Label = "总维护费";
            item2.Number = r.Next(1230, 4233) * ratio + 10000;
            info_list.Add(item2);
 
 
            DemoEnginePumpRightTopInfoDto item3 = new DemoEnginePumpRightTopInfoDto();
            item3.Label = "采购费用";
            item3.Number = r.Next(100, 120) * 100 + 100000;
            info_list.Add(item3);
 
            DemoEnginePumpRightTopInfoDto item5 = new DemoEnginePumpRightTopInfoDto();
            item5.Label = "其他费用";
            item5.Number = r.Next(123, 125) * 20 + 10000;
            info_list.Add(item5);
 
            return info_list;
        }
 
 
        /// <summary>
        /// 获取表单类型统计占比(右部中)
        /// </summary>
        /// <param name="ProductID">机泵ID</param>
        /// <param name="PageIndex">页面序号</param> 
        /// <returns></returns>
        [Route("GetRightCenterInfo")]
        [HttpGet]
        public DemoEnginePumpRightCenterInfoDto GetRightCenterInfo(long ProductID, int PageIndex)
        {
            // var r = new Random();
            List<DemoEnginePumpRightCenterItemInfoDto> item_list = new List<DemoEnginePumpRightCenterItemInfoDto>();
            if (PageIndex == 0)
            {
 
                DemoEnginePumpRightCenterItemInfoDto item5 = new DemoEnginePumpRightCenterItemInfoDto();
                item5.Time = "2020-9-11";
                item5.Type = "维修";
                item5.Content = "漏水,更换机封";
                item5.UserName = "机修二组";
                item_list.Add(item5);
 
                DemoEnginePumpRightCenterItemInfoDto item4 = new DemoEnginePumpRightCenterItemInfoDto();
                item4.Time = "2020-8-22";
                item4.Type = "保养";
                item4.Content = "更换易损件";
                item4.UserName = "机修一组";
                item_list.Add(item4);
 
                DemoEnginePumpRightCenterItemInfoDto item3 = new DemoEnginePumpRightCenterItemInfoDto();
                item3.Time = "2020-8-21";
                item3.Type = "维修";
                item3.Content = "漏水,更换机封";
                item3.UserName = "机修一组";
                item_list.Add(item3);
 
                DemoEnginePumpRightCenterItemInfoDto item2 = new DemoEnginePumpRightCenterItemInfoDto();
                item2.Time = "2020-8-11";
                item2.Type = "保养";
                item2.Content = "更换易损件";
                item2.UserName = "机修一组";
                item_list.Add(item2);
 
 
                DemoEnginePumpRightCenterItemInfoDto item1 = new DemoEnginePumpRightCenterItemInfoDto();
                item1.Time = "2020-7-20";
                item1.Type = "维修";
                item1.Content = "漏水,更换机封";
                item1.UserName = "机修一组";
                item_list.Add(item1);
 
 
            }
            else if (PageIndex == 1)
            {
                DemoEnginePumpRightCenterItemInfoDto item1 = new DemoEnginePumpRightCenterItemInfoDto();
                item1.Time = "2020-6-20";
                item1.Type = "维修";
                item1.Content = "漏水,更换机封";
                item1.UserName = "机修一组";
                item_list.Add(item1);
 
 
                DemoEnginePumpRightCenterItemInfoDto item2 = new DemoEnginePumpRightCenterItemInfoDto();
                item2.Time = "2020-6-11";
                item2.Type = "保养";
                item2.Content = "更换机油";
                item2.UserName = "机修一组";
                item_list.Add(item2);
 
                DemoEnginePumpRightCenterItemInfoDto item3 = new DemoEnginePumpRightCenterItemInfoDto();
                item3.Time = "2020-5-21";
                item3.Type = "维修";
                item3.Content = "漏水,更换电机机油";
                item3.UserName = "机修一组";
                item_list.Add(item3);
 
 
                DemoEnginePumpRightCenterItemInfoDto item4 = new DemoEnginePumpRightCenterItemInfoDto();
                item4.Time = "2020-5-19";
                item4.Type = "保养";
                item4.Content = "更换易损件";
                item4.UserName = "机修一组";
                item_list.Add(item4);
 
 
                DemoEnginePumpRightCenterItemInfoDto item5 = new DemoEnginePumpRightCenterItemInfoDto();
                item5.Time = "2020-5-2";
                item5.Type = "维修";
                item5.Content = "漏水,更换机封";
                item5.UserName = "机修二组";
                item_list.Add(item5);
            }
            else
            {
 
                DemoEnginePumpRightCenterItemInfoDto item1 = new DemoEnginePumpRightCenterItemInfoDto();
                item1.Time = "2020-4-30";
                item1.Type = "维修";
                item1.Content = "漏水,更换机封";
                item1.UserName = "机修一组";
                item_list.Add(item1);
 
 
                DemoEnginePumpRightCenterItemInfoDto item2 = new DemoEnginePumpRightCenterItemInfoDto();
                item2.Time = "2020-4-21";
                item2.Type = "保养";
                item2.Content = "更换易损件";
                item2.UserName = "机修一组";
                item_list.Add(item2);
 
                DemoEnginePumpRightCenterItemInfoDto item3 = new DemoEnginePumpRightCenterItemInfoDto();
                item3.Time = "2020-4-20";
                item3.Type = "维修";
                item3.Content = "漏水,更换机封";
                item3.UserName = "机修一组";
                item_list.Add(item3);
 
 
                DemoEnginePumpRightCenterItemInfoDto item4 = new DemoEnginePumpRightCenterItemInfoDto();
                item4.Time = "2020-4-15";
                item4.Type = "保养";
                item4.Content = "更换易损件";
                item4.UserName = "机修一组";
                item_list.Add(item4);
 
 
                DemoEnginePumpRightCenterItemInfoDto item5 = new DemoEnginePumpRightCenterItemInfoDto();
                item5.Time = "2020-4-10";
                item5.Type = "维修";
                item5.Content = "漏水,更换机封";
                item5.UserName = "机修二组";
                item_list.Add(item5);
 
 
            }
 
            DemoEnginePumpRightCenterInfoDto info = new DemoEnginePumpRightCenterInfoDto();
            info.PageNumber = 3;
            info.Details = item_list;
 
            return info;
        }
 
 
        /// <summary>
        /// 通过 StationID 获取简单列表
        /// </summary>
        [Route("GetSimpleListByStationID")]
        [HttpGet]
        public List<DemoEnginePumpSimpleDto> GetSimpleListByStationID([FromQuery][Required] StationIDUnderCorpInput input)
        {
            var corpId = input.CorpID;
            var stationId = input.StationID;
 
            var cacheKey = $"LargeScreen_Demo_EnginePump_GetSimpleListByStationID_{corpId}_{stationId}";
            var vmList = MemoryCacheHelper.GetSet(cacheKey, () =>
            {
                var serviceProduct = new Service.Product();
                var productList = serviceProduct.GetByBelongTypeAndBelongID(corpId, ObjectType.Station, stationId);
                var enginePumpList = productList?.Where(x => x.Catalog == Product.Catalog_JiBeng).ToList();
                if (enginePumpList == null || enginePumpList.Count < 1)
                    return default;
                var vmCacheList = enginePumpList.Select(x => new DemoEnginePumpSimpleDto(x)).ToList();
                return vmCacheList;
            }, CacheHelper.CacheLevel3);
 
            return vmList;
        }
 
 
        /// <summary>
        /// 通过 ID 获取详细
        /// </summary>
        [Route("GetDetailByID")]
        [HttpGet]
        public DemoEnginePumpDetailDto GetDetailByID([FromQuery][Required] IDUnderCorpInput input)
        {
            var corpId = input.CorpID;
            var id = input.ID;
 
            var cacheKey = $"LargeScreen_Demo_EnginePump_GetDetailByID_{corpId}_{id}";
            var vm = MemoryCacheHelper.GetSet(cacheKey, () =>
            {
                var serviceProduct = new Service.Product();
                var enginePump = serviceProduct.GetEnginePumpByProductID(corpId, id);
                if (enginePump == null)
                    return default;
                var serviceProperty = new Service.ProductTypePropertyGroup();
                var enginePumpPropertyList = serviceProperty.GetExItemsByProductTypeID(enginePump.CorpID, enginePump.ProductTypeID);
                var vmCache = new DemoEnginePumpDetailDto(enginePump, enginePumpPropertyList);
                var pump = serviceProduct.GetChildPumpByEnginePumpID(enginePump.CorpID, enginePump.ID);
                if (pump != null)
                {
                    var pumpPropertyList = serviceProperty.GetExItemsByProductTypeID(pump.CorpID, pump.ProductTypeID);
                    vmCache.Pump = new DemoPumpDetailDto(pump, pumpPropertyList);
                }
                var motor = serviceProduct.GetChildMotorByEnginePumpID(enginePump.CorpID, enginePump.ID);
                if (motor != null)
                {
                    var motorPropertyList = serviceProperty.GetExItemsByProductTypeID(motor.CorpID, motor.ID);
                    vmCache.Motor = new DemoMotorDetailDto(motor, motorPropertyList);
                }
                return vmCache;
            }, CacheHelper.CacheLevel4);
 
            return vm;
        }
 
    }
}