guoshilong
2024-03-18 af100201b0e8cbde2194651b12a136e2daba7f18
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sjztmd/mapper/AttResBaseMapper.xml
@@ -13,12 +13,46 @@
    <select id="selectAttResBaseGeneralInvestigation"
            resultType="cn.gistack.sm.sjztmd.vo.AttResBaseGeneralInvestigationVO">
        select a.*,b."check_state" AS tb_state,b."tb_year",b."tb_quarter" from sjzt_md."att_res_base" a
        select
            a.*,b."check_state" AS tb_state,
            b."tb_year",
            b."tb_quarter",
            tmp.totalLength,
            tmp.firstLength,
            tmp.secondLength,
            tmp.thirdLength,
            tmp.totalDangerNum,
            tmp.termiteNum,
            tmp.otherNum
        from sjzt_md."att_res_base" a
        left join "SJZT_MD"."att_ad_base" aab on aab."guid" = a."interior_ad_guid"
        left join "SJZT_MD"."att_ad_base" aa on aab."p_ad_code" = aa."ad_code"
        left join "SJZT_MD"."att_ad_base" ab on aa."p_ad_code" = ab."ad_code"
        left join "SJZT_MD"."att_ad_base" ac on ab."p_ad_code" = ac."ad_code"
        left join "SJZT_MD"."tb_res_general_investigation_state" b on a."code" = b."res_guid"
        left join
        (
            SELECT TRGI."tb_state_id",TRGI."res_guid",
            SUM(CASE WHEN trgi."hazard_rating" != '无危害' THEN 1 ELSE 0 END) AS totalLength,
            SUM(CASE WHEN trgi."hazard_rating" = 'I' THEN trgi."investigation_length" ELSE 0 END) AS firstLength,
            SUM(CASE WHEN trgi."hazard_rating" = 'II' THEN trgi."investigation_length" ELSE 0 END) AS secondLength,
            SUM(CASE WHEN trgi."hazard_rating" = 'III' THEN trgi."investigation_length" ELSE 0 END) AS thirdLength,
            SUM(CASE WHEN (trgi."hazard_rating" != '无危害') THEN 1 ELSE 0 END) AS totalDangerNum,
            SUM(CASE WHEN (trgi."investigation_variety" = '白蚁' and trgi."hazard_rating" != '无危害') THEN 1 ELSE 0 END) AS termiteNum,
            SUM(CASE WHEN (trgi."investigation_variety" != '白蚁' and trgi."hazard_rating" != '无危害') THEN 1 ELSE 0 END) AS otherNum
            from sjzt_md."tb_res_general_investigation" trgi
            <if test="attResBase.tbYear !=null and attResBase.tbYear !=''">
                AND trgi."tb_year" = #{attResBase.tbYear}
            </if>
            group by TRGI."tb_state_id",TRGI."res_guid"
        ) tmp on tmp."tb_state_id" = b."guid"
        where 1 = 1
        <if test="attResBase.tbYear !=null and attResBase.tbYear !=''">
            AND b."tb_year" = #{attResBase.tbYear}