lixiaojun
2023-03-21 c6c912c9a0b1235805dea4fbb471e26a7f13a47d
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
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/Glfq")]
    [ApiDescriptionSettings("LargeScreen", Name = "苏州金庭(管网分区)", Order = 999)]
    public class SzjtGlfq_Controller : IDynamicApiController, ITransient 
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
 
        /// <summary>
        /// 
        /// </summary>
        public SzjtGlfq_Controller(IHttpContextAccessor httpContextAccessor)
        {
            _httpContextAccessor = httpContextAccessor; 
        }
 
        private const long _corpid = 3;
 
        /// <summary>
        /// 管网概况 (左上部分 )
        /// </summary>
        /// <returns></returns>
        [Route("GetLeftTopInfo")]
        [HttpGet]
        public SzjtGlfqLeftTopInfoDto GetLeftTopInfo()
        {
            SzjtGlfqLeftTopInfoDto info_list = new SzjtGlfqLeftTopInfoDto();
            var r = new Random();
            info_list.Area = 310;
            info_list.Length = 15 + 25 + 35 + 25 + 23 + 45 + 35;
            info_list.Items = new List<SzjtGlfqLeftTopItemInfoDto>();
            info_list.Items.Add(new SzjtGlfqLeftTopItemInfoDto() { Label = "铸铁", Length = 15, Ratio = Math.Round(15 / info_list.Length, 1) });
            info_list.Items.Add(new SzjtGlfqLeftTopItemInfoDto() { Label = "钢管", Length = 25, Ratio = Math.Round(15 / info_list.Length, 1) });
            info_list.Items.Add(new SzjtGlfqLeftTopItemInfoDto() { Label = "PE", Length = 35, Ratio = Math.Round(15 / info_list.Length, 1) });
            info_list.Items.Add(new SzjtGlfqLeftTopItemInfoDto() { Label = "混凝土", Length = 25, Ratio = Math.Round(15 / info_list.Length, 1) });
            info_list.Items.Add(new SzjtGlfqLeftTopItemInfoDto() { Label = "PVC", Length = 23, Ratio = Math.Round(15 / info_list.Length, 1) });
            info_list.Items.Add(new SzjtGlfqLeftTopItemInfoDto() { Label = "SN", Length = 45, Ratio = Math.Round(15 / info_list.Length, 1) });
            info_list.Items.Add(new SzjtGlfqLeftTopItemInfoDto() { Label = "其他", Length = 35, Ratio = Math.Round(15 / info_list.Length, 1) });
 
            return info_list;
        }
 
        /// <summary>
        /// 获取泵站数据分析汇总信息(左中部分)
        /// </summary>
        /// <param name="StaticType">汇总类型(1按日  2 按周 3 按月 4 按年)</param> 
        [Route("GetLeftMiddleInfo")]
        [HttpGet]
        public List<SzjtGlfqLeftMiddleItemInfoDto> GetLeftMiddleInfo(int StaticType)
        {
            var r = new Random();
            List<SzjtGlfqLeftMiddleItemInfoDto> info_list = new List<SzjtGlfqLeftMiddleItemInfoDto>();
 
            int ratio = 1;
            if (StaticType == 2)
                ratio = 5;
            if (StaticType == 3)
                ratio = 20;
            if (StaticType == 4)
                ratio = 250;
 
            SzjtGlfqLeftMiddleItemInfoDto item1 = new SzjtGlfqLeftMiddleItemInfoDto();
            item1.Label = "机组故障";
            item1.Number = r.Next(8, 11) * ratio;
            info_list.Add(item1);
 
            SzjtGlfqLeftMiddleItemInfoDto item2 = new SzjtGlfqLeftMiddleItemInfoDto();
            item2.Label = "管道维修";
            item2.Number = r.Next(2, 5) * ratio;
            info_list.Add(item2);
 
 
            SzjtGlfqLeftMiddleItemInfoDto item3 = new SzjtGlfqLeftMiddleItemInfoDto();
            item3.Label = "阀门维修";
            item3.Number = r.Next(1, 3) * ratio;
            info_list.Add(item3);
 
            SzjtGlfqLeftMiddleItemInfoDto item4 = new SzjtGlfqLeftMiddleItemInfoDto();
            item4.Label = "仪表";
            item4.Number = r.Next(2, 4) * ratio;
            info_list.Add(item4);
 
            SzjtGlfqLeftMiddleItemInfoDto item5 = new SzjtGlfqLeftMiddleItemInfoDto();
            item5.Label = "其他";
            item5.Number = r.Next(5, 12) * ratio;
            info_list.Add(item5);
 
            return info_list;
        }
 
        /// <summary>
        /// 左面板信息(左):管网管理
        /// </summary>
        /// <returns></returns>
        [Route("GetLeftBottomInfo")]
        [HttpGet]
        public List<SzjtGlfqLeftBottomItemInfoDto> GetLeftBottomInfo()
        {
            var r = new Random();
            List<SzjtGlfqLeftBottomItemInfoDto> info_list = new List<SzjtGlfqLeftBottomItemInfoDto>();
 
            SzjtGlfqLeftBottomItemInfoDto item1 = new SzjtGlfqLeftBottomItemInfoDto();
            item1.Time = "2020-10-01";
            item1.Type = "巡检**路段";
            item1.UserName = "张三";
            info_list.Add(item1);
 
            SzjtGlfqLeftBottomItemInfoDto item2 = new SzjtGlfqLeftBottomItemInfoDto();
            item2.Time = "2020-10-01";
            item2.Type = "巡检**路段";
            item2.UserName = "张三";
            info_list.Add(item2);
 
 
            SzjtGlfqLeftBottomItemInfoDto item3 = new SzjtGlfqLeftBottomItemInfoDto();
            item3.Time = "2020-10-01";
            item3.Type = "巡检**路段";
            item3.UserName = "张三";
            info_list.Add(item3);
 
 
            SzjtGlfqLeftBottomItemInfoDto item4 = new SzjtGlfqLeftBottomItemInfoDto();
            item4.Time = "2020-10-01";
            item4.Type = "巡检**路段";
            item4.UserName = "张三";
            info_list.Add(item4);
 
 
            SzjtGlfqLeftBottomItemInfoDto item5 = new SzjtGlfqLeftBottomItemInfoDto();
            item5.Time = "2020-10-01";
            item5.Type = "巡检**路段";
            item5.UserName = "张三";
            info_list.Add(item5);
 
 
            SzjtGlfqLeftBottomItemInfoDto item6 = new SzjtGlfqLeftBottomItemInfoDto();
            item6.Time = "2020-10-01";
            item6.Type = "巡检**路段";
            item6.UserName = "张三";
            info_list.Add(item6);
 
 
            SzjtGlfqLeftBottomItemInfoDto item7 = new SzjtGlfqLeftBottomItemInfoDto();
            item7.Time = "2020-10-07";
            item7.Type = "巡检**路段";
            item7.UserName = "张三";
            info_list.Add(item7);
 
 
            return info_list;
        }
 
        /// <summary>
        /// 获取首页报警和信息公告(中间底部)
        /// </summary>
        /// <param name="InfoType">信息类型(1信息  2报警)</param> 
        [Route("GetCenterBottomInfo")]
        [HttpGet]
        public List<SzjtGlfqCenterBottomItemInfoDto> GetCenterBottomInfo(int InfoType)
        {
            var r = new Random();
            List<SzjtGlfqCenterBottomItemInfoDto> info_list = new List<SzjtGlfqCenterBottomItemInfoDto>();
 
 
            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 SzjtGlfqCenterBottomItemInfoDto();
                        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
            {
                var service = new Service.MonitorAlarmRecord();
                var serice_point = new IStation.Service.MonitorPoint();
                var alarms = service.GetLastByCorpID(_corpid, 8);
                if (alarms != null && alarms.Count > 0)
                {
                    var station_list = new Service.Station().GetByCorpID(_corpid);
                    var point_list = new Service.MonitorPoint().GetByCorpID(_corpid);
                    foreach (var alarm in alarms)
                    {
                        var point = point_list?.Find(t => t.ID == alarm.MonitorPointID);
                        if (point == null)
                            continue;
                        string belong_name = "";
                        if (point.BelongType == IStation.ObjectType.Station)
                        {
                            belong_name = string.Format("{0}的{1}",
                                (from x in station_list where x.ID == point.BelongID select x.Name).FirstOrDefault(),
                                point.Name);
                        }
 
                        var item1 = new SzjtGlfqCenterBottomItemInfoDto();
                        item1.ID = alarm.ID;
                        item1.Title = belong_name;
                        item1.Content = string.Format("{0} {1}的值为:{2},超过设定{3}",
                            alarm.AlarmTime.ToString("MM月dd日,HH时"),
                            point.Name,
                           alarm.DataValue == null ? "" : Math.Round(double.Parse(alarm.DataValue), 4).ToString(),
                            alarm.ThresholdValue);
                        info_list.Add(item1);
                    }
                }
            }
 
 
            return info_list;
        }
 
        /// <summary>
        /// 获取报修(中间底部)
        /// </summary>
        /// <param name="ID"> (RequesFormID)</param> 
        /// <returns></returns>
        [Route("GetRepairRequesFormDetalInfo")]
        [HttpGet]
        public SzjtGlfqRepairRequestFormDetailInfoDto GetRepairRequesFormDetalInfo(long ID)
        {
 
            var service = new Service.RepairRequestForm();
            var form = service.GetByID(_corpid, ID);
            if (form == null)
            {
                throw new Exception("表单不存在");
            }
            var station_list = new Service.Station().GetByCorpID(_corpid);
            var product_list = new Service.Product().GetByCorpID(_corpid);
            var user_list = new Service.User().GetByCorpID(_corpid);
 
 
            var view_model = new SzjtGlfqRepairRequestFormDetailInfoDto();
            view_model.BelongName = (from x in station_list where x.ID == form.BelongID select x.Name).FirstOrDefault();
            view_model.ReportUserName = (from x in user_list where x.ID == form.CreateUserID select x.RealName).FirstOrDefault();
            view_model.ObjectName = product_list?.Find(t => t.ID == form.ProductID)?.Name;
            view_model.ReportTime = form.CreateTime.ToString("yyyy-MM-dd HH:mm:ss");
            view_model.ProblemDescription = form.Question;
            view_model.FormSource = "小程序";
            if (form.FormStatus == Model.Repair.eRequestStatus.Pending)
                view_model.RequestFormStatus = "待受理";
 
            if (form.FormStatus == Model.Repair.eRequestStatus.Accepted)
                view_model.RequestFormStatus = "已受理";
 
            if (form.FormStatus == Model.Repair.eRequestStatus.Rejected)
                view_model.RequestFormStatus = "已驳回";
 
            return view_model;
        }
 
        /// <summary>
        /// 分区管理(右部上)
        /// </summary>
        /// <returns></returns>
        [Route("GetRightTopInfo")]
        [HttpGet]
        public SzjtGlfqRightTopInfoDto GetRightTopInfo()
        {
            var r = new Random();
 
 
            SzjtGlfqRightTopInfoDto item1 = new SzjtGlfqRightTopInfoDto();
 
            item1.DmaNumber = 8;
            item1.LastTotalSupplyWater = r.Next(2504, 2580);
            item1.LastMonthLeakRatio = 50.8;
            item1.ThisYearLeakRatio = 48.9;
 
            return item1;
        }
 
        /// <summary>
        /// 漏损分析 (右部中:)
        /// </summary>
        /// <param name="StaticType">统计类型(1按日  2 按周 3 按月 4 按年)</param> 
        [Route("GetRightCenterInfo")]
        [HttpGet]
        public List<SzjtGlfqRightCenterInfoDto> GetRightCenterInfo(int StaticType)
        {
            var r = new Random();
 
            List<SzjtGlfqRightCenterInfoDto> info_list = new List<SzjtGlfqRightCenterInfoDto>();
            if (DateTime.Now.Month < 2)
            {
                for (int month = 1; month <= 12; month++)
                {
                    SzjtGlfqRightCenterInfoDto m = new SzjtGlfqRightCenterInfoDto();
                }
            }
            else
            {
                for (int month = 1; month <= DateTime.Now.Month; month++)
                {
                    SzjtGlfqRightCenterInfoDto m = new SzjtGlfqRightCenterInfoDto();
                    m.Label = month.ToString();
                    m.ThisSupplyWater = r.Next(2000, 3000);
                    m.LastSupplyWater = r.Next(2000, 3000);
                    m.ThisSaleWater = r.Next(1800, 2500);
                    m.LastSaleWater = r.Next(1800, 2500);
                    if (m.ThisSupplyWater < m.ThisSaleWater)
                    {
                        double temp = m.ThisSaleWater;
                        m.ThisSaleWater = m.ThisSupplyWater;
                        m.ThisSupplyWater = temp;
                    }
                    if (m.LastSupplyWater < m.LastSaleWater)
                    {
                        double temp = m.LastSaleWater;
                        m.LastSaleWater = m.LastSupplyWater;
                        m.LastSupplyWater = temp;
                    }
                    m.ThisDistributionLosses = Math.Round(m.ThisSupplyWater * 100 / m.ThisSaleWater, 1);
                    m.LastDistributionLosses = Math.Round(m.LastSupplyWater * 100 / m.LastSaleWater, 1);
                    info_list.Add(m);
                }
            }
            return info_list;
        }
 
        /// <summary>
        /// 流量曲綫
        /// </summary>
        /// <param name="StaticType"></param>
        /// <returns></returns>
        [Route("GetRightBottomInfo")]
        [HttpGet]
        public SzjtGlfqRightBottomInfoDto GetRightBottomInfo(int StaticType)
        {
            var now = DateTime.Now;
            List<SzjtGlfqRecordBaseDto> today_records = new List<SzjtGlfqRecordBaseDto>();
            var r = new Random();
            for (int h = 0; h < now.Hour; h++)
            {
                for (int m = 0; m < 60; m++)
                {
                    var dt = new DateTime(now.Year, now.Month, now.Day, h, m, 0);
                    today_records.Add(new SzjtGlfqRecordBaseDto() { RecordTime = dt.ToString("yyyy-MM-dd HH:mm:ss"), RecordValue = r.Next(1000, 1100) / 100.0 });
                }
            }
            for (int m = 0; m < now.Minute; m++)
            {
                var dt = new DateTime(now.Year, now.Month, now.Day, now.Hour, m, 0);
                today_records.Add(new SzjtGlfqRecordBaseDto() { RecordTime = dt.ToString("yyyy-MM-dd HH:mm:ss"), RecordValue = r.Next(1000, 1100) / 100.0 });
            }
 
 
            var yest = DateTime.Now.AddDays(-1);
            List<SzjtGlfqRecordBaseDto> yest_records = new List<SzjtGlfqRecordBaseDto>();
            for (int h = 0; h < 24; h++)
            {
                for (int m = 0; m < 60; m++)
                {
                    var dt = new DateTime(yest.Year, yest.Month, yest.Day, h, m, 0);
                    yest_records.Add(new SzjtGlfqRecordBaseDto() { RecordTime = dt.ToString("yyyy-MM-dd HH:mm:ss"), RecordValue = r.Next(1000, 1100) / 100.0 });
                }
            }
 
            SzjtGlfqRightBottomInfoDto info = new SzjtGlfqRightBottomInfoDto();
            info.TodayFlowCurve = today_records;
            info.YesterdayFlowCurve = yest_records;
 
            return info;
        }
 
 
    }
}