shenyijian
2024-06-21 f20611265f7d34fd4fbcdfdaff6cb9cccd0b25fc
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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.gistack.sm.sjztmd.mapper.TbAttResBaseMapper">
 
    <!--查询水库填报详情信息-->
    <select id="getDetailByGuid" resultType="cn.gistack.sm.sjztmd.entity.TbAttResBase">
        SELECT * FROM "tb_att_res_base" WHERE "guid" = #{guid}
    </select>
 
    <!--更新水库填报信息-->
    <update id="updateByGuid">
        UPDATE "tb_att_res_base" SET
        <if test="tbAttResBase.buildAddress !=null and tbAttResBase.buildAddress != ''">
            "build_address" = #{tbAttResBase.buildAddress},
        </if>
        <if test="tbAttResBase.resScal !=null">
            "res_scal" = #{tbAttResBase.resScal},
        </if>
        <if test="tbAttResBase.engGrad !=null and tbAttResBase.engGrad != ''">
            "eng_grad" = #{tbAttResBase.engGrad},
        </if>
        <if test="tbAttResBase.lgtd !=null and tbAttResBase.lgtd != ''">
            "lgtd" = #{tbAttResBase.lgtd},
        </if>
        <if test="tbAttResBase.lttd !=null and tbAttResBase.lttd != ''">
            "lttd" = #{tbAttResBase.lttd},
        </if>
        <if test="tbAttResBase.elevationSystem !=null and tbAttResBase.elevationSystem != ''">
            "elevation_system" = #{tbAttResBase.elevationSystem},
        </if>
        <if test="tbAttResBase.basCode !=null and tbAttResBase.basCode != ''">
            "bas_code" = #{tbAttResBase.basCode},
        </if>
        <if test="tbAttResBase.riverSysCode !=null and tbAttResBase.riverSysCode != ''">
            "river_sys_code" = #{tbAttResBase.riverSysCode},
        </if>
        <if test="tbAttResBase.comControlBas !=null and tbAttResBase.comControlBas != ''">
            "com_control_bas" = #{tbAttResBase.comControlBas},
        </if>
        <if test="tbAttResBase.importFloodBas !=null and tbAttResBase.importFloodBas != ''">
            "import_flood_bas" = #{tbAttResBase.importFloodBas},
        </if>
        <if test="tbAttResBase.locRvName !=null and tbAttResBase.locRvName != ''">
            "loc_rv_name" = #{tbAttResBase.locRvName},
        </if>
        <if test="tbAttResBase.resFunc !=null and tbAttResBase.resFunc != ''">
            "res_func" = #{tbAttResBase.resFunc},
        </if>
        <if test="tbAttResBase.checkState !=null">
            "check_state" = #{tbAttResBase.checkState},
        </if>
        <if test="tbAttResBase.checkLog !=null and tbAttResBase.checkLog != ''">
            "check_log" = #{tbAttResBase.checkLog},
        </if>
        <if test="tbAttResBase.log !=null and tbAttResBase.log != ''">
            "log" = #{tbAttResBase.log},
        </if>
        "name" = #{tbAttResBase.name}
        WHERE "guid" = #{tbAttResBase.guid}
    </update>
 
 
    <!--查询水库基础填报数据-->
    <select id="getTbAttResBaseInfo" resultType="java.util.Map">
        SELECT 'tb_att_res_base' AS name,ifnull("check_state",-1) as value FROM "tb_att_res_base" WHERE "guid" = #{resGuid}
    </select>
 
    <!--查询水库其他填报数据-->
    <select id="getTbInfo" resultType="java.util.Map">
        SELECT ${tableNameColumn} AS name,ifnull("check_state",-1) as value FROM ${tableName} WHERE "res_guid" = #{resGuid} limit 1
    </select>
 
    <!--查询水库基本详情,水位特征,挡水,输水,泄洪建筑物,电站,水库效益,工程运用,管理体制,安全鉴定和除险加固,信息化建设,文件夹存储位置所有状态的一个总状态-->
    <select id="getFinalCheckStateByGuid" resultType="java.lang.Boolean">
        select if(sum(value)&lt;28,false,true) from (
            (SELECT ifnull(sum("check_state"),-1) as value FROM "tb_att_res_base" WHERE "guid" = #{guid} limit 1 )union all
            (SELECT ifnull(sum("check_state"),-1) as value FROM "tb_att_res_eng_bene" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT ifnull(sum("check_state"),-1) as value FROM "tb_att_res_infomation_project" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT ifnull(sum("check_state"),-1) as value FROM "tb_att_res_mgr_sys_b" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT ifnull(sum("check_state"),-1) as value FROM "tb_att_res_power_station" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT ifnull(sum("check_state"),-1) as value FROM "tb_att_res_project_utilize" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT ifnull(sum("check_state"),-1) as value FROM "tb_att_res_rsb_norspi" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT ifnull(sum("check_state"),-1) as value FROM "tb_att_res_rsb_spillway" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT ifnull(sum("check_state"),-1) as value FROM "tb_att_res_rsb_verspi" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT ifnull(sum("check_state"),-1) as value FROM "tb_att_res_safety_monitor" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT ifnull(sum("check_state"),-1) as value FROM "tb_att_res_stag_char" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT ifnull(sum("check_state"),-1) as value FROM "tb_att_res_water_block" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT ifnull(sum("check_state"),-1) as value FROM "tb_att_res_water_delivery" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT ifnull(sum("check_state"),-1) as value FROM "tb_file_storage_location" WHERE "res_guid" = #{guid} limit 1)
        ) a
    </select>
 
    <!--查询水库基本详情,水位特征,挡水,输水,泄洪建筑物,电站,水库效益,工程运用,管理体制,安全鉴定和除险加固,信息化建设,文件夹存储位置所有状态的一个总状态(是否为审核中)-->
    <select id="getFinalCheckStateCheckLoadingByGuid" resultType="java.lang.Boolean">
        select if(sum(value)&lt;14,false,true) from (
            (SELECT if(ifnull(sum("check_state"),-1)>0,1,0) as value FROM "tb_att_res_base" WHERE "guid" = #{guid} limit 1 )union all
            (SELECT if(ifnull(sum("check_state"),-1)>0,1,0) as value FROM "tb_att_res_eng_bene" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT if(ifnull(sum("check_state"),-1)>0,1,0) as value FROM "tb_att_res_infomation_project" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT if(ifnull(sum("check_state"),-1)>0,1,0) as value FROM "tb_att_res_mgr_sys_b" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT if(ifnull(sum("check_state"),-1)>0,1,0) as value FROM "tb_att_res_power_station" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT if(ifnull(sum("check_state"),-1)>0,1,0) as value FROM "tb_att_res_project_utilize" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT if(ifnull(sum("check_state"),-1)>0,1,0) as value FROM "tb_att_res_rsb_norspi" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT if(ifnull(sum("check_state"),-1)>0,1,0) as value FROM "tb_att_res_rsb_spillway" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT if(ifnull(sum("check_state"),-1)>0,1,0) as value FROM "tb_att_res_rsb_verspi" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT if(ifnull(sum("check_state"),-1)>0,1,0) as value FROM "tb_att_res_safety_monitor" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT if(ifnull(sum("check_state"),-1)>0,1,0) as value FROM "tb_att_res_stag_char" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT if(ifnull(sum("check_state"),-1)>0,1,0) as value FROM "tb_att_res_water_block" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT if(ifnull(sum("check_state"),-1)>0,1,0) as value FROM "tb_att_res_water_delivery" WHERE "res_guid" = #{guid} limit 1 )union all
            (SELECT if(ifnull(sum("check_state"),-1)>0,1,0) as value FROM "tb_file_storage_location" WHERE "res_guid" = #{guid} limit 1)
        ) a
    </select>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    <!--初始化水库基础信息-->
    <update id="initTbAttResBase">
        UPDATE SJZT_MD."tb_att_res_base" tarb
            JOIN SJZT_MD."att_res_base" arb on tarb."guid" = arb."guid"
            JOIN SJZT_ODS."yg_rsvr_b" yrb on yrb."id" = tarb."guid"
            JOIN (
                select
                REPLACE(
                    REPLACE(
                        REPLACE(
                            REPLACE(
                                REPLACE(
                                    REPLACE(
                                        REPLACE(
                                            REPLACE(
                                                REPLACE(
                                                    REPLACE(
                                                        "res_func",'防洪','1'
                                                    ),'灌溉','2'
                                                ),'供水','3'
                                            ),'发电','4'
                                        ),'航运','5'
                                    ),'防凌','6'
                                ),'生态','7'
                            ),'旅游','8'
                        ),'养殖','9'
                    ),'其他','10'
                ) "res_func","guid"
                FROM SJZT_MD."att_res_base"
            ) arbResFunc on arbResFunc."guid" = tarb."guid"
 
            join (
                SELECT
                    rrbl."res_guid",
                    abb."name"
                FROM
                    SJZT_MD."rel_res_bas_loc" rrbl
                LEFT JOIN SJZT_MD."att_bas_base" abb ON abb."code" = rrbl."bas_guid"
            ) bas on bas."res_guid" = tarb."guid"
 
            SET
                tarb."res_scal"  =
                    case
                        when arb."eng_scal" = '大(1)型' THEN 1
                        when arb."eng_scal" = '大(2)型' THEN 2
                        when arb."eng_scal" = '中型' THEN 3
                        when arb."eng_scal" = '小(1)型' THEN 4
                        when arb."eng_scal" = '小(2)型' THEN 5
                END,
 
                tarb."build_address" = arb."res_loc",
                tarb."eng_grad" = arb."eng_grad",
                tarb."lgtd" = arb."center_long",
                tarb."lttd" = arb."center_lat",
 
                tarb."elevation_system" =
                    case
                        when yrb."height_base_std_tp" = 1 THEN '56黄海高程'
                        when yrb."height_base_std_tp" = 2 THEN '85黄海高程'
                        when yrb."height_base_std_tp" = 3 THEN '吴淞高程'
                        when yrb."height_base_std_tp" = 4 THEN '珠江高程'
                        when yrb."height_base_std_tp" = 5 THEN '其他'
                    END,
 
                    tarb."bas_code" = arb."bas_name",
                    tarb."river_sys_code" =
                    case
                        when arb."bas_guid" = '乌江水系' THEN '0035FE'
                        when arb."bas_guid" = '汉江水系' THEN '0035FG'
                        when arb."bas_guid" = '洞庭湖水系' THEN '0035FF'
                        when arb."bas_guid" = '淮河干流水系' THEN '0034EA'
                        when arb."bas_guid" = '长江干流水系' THEN '0035FA'
                    END,
                    tarb."com_control_bas" = bas."name",
                    tarb."res_func" = arbResFunc."res_func",
                --工程始建时间,下闸蓄水时间没找到
                tarb."industry_dept" =
                case
                    when arb."industry_dept" = '水利部门' THEN '1'
                    when arb."industry_dept" = '能源部门' THEN '2'
                    when arb."industry_dept" = '交通部门' THEN '3'
                    when arb."industry_dept" = '住建部门' THEN '4'
                    when arb."industry_dept" = '农业部门' THEN '5'
                    when arb."industry_dept" = '林业部门' THEN '6'
                    when arb."industry_dept" = '旅游部门' THEN '7'
                    when arb."industry_dept" = '司法部门' THEN '8'
                    when arb."industry_dept" = '国资委' THEN '9'
                    when arb."industry_dept" = '其他' THEN '10,'
                END
                    WHERE tarb."final_state" = -1
 
 
    </update>
 
 
 
    <sql id="getAttResStagChar">
        SELECT
            tarb."guid",
            tarb."guid",
            arsc."con_area",
            NULL,
            arsc."moyear_fl_age",
            NULL,
            arsc."tb_chec_fl_stag",
            arsc."tb_des_fl_stag",
            arsc."tb_flpr_high_stag",
            arsc."tb_norm_pool_stag",
            arsc."tb_dead_stag",
            arsc."tb_tot_cap",
            arsc."stor_fl_cap",
            arsc."flco_cap",
            arsc."ben_res_cap",
            arsc."tb_dead_cap",
            arsc."des_fl_flow_max",
            arsc."chec_fl_flow_max",
            null,
 
            arsc."des_fl_stand",
            arsc."des_fl_flow",
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
 
            arsc."chec_fl_stand",
            arsc."chec_fl_flow",
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
 
            beforeArfl."tb_flse_lim_stag",
            NULL,
            NULL,
 
            midArfl."tb_flse_lim_stag",
            NULL,
            NULL,
 
            afterArfl."tb_flse_lim_stag",
            NULL,
            NULL,
 
            '0' as "check_state",
            NOW() as "create_time"
 
 
        FROM
            SJZT_MD."tb_att_res_base" tarb
                LEFT JOIN SJZT_MD."att_res_stag_char" arsc on arsc."res_guid" = tarb."guid"
                LEFT JOIN SJZT_MD."att_res_flse_lim" beforeArfl on beforeArfl."res_guid" = tarb."guid" and beforeArfl."flood_season_name" = '前汛期'
                LEFT JOIN SJZT_MD."att_res_flse_lim" midArfl on midArfl."res_guid" = tarb."guid" and midArfl."flood_season_name" = '中汛期'
                LEFT JOIN SJZT_MD."att_res_flse_lim" afterArfl on afterArfl."res_guid" = tarb."guid" and afterArfl."flood_season_name" = '后汛期'
        WHERE tarb."final_state" = -1
    </sql>
 
 
 
    <insert id="initTbAttResStagChar">
        INSERT INTO SJZT_MD."tb_att_res_stag_char"
        (
            "guid",
            "res_guid",
            "con_area",
            "moyear_rain_avg",
            "moyear_fl_avg",
            "adjust_prop",
 
            "chec_fl_stag",
            "des_fl_stag",
            "fl_con_top_stag",
            "cor_norm_stag",
            "dead_stag",
 
            "total_cap",
            "flpr_cap",
            "fl_stor_cap",
            "adjust_stor_cap",
            "dead_cap",
 
            "des_flood_flow_max",
            "chec_flood_flow_max",
            "down_waco_safe_disc",
            "des_fl_sta",
            "des_fl_flow",
 
            "des_fl_1h_cap",
            "des_fl_3h_cap",
            "des_fl_6h_cap",
            "des_fl_12h_cap",
            "des_fl_1day_cap",
 
            "des_fl_3day_cap",
            "chec_fl_sta",
            "chec_fl_flow",
            "chec_fl_1h_cap",
            "chec_fl_3h_cap",
 
            "chec_fl_6h_cap",
            "chec_fl_12h_cap",
            "chec_fl_1day_cap",
            "chec_fl_3day_cap",
            "before_flood_stag",
 
            "before_flood_start",
            "before_flood_end",
            "mid_flood_stag",
            "mid_flood_start",
            "mid_flood_end",
 
            "after_flood_stag",
            "after_flood_start",
            "after_flood_end",
            "check_state",
            "create_time"
        )
        <include refid="getAttResStagChar"></include>
 
 
 
    </insert>
 
    <sql id="getAttResWaterBlock">
        SELECT
            arwb."dam_width",
            '否',
            NULL,
            '其他',
            '其他',
            arwb."guid",
            '',
            CASE when arwb."sub_dam_num" = 0 THEN 1 ELSE arwb."sub_dam_num" +1 END,
            arwb."res_guid",
            case
                when arwb."dam_type" = '常态混凝土实体重力坝' THEN 'DAA001'
                when arwb."dam_type" = '常态混凝土宽缝重力坝' THEN 'DAA002'
                when arwb."dam_type" = '常态混凝土空腹重力坝' THEN 'DAA003'
                when arwb."dam_type" = '碾压混凝土重力坝' THEN 'DAA004'
                when arwb."dam_type" = '混凝土重力坝' THEN 'DAA0'
 
                when arwb."dam_type" = '常态混凝土单曲拱坝' THEN 'DAB001'
                when arwb."dam_type" = '常态混凝土双曲拱坝' THEN 'DAB002'
                when arwb."dam_type" = '常态混凝土变曲拱坝' THEN 'DAB003'
                when arwb."dam_type" = '碾压混凝土单曲拱坝' THEN 'DAB004'
                when arwb."dam_type" = '碾压混凝土双曲拱坝' THEN 'DAB005'
                when arwb."dam_type" = '碾压混凝土变曲拱坝' THEN 'DAB006'
                when arwb."dam_type" = '混凝土拱坝' THEN 'DAB0'
 
                when arwb."dam_type" = '平板坝' THEN 'DAC001'
                when arwb."dam_type" = '大头坝' THEN 'DAC002'
                when arwb."dam_type" = '连拱坝' THEN 'DAC003'
                when arwb."dam_type" = '混凝土支墩坝' THEN 'DAC0'
                when arwb."dam_type" = '混凝土坝' THEN 'DA'
 
                when arwb."dam_type" = '均质土坝' THEN 'DBA001'
                when arwb."dam_type" = '粘土心墙坝' THEN 'DBA002'
                when arwb."dam_type" = '沥青心墙坝' THEN 'DBA003'
                when arwb."dam_type" = '土工膜心墙坝' THEN 'DBA004'
                when arwb."dam_type" = '混凝土心墙坝' THEN 'DBA005'
                when arwb."dam_type" = '粘土斜墙坝' THEN 'DBA006'
                when arwb."dam_type" = '沥青斜墙坝' THEN 'DBA007'
                when arwb."dam_type" = '土工膜斜墙坝' THEN 'DBA008'
                when arwb."dam_type" = '土石混合坝' THEN 'DBA009'
                when arwb."dam_type" = '碾压式土石坝' THEN 'DBA0'
 
                when arwb."dam_type" = '面板堆石坝' THEN 'DBB0'
                when arwb."dam_type" = '水力冲填坝' THEN 'DBC0'
                when arwb."dam_type" = '定向爆破坝' THEN 'DBD0'
                when arwb."dam_type" = '土石坝' THEN 'DB'
 
                when arwb."dam_type" = '砌石重力坝' THEN 'DCA0'
                when arwb."dam_type" = '砌石拱坝' THEN 'DCB0'
                when arwb."dam_type" = '砌石坝' THEN 'DC'
                when arwb."dam_type" = '其他' THEN 'DD'
                END,
            '',
            arwb."tb_dam_top_elevation",
            arwb."dam_height",
            arwb."dam_top_length",
            '其他',
            NULL,
            '无',
            arwb."dam_body_type",
            arwb."sub_dam_num",
            arwb."sub_dam_total_length",
            arwb."sub_dam_max_height",
            NULL,
            '0' as "check_state",
            NOW() as "create_time"
 
        FROM SJZT_MD."tb_att_res_base" tarb
                 LEFT JOIN SJZT_MD."att_res_water_block" arwb on arwb."res_guid" = tarb."guid"
        WHERE tarb."final_state" = -1 and arwb."res_guid" is not null
    </sql>
 
 
 
    <insert id="initTbAttResWaterBlock">
        INSERT INTO SJZT_MD."tb_att_res_water_block"
        (
            "dam_width",
            "is_traffic",
            "wave_wall_top_elevation",
            "up_dam_protect_type",
            "down_dam_protect_type",
            "guid",
 
            "name",
            "num",
            "res_guid",
            "dam_type",
            "dam_main_foundation",
 
            "dam_top_elevation",
            "dam_height",
            "dam_top_length",
            "dam_main_body_type",
            "dam_main_body_top_elevation",
 
            "dam_main_drain_type",
            "dam_body_type",
            "sub_dam_num",
            "sub_dam_tot_length",
            "sub_dam_max_height",
 
            "sub_dam_top_width",
            "check_state",
            "create_time"
        )
        <include refid="getAttResWaterBlock"></include>
    </insert>
 
 
 
    <sql id="getAttResRsbNorspi">
        SELECT
            arrn."guid",
            '',
            1,
            arrn."res_guid",
            arrn."spillway_type",
            NULL,
            NULL,
            arrn."tb_weir_top_elevation",
            arrn."weir_top_width",
            arrn."working_gate_type",
            NULL,
            NULL,
            NULL,
            NULL,
            arrn."oc_type",
            NULL,
            arrn."dis_energy_type",
            '0' as "check_state",
            NOW() as "create_time"
 
        FROM SJZT_MD."tb_att_res_base" tarb
                 LEFT JOIN SJZT_MD."att_res_rsb_norspi" arrn on arrn."res_guid" = tarb."guid"
        WHERE tarb."final_state" = -1 and arrn."res_guid" is not null
    </sql>
 
 
    <insert id="initTbAttResRsbNorspi">
        INSERT INTO SJZT_MD."tb_att_res_rsb_norspi"
        (
            "guid",
            "name",
            "num",
            "res_guid",
            "spillway_type",
            "is_loc_dam_body",
 
            "is_gate",
            "weir_top_elevation",
            "weir_top_width",
            "working_gate_type",
            "gate_num",
 
            "gate_length",
            "gate_wide",
            "checking_flood_discharge",
            "oc_type",
            "oc_power",
 
            "dis_energy_type",
            "check_state",
            "create_time"
        )
<include refid="getAttResRsbNorspi"></include>
    </insert>
 
 
 
    <sql id="getAttResRsbSpillway">
        SELECT
            arrs."guid",
            arrs."build_name",
            numTmp.num,
            arrs."res_guid",
            case
                when arrs."spillway_type" = '城门洞型' then '城门洞型'
                when arrs."spillway_type" = '马蹄形' then '马蹄形'
                when arrs."spillway_type" = '圆形' then '圆形'
                when arrs."spillway_type" = '矩形' then '矩形'
                else '其他,'
                end,
            NULL,
            arrs."threshold_elevation",
            NULL,
            arrs."hole_num",
            NULL,
            NULL,
            arrs."checking_flood_discharge",
            arrs."working_gate_type",
            arrs."oc_type",
            NULL,
            '0' as "check_state",
            NOW() as "create_time"
        FROM SJZT_MD."tb_att_res_base" tarb
                 LEFT JOIN SJZT_MD."att_res_rsb_spillway" arrs on arrs."res_guid" = tarb."guid"
 
                 LEFT JOIN (
            SELECT COUNT(*) NUM ,"res_guid" FROM SJZT_MD."att_res_rsb_spillway" group by "res_guid"
        )numTmp on numTmp."res_guid" = tarb."guid"
        WHERE tarb."final_state" = -1 and arrs."res_guid" is not null
    </sql>
 
 
    <insert id="initTbAttResRsbSpillway">
        INSERT INTO SJZT_MD."tb_att_res_rsb_spillway"
        (
            "guid",
            "name",
            "num",
            "res_guid",
            "spillway_type",
            "cove_length",
 
            "threshold_elevation",
            "export_elevation",
            "section_num",
            "section_length",
            "section_wide",
 
            "check_fl_dis_charge",
            "working_gate_type",
            "oc_type",
            "oc_power",
 
            "check_state",
            "create_time"
        )
    <include refid="getAttResRsbSpillway"></include>
    </insert>
 
 
 
    <sql id="getTbAttResRsbVerspi">
        SELECT
            basic."enable_standards",
            basic."checking_flood_discharge",
            basic."guid",
            basic."build_name",
            numTmp.num,
            basic."res_guid",
            basic."spillway_type",
            basic."weir_top_elevation",
 
            '0' as "check_state",
            NOW() as "create_time"
 
 
        FROM SJZT_MD."tb_att_res_base" tarb
                 LEFT JOIN SJZT_MD."att_res_rsb_verspi" basic on basic."res_guid" = tarb."guid"
 
                 LEFT JOIN (
            SELECT COUNT(*) NUM ,"res_guid" FROM SJZT_MD."att_res_rsb_verspi" group by "res_guid"
        )numTmp on numTmp."res_guid" = tarb."guid"
        WHERE tarb."final_state" = -1 and basic."res_guid" is not null
    </sql>
 
    <insert id="initTbAttResRsbVerspi">
        INSERT INTO SJZT_MD."tb_att_res_rsb_verspi"
        (
            "enable_standards",
            "checking_flood_discharge",
            "guid",
            "name",
            "num",
            "res_guid",
            "spillway_type",
            "weir_top_width",
 
            "check_state",
            "create_time"
        )
        <include refid="getTbAttResRsbVerspi"></include>
 
    </insert>
 
    <sql id="getTbAttResWaterDelivery">
        SELECT
            basic."guid",
            '',
            numTmp.num,
            basic."res_guid",
            CASE WHEN basic."aqueduct_type" != 9 then basic."aqueduct_type" else '9,' end,
 
            basic."aqueduct_length",
            NULL,
            NULL,
            NULL,
            NULL,
 
            basic."design_flow",
            NULL,
            NULL,
            NULL,
            NULL,
 
            '0' as "check_state",
            NOW() as "create_time"
 
 
        FROM SJZT_MD."tb_att_res_base" tarb
                 LEFT JOIN SJZT_MD."att_res_water_delivery" basic on basic."res_guid" = tarb."guid"
 
                 LEFT JOIN (
            SELECT COUNT(*) NUM ,"res_guid" FROM SJZT_MD."att_res_water_delivery" group by "res_guid"
        )numTmp on numTmp."res_guid" = tarb."guid"
        WHERE tarb."final_state" = -1 and basic."res_guid" is not null
    </sql>
 
 
 
    <insert id="initTbAttResWaterDelivery">
 
        INSERT INTO SJZT_MD."tb_att_res_water_delivery"
        (
            "guid",
            "name",
            "num",
            "res_guid",
            "aqueduct_type",
 
            "aqueduct_length",
            "threshold_elevation",
            "export_elevation",
            "section_wide",
            "section_high",
 
            "design_flow",
            "working_gate_type",
            "oc_type",
            "oc_power",
            "is_across_dam_body",
 
            "check_state",
            "create_time"
        )
        <include refid="getTbAttResWaterDelivery"></include>
 
    </insert>
 
 
    <sql id="getTbAttResPowerStation">
        SELECT
            basic."id",
            '',
            numTmp.num,
            basic."rs_id",
            basic."plant_layout_type",
 
            basic."installed_capacity",
            NULL,
 
 
            '0' as "check_state",
            NOW() as "create_time"
 
 
        FROM SJZT_MD."tb_att_res_base" tarb
                 LEFT JOIN SJZT_ODS."yg_rsvr_power_st" basic on basic."rs_id" = tarb."guid"
 
                 LEFT JOIN (
            SELECT COUNT(*) NUM ,"rs_id" FROM SJZT_ODS."yg_rsvr_power_st" group by "rs_id"
        )numTmp on numTmp."rs_id" = tarb."guid"
        WHERE tarb."final_state" = -1 and basic."rs_id" is not null
    </sql>
 
 
 
    <insert id="initTbAttResPowerStation">
        INSERT INTO SJZT_MD."tb_att_res_power_station"
        (
            "guid",
            "name",
            "num",
            "res_guid",
            "plant_layout_type",
 
            "installed_capacity",
            "year_avg_hour",
            "check_state",
            "create_time"
        )
        <include refid="getTbAttResPowerStation"></include>
    </insert>
 
 
    <sql id="getTbAttResMgrSysB">
        SELECT
            basic."guid",
            basic."res_guid",
            basic."m_unit_name",
            basic."c_unit_name",
 
            CASE
                WHEN basic."m_unit_nature" = 1 THEN '其他'
                WHEN basic."m_unit_nature" = 2 THEN '企业'
                WHEN basic."m_unit_nature" = 3 THEN '民间组织'
                ELSE '其他'
                END,
            NULL,
            NULL,
            NULL,
            '0' as "check_state",
            NOW() as "create_time"
 
        FROM SJZT_MD."tb_att_res_base" tarb
                 LEFT JOIN SJZT_MD."att_res_mgr_sys_b" basic on basic."res_guid" = tarb."guid"
        WHERE tarb."final_state" = -1 and basic."res_guid" is not null
    </sql>
 
    <insert id="initTbAttResMgrSysB">
        INSERT INTO SJZT_MD."tb_att_res_mgr_sys_b"
        (
            "guid",
            "res_guid",
            "m_unit_name",
            "c_unit_name",
            "m_unit_nature",
 
            "m_unit_person_number",
            "person_economic_source",
            "maintenance_economic_source",
            "check_state",
            "create_time"
        )
    <include refid="getTbAttResMgrSysB"></include>
 
 
    </insert>
    <sql id="getTbAttResSafetyMonitor">
        SELECT
            basic."guid",
            basic."res_guid",
            basic."latest_safety_appraisal_time",
            basic."safety_appraisal_type",
            basic."tb_control_z",
            basic."exist_pblm",
            '否',
            basic."latest_reinforce_time",
            NULL,
            '0' as "check_state",
            NOW() as "create_time"
        FROM SJZT_MD."tb_att_res_base" tarb
                 LEFT JOIN SJZT_MD."att_res_danger_manage_special" basic on basic."res_guid" = tarb."guid"
        WHERE tarb."final_state" = -1 and basic."res_guid" is not null
    </sql>
 
    <insert id="initTbAttResSafetyMonitor">
        INSERT INTO SJZT_MD."tb_att_res_safety_monitor"
        (
            "guid",
            "res_guid",
            "safety_appraisal_time",
            "safety_appraisal_result",
            "control_rz",
            "survey_problem",
            "is_reinforce",
            "reinforce_tm",
            "completion_time",
            "check_state",
            "create_time"
        )
    <include refid="getTbAttResSafetyMonitor"></include>
    </insert>
 
 
</mapper>