ke
2024-07-19 08a962d2925baa255207fdf979e6fee794f1773b
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
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
package cn.gistack.alerts.alarmRule.service.impl;
 
import cn.gistack.alerts.alarmRule.DTO.WaterQueryDTO;
import cn.gistack.alerts.alarmRule.entity.FsRAtmtnFrcstInf;
import cn.gistack.alerts.alarmRule.mapper.FsRAtmtnFrcstInfMapper;
import cn.gistack.alerts.alarmRule.service.FsRAtmtnFrcstService;
import cn.gistack.alerts.alarmRule.vo.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StopWatch;
 
import java.io.InputStream;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.Instant;
import java.util.*;
import java.util.stream.Collectors;
 
@Service
@Slf4j
public class FsRAtmtnFrcstServiceImpl implements FsRAtmtnFrcstService {
    @Autowired
    private FsRAtmtnFrcstInfMapper fsRAtmtnFrcstInfMapper;
 
    private static final ObjectMapper objectMapper = new ObjectMapper();
 
    private static final String apikey = "F1DBECD719108635189480CF60E6553ADB3109616426BD537F25A430DFC613B491A025C4A51E77FD08C6E5B7CBE05917A461286E7B6D69F1AB1B14F946149D2065B0C675F8FEDF4B9B05C1496881BC5A";
    private static final String cookie = "userobj=%7B%22_id%22%3A%225adfd17ddd000ba4188c53e0%22%2C%22name%22%3A%22%E9%98%B2%E6%B1%9B%E5%80%BC%E7%8F%AD%22%2C%22phone%22%3A%2213612345678%22%2C%22utype%22%3A0%2C%22dept%22%3A%22%E7%9C%81%E6%B0%B4%E5%88%A9%E5%8E%85%22%2C%22tm%22%3A%222018-04-25T00%3A53%3A17.147Z%22%2C%22token%22%3A%224e30701b3ac0996c60569e7f4c65ca5d%22%2C%22chkc%22%3Afalse%2C%22ywjk%22%3Afalse%2C%22yywh%22%3Afalse%7D";
 
    private static final HttpClient client = HttpClient.newHttpClient();
    @Override
    public Object getAtmtnInfo(String STCM, Integer type) {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start("查询预报信息");
        List<String> stcds = new ArrayList<>();
        if (StringUtils.isNotBlank(STCM)){
             stcds = fsRAtmtnFrcstInfMapper.getStcdS(STCM);
        }
        List<FsRAtmtnFrcstInfVO> atmtnInfo = new ArrayList<>();
        List<FsRAtmtnFrcstInfVO> result = new ArrayList<>();
            if (type==1){
                atmtnInfo = fsRAtmtnFrcstInfMapper.getAtmtnInfo(type,stcds);
            }else if (type==2){
                atmtnInfo = fsRAtmtnFrcstInfMapper.getAtmtnInfo1(type,stcds);
            }
        Map<String, List<FsRAtmtnFrcstInfVO>> map = atmtnInfo.stream().filter(s->s.getSTCD()!=null).collect(Collectors.groupingBy(FsRAtmtnFrcstInf::getSTCD));
            if (!map.isEmpty()){
                for (Map.Entry<String, List<FsRAtmtnFrcstInfVO>> entry : map.entrySet()) {
                    List<FsRAtmtnFrcstInfVO> value = entry.getValue();
                    List<FsRAtmtnFrcstDtVO> dtVOList = value.stream().map(s -> FsRAtmtnFrcstDtVO.builder().TM(s.getTM()).TZ(s.getTZ()).TQ(s.getTQ()).build()).collect(Collectors.toList());
                    FsRAtmtnFrcstInfVO fsRAtmtnFrcstInfVO = value.get(0);
                    fsRAtmtnFrcstInfVO.setFrcstDtVOS(dtVOList);
                    result.add(fsRAtmtnFrcstInfVO);
                }
            }
        stopWatch.stop();
        stopWatch.start("查询站点信息");
        List<String> STCDs = result.stream().map(FsRAtmtnFrcstInf::getSTCD).collect(Collectors.toList());
        List<StStbprpBVO> stationInfos = fsRAtmtnFrcstInfMapper.getStationInfo(STCDs);
        stopWatch.stop();
        stopWatch.start("封装数据");
        Map<String, StStbprpBVO> stationMap = stationInfos.stream().collect(Collectors.toMap(StStbprpBVO::getSTCD, bvo -> bvo, (oldValue, newValue) -> oldValue));  // 合并函数:如果键冲突,选择保留哪个值(这里保留旧值)
        if (CollectionUtils.isNotEmpty(result)){
            for (FsRAtmtnFrcstInfVO infVO : result) {
                StStbprpBVO bvo = stationMap.get(infVO.getSTCD());
                if (Objects.nonNull(bvo)){
                    infVO.setGRZ(bvo.getGRZ());
                    infVO.setRVNM(bvo.getRVNM()==null?null: bvo.getRVNM().replaceAll(" ",""));
                    infVO.setSTNM(bvo.getSTNM()==null?null:bvo.getSTNM().replaceAll(" ",""));
                    infVO.setWRZ(bvo.getWRZ());
                    infVO.setFSLTDZ(bvo.getFSLTDZ());
                    infVO.setSFLZ(bvo.getSFLZ());
                }
                for (FsRAtmtnFrcstDtVO dtVO : infVO.getFrcstDtVOS()) {
                    List<FsRAtmtnFrcstDtDeatilVO> list = new ArrayList<>();
                    list.add(new FsRAtmtnFrcstDtDeatilVO("水位", dtVO.getTZ()==0?null:dtVO.getTZ().toString()));
                    list.add(new FsRAtmtnFrcstDtDeatilVO("流量", dtVO.getTQ()==0?null:dtVO.getTQ().toString()));
                    dtVO.setList(list);
                }
            }
        }
        stopWatch.stop();
        log.info(stopWatch.prettyPrint());
        return  result;
    }
 
    @Override
    public List<WarningTypeVO> warningStatistics() {
        List<WarningTypeVO> result = new ArrayList<>();
        StopWatch stopWatch = new StopWatch();
        stopWatch.start("水库统计");
        //水库统计
        Map<String,String> map = new HashMap<>();
        map.put("name","apikey");
        map.put("value",apikey);
        JsonNode jsonNode = doRequest("GET", "https://sk.hubeishuiyi.cn/services/1234567890ABCDEFGHIJKLMN/res_over_flpr_des_rain/api", map, null);
        JsonNode shuikuNode =  jsonNode.get("data").get("data");
        List<WarningTypeVO> shuikuChild = new ArrayList<>();
        for (JsonNode node : shuikuNode) {
            String overType = String.valueOf(node.get("over_type"));
            shuikuChild.add(WarningTypeVO.builder().warningType(overType.substring(1, overType.length() - 1)).warningNum(String.valueOf(node.get("over_number"))).build());
        }
        WarningTypeVO shuiku = WarningTypeVO.builder().warningType("水库").childList(shuikuChild).warningNum(String.valueOf(shuikuChild.stream().mapToInt(s -> Integer.parseInt(s.getWarningNum())).sum())).build();
        for (WarningTypeVO vo : shuikuChild) {
            if (vo.getWarningType().equals("超设计洪水位")||vo.getWarningType().equals("超防洪高水位")){
                shuiku.setColor("红色");
            }else if (vo.getWarningType().equals("暴雨")){
                shuiku.setColor("黄色");
            }
        }
        result.add(shuiku);
        stopWatch.stop();
 
        stopWatch.start("水文统计");
        //水文统计
        List<WarningTypeVO> shuiziyuanChild = new ArrayList<>();
        JsonNode jsonNode1 = doRequest("GET", "https://hfc.mwr.cn/warn-release-api/api/warninfo.custom/4MTAOTM1MzEyQHFxLmNvbQ==", new HashMap<>(), null);
        JsonNode data = jsonNode1.get("Data");
        List<WarningColorVO> hsChild = new ArrayList<>();
        List<WarningColorVO> ghChild = new ArrayList<>();
        for (JsonNode datum : data) {
            String wrType = datum.get("WRType").toString();
            wrType = wrType.substring(1,wrType.length()-1);
            String WRLevel = datum.get("WRLevel").toString();
            WRLevel = WRLevel.substring(1,WRLevel.length()-1);
            if (wrType.equals("洪水")){
                hsChild.add(WarningColorVO.builder().colorName(WRLevel).build());
            }else {
                ghChild.add(WarningColorVO.builder().colorName(WRLevel).build());
            }
        }
        WarningTypeVO hs = WarningTypeVO.builder().warningType("洪水预警").warningNum(String.valueOf(hsChild.size())).build();
        List<WarningColorVO> totals = hsChild.stream()
            .collect(Collectors.groupingBy(WarningColorVO::getColorName, Collectors.counting()))
            .entrySet().stream()
            .map(entry -> new WarningColorVO(entry.getKey(), Math.toIntExact(entry.getValue())))
            .collect(Collectors.toList());
        hs.setColorVOList(totals);
 
        WarningTypeVO gh = WarningTypeVO.builder().warningType("干旱预警").warningNum(String.valueOf(ghChild.size())).build();
        List<WarningColorVO> totals1 = ghChild.stream()
            .collect(Collectors.groupingBy(WarningColorVO::getColorName, Collectors.counting()))
            .entrySet().stream()
            .map(entry -> new WarningColorVO(entry.getKey(), Math.toIntExact(entry.getValue())))
            .collect(Collectors.toList());
        gh.setColorVOList(totals1);
        shuiziyuanChild.add(hs);
        shuiziyuanChild.add(gh);
        WarningTypeVO shuiwen = WarningTypeVO.builder().warningType("水文").childList(shuiziyuanChild).warningNum(String.valueOf(shuiziyuanChild.stream().mapToInt(s -> Integer.parseInt(s.getWarningNum())).sum())).build();
        totals.addAll(totals1);
        if (CollectionUtils.isNotEmpty(totals)){
            for (WarningColorVO vo : totals) {
                String colorName = vo.getColorName();
                if (colorName.equals("红色")){
                    shuiwen.setColor("红色");
                }else if (colorName.equals("橙色")){
                    shuiwen.setColor("橙色");
                }else if (colorName.equals("黄色")){
                    shuiwen.setColor("黄色");
                }else if (colorName.equals("蓝色")){
                    shuiwen.setColor("蓝色");
                }
            }
        }
        result.add(shuiwen);
        stopWatch.stop();
 
        stopWatch.start("山洪");
        //山洪
        List<WarningTypeVO> shList = new ArrayList<>();
        Map<String,String> map1 = new HashMap<>();
        map1.put("name","cookie");
        map1.put("value",cookie);
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH");
        String time = format.format(date);
        String type = "sh";
        JsonNode jsonNode2 = doRequest("GET", "https://sk.hubeishuiyi.cn/contourcale/hour6?tm="+time+"&type="+type, map1, null);
        JsonNode results = jsonNode2.get("results");
        int cnt = 0,wb = 0,nb = 0;
        for (JsonNode node : results) {
            JsonNode warnmap = node.get("warnmap");
            if (warnmap!=null){
                Iterator<JsonNode> elements = warnmap.elements();
                JsonNode jsonNode3  = elements.next();
                String cnt1 = jsonNode3.get("cnt").toString();
                cnt +=  Integer.parseInt(cnt1);
 
                String nbcnt1 = jsonNode3.get("nbcnt").toString();
                nb +=  Integer.parseInt(nbcnt1);
 
                String wbcnt1 = jsonNode3.get("wbcnt").toString();
                wb +=  Integer.parseInt(wbcnt1);
            }
        }
        shList.add(WarningTypeVO.builder().warningType("总数").warningNum(String.valueOf(cnt)).build());
        shList.add(WarningTypeVO.builder().warningType("内部预警").warningNum(String.valueOf(nb)).build());
        shList.add(WarningTypeVO.builder().warningType("外部预警").warningNum(String.valueOf(wb)).build());
        WarningTypeVO shanhong = WarningTypeVO.builder().warningType("山洪").childList(shList).warningNum(String.valueOf(cnt)).build();
        if (wb>0){
            shanhong.setColor("红色");
        }else if (nb>0){
            shanhong.setColor("黄色");
        }
        result.add(shanhong);
        stopWatch.stop();
 
        stopWatch.start("生态激流");
        //水资源
        //生态激流
        SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyy");
        String format1 = format.format(date);
        String format2 = dateFormat1.format(date);
        List<WarningTypeVO> szyList = new ArrayList<>();
        String dtBgTm = format2+"-01-01 00:00:00";
        String dtEdTm = format1+" 23:59:59";
        JsonNode jsonNode3 = doRequest("GET", "http://113.57.190.43:31700/api-szy-0.0.1/api/szy/v0.1/stjl/statis/b/queryBaseFlowList?addvcd=42", new HashMap<>(), null);
        JsonNode result1 = jsonNode3.get("result");
        int red = 0 , blue = 0;
        for (JsonNode node : result1) {
            if (node.get("Q")!=null){
                String s = node.get("Q").toString();
                if (!s.equals("null")){
                    String base_flow = node.get("BASE_FLOW").toString();
                    String blue_alert = node.get("WATER_LEVEL_BLUE_ALERT").toString();
                    double q = Double.parseDouble(s);
                    double flow = Double.parseDouble(base_flow.equals("null")?"0":base_flow.substring(1,base_flow.length()-1));
                    double alert = Double.parseDouble(blue_alert.equals("null")?"0":blue_alert.substring(1,blue_alert.length()-1));
                    if (q<flow){
                        red++;
                    }else if (q<alert){
                        blue++;
                    }
                }
            }else {
                String z = node.get("Z").toString();
                if (!z.equals("null")){
                    String water_level = node.get("WATER_LEVEL").toString();
                    String blueAlert = node.get("WATER_LEVEL_BLUE_ALERT").toString();
                    double Z = Double.parseDouble(z.substring(1,z.length()-1));
                    double level = Double.parseDouble(water_level.equals("null")?"0": water_level.substring(1,water_level.length()-1));
                    double alert = Double.parseDouble(blueAlert.equals("null")?"0": blueAlert.substring(1,blueAlert.length()-1));
                    if (Z>0){
                        if (Z>level){
                            red++;
                        }else if (Z>alert){
                            blue++;
                        }
                    }
                }
            }
        }
        List<WarningColorVO> stjl = new ArrayList<>();
        stjl.add(WarningColorVO.builder().colorName("红色").colorWarningNum(red).build());
        stjl.add(WarningColorVO.builder().colorName("蓝色").colorWarningNum(blue).build());
        szyList.add(WarningTypeVO.builder().warningNum(String.valueOf(red+blue)).colorVOList(stjl).warningType("河湖断面生态流量").build());
        stopWatch.stop();
 
        stopWatch.start("水量");
        //水量
        WaterQueryDTO queryDTO = WaterQueryDTO.builder().wiustTp("1").adlCd("42").tsBgTm(format2+"-01-01 00:00:00").tsEdTm(format1+" 00:00:00").build();
        int red1 = 0 , or = 0,blue1 = 0;
        try {
            String s = objectMapper.writeValueAsString(queryDTO);
            JsonNode jsonNode4 = doRequest("POST", "http://113.57.190.43:31700/api-szy-0.0.1/api/szy/v0.1/wr/wiu/b/list", new HashMap<>(), s);
            JsonNode result2 = jsonNode4.get("result");
            for (JsonNode node : result2) {
                String ratio = node.get("RATIO").toString();
                double r = Double.parseDouble(ratio.equals("null") ? "0" : ratio);
                if (r>1){
                    red1++;
                }else if (r>0.9&& r<=1){
                    or++;
                }else if (r>0.8&& r<=0.9){
                    blue1++;
                }
            }
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
        List<WarningColorVO> sl = new ArrayList<>();
        sl.add(WarningColorVO.builder().colorName("红色").colorWarningNum(red1).build());
        sl.add(WarningColorVO.builder().colorName("橙色").colorWarningNum(or).build());
        sl.add(WarningColorVO.builder().colorName("蓝色").colorWarningNum(blue1).build());
        szyList.add(WarningTypeVO.builder().warningNum(String.valueOf(red1+or+blue1)).colorVOList(sl).warningType("水量").build());
        stopWatch.stop();
        System.out.println(stopWatch.prettyPrint());
        WarningTypeVO shuiziyuan = WarningTypeVO.builder().warningType("水资源").childList(szyList).warningNum(String.valueOf(cnt)).build();
        result.add(shuiziyuan);
        if (red1>0||red>0){
            shuiziyuan.setColor("红色");
        }else if (or>0){
            shuiziyuan.setColor("橙色");
        }else if (blue1>0||blue>0){
            shuiziyuan.setColor("蓝色");
        }
        return result;
    }
 
    @Override
    public WarningTypeVO warningStatisticsSK() {
        StopWatch stopWatch = new StopWatch();
        //水库统计
        Map<String,String> map = new HashMap<>();
        map.put("name","apikey");
        map.put("value",apikey);
        stopWatch.start("调用水库远程接口");
        JsonNode jsonNode = doRequest("GET", "https://sk.hubeishuiyi.cn/services/1234567890ABCDEFGHIJKLMN/res_over_flpr_des_rain/api", map, null);
        stopWatch.stop();
        stopWatch.start("封装水库统计数据");
        JsonNode shuikuNode =  jsonNode.get("data").get("data");
        List<WarningTypeVO> shuikuChild = new ArrayList<>();
        int typeNum = 0;
        for (JsonNode node : shuikuNode) {
            String overType = String.valueOf(node.get("over_type"));
            JsonNode overNumber = node.get("over_number");
            if (overNumber!=null){
            if (Integer.parseInt(overNumber.toString())>0){
                typeNum++;
            };
            }
            shuikuChild.add(WarningTypeVO.builder().warningType(overType.substring(1, overType.length() - 1)).warningNum(String.valueOf(node.get("over_number"))).build());
        }
        WarningTypeVO shuiku = WarningTypeVO.builder().warningType("水库").childList(shuikuChild).warningNum(String.valueOf(shuikuChild.stream().mapToInt(s -> Integer.parseInt(s.getWarningNum())).sum())).build();
        for (WarningTypeVO vo : shuikuChild) {
            if (vo.getWarningType().equals("超设计洪水位")||vo.getWarningType().equals("超防洪高水位")){
                shuiku.setColor("红色");
            }else if (vo.getWarningType().equals("暴雨")){
                shuiku.setColor("黄色");
            }
        }
        shuiku.setTypeNum(String.valueOf(typeNum) );
        stopWatch.stop();
        log.info(stopWatch.prettyPrint());
        return shuiku;
    }
 
    @Override
    public WarningTypeVO warningStatisticsSW() {
        //水文统计
        List<WarningTypeVO> shuiziyuanChild = new ArrayList<>();
        JsonNode jsonNode1 = doRequest("GET", "https://hfc.mwr.cn/warn-release-api/api/warninfo.custom/4MTAOTM1MzEyQHFxLmNvbQ==", new HashMap<>(), null);
        JsonNode data = jsonNode1.get("Data");
        List<WarningColorVO> hsChild = new ArrayList<>();
        List<WarningColorVO> ghChild = new ArrayList<>();
        for (JsonNode datum : data) {
            String wrType = datum.get("WRType").toString();
            wrType = wrType.substring(1,wrType.length()-1);
            String WRLevel = datum.get("WRLevel").toString();
            WRLevel = WRLevel.substring(1,WRLevel.length()-1);
            if (wrType.equals("洪水")){
                hsChild.add(WarningColorVO.builder().colorName(WRLevel).build());
            }else {
                ghChild.add(WarningColorVO.builder().colorName(WRLevel).build());
            }
        }
        WarningTypeVO hs = WarningTypeVO.builder().warningType("洪水预警").warningNum(String.valueOf(hsChild.size())).build();
        List<WarningColorVO> totals = hsChild.stream()
            .collect(Collectors.groupingBy(WarningColorVO::getColorName, Collectors.counting()))
            .entrySet().stream()
            .map(entry -> new WarningColorVO(entry.getKey(), Math.toIntExact(entry.getValue())))
            .collect(Collectors.toList());
        hs.setColorVOList(totals);
 
        WarningTypeVO gh = WarningTypeVO.builder().warningType("干旱预警").warningNum(String.valueOf(ghChild.size())).build();
        List<WarningColorVO> totals1 = ghChild.stream()
            .collect(Collectors.groupingBy(WarningColorVO::getColorName, Collectors.counting()))
            .entrySet().stream()
            .map(entry -> new WarningColorVO(entry.getKey(), Math.toIntExact(entry.getValue())))
            .collect(Collectors.toList());
        gh.setColorVOList(totals1);
        shuiziyuanChild.add(hs);
        shuiziyuanChild.add(gh);
        WarningTypeVO shuiwen = WarningTypeVO.builder().warningType("水文").childList(shuiziyuanChild).warningNum(String.valueOf(shuiziyuanChild.stream().mapToInt(s -> Integer.parseInt(s.getWarningNum())).sum())).build();
        totals.addAll(totals1);
        if (CollectionUtils.isNotEmpty(totals)){
            for (WarningColorVO vo : totals) {
                String colorName = vo.getColorName();
                if (colorName.equals("红色")){
                    shuiwen.setColor("红色");
                }else if (colorName.equals("橙色")){
                    shuiwen.setColor("橙色");
                }else if (colorName.equals("黄色")){
                    shuiwen.setColor("黄色");
                }else if (colorName.equals("蓝色")){
                    shuiwen.setColor("蓝色");
                }
            }
        }
        shuiwen.setTypeNum(shuiwen.getWarningNum());
        return shuiwen;
    }
 
    @Override
    public WarningTypeVO warningStatisticsSH() {
        List<WarningTypeVO> shList = new ArrayList<>();
        Map<String,String> map1 = new HashMap<>();
        map1.put("name","cookie");
        map1.put("value",cookie);
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH");
        String time = format.format(date);
        String type = "sh";
        JsonNode jsonNode2 = doRequest("GET", "https://sk.hubeishuiyi.cn/contourcale/hour6?tm="+time+"&type="+type, map1, null);
        JsonNode results = jsonNode2.get("results");
        int cnt = 0,wb = 0,nb = 0;
        for (JsonNode node : results) {
            JsonNode warnmap = node.get("warnmap");
            if (warnmap!=null){
                Iterator<JsonNode> elements = warnmap.elements();
                JsonNode jsonNode3  = elements.next();
                String cnt1 = jsonNode3.get("cnt").toString();
                cnt +=  Integer.parseInt(cnt1);
 
                String nbcnt1 = jsonNode3.get("nbcnt").toString();
                nb +=  Integer.parseInt(nbcnt1);
 
                String wbcnt1 = jsonNode3.get("wbcnt").toString();
                wb +=  Integer.parseInt(wbcnt1);
            }
        }
        shList.add(WarningTypeVO.builder().warningType("总数").warningNum(String.valueOf(cnt)).build());
        shList.add(WarningTypeVO.builder().warningType("内部预警").warningNum(String.valueOf(nb)).build());
        shList.add(WarningTypeVO.builder().warningType("外部预警").warningNum(String.valueOf(wb)).build());
        WarningTypeVO shanhong = WarningTypeVO.builder().warningType("山洪").childList(shList).warningNum(String.valueOf(cnt)).build();
        if (wb>0){
            shanhong.setColor("红色");
        }else if (nb>0){
            shanhong.setColor("黄色");
        }
        shanhong.setTypeNum(shanhong.getWarningNum());
        return shanhong;
    }
 
    @Override
    public WarningTypeVO warningStatisticsSZY() {
        StopWatch stopWatch = new StopWatch();
        //水资源
        //生态激流
        Date date = new Date();
        SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyy");
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String format1 = format.format(date);
        String format2 = dateFormat1.format(date);
        List<WarningTypeVO> szyList = new ArrayList<>();
        String dtBgTm = format2+"-01-01 00:00:00";
        String dtEdTm = format1+" 23:59:59";
        stopWatch.start("调用生态激流接口");
        JsonNode jsonNode3 = doRequest("GET", "http://113.57.190.43:31700/api-szy-0.0.1/api/szy/v0.1/stjl/statis/b/queryBaseFlowList?addvcd=42", new HashMap<>(), null);
        stopWatch.stop();
        stopWatch.start("封装生态激流数据");
        JsonNode result1 = jsonNode3.get("result");
        int red = 0 , blue = 0;
        for (JsonNode node : result1) {
            if (node.get("Q")!=null){
                String s = node.get("Q").toString();
                if (!s.equals("null")){
                    String base_flow = node.get("BASE_FLOW").toString();
                    String blue_alert = node.get("WATER_LEVEL_BLUE_ALERT").toString();
                    float q = Float.parseFloat(s);
                    float flow = Float.parseFloat(base_flow.equals("null")?"0":base_flow.substring(1,base_flow.length()-1));
                    float alert = Float.parseFloat(blue_alert.equals("null")?"0":blue_alert.substring(1,blue_alert.length()-1));
                    if (q>=0&&q<flow){
                        red++;
                    }else if (q<alert){
                        blue++;
                    }
                }
            }else {
                String z = node.get("Z").toString();
                if (!z.equals("null")){
                    String water_level = node.get("WATER_LEVEL").toString();
                    String blueAlert = node.get("WATER_LEVEL_BLUE_ALERT").toString();
                    float Z = Float.parseFloat(z.substring(1,z.length()-1));
                    float level = Float.parseFloat(water_level.equals("null")?"0": water_level.substring(1,water_level.length()-1));
                    float alert = Float.parseFloat(blueAlert.equals("null")?"0": blueAlert.substring(1,blueAlert.length()-1));
                    if (Z>=0){
                        if (Z>level){
                            red++;
                        }else if (Z>alert){
                            blue++;
                        }
                    }
                }
            }
        }
        List<WarningColorVO> stjl = new ArrayList<>();
        stjl.add(WarningColorVO.builder().colorName("红色").colorWarningNum(red).build());
        stjl.add(WarningColorVO.builder().colorName("蓝色").colorWarningNum(blue).build());
        szyList.add(WarningTypeVO.builder().warningNum(String.valueOf(red+blue)).colorVOList(stjl).warningType("河湖断面生态流量").build());
        int typeNum = 0;
        if (red>0||blue>0){
            typeNum += 1;
        }
        stopWatch.stop();
        //水量
        WaterQueryDTO queryDTO = WaterQueryDTO.builder().wiustTp("1").adlCd("42").tsBgTm(format2+"-01-01 00:00:00").tsEdTm(format1+" 00:00:00").build();
        int red1 = 0 , or = 0,blue1 = 0;
        try {
            String s = objectMapper.writeValueAsString(queryDTO);
            stopWatch.start("调用水量接口");
            JsonNode jsonNode4 = doRequest("POST", "http://113.57.190.43:31700/api-szy-0.0.1/api/szy/v0.1/wr/wiu/b/list", new HashMap<>(), s);
            stopWatch.stop();
            stopWatch.start("封装水量数据");
            JsonNode result2 = jsonNode4.get("result");
            for (JsonNode node : result2) {
                String ratio = node.get("RATIO").toString();
                double r = Double.parseDouble(ratio.equals("null") ? "0" : ratio);
                if (r>1){
                    red1++;
                }else if (r>0.9&& r<=1){
                    or++;
                }else if (r>0.8&& r<=0.9){
                    blue1++;
                }
            }
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
        List<WarningColorVO> sl = new ArrayList<>();
        sl.add(WarningColorVO.builder().colorName("红色").colorWarningNum(red1).build());
        sl.add(WarningColorVO.builder().colorName("橙色").colorWarningNum(or).build());
        sl.add(WarningColorVO.builder().colorName("蓝色").colorWarningNum(blue1).build());
        szyList.add(WarningTypeVO.builder().warningNum(String.valueOf(red1+or+blue1)).colorVOList(sl).warningType("水量").build());
        WarningTypeVO shuiziyuan = WarningTypeVO.builder().warningType("水资源").childList(szyList).warningNum(String.valueOf(red1+or+blue1+red+blue)).build();
        if (red1>0||blue1>0||or>0){
            typeNum += 1;
        }
        if (red1>0||red>0){
            shuiziyuan.setColor("红色");
        }else if (or>0){
            shuiziyuan.setColor("橙色");
        }else if (blue1>0||blue>0){
            shuiziyuan.setColor("蓝色");
        }
        shuiziyuan.setTypeNum(String.valueOf(typeNum));
        stopWatch.stop();
        log.info(stopWatch.prettyPrint());
        return shuiziyuan;
    }
 
    @Override
    public Object countAtmtnInfo() {
        Map<String,String> map = new HashMap<>();
        List<FsRAtmtnFrcstInfVO> atmtnInfo = fsRAtmtnFrcstInfMapper.getAtmtnInfo1(null, null);
//        atmtnInfo.addAll(fsRAtmtnFrcstInfMapper.getAtmtnInfo1(null,null));
        List<String> STCDs = atmtnInfo.stream().map(FsRAtmtnFrcstInf::getSTCD).collect(Collectors.toList());
        List<StStbprpBVO> stationInfos = fsRAtmtnFrcstInfMapper.getStationInfo(STCDs);
        Map<String, StStbprpBVO> stationMap = stationInfos.stream().collect(Collectors.toMap(StStbprpBVO::getSTCD, bvo -> bvo, (oldValue, newValue) -> oldValue));
        Integer num = 0;
        if (CollectionUtils.isNotEmpty(atmtnInfo)){
            for (FsRAtmtnFrcstInfVO vo : atmtnInfo) {
                StStbprpBVO stbprpBVO = stationMap.get(vo.getSTCD());
                if (vo.getTQ()> Float.parseFloat(stbprpBVO.getWRZ()) ){
                    num++;
                }
            }
        }
        map.put("warningNum",String.valueOf(num));
        if (num>0){
            map.put("color","红色");
        }else {
            map.put("color","");
        }
        return map;
    }
 
    /**
     *处理远程请求
     */
    private static JsonNode doRequest(String method,String url,Map<String,String> headerParam,String param) {
        HttpRequest.Builder builder = HttpRequest.newBuilder();
        if (method.equals("GET")){
            builder.GET();
        }else {
            builder.POST(HttpRequest.BodyPublishers.ofString(param));
        }
        builder.uri(URI.create(url))
            .header("Accept", "application/json").header("Content-Type","application/json");
        if (!headerParam.isEmpty()){
            builder.header(headerParam.get("name"),headerParam.get("value"));
        }
        try {
            Instant requestS = Instant.now();
            HttpResponse<InputStream> response = client.send(builder.build(), HttpResponse.BodyHandlers.ofInputStream());
            Instant requestE= Instant.now();
            long requestTime = Duration.between(requestS, requestE).toMillis();
            log.info("请求时长为: " + requestTime + " milliseconds");
            Instant writeDataS = Instant.now();
            JsonNode jsonNode = objectMapper.readTree(response.body());
            Instant writeDataE = Instant.now();
            long writeDataTime = Duration.between(writeDataS, writeDataE).toMillis();
            log.info("接受数据时长: " + writeDataTime + " milliseconds");
            return jsonNode;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}