tangzy
2021-11-09 39caebba35fc84824f5cd51d189fe322d5145803
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
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
/**
 * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springblade.modules.river.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.modules.river.entity.RiverR;
import org.springblade.modules.river.service.IRiverRService;
import org.springblade.modules.river.vo.RiverRVO;
import org.springblade.modules.river.wrapper.RiverRWrapper;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.Valid;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
 
 
/**
 * 控制器
 *
 * @author Blade
 * @since 2019-11-07
 */
@RestController
@AllArgsConstructor
@RequestMapping("/riverr")
@Api(value = "", tags = "接口")
public class RiverRController extends BladeController {
 
    private IRiverRService riverRService;
 
    /**
     * 详情
     */
    @ApiLog("详情")
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "传入riverR")
    public R<RiverRVO> detail(RiverR riverR) {
        RiverR detail = riverRService.getOne(Condition.getQueryWrapper(riverR));
        return R.data(RiverRWrapper.build().entityVO(detail));
    }
 
    /**
     * 分页
     */
    @ApiLog("分页")
    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "分页", notes = "传入riverR")
    public R<IPage<RiverRVO>> list(RiverR riverR, Query query) {
        IPage<RiverR> pages = riverRService.page(Condition.getPage(query), Condition.getQueryWrapper(riverR));
        return R.data(RiverRWrapper.build().pageVO(pages));
    }
 
    /**
     * 新增
     */
    @ApiLog("新增")
    @PostMapping("/save")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增", notes = "传入riverR")
    public R save(@Valid @RequestBody RiverR riverR) {
        return R.status(riverRService.save(riverR));
    }
 
    /**
     * 修改
     */
    @ApiLog("修改")
    @PostMapping("/update")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改", notes = "传入riverR")
    public R update(@Valid @RequestBody RiverR riverR) {
        return R.status(riverRService.updateById(riverR));
    }
 
    /**
     * 新增或修改
     */
    @ApiLog("新增或修改")
    @PostMapping("/submit")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "新增或修改", notes = "传入riverR")
    public R submit(@Valid @RequestBody RiverR riverR) {
        return R.status(riverRService.saveOrUpdate(riverR));
    }
 
//    /**
//     * 河道自定义时间查询
//     *
//     * @param beginTime
//     * @param endTime
//     * @return
//     * @throws ParseException
//     */
//    @PostMapping("/selecthd")
//    public R selecthd(String beginTime, String endTime) throws ParseException {
//        String substring = beginTime.substring(0, 10);
//        String substrings = endTime.substring(0, 10);
//        String hs = beginTime.substring(11, 13);
//        String hss = endTime.substring(11, 13);
//        //截取月日
//        String[] strs = substring.split("-");
//        //月
//        String year = strs[1].toString();
//        //日
//        String day = strs[2].toString();
//        //截取月日
//        String[] strss = substrings.split("-");
//        //月
//        String years = strss[1].toString();
//        //日
//        String days = strss[2].toString();
//        //定义短信内容头
//        String text = year + "月" + day + "日" + hs + "时" + "-" + years + "月" + days + "日" + hss + "时";
//        String texta = "";
//        //定义统计数量
//        int number = 0;
//        //河道超警信息
//        List<Map<String, Object>> selecthd = riverRService.selecthd(beginTime, endTime);
//        //Map<String, Object> sel = riverRService.sel();
//        //selecthd.add(sel);
//        //基本站信息
//        List<Map<String, Object>> list1 = riverRService.selectP();
//        //用来判断是否重复统计超警信息
//        Map mnum = new HashMap();
//        Map mnums = new HashMap();
//        //定义list保存预警信息
//        List ylist = new ArrayList();
//        //定义list保存未预警信息
//        List alist = new ArrayList();
//        //查询数据为空
//        if (selecthd.size() == 0) {
//            text += "暂无河道超警信息。廖家湾水位暂无数据,流量暂无数据;娄家村水位暂无数据,流量暂无数据;";
//        }
//        //不为空遍历数据计算是否超出预警值
//        else {
//            int c = 0;
//            for (int i = 0; i < selecthd.size(); i++) {
//                //实时河道水位值
//                BigDecimal z = (BigDecimal) selecthd.get(i).get("Z");
//                double Z = z.doubleValue();
//                //超警戒水位值
//                if (mnum.containsKey(selecthd.get(i).get("STCD").toString()) == true) {
//                } else {
//                    if (selecthd.get(i).get("WRZ") == null || selecthd.get(i).get("Q") == null) {
//                        String stnm = selecthd.get(i).get("STNM").toString();
//                        mnum.put(selecthd.get(i).get("STCD").toString(), i);
//                        if (stnm.equals("廖家湾") || stnm.equals("娄家村")) {
//                            DecimalFormat df = new DecimalFormat("#0.00");
//                            texta += stnm.replaceAll(" ", "") + "水位" + df.format(Z) + "米,";
//                            if (selecthd.get(i).get("Q") == null) {
//                                texta += "流量暂无数据";
//                            }
//                        }
//                        alist.add(selecthd.get(i));
//                        continue;
//                    }
//                    BigDecimal wrz = (BigDecimal) selecthd.get(i).get("WRZ");
//                    double WRZ = wrz.doubleValue();
//                    BigDecimal q = (BigDecimal) selecthd.get(i).get("Q");
//                    double Q = q.doubleValue();
//                    if (Z <= WRZ) {
//                        if (mnum.containsKey(selecthd.get(i).get("STCD").toString()) == true) {
//                        } else {
//                            String stnm = selecthd.get(i).get("STNM").toString();
//                            mnum.put(selecthd.get(i).get("STCD").toString(), i);
//                            if (stnm.equals("廖家湾") || stnm.equals("娄家村")) {
//                                DecimalFormat df = new DecimalFormat("#0.00");
//                                texta += stnm.replaceAll(" ", "") + "水位" + df.format(Z) + "米,";
//                                if (selecthd.get(i).get("Q") == null) {
//                                    texta += "流量暂无数据";
//                                } else {
//                                    DecimalFormat dfs = new DecimalFormat("#0.000");
//                                    texta += "流量" + Q + "立方米每秒;";
//                                }
//                            }
//                        }
//                        alist.add(selecthd.get(i));
//                    } else {
//                        //如果map集合保存了站点则不重复统计数量
//                        if (mnum.containsKey(selecthd.get(i).get("STCD").toString()) == true) {
//                        } else {
//                            ylist.add(selecthd.get(i));
//                            mnum.put(selecthd.get(i).get("STCD").toString(), i);
//                            number++;
//                            //超出警戒水位多少
//                            Double num = Z - WRZ;
//                            double v3 = (double) Math.round(num * 100) / 100;
//                            //县,市
//                            String addvcd5 = selecthd.get(i).get("ADDVNM").toString();
//                            //站点名称
//                            String stnm = selecthd.get(i).get("STNM").toString();
//                            if (stnm.equals("廖家湾") || stnm.equals("娄家村")) {
//                                DecimalFormat df = new DecimalFormat("#0.00");
//                                texta += stnm.replaceAll(" ", "") + "站超出警戒水位" + df.format(v3) + "米," + "水位" + df.format(Z) + "米,";
//                                if (selecthd.get(i).get("Q") == null) {
//                                    texta += "流量暂无数据;";
//                                } else {
//                                    //DecimalFormat dfs = new DecimalFormat("#0.000");
//                                    texta += "流量" + Q + "立方米每秒;";
//                                }
//                            }
//                        }
//                    }
//                }
//            }
//        }
////        //河道涨幅,跌幅信息
//        //List<Map<String, Object>> selecthds = riverRService.selecthds(beginTime, endTime);
//        Map m1 = new HashMap();
//        Map m2 = new HashMap();
//        Map c = new HashMap();
//        Map m = new HashMap();
//        List list = new ArrayList();
////        for (int j = 0; j < selecthds.size(); j++) {
////            //站点编码
////            String stcd = selecthds.get(j).get("STCD").toString();
////            //站点名称
////            String stnm = selecthds.get(j).get("STNM").toString();
////            //省,市
////            String addvcd5 = selecthds.get(j).get("ADDVNM").toString();
////            //最大值
////            BigDecimal maxZ = (BigDecimal) selecthds.get(j).get("maxZ");
////            //最大值出现时间
////            String maxTM = selecthds.get(j).get("maxTM").toString();
////            //最小值
////            BigDecimal minZ = (BigDecimal) selecthds.get(j).get("minZ");
////            //最小值出现时间
////            String minTM = selecthds.get(j).get("minTM").toString();
////            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
////            Date sd1 = df.parse(maxTM);
////            Date sd2 = df.parse(minTM);
////            double v = maxZ.doubleValue();
////            double v1 = minZ.doubleValue();
////            //涨幅值
////            double v2 = v - v1;
////            double v3 = (double) Math.round(v2 * 100) / 100;
////            m1.put(v3, stnm.replaceAll(" ", "") + "站");
////            c.put(stcd, v3);
////        }
//        if (number == 0) {
//            text += "暂无河道超警戒信息。" + texta;
//        } else {
//            text += "有" + number + "个河道站超警戒。" + texta;
//        }
////        if (m1.size() != 0) {
////            Object maxKey = getMaxKey(m1);
////            String s1 = m1.get(maxKey).toString();
////            text += " 涨幅最大的是:" + s1 + "(涨" + maxKey + "米)。";
////        }
//        m.put("text", text);
//        m.put("number", number);
//        m.put("Yjlist", ylist);
//        m.put("list", alist);
//        m.put("list1", list1);
//        m.put("clist", c);
//        list.add(m);
//        return R.data(list);
//
//    }
 
 
    /**
     * 河道最新
     *
     * @return
     * @throws ParseException
     */
    @PostMapping("/selecthdt")
    public R selecthdt() throws ParseException {
        int w = 1;
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = df.format(new Date());
        String yearc = time.substring(0, 4);
        int years = Integer.parseInt(yearc);
        String monthc = time.substring(5, 7);
        int months = Integer.parseInt(monthc);
        String dayc = time.substring(8, 10);
        int days = Integer.parseInt(dayc);
        int da = days - w;
        String hss = time.substring(11, 13);
        int hs = Integer.parseInt(hss);
        //前一天的8时
        //String timec = years + "-" + months + "-" + da + " 08:00:00";
        SimpleDateFormat sdfs=new SimpleDateFormat("yyyy-MM-dd 08:00:00");
        Calendar now = Calendar.getInstance();
        now.setTime(new Date());
        now.add(Calendar.DAY_OF_MONTH, -1);
        String timec = sdfs.format(now.getTime());
        //前24小时
        Calendar calendar6 = Calendar.getInstance();
        calendar6.set(Calendar.HOUR_OF_DAY, calendar6.get(Calendar.HOUR_OF_DAY) - 24);
        String dateBegin24 = df.format(calendar6.getTime());
        String substring = time.substring(0, 10);
        //截取月日
        String[] strs = substring.split("-");
        //月
        String year = strs[1].toString();
        //日
        String day = strs[2].toString();
        //定义短信内容头
        String text = year + "月" + day + "日" + hs + "时";
        String texta = "";
        //定义统计数量
        int number = 0;
        //定义List保存警戒信息
        List alist = new ArrayList();
        //定义List保存未警戒信息
        List blist = new ArrayList();
        //河道超警信息
        List<Map<String, Object>> selecthd = riverRService.selecthdt(dateBegin24, time, timec);
        //Map<String, Object> sel = riverRService.sel();
        //selecthd.add(sel);
        List<Map<String, Object>> list1 = riverRService.selectP();
        //用来判断是否重复统计超警信息
        Map mnum = new HashMap();
        //查询数据为空
        if (selecthd.size() == 0) {
            text += "暂无河道超警信息。廖家湾水位暂无数据,流量暂无数据;娄家村水位暂无数据,流量暂无数据;";
        }
        //不为空遍历数据计算是否超出预警值
        else {
            for (int i = 0; i < selecthd.size(); i++) {
                //实时河道水位值
                BigDecimal z = (BigDecimal) selecthd.get(i).get("Z");
                double Z = z.doubleValue();
                //超警戒水位值
                if (selecthd.get(i).get("WRZ") == null || selecthd.get(i).get("Q") == null) {
                    String stnm = selecthd.get(i).get("STNM").toString();
                    if (stnm.equals("廖家湾") || stnm.equals("娄家村")) {
                        String stcd = selecthd.get(i).get("STCD").toString();
                        //Map<String, Object> stringObjectMap = riverRService.selectZ(stcd, timec);
                        BigDecimal zc = (BigDecimal) selecthd.get(i).get("Zc");
                        double ZC = zc.doubleValue();
                        double vz = Z - ZC;
                        DecimalFormat dfc = new DecimalFormat("#0.00");
                        String format = dfc.format(vz);
                        double v = Double.parseDouble(format);
                        texta += stnm.replaceAll(" ", "") + "水位" + dfc.format(Z) + "米、";
                        if (v < 0) {
                            texta += "比昨日8时下跌" + Math.abs(v) + "米、";
                        } else {
                            texta += "比昨日8时上涨" + Math.abs(v) + "米、";
                        }
                        if (selecthd.get(i).get("Q") == null) {
                            texta += "流量暂无信息;";
                        }
                    }
                    blist.add(selecthd.get(i));
                    continue;
                }
                BigDecimal wrz = (BigDecimal) selecthd.get(i).get("WRZ");
                double WRZ = wrz.doubleValue();
                BigDecimal q = (BigDecimal) selecthd.get(i).get("Q");
                double Q = q.doubleValue();
                if (Z <= WRZ) {
                    String stnm = selecthd.get(i).get("STNM").toString();
                    if (stnm.equals("廖家湾") || stnm.equals("娄家村")) {
                        String stcd = selecthd.get(i).get("STCD").toString();
                        //Map<String, Object> stringObjectMap = riverRService.selectZ(stcd, timec);
                        BigDecimal zc = (BigDecimal) selecthd.get(i).get("Zc");
                        double ZC = zc.doubleValue();
                        double vz = Z - ZC;
                        DecimalFormat dfc = new DecimalFormat("#0.00");
                        String format = dfc.format(vz);
                        double v = Double.parseDouble(format);
                        texta += stnm.replaceAll(" ", "") + "水位" + dfc.format(Z) + "米、";
                        if (v < 0) {
                            texta += "比昨日8时下跌" + Math.abs(v) + "米、";
                        } else {
                            texta += "比昨日8时上涨" + Math.abs(v) + "米、";
                        }
                        if (selecthd.get(i).get("Q") == null) {
                            texta += "流量暂无数据;";
                        } else {
                            //DecimalFormat dfl = new DecimalFormat("#0.000");
                            double v5 = roundToSignificantFigures(Q, 3);
                            String a = String.valueOf(v5);
                            String s1 = subZeroAndDot(a);
                            texta += "流量" + s1 + "立方米每秒;";
                        }
                    }
                    blist.add(selecthd.get(i));
                } else {
                    //如果map集合保存了站点则不重复统计数量
                    if (mnum.containsKey(selecthd.get(i).get("STCD").toString()) == true) {
                    } else {
                        alist.add(selecthd.get(i));
                        mnum.put(selecthd.get(i).get("STCD").toString(), i);
                        number++;
                        //超出警戒水位多少
                        Double num = Z - WRZ;
                        double v3 = (double) Math.round(num * 100) / 100;
                        //县,市
                        String addvcd5 = selecthd.get(i).get("ADDVNM").toString();
                        //站点名称
                        String stnm = selecthd.get(i).get("STNM").toString();
                        if (stnm.equals("廖家湾") || stnm.equals("娄家村")) {
                            String stcd = selecthd.get(i).get("STCD").toString();
                            //Map<String, Object> stringObjectMap = riverRService.selectZ(stcd, timec);
                            BigDecimal zc = (BigDecimal) selecthd.get(i).get("Zc");
                            double ZC = zc.doubleValue();
                            double vz = Z - ZC;
                            DecimalFormat dfc = new DecimalFormat("#0.00");
                            String format = dfc.format(vz);
                            double v = Double.parseDouble(format);
                            texta += "。" + stnm.replaceAll(" ", "") + "站超出警戒水位" + dfc.format(v3) + "米、" + "水位" + dfc.format(Z) + "米、";
                            if (v < 0) {
                                texta += "比昨日8时下跌" + Math.abs(v) + "米、";
                            } else {
                                texta += "比昨日8时上涨" + Math.abs(v) + "米、";
                            }
                            if (selecthd.get(i).get("Q") == null) {
                                texta += "流量暂无数据、";
                            } else {
                                //DecimalFormat dfl = new DecimalFormat("#0.000");
                                //texta += "流量" + Q + "立方米每秒;";
                                double v5 = roundToSignificantFigures(Q, 3);
                                String a = String.valueOf(v5);
                                String s1 = subZeroAndDot(a);
                                texta += "流量" + s1 + "立方米每秒;";
                            }
                        }
                    }
                }
            }
            if (number == 0) {
                text += "暂无河道超警戒信息。" + texta;
            } else {
                text += "有" + number + "个河道站超警戒。" + texta;
            }
        }
        Map m = new HashMap();
        List list = new ArrayList();
        m.put("text", text);
        m.put("number", number);
        m.put("Yjlist", alist);
        m.put("list1", list1);
        m.put("list", blist);
        list.add(m);
        return R.data(list);
    }
 
    /**
     * 河道实时预警
     *
     * @return
     */
    @ApiLog("河道实时预警")
    @PostMapping("/selecthdyj")
    public R selecthdyj(String times, int k) {
        Date date = null;
        // 把Date按照格式转换成字符串
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            date = sdf.parse(times);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String dateEnd = sdf.format(date);
        List<Map<String, Object>> list;
        if (k == 13) {
            list = riverRService.selecthdyj(times, dateEnd);
        } else {
            list = riverRService.selecthdyj(times, dateEnd);
        }
        List<Map<String, Object>> lists = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> maps = new HashMap<String, Object>();
            BigDecimal b = (BigDecimal) list.get(i).get("Z");
            int i1 = b.intValue();
            if (i1 == 0) {
                list.get(i).put("yuc", "无预警");
            } else {
                BigDecimal bigDecimalz = (BigDecimal) list.get(i).get("Z");//实时水位
                BigDecimal bigDecimalw = (BigDecimal) list.get(i).get("WRZ");//警戒水位
                double wrz = bigDecimalw.doubleValue();//警戒水位
                double z = bigDecimalz.doubleValue();//实时水位
                Double fy = (Double) list.get(i).get("fy");
                Double oy = (Double) list.get(i).get("oy");
                Double toy = (Double) list.get(i).get("toy");
                Double ty = (Double) list.get(i).get("ty");
                if (z < wrz || wrz == 0) {
                    list.get(i).put("yuc", "无预警");
                } else if (z >= wrz && z < fy) {
                    list.get(i).put("yuc", "蓝色预警");
                } else if (z >= fy && z < oy) {
                    list.get(i).put("yuc", "黄色预警");
                } else if (z >= oy && z < ty) {
                    list.get(i).put("yuc", "橙色预警");
                } else {
                    list.get(i).put("yuc", "红色预警");
                }
            }
            maps.put("YjList", list.get(i));
            lists.add(maps);
        }
        return R.data(lists);
    }
 
 
    /**
     * 求Map<K,V>中Key(键)的最大值
     *
     * @param map
     * @return
     */
    public static Object getMaxKey(Map<Double, Integer> map) {
        if (map == null) return null;
        Set<Double> set = map.keySet();
        Object[] obj = set.toArray();
        Arrays.sort(obj);
        return obj[obj.length - 1];
    }
 
    /**
     * 求Map<K,V>中Value(值)的最大值
     *
     * @param map
     * @return
     */
    public static Object getMaxValue(Map<Integer, Integer> map) {
        if (map == null) return null;
        Collection<Integer> c = map.values();
        Object[] obj = c.toArray();
        Arrays.sort(obj);
        return obj[obj.length - 1];
    }
 
 
    public static double roundToSignificantFigures(double num, int n) {
 
        if (num == 0) {
 
            return 0;
 
        }
 
        final double d = Math.ceil(Math.log10(num < 0 ? -num : num));
 
        final int power = n - (int) d;
 
        final double magnitude = Math.pow(10, power);
 
        final long shifted = Math.round(num * magnitude);
 
        return shifted / magnitude;
 
    }
 
    public static String subZeroAndDot(String s) {
        if (s.indexOf(".") > 0) {
            s = s.replaceAll("0+?$", "");//去掉多余的0
            s = s.replaceAll("[.]$", "");//如最后一位是.则去掉
        }
        return s;
    }
 
    //    @PostMapping("/ss")
//    public void ss() {
//        String s = riverRService.selectCode();
//        String[] split = s.split(",");
//        String strArrays = "";
//        for (int i = 0; i < split.length; i++) {
//            strArrays += "'" + split[i] + "',";
//        }
//        String code = strArrays.substring(0, strArrays.length() - 1);
//        System.out.println(code);
//    }
 
//    /**
//     * 河道自定义时间查询
//     *
//     * @param beginTime
//     * @param endTime
//     * @return
//     * @throws ParseException
//     */
//    @PostMapping("/selecthd")
//    public R selecthd(String beginTime, String endTime) throws ParseException {
//        String substring = beginTime.substring(0, 10);
//        String substrings = endTime.substring(0, 10);
//        String t = beginTime.substring(11, 13);
//        String hs;
//        if (t.substring(0, 1).equals("0")) {
//            hs = beginTime.substring(12, 13);
//        } else {
//            hs = beginTime.substring(11, 13);
//        }
//        String ts = endTime.substring(11, 13);
//        String hss;
//        if (ts.substring(0, 1).equals("0")) {
//            hss = beginTime.substring(12, 13);
//        } else {
//            hss = beginTime.substring(11, 13);
//        }
//        //截取月日
//        String[] strs = substring.split("-");
//        //月
//        String year = strs[1].toString();
//        //日
//        String day = strs[2].toString();
//        //截取月日
//        String[] strss = substrings.split("-");
//        //月
//        String years = strss[1].toString();
//        //日
//        String days = strss[2].toString();
//        //定义短信内容头
//        String text = year + "月" + day + "日" + hs + "时" + "-" + years + "月" + days + "日" + hss + "时";
//        String texta = "";
//        //定义统计数量
//        int number = 0;
//        //河道超警信息
//        List<Map<String, Object>> selecthd = riverRService.selecthdcs(beginTime, endTime);
//        //Map<String, Object> sel = riverRService.sel();
//        //selecthd.add(sel);
//        //基本站信息
//        List<Map<String, Object>> list1 = riverRService.selectP();
//        //用来判断是否重复统计超警信息
//        Map mnum = new HashMap();
//        Map mnums = new HashMap();
//        //定义list保存预警信息
//        List ylist = new ArrayList();
//        //定义list保存未预警信息
//        List alist = new ArrayList();
//        Map m1 = new HashMap();
//        Map m2 = new HashMap();
//        Map czf = new HashMap();
//        Map m = new HashMap();
//        List list = new ArrayList();
//        //查询数据为空
//        if (selecthd.size() == 0) {
//            text += "暂无河道超警信息。廖家湾水位暂无数据,流量暂无数据;娄家村水位暂无数据,流量暂无数据;";
//        }
//        //不为空遍历数据计算是否超出预警值
//        else {
//            int c = 0;
//            for (int i = 0; i < selecthd.size(); i++) {
//                //实时河道水位值
//                BigDecimal z = (BigDecimal) selecthd.get(i).get("Z");
//                double Z = z.doubleValue();
//                String stcd = selecthd.get(i).get("STCD").toString();
//                //站点名称
//                String stnms = selecthd.get(i).get("STNM").toString();
//                //最大值
//                BigDecimal maxZ = (BigDecimal) selecthd.get(i).get("maxZ");
//                //最小值
//                BigDecimal minZ = (BigDecimal) selecthd.get(i).get("minZ");
//                double v = maxZ.doubleValue();
//                double v1 = minZ.doubleValue();
//                //涨幅值
//                double v2 = v - v1;
//                double v4 = (double) Math.round(v2 * 100) / 100;
//                m1.put(v4, stnms.replaceAll(" ", "") + "站");
//                czf.put(stcd, v4);
//                //超警戒水位值
//                if (mnum.containsKey(selecthd.get(i).get("STCD").toString()) == true) {
//                } else {
//                    if (selecthd.get(i).get("WRZ") == null || selecthd.get(i).get("Q") == null) {
//                        String stnm = selecthd.get(i).get("STNM").toString();
//                        mnum.put(selecthd.get(i).get("STCD").toString(), i);
//                        if (stnm.equals("廖家湾") || stnm.equals("娄家村")) {
//                            DecimalFormat df = new DecimalFormat("#0.00");
//                            texta += stnm.replaceAll(" ", "") + "水位" + df.format(Z) + "米,";
//                            if (selecthd.get(i).get("Q") == null) {
//                                texta += "流量暂无数据";
//                            }
//                        }
//                        alist.add(selecthd.get(i));
//                        continue;
//                    }
//                    BigDecimal wrz = (BigDecimal) selecthd.get(i).get("WRZ");
//                    double WRZ = wrz.doubleValue();
//                    BigDecimal q = (BigDecimal) selecthd.get(i).get("Q");
//                    double Q = q.doubleValue();
//                    if (Z <= WRZ) {
//                        if (mnum.containsKey(selecthd.get(i).get("STCD").toString()) == true) {
//                        } else {
//                            String stnm = selecthd.get(i).get("STNM").toString();
//                            mnum.put(selecthd.get(i).get("STCD").toString(), i);
//                            if (stnm.equals("廖家湾") || stnm.equals("娄家村")) {
//                                DecimalFormat df = new DecimalFormat("#0.00");
//                                texta += stnm.replaceAll(" ", "") + "水位" + df.format(Z) + "米,";
//                                if (selecthd.get(i).get("Q") == null) {
//                                    texta += "流量暂无数据";
//                                } else {
//                                    double v5 = roundToSignificantFigures(Q, 3);
//                                    String a = String.valueOf(v5);
//                                    String s1 = subZeroAndDot(a);
//                                    texta += "流量" + s1 + "立方米每秒;";
//                                }
//                            }
//                        }
//                        alist.add(selecthd.get(i));
//                    } else {
//                        //如果map集合保存了站点则不重复统计数量
//                        if (mnum.containsKey(selecthd.get(i).get("STCD").toString()) == true) {
//                        } else {
//                            ylist.add(selecthd.get(i));
//                            mnum.put(selecthd.get(i).get("STCD").toString(), i);
//                            number++;
//                            //超出警戒水位多少
//                            Double num = Z - WRZ;
//                            double v3 = (double) Math.round(num * 100) / 100;
//                            //县,市
//                            String addvcd5 = selecthd.get(i).get("ADDVNM").toString();
//                            //站点名称
//                            String stnm = selecthd.get(i).get("STNM").toString();
//                            if (stnm.equals("廖家湾") || stnm.equals("娄家村")) {
//                                DecimalFormat df = new DecimalFormat("#0.00");
//                                texta += stnm.replaceAll(" ", "") + "站超出警戒水位" + df.format(v3) + "米," + "水位" + df.format(Z) + "米,";
//                                if (selecthd.get(i).get("Q") == null) {
//                                    texta += "流量暂无数据;";
//                                } else {
//                                    //DecimalFormat dfs = new DecimalFormat("#0.000");
//                                    double v5 = roundToSignificantFigures(Q, 3);
//                                    String a = String.valueOf(v5);
//                                    String s1 = subZeroAndDot(a);
//                                    texta += "流量" + s1 + "立方米每秒;";
//                                }
//                            }
//                        }
//                    }
//                }
//
//            }
//        }
//        if (number == 0) {
//            text += "暂无河道超警戒信息。" + texta;
//        } else {
//            text += "有" + number + "个河道站超警戒。" + texta;
//        }
//        if (m1.size() != 0) {
//            Object maxKey = getMaxKey(m1);
//            String s1 = m1.get(maxKey).toString();
//            text += " 涨幅最大的是:" + s1 + "(涨" + maxKey + "米)。";
//        }
//        m.put("text", text);
//        m.put("number", number);
//        m.put("Yjlist", ylist);
//        m.put("list", alist);
//        m.put("list1", list1);
//        m.put("clist", czf);
//        list.add(m);
//        return R.data(list);
//
//    }
 
    /**
     * 河道自定义时间查询
     *
     * @param beginTime
     * @param endTime
     * @return
     * @throws ParseException
     */
    @PostMapping("/selecthd")
    public R selecthd(String beginTime, String endTime) throws ParseException {
        String substring = beginTime.substring(0, 10);
        String substrings = endTime.substring(0, 10);
        String t = beginTime.substring(11, 13);
        String hs;
        if (t.substring(0, 1).equals("0")) {
            hs = beginTime.substring(12, 13);
        } else {
            hs = beginTime.substring(11, 13);
        }
        String ts = endTime.substring(11, 13);
        String hss;
        if (ts.substring(0, 1).equals("0")) {
            hss = beginTime.substring(12, 13);
        } else {
            hss = beginTime.substring(11, 13);
        }
        //截取月日
        String[] strs = substring.split("-");
        //月
        String year = strs[1].toString();
        //日
        String day = strs[2].toString();
        //截取月日
        String[] strss = substrings.split("-");
        //月
        String years = strss[1].toString();
        //日
        String days = strss[2].toString();
        //定义短信内容头
        String text = year + "月" + day + "日" + hs + "时" + "-" + years + "月" + days + "日" + hss + "时";
        String texta = "";
        //定义统计数量
        int number = 0;
        String s = riverRService.selectCode();
        String[] split = s.split(",");
        String strArrays = "";
        for (int i = 0; i < split.length; i++) {
            strArrays += "'" + split[i] + "',";
        }
        String code = strArrays.substring(0, strArrays.length() - 1);
        //河道超警信息
        List<Map<String, Object>> selecthd = riverRService.selecthdcss(beginTime, endTime,code);
        Collections.sort(selecthd, new Comparator<Map<String, Object>>() {
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                Double name1 = Double.valueOf(o1.get("Z").toString()) ;//name1是从你list里面拿出来的一个
                Double name2 = Double.valueOf(o2.get("Z").toString()) ; //name1是从你list里面拿出来的第二个name
                return name2.compareTo(name1);
            }
        });
        //基本站信息
        List<Map<String, Object>> list1 = riverRService.selectP();
        //用来判断是否重复统计超警信息
        Map mnum = new HashMap();
        Map mnums = new HashMap();
        //定义list保存预警信息
        List ylist = new ArrayList();
        //定义list保存未预警信息
        List alist = new ArrayList();
        Map m1 = new HashMap();
        Map m2 = new HashMap();
        Map czf = new HashMap();
        Map m = new HashMap();
        List list = new ArrayList();
        //查询数据为空
        if (selecthd.size() == 0) {
            text += "暂无河道超警信息。廖家湾水位暂无数据,流量暂无数据;娄家村水位暂无数据,流量暂无数据;";
        }
        //不为空遍历数据计算是否超出预警值
        else {
            int c = 0;
            for (int i = 0; i < selecthd.size(); i++) {
                //实时河道水位值
                BigDecimal z = (BigDecimal) selecthd.get(i).get("Z");
                double Z = z.doubleValue();
                String stcd = selecthd.get(i).get("STCD").toString();
                //站点名称
                String stnms = selecthd.get(i).get("STNM").toString();
                //最大值
                BigDecimal maxZ = (BigDecimal) selecthd.get(i).get("maxZ");
                //最小值
                BigDecimal minZ = (BigDecimal) selecthd.get(i).get("minZ");
                double v = maxZ.doubleValue();
                double v1 = minZ.doubleValue();
                //涨幅值
                double v2 = v - v1;
                double v4 = (double) Math.round(v2 * 100) / 100;
                m1.put(v4, stnms.replaceAll(" ", "") + "站");
                czf.put(stcd, v4);
                //超警戒水位值
                if (mnum.containsKey(selecthd.get(i).get("STCD").toString()) == true) {
                } else {
                    if (selecthd.get(i).get("WRZ") == null || selecthd.get(i).get("Q") == null) {
                        String stnm = selecthd.get(i).get("STNM").toString();
                        mnum.put(selecthd.get(i).get("STCD").toString(), i);
                        if (stnm.equals("廖家湾") || stnm.equals("娄家村")) {
                            DecimalFormat df = new DecimalFormat("#0.00");
                            texta += stnm.replaceAll(" ", "") + "水位" + df.format(Z) + "米,";
                            if (selecthd.get(i).get("Q") == null) {
                                texta += "流量暂无数据";
                            }
                        }
                        alist.add(selecthd.get(i));
                        continue;
                    }
                    BigDecimal wrz = (BigDecimal) selecthd.get(i).get("WRZ");
                    double WRZ = wrz.doubleValue();
                    BigDecimal q = (BigDecimal) selecthd.get(i).get("Q");
                    double Q = q.doubleValue();
                    if (Z <= WRZ) {
                        if (mnum.containsKey(selecthd.get(i).get("STCD").toString()) == true) {
                        } else {
                            String stnm = selecthd.get(i).get("STNM").toString();
                            mnum.put(selecthd.get(i).get("STCD").toString(), i);
                            if (stnm.equals("廖家湾") || stnm.equals("娄家村")) {
                                DecimalFormat df = new DecimalFormat("#0.00");
                                texta += stnm.replaceAll(" ", "") + "水位" + df.format(Z) + "米,";
                                if (selecthd.get(i).get("Q") == null) {
                                    texta += "流量暂无数据";
                                } else {
                                    double v5 = roundToSignificantFigures(Q, 3);
                                    String a = String.valueOf(v5);
                                    String s1 = subZeroAndDot(a);
                                    texta += "流量" + s1 + "立方米每秒;";
                                }
                            }
                        }
                        alist.add(selecthd.get(i));
                    } else {
                        //如果map集合保存了站点则不重复统计数量
                        if (mnum.containsKey(selecthd.get(i).get("STCD").toString()) == true) {
                        } else {
                            ylist.add(selecthd.get(i));
                            mnum.put(selecthd.get(i).get("STCD").toString(), i);
                            number++;
                            //超出警戒水位多少
                            Double num = Z - WRZ;
                            double v3 = (double) Math.round(num * 100) / 100;
                            //县,市
                            String addvcd5 = selecthd.get(i).get("ADDVNM").toString();
                            //站点名称
                            String stnm = selecthd.get(i).get("STNM").toString();
                            if (stnm.equals("廖家湾") || stnm.equals("娄家村")) {
                                DecimalFormat df = new DecimalFormat("#0.00");
                                texta += stnm.replaceAll(" ", "") + "站超出警戒水位" + df.format(v3) + "米," + "水位" + df.format(Z) + "米,";
                                if (selecthd.get(i).get("Q") == null) {
                                    texta += "流量暂无数据;";
                                } else {
                                    //DecimalFormat dfs = new DecimalFormat("#0.000");
                                    double v5 = roundToSignificantFigures(Q, 3);
                                    String a = String.valueOf(v5);
                                    String s1 = subZeroAndDot(a);
                                    texta += "流量" + s1 + "立方米每秒;";
                                }
                            }
                        }
                    }
                }
 
            }
        }
        if (number == 0) {
            text += "暂无河道超警戒信息。" + texta;
        } else {
            text += "有" + number + "个河道站超警戒。" + texta;
        }
        if (m1.size() != 0) {
            Object maxKey = getMaxKey(m1);
            String s1 = m1.get(maxKey).toString();
            text += " 涨幅最大的是:" + s1 + "(涨" + maxKey + "米)。";
        }
        m.put("text", text);
        m.put("number", number);
        m.put("Yjlist", ylist);
        m.put("list", alist);
        m.put("list1", list1);
        m.put("clist", czf);
        list.add(m);
        return R.data(list);
 
    }
 
 
 
 
//    @PostMapping("/ss")
//    public R ss(String beginTime, String endTime) {
//        String s = riverRService.selectCode();
//        String[] split = s.split(",");
//        String strArrays = "";
//        for (int i = 0; i < split.length; i++) {
//            strArrays += "'" + split[i] + "',";
//        }
//        String code = strArrays.substring(0, strArrays.length() - 1);
//        List<Map<String, Object>> list = riverRService.selecthdcss(beginTime, endTime, code);
//        Collections.sort(list, new Comparator<Map<String, Object>>() {
//            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
//                Double name1 = Double.valueOf(o1.get("Z").toString()) ;//name1是从你list里面拿出来的一个
//                Double name2 = Double.valueOf(o2.get("Z").toString()) ; //name1是从你list里面拿出来的第二个name
//                return name2.compareTo(name1);
//            }
//        });
//        return  R.data(list);
//    }
}