zhangk
2024-06-22 3570bc18d5daed8079dd67891062ad8585a4e696
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
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
package cn.gistack.sm.sjztmd.word.service.impl;
 
import cn.gistack.common.utils.SpringContextUtil;
import cn.gistack.sm.sjztmd.entity.*;
import cn.gistack.sm.sjztmd.vo.AttResWithRainfall;
import cn.gistack.sm.sjztmd.vo.StationExport;
import cn.gistack.sm.sjztmd.vo.ZtResultInfo;
import cn.gistack.sm.sjztmd.vo.StationParams;
import cn.gistack.sm.sjztmd.mapper.SjztMdMapper;
import cn.gistack.sm.sjztmd.service.*;
import cn.gistack.sm.sjztmd.word.enums.*;
import cn.gistack.sm.sjztmd.word.service.ISjztmdService;
import cn.gistack.sm.sjztmd.word.vo.*;
import cn.gistack.sm.sjztods.constant.ZtApiUrlConstant;
import cn.gistack.sm.sjztods.constant.ZtConfigConstant;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
 
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
 
@Service
@AllArgsConstructor
@DS("zt")
@Slf4j
public class SjztmdServiceImpl implements ISjztmdService {
 
    //总计
    private final String RIBAO_SHEET1_TOTAL_URL = "/services/1234567890ABCDEFGHIJKLMN/ribao_sheet1/api?small_start_stag=0&mid_start_stag=0&big_start_stag=0";
    private final String RIBAO_SHEET1_OVER_NORM_POOL_STAG = "/services/1234567890ABCDEFGHIJKLMN/ribao/sheet1_over_norm_pool_stag/api?";
    //中大型水库
    private final String RIBAO_SHEET2_ZDX_URL = "/services/1234567890ABCDEFGHIJKLMN/ribao/sheet2_zdx/api?mid_start_stag=0&big_start_stag=0";
    //超汛明细
    private final String RIBAO_SHEET3_OVER_STAG_LIST_URL = "/services/1234567890ABCDEFGHIJKLMN/ribao/sheet3_over_stag_list/api?small_start_stag=0&mid_start_stag=0&big_start_stag=0";
    //省直管
    private final String SZ_INFO = "/services/1234567890ABCDEFGHIJKLMN/ribao/shengzh_new_rz/api";
 
    private final String WATER_LEVEL_API = "/services/1234567890ABCDEFGHIJKLMN/water/device/detail/new?";
    private final String RAIN_FALL_API = "/services/1234567890ABCDEFGHIJKLMN/rain/device/21/api?";
    private final String VIDEO_STATION_API = "/services/1234567890ABCDEFGHIJKLMN/device_monitor_wmst_list/api?";
    private final String IMAGE_STATION_API = "/services/1234567890ABCDEFGHIJKLMN/device_monitor_image_list/api?";
    private final String OSMOTIC_API = "/services/1234567890ABCDEFGHIJKLMN/press/device/is_child/api?";
    private final String SEEPAGE_API = "/services/1234567890ABCDEFGHIJKLMN/sl/device/is_child/api?";
    private final String DISPLACEMENT_API = "/services/1234567890ABCDEFGHIJKLMN/wy/device/is_child/api?";
    private final String TERMITE_API = "/services/1234567890ABCDEFGHIJKLMN/termite/device/is_child/api?";
 
 
    @Autowired
    private RestTemplate restTemplate;
    private final SjztMdMapper mapper;
    private final IAttResBaseService attResBase;
    private final ITbAttResBaseService attResBaseService;
    private final ITbAttResStagCharService attResStagCharService;
    private final ITbAttResWaterDeliveryService attResWaterDeliveryService;
    private final ITbAttResEngBeneService attResEngBeneService;
    private final ITbAttResSafetyMonitorService attResSafetyMonitorService;
    private final ITbAttResMgrSysBService attResMgrSysBService;
    private final IAttResManagePersonService attResManagePersonService;
    private final ITbAttResWaterBlockService attResWaterBlockService;
    private final ITbAttResRsbNorspiService attResRsbNorspiService;
    private final ITbAttResPowerStationService attResPowerStationService;
    private final IStResRainfallService stResRainfallService;
    private final ITbAttResProjectUtilizeService attResProjectUtilizeService;
    private final ITbAttResInformationProjectService attResInformationProjectService;
 
    @Override
    public HashMap<String, Object> getTbWordVO(String resCd) {
 
 
        TbAttResBase tbAttResBase = attResBaseService.getDetailByGuid(resCd);
        TbAttResStagChar tbAttResStagChar = attResStagCharService.getDetailByGuid(resCd);
        List<TbAttResWaterDelivery> tbAttResWaterDeliveryList = attResWaterDeliveryService.getDetailByGuid(resCd);
        //挡水建筑物
        List<TbAttResWaterBlock> tbAttResWaterBlockList = attResWaterBlockService.getDetailByGuid(resCd);
 
        //正常溢洪道、泄洪洞、非常溢洪道
        Map<String, Object> resRsbNorsipiVerspiMionitorDetailByGuid = attResRsbNorspiService.getResRsbNorsipiVerspiMionitorDetailByGuid(resCd);
 
        //电站
        List<TbAttResPowerStation> tbAttResPowerStationList = attResPowerStationService.getDetailByGuid(resCd);
 
        //工程运用
        TbAttResProjectUtilize tbAttResProjectUtilize = attResProjectUtilizeService.getDetailByGuid(resCd);
 
        //信息化建设
        TbAttResInformationProject tbAttResInformationProject = attResInformationProjectService.getDetailByGuid(resCd);
 
        TbAttResEngBene tbAttResEngBene = attResEngBeneService.getDetailByGuid(resCd);
        TbAttResSafetyMonitor tbAttResSafetyMonitor = attResSafetyMonitorService.getDetailByGuid(resCd);
        TbAttResMgrSysB tbAttResMgrSysB = attResMgrSysBService.getDetailByGuid(resCd);
        List<AttResManagePerson> attResManagePeople = attResManagePersonService.getPersonList(resCd);
 
        String depart = attResManagePersonService.getCompetentDepart(resCd);
 
        TbWordVO tbWordVO = new TbWordVO(tbAttResBase, tbAttResStagChar, tbAttResWaterBlockList, resRsbNorsipiVerspiMionitorDetailByGuid, tbAttResPowerStationList,
            tbAttResWaterDeliveryList, tbAttResEngBene, tbAttResSafetyMonitor, tbAttResMgrSysB, attResManagePeople);
        tbWordVO.setCUnitName(depart);
 
        Map<String, Object> tableMap = buildTableMap(tbAttResBase, tbAttResStagChar, tbAttResWaterBlockList, resRsbNorsipiVerspiMionitorDetailByGuid, tbAttResPowerStationList,
            tbAttResWaterDeliveryList, tbAttResEngBene, tbAttResSafetyMonitor, tbAttResMgrSysB, tbAttResProjectUtilize, tbAttResInformationProject);
 
 
        HashMap<String, Object> obj = new HashMap<>();
        obj.put("tbWordVO", tbWordVO);
        obj.put("tableMap", tableMap);
 
        return obj;
    }
 
    /**
     * 创建表格参数
     *
     * @param tbAttResBase                            水库基础信息
     * @param tbAttResStagChar                        水文特征
     * @param tbAttResWaterBlockList                  挡水建筑物
     * @param resRsbNorsipiVerspiMionitorDetailByGuid 正常溢洪道、泄洪洞、非常溢洪道
     * @param tbAttResPowerStationList                电站
     * @param tbAttResWaterDeliveryList               输水建筑物
     * @param tbAttResEngBene                         水库效益
     * @param tbAttResSafetyMonitor                   安全鉴定
     * @param tbAttResMgrSysB                         管理体制
     * @param tbAttResProjectUtilize                  工程运用
     * @param tbAttResInformationProject              信息化建设
     * @return
     */
    private Map<String, Object> buildTableMap(TbAttResBase tbAttResBase, TbAttResStagChar tbAttResStagChar,
                                              List<TbAttResWaterBlock> tbAttResWaterBlockList, Map<String, Object> resRsbNorsipiVerspiMionitorDetailByGuid,
                                              List<TbAttResPowerStation> tbAttResPowerStationList, List<TbAttResWaterDelivery> tbAttResWaterDeliveryList,
                                              TbAttResEngBene tbAttResEngBene, TbAttResSafetyMonitor tbAttResSafetyMonitor, TbAttResMgrSysB tbAttResMgrSysB,
                                              TbAttResProjectUtilize tbAttResProjectUtilize, TbAttResInformationProject tbAttResInformationProject) {
 
        Map<String, Object> tableMap = new HashMap<>();
 
        tableMap.put("resName", tbAttResBase.getName());
        tableMap.put("resRegCode", tbAttResBase.getResRegCode());
        tableMap.put("engScal", ResScalEnum.find(tbAttResBase.getResScal()).getLabel());
        tableMap.put("engGrad", tbAttResBase.getEngGrad());
        tableMap.put("longitude", tbAttResBase.getLgtd());
        tableMap.put("latitude", tbAttResBase.getLttd());
        tableMap.put("elevationSystem",tbAttResBase.getElevationSystem()==null?"": tbAttResBase.getElevationSystem().replace(",","").replace("其它",""));
        tableMap.put("region", tbAttResBase.getBuildAddress());
        tableMap.put("basName", BasCodeEnum.find(tbAttResBase.getBasCode()).getLabel());
        tableMap.put("locRvName", tbAttResBase.getLocRvName());
 
        String st = tbAttResBase.getStartTime() != null ? new SimpleDateFormat("YYYY年M月dd日").format(tbAttResBase.getStartTime()) : "";
        String wst = tbAttResBase.getWaterStorageTm() != null ? new SimpleDateFormat("YYYY年M月dd日").format(tbAttResBase.getWaterStorageTm()) : "";
        tableMap.put("startTime", st);
        tableMap.put("waterStorageTm", wst);
 
 
        tableMap.put("reinforceTm", tbAttResSafetyMonitor == null ? "":tbAttResSafetyMonitor.getReinforceTm() != null? new SimpleDateFormat("YYYY年M月dd日").format(tbAttResSafetyMonitor.getReinforceTm()) : "");
        tableMap.put("completionTime", tbAttResSafetyMonitor == null ? "":tbAttResSafetyMonitor.getCompletionTime() != null? new SimpleDateFormat("YYYY年M月dd日").format(tbAttResSafetyMonitor.getCompletionTime()) : "");
 
        String resFunc = tbAttResBase.getResFunc();
        if (StringUtil.isNotBlank(resFunc)) {
            List<String> resFucList = Arrays.asList(tbAttResBase.getResFunc().split(","));
            List<String> resFucTextList = new ArrayList<>();
            for (int i = 0; i < resFucList.size(); i++) {
                String key = resFucList.get(i);
                ResFucEnum resFucEnum = ResFucEnum.find(key);
                resFucTextList.add(resFucEnum.getLabel());
            }
            resFunc = String.join("、", resFucTextList);
        }
        tableMap.put("resFunc", resFunc);
        //水文特征
        tableMap.put("conArea", tbAttResStagChar==null?"":tbAttResStagChar.getConArea());
        tableMap.put("moyearRainAvg", tbAttResStagChar==null?"":tbAttResStagChar.getMoyearRainAvg());
        tableMap.put("moyearFlAvg", tbAttResStagChar==null?"":tbAttResStagChar.getMoyearFlAvg());
        tableMap.put("downWacoSafeDisc", tbAttResStagChar==null?"":tbAttResStagChar.getDownWacoSafeDisc());
        tableMap.put("desFlSta", tbAttResStagChar==null?"":tbAttResStagChar.getDesFlSta());
        tableMap.put("desFlFlow", tbAttResStagChar==null?"":tbAttResStagChar.getDesFlFlow());
        tableMap.put("desFl1dayCap", tbAttResStagChar==null?"":tbAttResStagChar.getDesFl1dayCap());
        tableMap.put("desFl3dayCap", tbAttResStagChar==null?"":tbAttResStagChar.getDesFl3dayCap());
        tableMap.put("checFlSta", tbAttResStagChar==null?"":tbAttResStagChar.getChecFlSta());
        tableMap.put("checFlFlow", tbAttResStagChar==null?"":tbAttResStagChar.getChecFlFlow());
        tableMap.put("checFl1dayCap", tbAttResStagChar==null?"":tbAttResStagChar.getChecFl1dayCap());
        tableMap.put("checFl3dayCap", tbAttResStagChar==null?"":tbAttResStagChar.getChecFl3dayCap());
 
        //水库特征
        tableMap.put("adjustProp", tbAttResStagChar==null?"":AdjustPropEnum.find(tbAttResStagChar.getAdjustProp()).getLabel());
        tableMap.put("checFlStag", tbAttResStagChar==null?"":tbAttResStagChar.getChecFlStag());
        tableMap.put("totalCap", tbAttResStagChar==null?"":tbAttResStagChar.getTotalCap());
        tableMap.put("desFlStag", tbAttResStagChar==null?"":tbAttResStagChar.getDesFlStag());
        tableMap.put("flprCap", tbAttResStagChar==null?"":tbAttResStagChar.getFlprCap());
        tableMap.put("flConTopStag", tbAttResStagChar==null?"":tbAttResStagChar.getFlConTopStag());
        tableMap.put("flSortCap", tbAttResStagChar==null?"":tbAttResStagChar.getFlStorCap());
        tableMap.put("corNormStag", tbAttResStagChar==null?"":tbAttResStagChar.getCorNormStag());
        tableMap.put("adjustStorCap", tbAttResStagChar==null?"":tbAttResStagChar.getAdjustStorCap());
        tableMap.put("deadStag", tbAttResStagChar==null?"":tbAttResStagChar.getDeadStag());
        tableMap.put("deadCap", tbAttResStagChar==null?"":tbAttResStagChar.getDeadCap());
        tableMap.put("beforeFloodStag", tbAttResStagChar==null?"":tbAttResStagChar.getBeforeFloodStag());
        tableMap.put("midFloodStag", tbAttResStagChar==null?"":tbAttResStagChar.getMidFloodStag());
        tableMap.put("afterFloodStag", tbAttResStagChar==null?"":tbAttResStagChar.getAfterFloodStag());
 
        //new SimpleDateFormat("yyyy年MM月").format(tbAttResBase.getStartTime());
 
        String bfs = tbAttResStagChar==null?"":tbAttResStagChar.getBeforeFloodStart() != null ? new SimpleDateFormat("M月dd日").format(tbAttResStagChar.getBeforeFloodStart()) : "";
        String bfe = tbAttResStagChar==null?"":tbAttResStagChar.getBeforeFloodEnd() != null ? new SimpleDateFormat("M月dd日").format(tbAttResStagChar.getBeforeFloodEnd()) : "";
        String mfs = tbAttResStagChar==null?"":tbAttResStagChar.getMidFloodStart() != null ? new SimpleDateFormat("M月dd日").format(tbAttResStagChar.getMidFloodStart()) : "";
        String mfe = tbAttResStagChar==null?"":tbAttResStagChar.getMidFloodEnd() != null ? new SimpleDateFormat("M月dd日").format(tbAttResStagChar.getMidFloodEnd()) : "";
        String afs = tbAttResStagChar==null?"":tbAttResStagChar.getAfterFloodStart() != null ? new SimpleDateFormat("M月dd日").format(tbAttResStagChar.getAfterFloodStart()) : "";
        String afe = tbAttResStagChar==null?"":tbAttResStagChar.getAfterFloodEnd() != null ? new SimpleDateFormat("M月dd日").format(tbAttResStagChar.getAfterFloodEnd()) : "";
        tableMap.put("beforeFloodStart", bfs);
        tableMap.put("beforeFloodEnd", bfe);
        tableMap.put("midFloodStart", mfs);
        tableMap.put("midFloodEnd", mfe);
        tableMap.put("afterFloodStart", afs);
        tableMap.put("afterFloodEnd", afe);
        tableMap.put("desFloodFlow", tbAttResStagChar==null?"":tbAttResStagChar.getDesFloodFlowMax());
        tableMap.put("checFloodFlowMax", tbAttResStagChar==null?"":tbAttResStagChar.getChecFloodFlowMax());
 
        String mainDamType = "";
        String mainDamMainFoundation = "";
        String mainDamTopElevation = "";
        String mainDamHeight = "";
        String mainDamTopLength = "";
        String mainDamWidth = "";
        String mainIsTraffic = "";
        String mainWaveWallTopElevation = "";
        String mainUpDamProtectType = "";
        String mainDownDamProtectType = "";
        String damMainBodyType = "";
        String damMainBodyTopElevation = "";
        String damMainDrainType = "";
        String mainDamBodyType = "";
        String subDamNum = "";
        String subDamTotLength = "";
        String subDamMaxHeight = "";
        String subDamTopWidth = "";
 
 
        if (tbAttResWaterBlockList != null && tbAttResWaterBlockList.size() > 0 && tbAttResWaterBlockList.get(0).getNum() > 0) {
            //主坝
            TbAttResWaterBlock tbAttResWaterBlock = tbAttResWaterBlockList.get(0);
 
            mainDamType = DamTypeEnum.find(tbAttResWaterBlock.getDamType()).getLabel();
            mainDamMainFoundation = tbAttResWaterBlock.getDamMainFoundation();
            mainDamTopElevation = isNullObject(tbAttResWaterBlock.getDamTopElevation());
            mainDamHeight = isNullObject(tbAttResWaterBlock.getDamHeight());
            mainDamTopLength = isNullObject(tbAttResWaterBlock.getDamTopLength());
            mainDamWidth = isNullObject(tbAttResWaterBlock.getDamWidth());
            mainIsTraffic = tbAttResWaterBlock.getIsTraffic();
            mainWaveWallTopElevation = isNullObject(tbAttResWaterBlock.getWaveWallTopElevation());
            mainUpDamProtectType = convertType(tbAttResWaterBlock.getUpDamProtectType(), "Explain");
            mainDownDamProtectType = convertType(tbAttResWaterBlock.getDownDamProtectType(), "Explain");
            damMainBodyType = convertType(tbAttResWaterBlock.getDamMainBodyType(), "Explain");
            damMainBodyTopElevation = isNullObject(tbAttResWaterBlock.getDamTopElevation());
            damMainDrainType = convertType(tbAttResWaterBlock.getDamMainDrainType(), "Explain");
            mainDamBodyType = convertType(isNullObject(tbAttResWaterBlock.getDamBodyType()), "Explain");
 
            //副坝
            subDamNum = isNullObject(tbAttResWaterBlock.getSubDamNum());
            subDamTotLength = isNullObject(tbAttResWaterBlock.getSubDamTotLength());
            subDamMaxHeight = isNullObject(tbAttResWaterBlock.getSubDamMaxHeight());
            subDamTopWidth = isNullObject(tbAttResWaterBlock.getSubDamTopWidth());
 
 
        }
 
        tableMap.put("mainDamType", mainDamType);
        tableMap.put("mainDamMainFoundation", mainDamMainFoundation);
        tableMap.put("mainDamTopElevation", mainDamTopElevation);
        tableMap.put("mainDamHeight", mainDamHeight);
        tableMap.put("mainDamTopLength", mainDamTopLength);
        tableMap.put("mainDamWidth", mainDamWidth);
        tableMap.put("mainIsTraffic", mainIsTraffic);
        tableMap.put("mainWaveWallTopElevation", mainWaveWallTopElevation);
        tableMap.put("mainUpDamProtectType", mainUpDamProtectType);
        tableMap.put("mainDownDamProtectType", mainDownDamProtectType);
        tableMap.put("damMainBodyType", damMainBodyType);
        tableMap.put("damMainBodyTopElevation", damMainBodyTopElevation);
        tableMap.put("damMainDrainType", damMainDrainType);
        tableMap.put("mainDamBodyType", mainDamBodyType);
        tableMap.put("subDamNum", subDamNum);
        tableMap.put("subDamTotLength", subDamTotLength);
        tableMap.put("subDamMaxHeight", subDamMaxHeight);
        tableMap.put("subDamTopWidth", subDamTopWidth);
 
        //正常溢洪道
        List<TbAttResRsbNorspi> tbAttResRsbNorspiList = (List<TbAttResRsbNorspi>) resRsbNorsipiVerspiMionitorDetailByGuid.get("tbAttResRsbNorspiList");
 
        String norSpillwayType = "";
        String isLocDamBody = "";
        String norWeirTopElevation = "";
        String norWeirTopWidth = "";
        String norWorkingGateType = "";
        String norCheckingFloodDischarge = "";
        String disEnergyType = "";
        String norOc = "";
 
        if (tbAttResRsbNorspiList != null && tbAttResRsbNorspiList.size() > 0 && tbAttResRsbNorspiList.get(0).getNum() != null && tbAttResRsbNorspiList.get(0).getNum() > 0) {
            TbAttResRsbNorspi tbAttResRsbNorspi = tbAttResRsbNorspiList.get(0);
 
            norSpillwayType = SpillwayTypeEnum.find(tbAttResRsbNorspi.getSpillwayType()).getLabel();
 
            isLocDamBody = tbAttResRsbNorspi.getIsLocDamBody();
            norWeirTopElevation = isNullObject(tbAttResRsbNorspi.getWeirTopElevation());
            norWeirTopWidth = isNullObject(tbAttResRsbNorspi.getWeirTopWidth());
 
            if (tbAttResRsbNorspi.getIsGate() == "否") {
                norWorkingGateType = "无闸控制";
            } else if (tbAttResRsbNorspi.getIsGate() == "是") {
                // 平板闸门,3X3
                String typeName = RsbWorkingGateEnum.find(tbAttResRsbNorspi.getWorkingGateType().toString()).getLabel();
                norWorkingGateType = StringUtil.format("{},{}X{}", typeName, tbAttResRsbNorspi.getGateWide(), tbAttResRsbNorspi.getGateLength());
            }
 
            norCheckingFloodDischarge = isNullObject(tbAttResRsbNorspi.getCheckingFloodDischarge());
            disEnergyType = isNullObject(tbAttResRsbNorspi.getDisEnergyType()).equals("1")?"挑流消能":
                isNullObject(tbAttResRsbNorspi.getDisEnergyType()).equals("2")?"底流消能":
                    isNullObject(tbAttResRsbNorspi.getDisEnergyType()).equals("3")?"面流消能":
                    isNullObject(tbAttResRsbNorspi.getDisEnergyType()).equals("4")?"戽流消能":
                    isNullObject(tbAttResRsbNorspi.getDisEnergyType()).equals("5")?"跌流消能":
                    isNullObject(tbAttResRsbNorspi.getDisEnergyType()).equals("6")?"孔板消能":
                    isNullObject(tbAttResRsbNorspi.getDisEnergyType()).equals("9")?"其他":"";
            List<String> list = new ArrayList<>();
 
 
            String ocType = OcTypeEnum.find(isNullObject(tbAttResRsbNorspi.getOcType())).getLabel();
            list.add(ocType);
            list.add(tbAttResRsbNorspi.getOcPower());
            norOc = String.join(",", list);
        }
 
        tableMap.put("norSpillwayType", norSpillwayType);
        tableMap.put("isLocDamBody", isLocDamBody);
        tableMap.put("norWeirTopElevation", norWeirTopElevation);
        tableMap.put("norWeirTopWidth", norWeirTopWidth);
        tableMap.put("norWorkingGateType", norWorkingGateType);
        tableMap.put("norCheckingFloodDischarge", norCheckingFloodDischarge);
        tableMap.put("disEnergyType", disEnergyType);
        tableMap.put("norOc", norOc);
 
 
        //非常溢洪道
        List<TbAttResRsbVerspi> tbAttResRsbVerspiList = (List<TbAttResRsbVerspi>) resRsbNorsipiVerspiMionitorDetailByGuid.get("tbAttResRsbVerspiList");
 
        String verSpillwayType = "";
        String weirTopWidth = "";
        String enableStandar = "";
        String checkingFloodDischarge = "";
 
        if (tbAttResRsbVerspiList != null && tbAttResRsbVerspiList.size() > 0 && tbAttResRsbVerspiList.get(0).getNum() !=null && tbAttResRsbVerspiList.get(0).getNum() > 0) {
            TbAttResRsbVerspi tbAttResRsbVerspi = tbAttResRsbVerspiList.get(0);
 
            verSpillwayType = VerSpillwayTypeEnum.find(tbAttResRsbVerspi.getSpillwayType()).getLabel();
            weirTopWidth = isNullObject(tbAttResRsbVerspi.getWeirTopWidth());
            enableStandar = tbAttResRsbVerspi.getEnableStandards();
            checkingFloodDischarge = isNullObject(tbAttResRsbVerspi.getCheckingFloodDischarge());
        }
        tableMap.put("verSpillwayType", verSpillwayType);
        tableMap.put("weirTopWidth", weirTopWidth);
        tableMap.put("enableStandar", enableStandar);
        tableMap.put("checkingFloodDischarge", checkingFloodDischarge);
 
        //泄洪洞
        List<TbAttResRsbSpillway> tbAttResRsbSpillwayList = (List<TbAttResRsbSpillway>) resRsbNorsipiVerspiMionitorDetailByGuid.get("tbAttResRsbSpillwayList");
 
        String rsbSpillwayType = "";
        String coveLength = "";
        String rsbThresholdElevation = "";
        String rsbExportElevation = "";
        String rsbSection = "";
        String checkFlDisCharge = "";
        String rsbWorkingGateType = "";
        String rsbOc = "";
 
        if (tbAttResRsbSpillwayList != null && tbAttResRsbSpillwayList.size() > 0 && tbAttResRsbSpillwayList.get(0).getNum() > 0) {
            TbAttResRsbSpillway tbAttResRsbSpillway = tbAttResRsbSpillwayList.get(0);
 
            //类型为其他,有补充说明
            rsbSpillwayType = convertType(tbAttResRsbSpillway.getSpillwayType(), "SpillwayHoleType");
            rsbWorkingGateType = convertType(tbAttResRsbSpillway.getWorkingGateType(), "RsbWorkingGateEnum");
 
            coveLength = isNullObject(tbAttResRsbSpillway.getCoveLength());
            rsbThresholdElevation = isNullObject(tbAttResRsbSpillway.getThresholdElevation());
            rsbExportElevation = isNullObject(tbAttResRsbSpillway.getExportElevation());
            rsbSection = StringUtil.format("{}×{}", tbAttResRsbSpillway.getSectionWide(), tbAttResRsbSpillway.getSectionLength());
            ;
            checkFlDisCharge = isNullObject(tbAttResRsbSpillway.getCheckFlDisCharge());
 
 
            List<String> list = new ArrayList<>();
            list.add(convertType(tbAttResRsbSpillway.getOcType(), "OcTypeEnum"));
            list.add(tbAttResRsbSpillway.getOcPower());
            rsbOc = String.join(",", list);
        }
 
 
        tableMap.put("rsbSpillwayType", rsbSpillwayType);
        tableMap.put("coveLength", coveLength);
        tableMap.put("rsbThresholdElevation", rsbThresholdElevation);
        tableMap.put("rsbExportElevation", rsbExportElevation);
        tableMap.put("rsbSection", rsbSection);
        tableMap.put("checkFlDisCharge", checkFlDisCharge);
        tableMap.put("rsbWorkingGateType", rsbWorkingGateType);
        tableMap.put("rsbOc", rsbOc);
 
        //输水
        String aqueductType = "";
        String aqueductLength = "";
        String thresholdElevation = "";
        String exportElevation = "";
        String deliverSection = "";
        String designFlow = "";
        String workingGateType = "";
        String deliverOc = "";
 
        if (tbAttResWaterDeliveryList != null && tbAttResWaterDeliveryList.size() > 0 && tbAttResWaterDeliveryList.get(0).getNum() > 0) {
            //取设计流量大的进行描述
//            List<TbAttResWaterDelivery> sortList = tbAttResWaterDeliveryList.stream().sorted((a, b) -> b.getDesignFlow().compareTo(a.getDesignFlow())).collect(Collectors.toList());
            List<TbAttResWaterDelivery> sortList =
                tbAttResWaterDeliveryList.stream()
                    .sorted((a, b) -> {
                        Optional<Double> flowA = Optional.ofNullable(a.getDesignFlow());
                        Optional<Double> flowB = Optional.ofNullable(b.getDesignFlow());
                        return flowA.isPresent() && flowB.isPresent() ? flowA.get().compareTo(flowB.get()) : (flowA.isPresent() ? 1 : (flowB.isPresent() ? -1 : 0));
                    })
                    .collect(Collectors.toList());
 
            TbAttResWaterDelivery tbAttResWaterDelivery = sortList.get(0);
 
            aqueductType = convertType(tbAttResWaterDelivery.getAqueductType(), "AqueductTypeEnum");
            aqueductLength = isNullObject(tbAttResWaterDelivery.getAqueductLength());
            thresholdElevation = isNullObject(tbAttResWaterDelivery.getThresholdElevation());
            exportElevation = isNullObject(tbAttResWaterDelivery.getExportElevation());
            deliverSection = StringUtil.format("{}×{}", tbAttResWaterDelivery.getSectionWide(), tbAttResWaterDelivery.getSectionHigh());
            designFlow = isNullObject(tbAttResWaterDelivery.getDesignFlow());
            workingGateType = tbAttResWaterDelivery.getWorkingGateType();
            List<String> list = new ArrayList<>();
            list.add(tbAttResWaterDelivery.getOcType());
            list.add(tbAttResWaterDelivery.getOcPower());
            deliverOc = String.join(",", list);
        }
        tableMap.put("aqueductType", aqueductType);
        tableMap.put("aqueductLength", aqueductLength);
        tableMap.put("thresholdElevation", thresholdElevation);
        tableMap.put("exportElevation", exportElevation);
        tableMap.put("deliverSection", deliverSection);
        tableMap.put("designFlow", designFlow);
        tableMap.put("workingGateType", workingGateType);
        tableMap.put("deliverOc", deliverOc);
 
 
        //水电站
        String plantLayoutType = "";
        String installedCapacity = "";
        String yearAvgHour = "";
        //当电站列表不为空 且 电站列表数量大于0 且num大于0
        if (tbAttResPowerStationList != null && tbAttResPowerStationList.size() > 0 && tbAttResPowerStationList.get(0).getNum()!=null && tbAttResPowerStationList.get(0).getNum() > 0) {
            TbAttResPowerStation tbAttResPowerStation = tbAttResPowerStationList.get(0);
 
            //取第一个电站
            plantLayoutType = PlantLayoutTypeEnum.find(tbAttResPowerStation.getPlantLayoutType()).getLabel();
            installedCapacity = isNullObject(tbAttResPowerStation.getInstalledCapacity());
            yearAvgHour = isNullObject(tbAttResPowerStation.getYearAvgHour());
        }
        tableMap.put("plantLayoutType", plantLayoutType);
        tableMap.put("installedCapacity", installedCapacity);
        tableMap.put("yearAvgHour", yearAvgHour);
 
        //水库效益
        List<String> protectList = new ArrayList<>();
 
        if (null != tbAttResEngBene) {
 
        }
 
        if (tbAttResEngBene!=null &&!tbAttResEngBene.getCity().equals("无") ) {
            protectList.add(tbAttResEngBene.getCity());
 
        }
        if (tbAttResEngBene!=null &&!tbAttResEngBene.getTown().equals("无")) {
            protectList.add(tbAttResEngBene.getTown());
        }
        if (tbAttResEngBene!=null &&!tbAttResEngBene.getRailway().equals("无")) {
            protectList.add(tbAttResEngBene.getRailway());
        }
 
        if (tbAttResEngBene!=null &&!tbAttResEngBene.getHighway().equals("无")) {
            protectList.add(tbAttResEngBene.getHighway());
        }
 
        if (tbAttResEngBene!=null &&!tbAttResEngBene.getImportCommunication().equals("无")) {
            protectList.add(tbAttResEngBene.getImportCommunication());
        }
 
        if (tbAttResEngBene!=null &&!tbAttResEngBene.getImportFactory().equals("无")) {
            protectList.add(tbAttResEngBene.getImportFactory());
        }
 
        if (tbAttResEngBene!=null &&!tbAttResEngBene.getImportOtherFac().equals("无")) {
            protectList.add(tbAttResEngBene.getImportOtherFac());
        }
        //只留前四个
        if (protectList.size()>=4){
            List<String> subList = protectList.subList(0, 4);
            tableMap.put("protect", String.join("、", subList));
 
        }else {
            tableMap.put("protect", String.join("、", protectList));
        }
        double person = 0;
        if (tbAttResEngBene !=null && tbAttResEngBene.getFlControlPerson() != null) {
            person = tbAttResEngBene.getFlControlPerson() / 10000.0;
            tableMap.put("flControlPerson", String.format("%.2f", person));
        } else {
            tableMap.put("flControlPerson", "");
        }
        tableMap.put("flControlLand", tbAttResEngBene==null?"":tbAttResEngBene.getFlControlLand()==null?"":String.format("%.2f", tbAttResEngBene.getFlControlLand() / 10000));
        tableMap.put("irrObject", tbAttResEngBene==null?"":tbAttResEngBene.getIrrObject()==null?"":tbAttResEngBene.getIrrObject());
        tableMap.put("moyearIrrAvg", tbAttResEngBene==null?"":tbAttResEngBene.getMoyearIrrAvg() == null?"":tbAttResEngBene.getMoyearIrrAvg());
        tableMap.put("desIrrArea", tbAttResEngBene==null?"":tbAttResEngBene.getDesIrrArea() == null ?"":String.format("%.2f", tbAttResEngBene.getDesIrrArea() / 10000));
        tableMap.put("checIrrArea", tbAttResEngBene==null?"":tbAttResEngBene.getChecIrrArea()==null?"":String.format("%.2f", tbAttResEngBene.getChecIrrArea() / 10000));
        tableMap.put("supplyObject", tbAttResEngBene==null?"":tbAttResEngBene.getSupplyObject()==null?"":tbAttResEngBene.getSupplyObject());
 
        Double sup = 0.0;
        String supS = "";
        if (tbAttResEngBene!=null && StringUtil.isNotBlank(tbAttResEngBene.getSupplyPopulation())) {
            sup = Double.parseDouble(tbAttResEngBene.getSupplyPopulation()) / 10000;
            supS = String.format("%.2f", sup);
        }
 
 
        tableMap.put("supplyPopulation", supS);
        tableMap.put("moyearSupplyAvg", tbAttResEngBene==null?"":tbAttResEngBene.getMoyearSupplyAvg()==null?"":tbAttResEngBene.getMoyearSupplyAvg());
        tableMap.put("moyearPowerAvg", tbAttResEngBene==null?"":tbAttResEngBene.getMoyearPowerAvg()==null?"":tbAttResEngBene.getMoyearPowerAvg());
        tableMap.put("ecologicalFlow", tbAttResEngBene==null?"":tbAttResEngBene.getEcologicalFlow()==null?"":tbAttResEngBene.getEcologicalFlow());
 
        //工程管理
        tableMap.put("munitName", tbAttResMgrSysB==null?"":tbAttResMgrSysB.getMUnitName()==null?"":tbAttResMgrSysB.getMUnitName());
        tableMap.put("cunitName", tbAttResMgrSysB==null?"":tbAttResMgrSysB.getCUnitName()==null?"":tbAttResMgrSysB.getCUnitName());
        tableMap.put("mUnitNature", tbAttResMgrSysB==null?"":tbAttResMgrSysB.getMUnitNature()==null?"":tbAttResMgrSysB.getMUnitNature());
        tableMap.put("mUnitPersonNumber", tbAttResMgrSysB==null?"":tbAttResMgrSysB.getMUnitPersonNumber()==null?"":tbAttResMgrSysB.getMUnitPersonNumber());
        tableMap.put("personEconomicSource", tbAttResMgrSysB==null?"":tbAttResMgrSysB.getPersonEconomicSource()==null?"":tbAttResMgrSysB.getPersonEconomicSource());
        tableMap.put("maintenanceEconomicSource", tbAttResMgrSysB==null?"":tbAttResMgrSysB.getMaintenanceEconomicSource()==null?"":tbAttResMgrSysB.getMaintenanceEconomicSource());
 
        //工程运用
        tableMap.put("resMaxStag", tbAttResProjectUtilize == null? "" :tbAttResProjectUtilize.getResMaxStag());
        tableMap.put("resMinStag", tbAttResProjectUtilize == null? "" :tbAttResProjectUtilize.getResMinStag());
        tableMap.put("resMaxInFlow", tbAttResProjectUtilize == null? "" :tbAttResProjectUtilize.getResMaxInFlow());
        tableMap.put("resMaxOutFlow", tbAttResProjectUtilize == null? "" :tbAttResProjectUtilize.getResMaxOutFlow());
        //new SimpleDateFormat("yyyy-MM-dd").format(tbAttResProjectUtilize.getResMaxStagDate())
 
        String resMaxStagDate = tbAttResProjectUtilize == null? "" :tbAttResProjectUtilize.getResMaxStagDate() != null ? new SimpleDateFormat("yyyy年MM月dd日").format(tbAttResProjectUtilize.getResMaxStagDate()) : "";
        String resMinStagDate = tbAttResProjectUtilize == null? "" :tbAttResProjectUtilize.getResMinStagDate() != null ? new SimpleDateFormat("yyyy年MM月dd日").format(tbAttResProjectUtilize.getResMinStagDate()) : "";
        String resMaxInFlowDate = tbAttResProjectUtilize == null? "" :tbAttResProjectUtilize.getResMaxInFlowDate() != null ? new SimpleDateFormat("yyyy年MM月dd日").format(tbAttResProjectUtilize.getResMaxInFlowDate()) : "";
        String resMaxOutFlowDate = tbAttResProjectUtilize == null? "" :tbAttResProjectUtilize.getResMaxOutFlowDate() != null ? new SimpleDateFormat("yyyy年MM月dd日").format(tbAttResProjectUtilize.getResMaxOutFlowDate()) : "";
        tableMap.put("resMaxStagDate", resMaxStagDate);
        tableMap.put("resMinStagDate", resMinStagDate);
        tableMap.put("resMaxInFlowDate", resMaxInFlowDate);
        tableMap.put("resMaxOutFlowDate", resMaxOutFlowDate);
 
        //信息化建设
        tableMap.put("isRain", InfoBuildingEnum.find(tbAttResInformationProject.getIsRain()).getLabel());
        tableMap.put("isRsvr", InfoBuildingEnum.find(tbAttResInformationProject.getIsRsvr()).getLabel());
        tableMap.put("isGnssHorizontal", InfoBuildingEnum.find(tbAttResInformationProject.getIsGnssHorizontal()).getLabel());
        tableMap.put("isSppr", InfoBuildingEnum.find(tbAttResInformationProject.getIsSppr()).getLabel());
        tableMap.put("isSpqnmp", InfoBuildingEnum.find(tbAttResInformationProject.getIsSpqnmp()).getLabel());
        tableMap.put("isWmst", InfoBuildingEnum.find(tbAttResInformationProject.getIsWmst()).getLabel());
        tableMap.put("isTermites", InfoBuildingEnum.find(tbAttResInformationProject.getIsTermites()).getLabel());
        //
        String tm = tbAttResSafetyMonitor==null?"":tbAttResSafetyMonitor.getSafetyAppraisalTime() != null ? new SimpleDateFormat("yyyy年MM月dd日").format(tbAttResSafetyMonitor.getSafetyAppraisalTime()) : "";
        tableMap.put("safetyAppraisalTime", tm);
        tableMap.put("safetyAppraisalResult", tbAttResSafetyMonitor==null?"":tbAttResSafetyMonitor.getSafetyAppraisalResult()==null?"":tbAttResSafetyMonitor.getSafetyAppraisalResult()
            .replace("1","一类坝").replace("2","二类坝").replace("3","三类坝"));
 
 
        return tableMap;
    }
 
 
    @Override
    public List<TotalInfo> getTotalInfo(String isShow) {
        JSONObject ztData = this.getZtData("&is_show="+isShow, RIBAO_SHEET1_TOTAL_URL);
        JSONArray data = ztData.getJSONArray("data");
        List<TotalInfo> list = data.toJavaList(TotalInfo.class);
        return list;
    }
 
    @Override
    public List<TotalInfo> getTotalOverInfo(String isShow, HashMap<String, String> map) {
 
        String params = "&is_show=" + isShow;
        if (map != null){
            for (Map.Entry<String, String> entry : map.entrySet()){
                String key=entry.getKey();
                String vlaue = entry.getValue();
 
                String p = StringUtil.format("&{}={}",key,vlaue);
                params +=p;
            }
        }
 
        JSONObject ztData = this.getZtData(params, RIBAO_SHEET1_OVER_NORM_POOL_STAG);
        JSONArray data = ztData.getJSONArray("data");
        List<TotalInfo> list = data.toJavaList(TotalInfo.class);
        return list;
 
    }
 
    @Override
    public void getReservoirRainfallForecast(List<String> dayIndexList) {
        List<StResRainfall> stResRainfalls = new ArrayList<>();
        for (String dayIndex : dayIndexList) {
            List<AttResWithRainfall> attResByRainfall = attResBase.getAttResByRainfall(null, null, dayIndex);
            for (AttResWithRainfall attResWithRainfall : attResByRainfall) {
                StResRainfall stResRainfall = new StResRainfall();
                stResRainfall.setId(UUID.randomUUID().toString().replaceAll("-", ""));
                stResRainfall.setResCd(attResWithRainfall.getCode());
                stResRainfall.setDrp(attResWithRainfall.getRainfall());
                stResRainfall.setFileName(attResWithRainfall.getFileName());
                stResRainfall.setDayIndex(dayIndex);
                stResRainfall.setCreateTime(new Date());
                stResRainfalls.add(stResRainfall);
            }
        }
        if (!stResRainfalls.isEmpty()) {
            stResRainfallService.remove(Wrappers.<StResRainfall>query().lambda());
            stResRainfallService.saveBatch(stResRainfalls);
        }
    }
 
 
    @Override
    public List<DzkInfo> getDzkInfo(String isShow) {
        JSONObject ztData = this.getZtData("&is_show="+isShow, RIBAO_SHEET2_ZDX_URL);
        JSONArray data = ztData.getJSONArray("data");
        List<DzkInfo> list = data.toJavaList(DzkInfo.class);
        return list;
    }
 
    @Override
    public List<OverDetail> getOverDetailInfo(String isShow) {
        JSONObject ztData = this.getZtData("&is_show="+isShow, RIBAO_SHEET3_OVER_STAG_LIST_URL);
        JSONArray data = ztData.getJSONArray("data");
        List<OverDetail> list = data.toJavaList(OverDetail.class);
        return list;
    }
 
    @Override
    public List<SzInfo> getSzInfo(String isShow) {
        JSONObject ztData = this.getZtData("?is_show="+isShow, SZ_INFO);
        JSONArray data = ztData.getJSONArray("data");
        List<SzInfo> list = data.toJavaList(SzInfo.class);
        return list;
    }
 
    @Override
    public List<StationExport> getWaterLevelInfo(HttpServletResponse response, StationParams params, String exportFunc) {
        String urlParam = buildParams(params);
        String url = WATER_LEVEL_API + urlParam;
        JSONObject ztData = getZtData(null, url);
        JSONObject result = ztData.getJSONObject("data");
        JSONArray data = result.getJSONArray("data");
        List<ZtResultInfo> list = data.toJavaList(ZtResultInfo.class);
 
        List<StationExport> exportList = new ArrayList<>();
        //按水库主站导出
        if (exportFunc.equals("reservoir")) {
            exportList = exportByReservoir(list);
        } else if (exportFunc.equals("station")) {
            //按测站导出
            exportList = exportByStation(list);
        }
        return exportList;
    }
 
    /**
     * 站点导出
     *
     * @param list
     * @return
     */
    private List<StationExport> exportByStation(List<ZtResultInfo> list) {
        List<StationExport> exportList = new ArrayList<>();
 
        list.forEach(ztResultInfo -> {
            StationExport stationExport = new StationExport();
 
            if (ztResultInfo.getChildren() == null || ztResultInfo.getChildren().size() == 0) {
                return;
 
            } else {
                //获取子集中所有站点的数据
                ztResultInfo.getChildren().forEach(e -> {
                    StationExport stationExport1 = buildStationExportWater(e);
                    exportList.add(stationExport1);
                });
            }
        });
 
        return exportList;
 
    }
 
    /**
     * 水库导出
     *
     * @param list
     * @return
     */
    private List<StationExport> exportByReservoir(List<ZtResultInfo> list) {
 
        List<StationExport> exportList = new ArrayList<>();
 
        list.forEach(ztResultInfo -> {
            StationExport stationExport = new StationExport();
 
            if (ztResultInfo.getChildren() == null || ztResultInfo.getChildren().size() == 0) {
                stationExport.setRes_cd(ztResultInfo.getRes_cd());
                stationExport.setRes_nm(ztResultInfo.getRes_nm());
 
            } else {
                //获取主站的站点
                List<HashMap<String, Object>> mainList = ztResultInfo.getChildren().stream().filter(e -> isNullValue("is_main_rsvr", e).equals(1)).collect(Collectors.toList());
                if (mainList != null && mainList.size() > 0) {
                    //获取主站数据
                    stationExport = buildStationExportWater(mainList.get(0));
                } else {
                    //获取子集中第一个站点的数据
                    stationExport = buildStationExportWater(ztResultInfo.getChildren().get(0));
                }
            }
 
            exportList.add(stationExport);
        });
 
        return exportList;
    }
 
    private StationExport buildStationExportWater(HashMap<String, Object> map) {
        StationExport stationExport = new StationExport();
 
        stationExport.setRes_nm(isNullValue("res_nm", map));
        stationExport.setRes_reg_code(isNullValue("res_reg_code", map));
        stationExport.setRes_cd(isNullValue("res_cd", map));
        stationExport.setEng_scal(isNullValue("eng_scal", map));
        stationExport.setCity_nm(isNullValue("city_nm", map));
        stationExport.setCounty_nm(isNullValue("county_nm", map));
        stationExport.setTown_nm(isNullValue("town_nm", map));
        stationExport.setSt_nm(isNullValue("st_nm", map));
        stationExport.setFlag(isNullValue("flag", map));
 
        String stationStatus = isNullValue("station_status", map);
 
        String stationStatusText = "";
        if (stationStatus.equals("1")) {
            stationStatusText = "在线";
        } else if (stationStatus.equals("0")) {
            stationStatusText = "离线";
        }
        stationExport.setStation_status_text(stationStatusText);
 
        stationExport.setManufacturer(isNullValue("manufacturer", map));
 
        //应报
        String shouldCnt = isNullValue("should_cnt", map);
        //已报
        String actualCnt = isNullValue("actual_cnt", map);
 
        String shouldReportAndReport = StringUtil.format("{}/{}", shouldCnt, actualCnt);
        stationExport.setShouldReportAndReport(shouldReportAndReport);
        //到报率
        double reportRate = Double.parseDouble(isNullValue("report_rate", map));
        String rate = "0";
        if (reportRate * 100 == 100) {
            rate = "100%";
        } else if (reportRate > 0) {
            rate = String.format("%.2f", reportRate * 100) + "%";
        }
        stationExport.setRate(rate);
        return stationExport;
    }
 
 
    @Override
    public List<StationExport> getRainfallInfo(HttpServletResponse response, StationParams params, String exportFunc) {
        String urlParam = buildParams(params);
        String url = RAIN_FALL_API + urlParam;
        JSONObject ztData = getZtData(null, url);
        JSONObject result = ztData.getJSONObject("data");
        JSONArray data = result.getJSONArray("data");
        List<ZtResultInfo> list = data.toJavaList(ZtResultInfo.class);
 
        List<StationExport> exportList = new ArrayList<>();
 
        //按水库主站导出
        if (exportFunc.equals("reservoir")) {
            exportList = exportByReservoirRain(list);
        } else if (exportFunc.equals("station")) {
            //按测站导出
            exportList = exportByStationRain(list);
        }
 
        return exportList;
    }
 
    private List<StationExport> exportByStationRain(List<ZtResultInfo> list) {
        List<StationExport> exportList = new ArrayList<>();
        list.forEach(ztResultInfo -> {
            StationExport stationExport = new StationExport();
 
            if (ztResultInfo.getChildren() == null || ztResultInfo.getChildren().size() == 0) {
                return;
            } else {
                //获取子集中所有站点的数据
                ztResultInfo.getChildren().forEach(e -> {
                    StationExport stationExport1 = buildStationExportRain(e, ztResultInfo);
                    exportList.add(stationExport1);
                });
            }
        });
 
        return exportList;
    }
 
    private List<StationExport> exportByReservoirRain(List<ZtResultInfo> list) {
        List<StationExport> exportList = new ArrayList<>();
 
        list.forEach(ztResultInfo -> {
            StationExport stationExport = new StationExport();
 
            if (ztResultInfo.getChildren() == null || ztResultInfo.getChildren().size() == 0) {
                stationExport.setRes_cd(ztResultInfo.getRes_cd());
                stationExport.setRes_nm(ztResultInfo.getRes_nm());
                stationExport.setRes_reg_code(ztResultInfo.getRes_reg_cd());
                stationExport.setEng_scal(ztResultInfo.getEng_scal());
                stationExport.setCity_nm(ztResultInfo.getCity_nm());
                stationExport.setCounty_nm(ztResultInfo.getCounty_nm());
                stationExport.setTown_nm(ztResultInfo.getTown_nm());
 
            } else {
                //获取主站的站点
                List<HashMap<String, Object>> mainList = ztResultInfo.getChildren().stream().filter(e -> isNullValue("is_main_rsvr", e).equals(1)).collect(Collectors.toList());
                if (mainList != null && mainList.size() > 0) {
                    //获取主站数据
                    stationExport = buildStationExportRain(mainList.get(0), ztResultInfo);
                } else {
                    //获取子集中第一个站点的数据
                    stationExport = buildStationExportRain(ztResultInfo.getChildren().get(0), ztResultInfo);
                }
            }
 
            exportList.add(stationExport);
        });
 
        return exportList;
    }
 
    private StationExport buildStationExportRain(HashMap<String, Object> map, ZtResultInfo ztResultInfo) {
 
        StationExport stationExport = new StationExport();
 
        stationExport.setRes_nm(ztResultInfo.getRes_nm());
        stationExport.setRes_reg_code(ztResultInfo.getRes_reg_cd());
        stationExport.setRes_cd(ztResultInfo.getRes_cd());
        stationExport.setEng_scal(ztResultInfo.getEng_scal());
        stationExport.setCity_nm(ztResultInfo.getCity_nm());
        stationExport.setCounty_nm(ztResultInfo.getCounty_nm());
        stationExport.setTown_nm(ztResultInfo.getTown_nm());
        stationExport.setSt_nm(isNullValue("st_nm", map));
        stationExport.setFlag(isNullValue("flag", map));
 
        String stationStatus = isNullValue("station_status", map);
 
        String stationStatusText = "";
        if (stationStatus.equals("1")) {
            stationStatusText = "在线";
        } else if (stationStatus.equals("0")) {
            stationStatusText = "离线";
        }
        stationExport.setStation_status_text(stationStatusText);
 
        stationExport.setManufacturer(isNullValue("manufacturer", map));
 
        //应报
        String shouldCnt = isNullValue("should_cnt", map);
        //已报
        String actualCnt = isNullValue("actual_cnt", map);
 
        String shouldReportAndReport = StringUtil.format("{}/{}", shouldCnt, actualCnt);
        stationExport.setShouldReportAndReport(shouldReportAndReport);
        //到报率
        double reportRate = Double.parseDouble(isNullValue("report_rate", map));
        String rate = "0";
        if (reportRate * 100 == 100) {
            rate = "100%";
        } else if (reportRate > 0) {
            rate = String.format("%.2f", reportRate * 100) + "%";
        }
        stationExport.setRate(rate);
        return stationExport;
 
 
    }
 
 
    @Override
    public List<StationExport> getVideoStationInfo(HttpServletResponse response, StationParams params, String exportFunc) {
 
        String urlParam = buildParams(params);
        String url = VIDEO_STATION_API + urlParam;
        JSONObject ztData = getZtData(null, url);
        JSONObject result = ztData.getJSONObject("data");
        JSONArray data = result.getJSONArray("data");
        List<ZtResultInfo> list = data.toJavaList(ZtResultInfo.class);
 
        List<StationExport> exportList = new ArrayList<>();
 
        //按水库主站导出
        if (exportFunc.equals("reservoir")) {
            exportList = exportByReservoirVideo(list);
        } else if (exportFunc.equals("station")) {
            //按测站导出
            exportList = exportByStationVideo(list);
        }
 
        return exportList;
    }
 
    private List<StationExport> exportByStationVideo(List<ZtResultInfo> list) {
        List<StationExport> exportList = new ArrayList<>();
        list.forEach(ztResultInfo -> {
            StationExport stationExport = new StationExport();
 
            if (ztResultInfo.getChildren() == null || ztResultInfo.getChildren().size() == 0) {
                return;
            } else {
                //获取子集中所有站点的数据
                ztResultInfo.getChildren().forEach(e -> {
                    StationExport stationExport1 = buildStationExportVideo(e, ztResultInfo);
                    exportList.add(stationExport1);
                });
            }
        });
 
        return exportList;
    }
 
    private List<StationExport> exportByReservoirVideo(List<ZtResultInfo> list) {
        return null;
    }
 
    private StationExport buildStationExportVideo(HashMap<String, Object> map, ZtResultInfo ztResultInfo) {
 
        StationExport stationExport = new StationExport();
 
        stationExport.setRes_nm(ztResultInfo.getName());
        stationExport.setRes_reg_code(isNullValue("res_reg_code", map));
        stationExport.setRes_cd(ztResultInfo.getRes_guid());
        stationExport.setEng_scal(isNullValue("eng_scal", map));
        stationExport.setCity_nm(ztResultInfo.getCity_nm());
        stationExport.setCounty_nm(ztResultInfo.getCounty_nm());
        stationExport.setTown_nm(ztResultInfo.getTown_nm());
        stationExport.setSt_nm(isNullValue("st_nm", map));
        stationExport.setFlag(isNullValue("flag", map));
 
 
        stationExport.setStation_status_text(isNullValue("online", map));
        stationExport.setManufacturer(isNullValue("manufacturer", map));
 
        return stationExport;
    }
 
 
    @Override
    public List<StationExport> getImageStation(HttpServletResponse response, StationParams params, String exportFunc) {
 
        String urlParam = buildParams(params);
        String url = IMAGE_STATION_API + urlParam;
        JSONObject ztData = getZtData(null, url);
        JSONObject result = ztData.getJSONObject("data");
        JSONArray data = result.getJSONArray("data");
        List<ZtResultInfo> list = data.toJavaList(ZtResultInfo.class);
 
        List<StationExport> exportList = new ArrayList<>();
 
        //按水库主站导出
        if (exportFunc.equals("reservoir")) {
            exportList = exportByReservoirImage(list);
        } else if (exportFunc.equals("station")) {
            //按测站导出
            exportList = exportByStationImage(list);
        }
 
        return exportList;
    }
 
 
    private List<StationExport> exportByStationImage(List<ZtResultInfo> list) {
        List<StationExport> exportList = new ArrayList<>();
 
        list.forEach(ztResultInfo -> {
            StationExport stationExport = new StationExport();
 
            if (ztResultInfo.getChildren() == null || ztResultInfo.getChildren().size() == 0) {
                return;
 
            } else {
                //获取子集中所有站点的数据
                ztResultInfo.getChildren().forEach(e -> {
                    StationExport stationExport1 = buildStationExportImage(e, ztResultInfo);
                    exportList.add(stationExport1);
                });
            }
        });
 
        return exportList;
    }
 
    private List<StationExport> exportByReservoirImage(List<ZtResultInfo> list) {
        List<StationExport> exportList = new ArrayList<>();
 
        list.forEach(ztResultInfo -> {
            StationExport stationExport = new StationExport();
 
            if (ztResultInfo.getChildren() == null || ztResultInfo.getChildren().size() == 0) {
                stationExport.setRes_cd(ztResultInfo.getRes_code());
                stationExport.setRes_nm(ztResultInfo.getRes_nm());
                stationExport.setCity_nm(ztResultInfo.getCity_nm());
                stationExport.setCounty_nm(ztResultInfo.getCounty_nm());
                stationExport.setTown_nm(ztResultInfo.getTown_nm());
            } else {
                //获取子集第一个
                stationExport = buildStationExportImage(ztResultInfo.getChildren().get(0), ztResultInfo);
            }
 
            exportList.add(stationExport);
        });
 
        return exportList;
    }
 
    private StationExport buildStationExportImage(HashMap<String, Object> map, ZtResultInfo ztResultInfo) {
 
        StationExport stationExport = new StationExport();
 
        stationExport.setRes_nm(ztResultInfo.getRes_name());
        stationExport.setRes_reg_code(isNullValue("res_reg_code", map));
        stationExport.setRes_cd(ztResultInfo.getRes_code());
        stationExport.setEng_scal(isNullValue("eng_scal", map));
        stationExport.setCity_nm(ztResultInfo.getCity_nm());
        stationExport.setCounty_nm(ztResultInfo.getCounty_nm());
        stationExport.setTown_nm(ztResultInfo.getTown_nm());
        stationExport.setSt_nm(isNullValue("st_nm", map));
        stationExport.setFlag(isNullValue("flag", map));
 
        String stationStatus = isNullValue("station_status", map);
 
        String stationStatusText = "";
        if (stationStatus.equals("1")) {
            stationStatusText = "在线";
        } else if (stationStatus.equals("0")) {
            stationStatusText = "离线";
        }
        stationExport.setStation_status_text(stationStatusText);
 
        stationExport.setManufacturer(isNullValue("manufacturer", map));
 
        //应报
        String shouldCnt = isNullValue("should_cnt", map);
        //已报
        String actualCnt = isNullValue("actual_cnt", map);
 
        String shouldReportAndReport = StringUtil.format("{}/{}", shouldCnt, actualCnt);
        stationExport.setShouldReportAndReport(shouldReportAndReport);
        //到报率
        double reportRate = Double.parseDouble(isNullValue("report_rate", map));
        String rate = "0";
        if (reportRate * 100 == 100) {
            rate = "100%";
        } else if (reportRate > 0) {
            rate = String.format("%.2f", reportRate * 100) + "%";
        }
        stationExport.setRate(rate);
        return stationExport;
    }
 
 
    @Override
    public List<StationExport> getOsmotic(HttpServletResponse response, StationParams params, String exportFunc) {
        return null;
    }
 
 
    private String isNullValue(String key, HashMap<String, Object> map) {
        if (map.get(key) == null) {
            return "";
        } else {
            return map.get(key).toString();
        }
    }
 
    private String isNullObject(Object value) {
        if (value != null) {
            return value.toString();
        } else {
            return "";
        }
    }
 
 
    private String convertType(String type, String enumName) {
        String text = "";
 
        List<String> typeList = Arrays.asList(type.split(","));
        if (typeList.size() >0) {
            String typeKey = typeList.get(0);
            String explain = "";
            if (typeList.size() > 1) {
                explain = typeList.get(1);
            }
            //key值表示其他
            if (typeKey.equals("9") || typeKey.equals("其他")) {
                text = explain;
            } else {
                switch (enumName) {
                    case "AqueductTypeEnum":
                        text = AqueductTypeEnum.find(typeKey).getLabel();
                        break;
                    case "RsbWorkingGateEnum":
                        text = RsbWorkingGateEnum.find(typeKey).getLabel();
                        break;
                    case "OcTypeEnum":
                        text = OcTypeEnum.find(typeKey).getLabel();
                        break;
                    case "SpillwayHoleType":
                        text = typeKey;
                        break;
                    case "Explain":
                        text = typeKey;
                        break;
                }
            }
        }
 
 
 
 
        return text;
    }
 
 
    /**
     * 调用接口获取中台数据
     */
    public JSONObject getZtData(String params, String url) {
        // 获取环境
        String activeProfile = SpringContextUtil.getActiveProfile();
        if (activeProfile.equals("dev")) {
            url = ZtApiUrlConstant.url_prefix_dev + url + params;
        }
        if (activeProfile.equals("prod")) {
            url = ZtApiUrlConstant.url_prefix_prod + url + params;
        }
        if (activeProfile.equals("test")) {
            url = ZtApiUrlConstant.url_prefix_test + url + params;
        }
 
        log.info("请求url地址:{}", url);
        //设置请求头
        HttpHeaders headers = new HttpHeaders();
        headers.add(ZtConfigConstant.header_key, ZtConfigConstant.header_value);
        //封装请求头
        HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<MultiValueMap<String, Object>>(headers);
        try {
            //有请求头,有参数请求
            ResponseEntity<String> responseEntity =
                restTemplate.exchange(url,
                    HttpMethod.GET,
                    formEntity,
                    String.class);
            // Feature.IgnoreNotMatch 保留null值的属性
            JSONObject jsonObject = JSON.parseObject(responseEntity.getBody(), Feature.IgnoreNotMatch);
            // 返回
            return jsonObject;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
 
    //根据参数对象构建url后的参数
    private String buildParams(StationParams params) {
        List<String> list = new ArrayList<>();
        String text = "";
        Class<? extends StationParams> clazz = params.getClass();
        Arrays.stream(clazz.getDeclaredFields())
            .peek(field -> field.setAccessible(true))
            .forEach(field -> {
                try {
                    Object value = field.get(params);
                    if (ObjectUtil.isNotEmpty(value)) {
                        list.add(StringUtil.format("{}={}", field.getName(), value.toString()));
                    }
 
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            });
 
 
        text = String.join("&", list);
        return text;
    }
 
 
}