ningshuxia
2022-08-12 ad12ac859cd0c875b6ec220a48b28b747744186e
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
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/Szjt/Bzgl")]
    [ApiDescriptionSettings("LargeScreen", Name = "苏州金庭(泵站管理)", Order = 999)]
    public class SzjtBzgl_Controller : IDynamicApiController, ITransient 
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
 
        /// <summary>
        /// 
        /// </summary>
        public SzjtBzgl_Controller(IHttpContextAccessor httpContextAccessor)
        {
            _httpContextAccessor = httpContextAccessor;
        }
 
        #region const
 
        private const long _corpid = 3;//客户标识
 
        private const long _stationId = 23;//泵站标识
 
        private const long _tlpointid_23 = 1688;//累积流量
        private const long _tlsignalid_23 = 2388;//累积流量信号
 
        private const long _lpointid_23 = 1687;//瞬时流量
        private const long _lsignalid_23 = 2387;//瞬时流量信号
 
        private const long _zdpointId_23 = 1692;//浊度
        private const long _zdsignalid_23 = 2392;//浊度信号
 
        private const long _ylpointid_23 = 1693;//余氯
        private const long _ylsignalid_23 = 2393;//余氯信号
 
        private const long _ckylpointid_23 = 1690;//出口压力
        private const long _ckylsignalid_23 = 2390;//出口压力信号
 
 
        #endregion
 
        /// <summary>
        /// 制水生产 (左上部分)
        /// </summary>
        /// <returns></returns>
        [Route("GetLeftTopInfo")]
        [HttpGet]
        public SzjtBzglLeftTopInfoDto GetLeftTopInfo()
        {
 
            SzjtBzglLeftTopInfoDto info_list = new SzjtBzglLeftTopInfoDto();
            var r = new Random();
            info_list.StationNumber = 10;
            info_list.PumpNumber = r.Next(35, 42).ToString() + "/50";
            info_list.TotalSupplyWater = r.Next(4535, 4642);
            info_list.TotalEnergyConsumption = r.Next(12535, 12642);
 
            info_list.YesterdayUnitEnergyConsumption = r.Next(883, 915) / 10.0;
            info_list.YesterdayEnergyConsumption = r.Next(2860, 2965);
            info_list.YesterdaySupplyWater = r.Next(2600, 2800);
            return info_list;
 
            //       LeftTopInfo info_list = new LeftTopInfo();
            //var service_station = new Service.StationBase();
            //var service_product = new Service.ProductBase();
            //var servive_record = new Service.GeneralRecord();
            //var service_stationRun = new Service.StationRun();
            //var service_pumpRun = new Service.PumpRun();
 
            ////泵站数量
            //var allStations = service_station.GetByCorpID(CorpID);
            //if (allStations != null)
            //    info_list.StationNumber = allStations.Count();
 
            ////开机数/总数
            //int pumpsCount=0, pumpRunCount = 0;
            //var pumps = service_product.GetMachine机泵ByCorpID(CorpID);
            //if (pumps != null && pumps.Count > 0)
            //{
            //    pumpsCount = pumps.Count;
            //    var allPumpRealStatus = service_pumpRun.GetRunRealStatus(pumps.Select(x=>x.ID));
            //    if (allPumpRealStatus != null && allPumpRealStatus.Count > 0)
            //    {
            //        pumpRunCount = allPumpRealStatus.Where(x => x.RunStatus == Model.eRunStatus.开机).Count();
            //    }
            //}
            //info_list.PumpNumber = string.Format("{0}/{1}",pumpRunCount,pumpsCount);
 
            ////总供水量
            //var tq_record = servive_record.GetLastRecordValue(_tlpointid_13);
            //info_list.TotalSupplyWater =NumberHelper.Round( tq_record,2);
 
            ////总能耗
            //info_list.TotalEnergyConsumption =NumberHelper.Round( servive_record.GetLastRecordValue(_dpointId_13),2);
 
            ////昨日总能耗
            //var d_yes_firstValue = servive_record.GetFirstRecordInDayByPointID(_dpointId_13, DateTime.Now.AddDays(-1));
            //var d_yes_lastVlaue = servive_record.GetLastRecordInDayByPointID(_dpointId_13, DateTime.Now.AddDays(-1));
            //if (d_yes_firstValue != null && d_yes_lastVlaue != null)
            //    info_list.YesterdayEnergyConsumption = NumberHelper.Round(d_yes_lastVlaue.DataValue - d_yes_firstValue.DataValue, 2); 
 
            ////昨日累积供水量
            //var tl_yes_firstValue = servive_record.GetFirstRecordInDayByPointID(_tlpointid_13, DateTime.Now.AddDays(-1));
            //var tl_yes_lastVlaue = servive_record.GetLastRecordInDayByPointID(_tlpointid_13, DateTime.Now.AddDays(-1));
            //if (tl_yes_firstValue != null && tl_yes_lastVlaue != null)
            //    info_list.YesterdaySupplyWater = NumberHelper.Round(tl_yes_lastVlaue.DataValue - tl_yes_firstValue.DataValue, 2); 
 
            ////昨日单耗
            //if (info_list.YesterdayEnergyConsumption != null)
            //{
            //    if (info_list.YesterdaySupplyWater != null&&info_list.YesterdaySupplyWater!=0)
            //    {
            //        info_list.YesterdayUnitEnergyConsumption = NumberHelper.Round(info_list.YesterdayEnergyConsumption.Value / info_list.YesterdaySupplyWater.Value * 1000, 2);
            //    }
            //}
 
 
 
        }
 
        /// <summary>
        ///  泵站分析  (左中部分)
        /// </summary>
        /// <param name="StaticType">汇总类型(1按日  2 按周 3 按月 4 按年)</param> 
        [Route("GetLeftMiddleInfo")]
        [HttpGet]
        public List<SzjtBzglLeftMiddleItemInfoDto> GetLeftMiddleInfo(int StaticType)
        {
            var r = new Random();
            List<SzjtBzglLeftMiddleItemInfoDto> info_list = new List<SzjtBzglLeftMiddleItemInfoDto>();
            if (StaticType == 1 || StaticType <= 0)
            {
                for (DateTime day = DateTime.Today.AddMonths(-1); day < DateTime.Today; day = day.AddDays(1))
                {
                    SzjtBzglLeftMiddleItemInfoDto item = new SzjtBzglLeftMiddleItemInfoDto();
                    item.Label = day.ToString("yyyy-MM-dd");
                    item.SupplyWater = r.Next(2600, 2800);
                    item.EnergyConsumption = r.Next(2860, 2965);
                    info_list.Add(item);
                }
            }
            else if (StaticType == 3 || StaticType == 2)
            {//2按月
                for (int month = 1; month < DateTime.Today.Month; month = month + 1)
                {
                    SzjtBzglLeftMiddleItemInfoDto item = new SzjtBzglLeftMiddleItemInfoDto();
                    item.Label = month.ToString();
                    item.SupplyWater = r.Next(2600, 2800) * 30;
                    item.EnergyConsumption = r.Next(2860, 2965) * 30;
                    info_list.Add(item);
                }
            }
            else
            {//4 按年
                for (int year = 1; year < 4; year = year + 1)
                {
                    SzjtBzglLeftMiddleItemInfoDto item = new SzjtBzglLeftMiddleItemInfoDto();
                    item.Label = (DateTime.Today.Year - 3 + year).ToString();
                    item.SupplyWater = r.Next(2600, 2800) * 300;
                    item.EnergyConsumption = r.Next(2860, 2965) * 300;
                    info_list.Add(item);
                }
            }
            return info_list;
        }
 
        /// <summary>
        /// 获取泵站数据分析明细信息(左下部分)
        /// </summary>
        /// <param name="StaticType">汇总类型(1按日  2 按周 3 按月 4 按年)</param> 
        [Route("GetLeftBottomInfo")]
        [HttpGet]
        public List<SzjtBzglLeftBottomItemInfoDto> GetLeftBottomInfo(int StaticType)
        {
            var info_list = new List<SzjtBzglLeftBottomItemInfoDto>();
            var service_station = new Service.Station();
            var service_record = new Service.MonitorRealRecord();
 
            var station_list = service_station.GetByCorpID(_corpid);
 
            foreach (var station in station_list)
            {
                var item = new SzjtBzglLeftBottomItemInfoDto();
                item.ID = station.ID;
                item.Name = station.Name;
                if (station.ID == _stationId)
                {
                    item.Flow = NumberHelper.RoundString(double.Parse(service_record.GetLastRecord(_corpid, _lpointid_23, _lsignalid_23).DataValue), 2);
                    item.Press = NumberHelper.RoundString(double.Parse(service_record.GetLastRecord(_corpid, _ckylpointid_23, _ckylsignalid_23).DataValue), 2);
                    item.ResidualChlorine = NumberHelper.RoundString(double.Parse(service_record.GetLastRecord(_corpid, _ylpointid_23, _ylsignalid_23).DataValue), 3);
                    item.Turbidity = NumberHelper.RoundString(double.Parse(service_record.GetLastRecord(_corpid, _zdpointId_23, _zdsignalid_23).DataValue), 3);
                }
                info_list.Add(item);
            }
 
            //var r = new Random();
            //List<LeftBottomItemInfo> info_list = new List<LeftBottomItemInfo>();
 
            //var all_station = new Service.StationBase().GetByCorpID(1);
 
            //foreach (var station in all_station)
            //{
            //    LeftBottomItemInfo item = new LeftBottomItemInfo();
            //    item.ID = station.ID;
            //    item.Name = station.Name;
            //    item.Flow = r.Next(2600, 2800) / 100.0;
            //    item.Press = r.Next(211, 225) / 1000.0;
            //    item.WaterQuality = r.Next(210, 225) / 100.0;
 
            //    info_list.Add(item);
 
            //}
            return info_list;
        }
 
        /// <summary>
        /// 获取首页报警和信息公告(中间底部)
        /// </summary>
        /// <param name="InfoType">信息类型(1信息  2报警)</param> 
        [Route("GetCenterBottomInfo")]
        [HttpGet]
        public List<SzjtBzglCenterBottomItemInfoDto> GetCenterBottomInfo(int InfoType)
        {
            var r = new Random();
            List<SzjtBzglCenterBottomItemInfoDto> info_list = new List<SzjtBzglCenterBottomItemInfoDto>();
 
 
            if (InfoType == 1)
            {
                var service = new Service.RepairRequestForm();
                var forms = service.GetLastByCorpID(_corpid, 8);
                foreach (var f in forms)
                {
                    var station_list = new Service.Station().GetByCorpID(_corpid);
                    var product_list = new Service.Product().GetByCorpID(_corpid);
                    var user_list = new Service.User().GetByCorpID(_corpid);
                    if (f.BelongType == ObjectType.Station)
                    {
                        var item1 = new SzjtBzglCenterBottomItemInfoDto();
                        item1.ID = f.ID;
                        item1.Title = station_list?.Find(t => t.ID == f.BelongID)?.Name;
                        item1.UserName = user_list?.Find(t => t.ID == f.CreateUserID)?.RealName;
                        item1.Content = string.Format("{0} {1}发生:{2}", f.CreateTime.ToString("MM月dd日,HH时"), product_list?.Find(t => t.ID == f.ProductID)?.Name, f.Question);
                        info_list.Add(item1);
                    }
                }
            }
            else
            {
                SzjtBzglCenterBottomItemInfoDto item1 = new SzjtBzglCenterBottomItemInfoDto();
                item1.Title = "金庭镇第一水厂";
                item1.UserName = "李三林";
                item1.Content = "2020年11月20日 12时30分,一号机漏水严重。";
                info_list.Add(item1);
 
                SzjtBzglCenterBottomItemInfoDto item2 = new SzjtBzglCenterBottomItemInfoDto();
                item2.Title = "金庭镇第一水厂";
                item2.UserName = "李三林";
                item2.Content = "2020年11月21日 12时30分,一号机漏水严重。";
                info_list.Add(item2);
 
 
                SzjtBzglCenterBottomItemInfoDto item3 = new SzjtBzglCenterBottomItemInfoDto();
                item3.Title = "涵村待诏坞";
                item3.UserName = "管理员";
                item3.Content = "2020年10月25日 12时30分,巡检员张坤成在东蔡村附件发现曝管。";
                info_list.Add(item2);
            }
 
 
            return info_list;
        }
 
        /// <summary>
        /// 工单数量 (右部上 )
        /// </summary>
        /// <returns></returns>
        [Route("GetRightTopInfo")]
        [HttpGet]
        public SzjtBzglRightTopInfoDto GetRightTopInfo()
        {
            var start = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            var taskFormList = new Service.RepairTaskForm().GetFluzzyList(_corpid, null, null, null, null, null, null, null, start, null);
            var taskFormCount = new Service.RepairTaskForm().GetCountByCorpID(_corpid);
            var requestPendingCount = new Service.RepairRequestForm().GetPendingCountByCorpID(_corpid);
 
            var vm = new SzjtBzglRightTopInfoDto();
            vm.UnProcessingForm = requestPendingCount;
            if (taskFormList == null || taskFormList.Count < 1)
            {
                vm.HistoryTotalForm = taskFormCount;
            }
            else
            {
                vm.TotalForm = taskFormList.Count;
                vm.HistoryTotalForm = taskFormCount - vm.TotalForm;
                vm.ProcessedForm = taskFormList.Where(x => x.Item1.FormStatus == Model.Repair.eTaskStatus.Accepted).Count();
                vm.ProcessingForm = taskFormList.Where(x => x.Item1.FormStatus > Model.Repair.eTaskStatus.Accepted && x.Item1.FormStatus < Model.Repair.eTaskStatus.Succeed).Count();
                vm.CheckedForm = taskFormList.Where(x => x.Item1.FormStatus >= Model.Repair.eTaskStatus.Succeed).Count();
            }
 
            return vm;
 
        }
 
        /// <summary>
        /// 获取表单类型统计占比(右部中)
        /// </summary>
        /// <param name="StaticType">统计类型(1按日  2 按周  3 按月 4 按年)</param> 
        [Route("GetRightCenterInfo")]
        [HttpGet]
        public List<SzjtBzglRightCenterInfoDto> GetRightCenterInfo(int StaticType)
        {
            DateTime today = DateTime.Today;
            DateTime start = new DateTime(today.Year, today.Month, 1);
            if (today.Day < 5)
            {
                start = new DateTime(today.Year, today.Month, 1).AddMonths(-1);
            }
            DateTime end = today.AddDays(1);
 
            IStation.Service.Product productService = new Service.Product();
            var allProduct = productService.GetByCorpID(_corpid);
 
 
            IStation.Service.RepairTaskForm service = new Service.RepairTaskForm();
            var form_list = service.GetFluzzyList(_corpid,null,null,null,null,null,null,null, start, end);
 
            int yb = 0;
            int jb = 0;
            int f = 0;
            int other = 0;
            foreach (var form in form_list)
            {
                var product = (from x in allProduct where form.Item1.ProductID == x.ID select x).FirstOrDefault();
                if (product == null)
                    continue;
 
 
                if (product.Catalog == IStation.Product.Catalog_JiBeng)
                {
                    jb++;
                }
                else if (product.Catalog == IStation.Product.Catalog_Beng)
                {
                    jb++;
                }
                else if (product.Catalog == IStation.Product.Catalog_DianJi)
                {
                    jb++;
                }
                else if (product.Catalog == IStation.Product.Catalog_Fa)
                {
                    f++;
                }
                else if (product.Catalog == IStation.Product.Catalog_ShuiBiao)
                {
                    yb++;
                }
                else if (product.Catalog == IStation.Product.Catalog_LiuLiangJi)
                {
                    yb++;
                }
                else if (product.Catalog == IStation.Product.Catalog_YaLiJi)
                {
                    yb++;
                }
                else if (product.Catalog == IStation.Product.Catalog_ShuiZhiYi)
                {
                    yb++;
                }
                else
                {
                    other++;
                }
            }
 
            List<SzjtBzglRightCenterInfoDto> info_list = new List<SzjtBzglRightCenterInfoDto>();
 
            SzjtBzglRightCenterInfoDto item1 = new SzjtBzglRightCenterInfoDto();
            item1.Label = "机组故障";
            item1.Number = jb;
            info_list.Add(item1);
 
 
            SzjtBzglRightCenterInfoDto item2 = new SzjtBzglRightCenterInfoDto();
            item2.Label = "管道维修";
            item2.Number = 0;
            info_list.Add(item2);
 
 
            SzjtBzglRightCenterInfoDto item3 = new SzjtBzglRightCenterInfoDto();
            item3.Label = "阀门维修";
            item3.Number = f;
            info_list.Add(item3);
 
            SzjtBzglRightCenterInfoDto item4 = new SzjtBzglRightCenterInfoDto();
            item4.Label = "仪表";
            item4.Number = yb;
            info_list.Add(item4);
 
            SzjtBzglRightCenterInfoDto item5 = new SzjtBzglRightCenterInfoDto();
            item5.Label = "其他";
            item5.Number = other;
            info_list.Add(item5);
            return info_list;
        }
 
 
    }
}