shenyijian
2024-06-21 f20611265f7d34fd4fbcdfdaff6cb9cccd0b25fc
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sjztmd/mapper/TbAttResBaseMapper.xml
@@ -59,4 +59,763 @@
        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>