<?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="com.tofly.xrtygis.mapper.CostrlfixedMapper">

    <resultMap id="costrlfixedMap" type="com.tofly.xrtygis.entity.Costrlfixed">
        <id property="id" column="ID"/>
        <result property="upDate" column="UP_DATE"/>
        <result property="paczfyOne" column="PACZFY_ONE"/>
        <result property="paczfyTwo" column="PACZFY_TWO"/>
        <result property="syzfyOne" column="SYZFY_ONE"/>
        <result property="ylzfyTwo" column="YLZFY_TWO"/>
        <result property="pamzszfy" column="PAMZSZFY"/>
        <result property="ftzfy" column="FTZFY"/>
        <result property="cnzfy" column="CNZFY"/>
        <result property="gmsjfhyzfy" column="GMSJFHYZFY"/>
        <result property="pamwnzfy" column="PAMWNZFY"/>
        <result property="bcszfy" column="BCSZFY"/>
        <result property="wnzyf" column="WNZYF"/>
        <result property="jbdfOne" column="JBDF_ONE"/>
        <result property="jbdfTwo" column="JBDF_TWO"/>
        <result property="jbdfTotal" column="JBDF_TOTAL"/>
        <result property="dldfOne" column="DLDF_ONE"/>
        <result property="dldfTwo" column="DLDF_TWO"/>
        <result property="dldfTotal" column="DLDF_TOTAL"/>
        <result property="ysf" column="YSF"/>
        <result property="szysfOne" column="SZYSF_ONE"/>
        <result property="szysfTwo" column="SZYSF_TWO"/>
        <result property="szysfTotal" column="SZYSF_TOTAL"/>
        <result property="dfcbOne" column="DFCB_ONE"/>
        <result property="dfcbTwo" column="DFCB_TWO"/>
        <result property="dfcbTotal" column="DFCB_TOTAL"/>
        <result property="paccbOne" column="PACCB_ONE"/>
        <result property="sycbOne" column="SYCB_ONE"/>
        <result property="cncbOne" column="CNCB_ONE"/>
        <result property="bcscbOne" column="BCSCB_ONE"/>
        <result property="zsclcbOne" column="ZSCLCB_ONE"/>
        <result property="paccbTwo" column="PACCB_TWO"/>
        <result property="ylcbTwo" column="YLCB_TWO"/>
        <result property="pamzscbTwo" column="PAMZSCB_TWO"/>
        <result property="ftcbTwo" column="FTCB_TWO"/>
        <result property="gmsjfhycbTwo" column="GMSJFHYCB_TWO"/>
        <result property="pamwncbTwo" column="PAMWNCB_TWO"/>
        <result property="wnzycbTwo" column="WNZYCB_TWO"/>
        <result property="zsclcbTwo" column="ZSCLCB_TWO"/>
        <result property="zsclcbTotal" column="ZSCLCB_TOTAL"/>
        <result property="ysfcb" column="YSFCB"/>
        <result property="szysfcbOne" column="SZYSFCB_ONE"/>
        <result property="szysfcbTwo" column="SZYSFCB_TWO"/>
        <result property="szysfcbTotal" column="SZYSFCB_TOTAL"/>
        <result property="zfyOne" column="ZFY_ONE"/>
        <result property="zfyTwo" column="ZFY_TWO"/>
        <result property="dwcbOne" column="DWCB_ONE"/>
        <result property="dwcbTwo" column="DWCB_TWO"/>
        <result property="dwcbTotal" column="DWCB_TOTAL"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="zzsclfyOne" column="ZZSCLFY_ONE"/>
        <result property="zzsclfyTwo" column="ZZSCLFY_TWO"/>
        <result property="zfy" column="ZFY"/>
        <result property="mark" column="MARK"/>
        <result property="otherzfy" column="OTHERZDY"/>
        <result property="othercb" column="OTHERCB"/>
        <result property="dfOneTotal" column="DF_ONE_TOTAL"/>
        <result property="dfTwoTotal" column="DF_TWO_TOTAL"/>
        <result property="dlOneTotal" column="DL_TWO_TOTAL"/>
        <result property="dlTwoTotal" column="DL_TWO_TOTAL"/>
        <result property="updateTime" column="UPDATE_TIME"/>
        <result property="cnzfyTwo" column="CNZFY_TWO"/>
        <result property="cncbTwo" column="CNCB_TWO"/>
        <result property="otherOneZfy" column="OTHER_ONE_ZFY"/>
        <result property="otherTwoZfy" column="OTHER_TWO_ZFY"/>
        <result property="otherOneCb" column="OTHER_ONE_CB"/>
        <result property="otherTwoCb" column="OTHER_TWO_CB"/>
        <association property="createUserName" column="CREATE_USER"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
    </resultMap>

    <select id="getWaterDataMonth" resultType="java.util.Map">
        SELECT TO_CHAR(UP_DATE, 'yyyy') YEAR, TO_CHAR(UP_DATE, 'MM') MONTH, round(${typet}, 4) reslutData
        FROM TF_YWPN_COSTRLFIXED_W
        WHERE TO_CHAR(UP_DATE, 'yyyy') between #{startYear} and #{endYear}
          and MARK = '1'
        ORDER BY MONTH
    </select>

    <select id="getWaterDataQuarter" resultType="java.util.Map">
        SELECT SUBSTR(quarter, 1, 4) YEAR, quarter MONTH, round(SUM(${typet}), 4) reslutData
        FROM (SELECT TO_CHAR(UP_DATE, 'yyyy')   UP_DATE,
                     TO_CHAR(UP_DATE, 'yyyy-Q') quarter,
                     nvl(${typet}, 0)           ${typet}
              FROM TF_YWPN_COSTRLFIXED_W
              WHERE TO_CHAR(UP_DATE, 'yyyy') between #{startYear} and #{endYear}
                and MARK = '1')
        GROUP BY quarter
        ORDER BY quarter ASC
    </select>

    <select id="getWaterDataQuarterTest" resultType="map">
        SELECT
        <if test="type = 'CNCB_ONE'">
            round(sum(CNZFY) / nullif(sum(GSL_ONE),0) * 1000,4) reslutData,
        </if>
        <if test="type = 'CNCB_TWO'">
            round(sum(CNZFY_TWO) / nullif(sum(GSL_TWO),0) * 1000,4) reslutData,
        </if>
        <if test="type ='PACCB_ONE'">
            round(sum(PACZFY_ONE) / nullif(sum(GSL_ONE),0) * 1000,4) reslutData,
        </if>
        <if test="type = 'SYCB_ONE'">
            round(sum(SYZFY_ONE) / nullif(sum(GSL_ONE),0) * 1000,4) reslutData,
        </if>
        <if test="type ='BCSCB_ONE'">
            round(sum(BCSZFY) / nullif(sum(GSL_ONE),0) * 1000,4) reslutData,
        </if>
        <if test="type = 'OTHERCB'">
            round(sum(OTHERZFY) / nullif(sum(GSL_ONE),0) * 1000,4) reslutData,
        </if>
        <if test="type = 'OTHER_ONE_CB'">
            round(sum(OTHER_ONE_ZFY) / nullif(sum(GSL_ONE),0) * 1000,4) reslutData,
        </if>
        <if test="type = 'OTHER_TWO_CB'">
            round(sum(OTHER_TWO_ZFY) / nullif(sum(GSL_TWO),0) * 1000,4) reslutData,
        </if>
        <if test="type ='PACCB_TWO'">
            round(sum(PACZFY_TWO) / nullif(sum(GSL_TWO),0) * 1000,4) reslutData,
        </if>
        <if test="type ='YLCB_TWO'">
            round(sum(YLZFY_TWO) / nullif(sum(GSL_TWO),0) * 1000,4) reslutData,
        </if>
        <if test="type ='PAMZSCB_TWO'">
            round(sum(PAMZSZFY) / nullif(sum(GSL_TWO),0) * 1000,4) reslutData,
        </if>
        <if test="type ='FTCB_TWO'">
            round(sum(FTZFY) / nullif(sum(GSL_TWO),0) * 1000,4) reslutData,
        </if>
        <if test="type ='GMSJFHYCB_TWO'">
            round(sum(GMSJFHYZFY) / nullif(sum(GSL_TWO),0) * 1000,4) reslutData,
        </if>
        <if test="type ='PAMWNCB_TWO'">
            round(sum(PAMWNZFY) / nullif(sum(GSL_TWO),0) * 1000,4) reslutData,
        </if>
        <if test="type ='WNZYCB_TWO'">
            round(sum(WNZYF) / nullif(sum(GSL_TWO),0) * 1000,4) reslutData,
        </if>
        <if test="type ='WNZYCB_TWO'">
            round(sum(DLDF_ONE),4) reslutData,
        </if>
        <if test="type ='DLDF_TWO'">
            round(sum(DLDF_TWO) ,4) reslutData,
        </if>
        <if test="type ='DLDF_TOTAL'">
            round(sum(DLDF_TOTAL) ,4) reslutData,
        </if>
        <if test="type ='DFCB_ONE'">
            round((sum(JBDF_ONE) + sum(DLDF_TWO)) / nullif(sum(GSL_ONE),0) * 1000,4) reslutData,
        </if>
        <if test="type ='DFCB_TWO'">
            round((sum(JBDF_TWO) + sum(DLDF_TWO)) / nullif(sum(GSL_TWO),0) * 1000,4) reslutData,
        </if>
        <if test="type ='DFCB_TOTAL'">
            round((sum(JBDF_TOTAL) + sum(DLDF_TOTAL)) / nullif(sum(GSL_TOTAL),0) * 1000,4) reslutData,
        </if>
        <if test="type ='YSF'">
            round(sum(YSF),4) reslutData,
        </if>
        <if test="type ='YSFCB'">
            round(sum(YSF) / nullif(sum(GSL_TOTAL),0) * 1000,4) reslutData,
        </if>
        <if test="type ='SZYSF_ONE'">
            round(sum(SZYSF_ONE),4) reslutData,
        </if>
        <if test="type ='SZYSF_TWO'">
            round(sum(SZYSF_TWO),4) reslutData,
        </if>
        <if test="type ='SZYSF_TOTAL'">
            round(sum(SZYSF_TOTAL) ,4) reslutData,
        </if>
        <if test="type ='SZYSFCB_ONE'">
            round(sum(SZYSF_ONE) / nullif(sum(GSL_ONE),0) * 1000,4) reslutData,
        </if>
        <if test="type ='SZYSFCB_TWO'">
            round(sum(SZYSF_TWO) / nullif(sum(GSL_TWO),0) * 1000,4) reslutData,
        </if>
        <if test="type ='SZYSFCB_TOTAL'">
            round(sum(SZYSF_TOTAL) / nullif(sum(GSL_TOTAL),0) * 1000,4) reslutData,
        </if>
        TO_CHAR(f.UP_DATE, 'yyyy') YEAR,
        TO_CHAR(f.UP_DATE, 'yyyy-Q') MONTH
        FROM TF_YWPN_COSTRLFIXED_W f left join TF_YWPN_COSTRLWATER_W w on to_char(f.UP_DATE,'yyyy-mm') =
        to_char(w.UP_DATE,'yyyy-mm') and f.MARK = w.MARK
        WHERE TO_CHAR(f.UP_DATE, 'yyyy') between #{startYear} and #{endYear}
        and f.MARK = '1'
        GROUP BY TO_CHAR(f.UP_DATE, 'yyyy-Q'), TO_CHAR(f.UP_DATE, 'yyyy')
        ORDER BY MONTH
    </select>

    <select id="getWaterDataYear" resultType="java.util.Map">
        SELECT UP_DATE YEAR, nvl(SUM(${typet}), 0) reslutData
        FROM (SELECT TO_CHAR(UP_DATE, 'yyyy') UP_DATE, nvl(${typet}, 0) ${typet}
              FROM TF_YWPN_COSTRLFIXED_W
              WHERE TO_CHAR(UP_DATE, 'yyyy') between #{startYear} and #{endYear}
                and MARK = '1')
        GROUP BY UP_DATE
        ORDER BY UP_DATE
    </select>

    <select id="getWaterDataYearTest" resultType="map">
        SELECT
        <if test="type = 'CNCB_ONE'">
            round(sum(CNZFY) / nullif(sum(GSL_ONE),0) * 1000,4) reslutData,
        </if>
        <if test="type = 'CNCB_TWO'">
            round(sum(CNZFY_TWO) / nullif(sum(GSL_TWO),0) * 1000,4) reslutData,
        </if>
        <if test="type ='PACCB_ONE'">
            round(sum(PACZFY_ONE) / nullif(sum(GSL_ONE),0) * 1000,4) reslutData,
        </if>
        <if test="type = 'SYCB_ONE'">
            round(sum(SYZFY_ONE) / nullif(sum(GSL_ONE),0) * 1000,4) reslutData,
        </if>
        <if test="type ='BCSCB_ONE'">
            round(sum(BCSZFY) / nullif(sum(GSL_ONE),0) * 1000,4) reslutData,
        </if>

        <if test="type ='PACCB_TWO'">
            round(sum(PACZFY_TWO) / nullif(sum(GSL_TWO),0) * 1000,4) reslutData,
        </if>
        <if test="type ='YLCB_TWO'">
            round(sum(YLZFY_TWO) / nullif(sum(GSL_TWO),0) * 1000,4) reslutData,
        </if>
        <if test="type ='PAMZSCB_TWO'">
            round(sum(PAMZSZFY) / nullif(sum(GSL_TWO),0) * 1000,4) reslutData,
        </if>
        <if test="type ='FTCB_TWO'">
            round(sum(FTZFY) / nullif(sum(GSL_TWO),0) * 1000,4) reslutData,
        </if>
        <if test="type ='GMSJFHYCB_TWO'">
            round(sum(GMSJFHYZFY) / nullif(sum(GSL_TWO),0) * 1000,4) reslutData,
        </if>
        <if test="type ='PAMWNCB_TWO'">
            round(sum(PAMWNZFY) / nullif(sum(GSL_TWO),0) * 1000,4) reslutData,
        </if>
        <if test="type ='WNZYCB_TWO'">
            round(sum(WNZYF) / nullif(sum(GSL_TWO),0) * 1000,4) reslutData,
        </if>
        <if test="type ='DLDF_ONE'">
            round(sum(DLDF_ONE),4) reslutData,
        </if>
        <if test="type ='DLDF_TWO'">
            round(sum(DLDF_TWO) ,4) reslutData,
        </if>
        <if test="type ='DLDF_TOTAL'">
            round(sum(DLDF_TOTAL) ,4) reslutData,
        </if>
        <if test="type ='DFCB_ONE'">
            round((sum(JBDF_ONE) + sum(DLDF_TWO)) / nullif(sum(GSL_ONE),0) * 1000,4) reslutData,
        </if>
        <if test="type ='DFCB_TWO'">
            round((sum(JBDF_TWO) + sum(DLDF_TWO)) / nullif(sum(GSL_TWO),0) * 1000,4) reslutData,
        </if>
        <if test="type ='DFCB_TOTAL'">
            round((sum(JBDF_TOTAL) + sum(DLDF_TOTAL)) / nullif(sum(GSL_TOTAL),0) * 1000,4) reslutData,
        </if>
        <if test="type ='YSF'">
            round(sum(YSF),4) reslutData,
        </if>
        <if test="type ='YSFCB'">
            round(sum(YSF) / nullif(sum(GSL_TOTAL),0) * 1000,4) reslutData,
        </if>
        <if test="type ='SZYSF_ONE'">
            round(sum(SZYSF_ONE),4) reslutData,
        </if>
        <if test="type ='SZYSF_TWO'">
            round(sum(SZYSF_TWO),4) reslutData,
        </if>
        <if test="type ='SZYSF_TOTAL'">
            round(sum(SZYSF_TOTAL) ,4) reslutData,
        </if>
        <if test="type ='SZYSFCB_ONE'">
            round(sum(SZYSF_ONE) / nullif(sum(GSL_ONE),0) * 1000,4) reslutData,
        </if>
        <if test="type ='SZYSFCB_TWO'">
            round(sum(SZYSF_TWO) / nullif(sum(GSL_TWO),0) * 1000,4) reslutData,
        </if>
        <if test="type ='SZYSFCB_TOTAL'">
            round(sum(SZYSF_TOTAL) / nullif(sum(GSL_TOTAL),0) * 1000,4) reslutData,
        </if>
        <if test="type = 'OTHERCB'">
            round(sum(OTHERZFY) / nullif(sum(GSL_ONE),0) * 1000,4) reslutData,
        </if>
        <if test="type = 'OTHER_ONE_CB'">
            round(sum(OTHER_ONE_ZFY) / nullif(sum(GSL_ONE),0) * 1000,4) reslutData,
        </if>
        <if test="type = 'OTHER_TWO_CB'">
            round(sum(OTHER_TWO_ZFY) / nullif(sum(GSL_TWO),0) * 1000,4) reslutData,
        </if>
        TO_CHAR(f.UP_DATE, 'yyyy') YEAR
        FROM TF_YWPN_COSTRLFIXED_W f left join TF_YWPN_COSTRLWATER_W w on to_char(f.UP_DATE,'yyyy-mm') =
        to_char(w.UP_DATE,'yyyy-mm') and f.MARK = w.MARK
        WHERE TO_CHAR(f.UP_DATE, 'yyyy') between #{startYear} and #{endYear}
        and f.MARK = '1'
        GROUP BY TO_CHAR(f.UP_DATE, 'yyyy')
        ORDER BY YEAR
    </select>

    <select id="sumWaterDataYear" resultType="double">
        SELECT
        <if test="type == 'OTHERCB'">
            round(sum(OTHERZFY) / nullif(sum(GSL_ONE),0) * 1000,4) val
        </if>
        <if test="type == 'OTHER_ONE_CB'">
            round(sum(OTHER_ONE_ZFY) / nullif(sum(GSL_ONE),0) * 1000,4) val
        </if>
        <if test="type == 'OTHER_TWO_CB'">
            round(sum(OTHER_TWO_ZFY) / nullif(sum(GSL_TWO),0) * 1000,4) val
        </if>
        <if test="type == 'CNCB_ONE'">
            round(sum(CNZFY) / nullif(sum(GSL_ONE),0) * 1000,4) val
        </if>
        <if test="type == 'CNCB_TWO'">
            round(sum(CNZFY_TWO) / nullif(sum(GSL_TWO),0) * 1000,4) val
        </if>
        <if test="type == 'PACCB_ONE'">
            round(sum(PACZFY_ONE) / nullif(sum(GSL_ONE),0) * 1000,4) val
        </if>
        <if test="type == 'SYCB_ONE'">
            round(sum(SYZFY_ONE) / nullif(sum(GSL_ONE),0) * 1000,4) val
        </if>
        <if test="type == 'BCSCB_ONE'">
            round(sum(BCSZFY) / nullif(sum(GSL_ONE),0) * 1000,4) val
        </if>

        <if test="type == 'PACCB_TWO'">
            round(sum(PACZFY_TWO) / nullif(sum(GSL_TWO),0) * 1000,4) val
        </if>
        <if test="type == 'YLCB_TWO'">
            round(sum(YLZFY_TWO) / nullif(sum(GSL_TWO),0) * 1000,4) val
        </if>
        <if test="type == 'PAMZSCB_TWO'">
            round(sum(PAMZSZFY) / nullif(sum(GSL_TWO),0) * 1000,4) val
        </if>
        <if test="type == 'FTCB_TWO'">
            round(sum(FTZFY) / nullif(sum(GSL_TWO),0) * 1000,4) val
        </if>
        <if test="type == 'GMSJFHYCB_TWO'">
            round(sum(GMSJFHYZFY) / nullif(sum(GSL_TWO),0) * 1000,4) val
        </if>
        <if test="type == 'PAMWNCB_TWO'">
            round(sum(PAMWNZFY) / nullif(sum(GSL_TWO),0) * 1000,4) val
        </if>
        <if test="type == 'WNZYCB_TWO'">
            round(sum(WNZYF) / nullif(sum(GSL_TWO),0) * 1000,4) val
        </if>
        <if test="type == 'DLDF_ONE'">
            round(sum(DLDF_ONE), 4) val
        </if>
        <if test="type == 'DLDF_TWO'">
            round(sum(DLDF_TWO) ,4) val
        </if>
        <if test="type == 'DLDF_TOTAL'">
            round(sum(DLDF_TOTAL) ,4) val
        </if>
        <if test="type == 'DFCB_ONE'">
            round((sum(JBDF_ONE) + sum(DLDF_ONE)) / nullif(sum(GSL_ONE),0) * 1000,4) val
        </if>
        <if test="type == 'DFCB_TWO'">
            round((sum(JBDF_TWO) + sum(DLDF_TWO)) / nullif(sum(GSL_TWO),0) * 1000,4) val
        </if>
        <if test="type == 'DFCB_TOTAL'">
            round((sum(JBDF_TOTAL) + sum(DLDF_TOTAL)) / nullif(sum(GSL_TOTAL),0) * 1000,4) val
        </if>
        <if test="type == 'YSF'">
            round(sum(YSF),4) val
        </if>
        <if test="type == 'YSFCB'">
            round(sum(YSF) / nullif(sum(GSL_TOTAL),0) * 1000,4) val
        </if>
        <if test="type == 'SZYSF_ONE'">
            round(sum(SZYSF_ONE),4) val
        </if>
        <if test="type == 'SZYSF_TWO'">
            round(sum(SZYSF_TWO),4) val
        </if>
        <if test="type == 'SZYSF_TOTAL'">
            round(sum(SZYSF_TOTAL) ,4) val
        </if>
        <if test="type == 'SZYSFCB_ONE'">
            round(sum(SZYSF_ONE) / nullif(sum(GSL_ONE),0) * 1000,4) val
        </if>
        <if test="type == 'SZYSFCB_TWO'">
            round(sum(SZYSF_TWO) / nullif(sum(GSL_TWO),0) * 1000,4) val
        </if>
        <if test="type == 'SZYSFCB_TOTAL'">
            round(sum(SZYSF_TOTAL) / nullif(sum(GSL_TOTAL),0) * 1000,4) val
        </if>
        FROM TF_YWPN_COSTRLFIXED_W f left join TF_YWPN_COSTRLWATER_W w on to_char(f.UP_DATE,'yyyy-mm') =
        to_char(w.UP_DATE,'yyyy-mm') and f.MARK = w.MARK
        where to_char(f.UP_DATE,'yyyy') = #{year}
        and f.mark = 1 and w.mark = 1
    </select>

    <select id="quaWaterDataYear" resultType="map">
        SELECT
        <if test="type == 'OTHERCB'">
            round(sum(OTHERZFY) / nullif(sum(GSL_ONE),0) * 1000,4) val,
        </if>
        <if test="type == 'OTHER_ONE_CB'">
            round(sum(OTHER_ONE_ZFY) / nullif(sum(GSL_ONE),0) * 1000,4) val,
        </if>
        <if test="type == 'OTHER_TWO_CB'">
            round(sum(OTHER_TWO_ZFY) / nullif(sum(GSL_TWO),0) * 1000,4) val,
        </if>
        <if test="type == 'CNCB_ONE'">
            round(sum(CNZFY) / nullif(sum(GSL_ONE),0) * 1000,4) val,
        </if>
        <if test="type == 'CNCB_TWO'">
            round(sum(CNZFY_TWO) / nullif(sum(GSL_TWO),0) * 1000,4) val,
        </if>
        <if test="type =='PACCB_ONE'">
            round(sum(PACZFY_ONE) / nullif(sum(GSL_ONE),0) * 1000,4) val,
        </if>
        <if test="type == 'SYCB_ONE'">
            round(sum(SYZFY_ONE) / nullif(sum(GSL_ONE),0) * 1000,4) val,
        </if>
        <if test="type =='BCSCB_ONE'">
            round(sum(BCSZFY) / nullif(sum(GSL_ONE),0) * 1000,4) val,
        </if>

        <if test="type =='PACCB_TWO'">
            round(sum(PACZFY_TWO) / nullif(sum(GSL_TWO),0) * 1000,4) val,
        </if>
        <if test="type =='YLCB_TWO'">
            round(sum(YLZFY_TWO) / nullif(sum(GSL_TWO),0) * 1000,4) val,
        </if>
        <if test="type =='PAMZSCB_TWO'">
            round(sum(PAMZSZFY) / nullif(sum(GSL_TWO),0) * 1000,4) val,
        </if>
        <if test="type =='FTCB_TWO'">
            round(sum(FTZFY) / nullif(sum(GSL_TWO),0) * 1000,4) val,
        </if>
        <if test="type =='GMSJFHYCB_TWO'">
            round(sum(GMSJFHYZFY) / nullif(sum(GSL_TWO),0) * 1000,4) val,
        </if>
        <if test="type =='PAMWNCB_TWO'">
            round(sum(PAMWNZFY) / nullif(sum(GSL_TWO),0) * 1000,4) val,
        </if>
        <if test="type =='WNZYCB_TWO'">
            round(sum(WNZYF) / nullif(sum(GSL_TWO),0) * 1000,4) val,
        </if>
        <if test="type =='DLDF_ONE'">
            round(sum(DLDF_ONE),4) val,
        </if>
        <if test="type =='DLDF_TWO'">
            round(sum(DLDF_TWO) ,4) val,
        </if>
        <if test="type =='DLDF_TOTAL'">
            round(sum(DLDF_TOTAL) ,4) val,
        </if>
        <if test="type =='DFCB_ONE'">
            round((sum(JBDF_ONE) + sum(DLDF_ONE)) / nullif(sum(GSL_ONE),0) * 1000,4) val,
        </if>
        <if test="type =='DFCB_TWO'">
            round((sum(JBDF_TWO) + sum(DLDF_TWO)) / nullif(sum(GSL_TWO),0) * 1000,4) val,
        </if>
        <if test="type =='DFCB_TOTAL'">
            round((sum(JBDF_TOTAL) + sum(DLDF_TOTAL)) / nullif(sum(GSL_TOTAL),0) * 1000,4) val,
        </if>
        <if test="type =='YSF'">
            round(sum(YSF),4) val,
        </if>
        <if test="type =='YSFCB'">
            round(sum(YSF) / nullif(sum(GSL_TOTAL),0) * 1000,4) val,
        </if>
        <if test="type =='SZYSF_ONE'">
            round(sum(SZYSF_ONE),4) val,
        </if>
        <if test="type =='SZYSF_TWO'">
            round(sum(SZYSF_TWO),4) val,
        </if>
        <if test="type =='SZYSF_TOTAL'">
            round(sum(SZYSF_TOTAL) ,4) val,
        </if>
        <if test="type =='SZYSFCB_ONE'">
            round(sum(SZYSF_ONE) / nullif(sum(GSL_ONE),0) * 1000,4) val,
        </if>
        <if test="type =='SZYSFCB_TWO'">
            round(sum(SZYSF_TWO) / nullif(sum(GSL_TWO),0) * 1000,4) val,
        </if>
        <if test="type =='SZYSFCB_TOTAL'">
            round(sum(SZYSF_TOTAL) / nullif(sum(GSL_TOTAL),0) * 1000,4) val,
        </if>
        TO_CHAR(f.UP_DATE, 'yyyy-Q') year
        FROM TF_YWPN_COSTRLFIXED_W f left join TF_YWPN_COSTRLWATER_W w on to_char(f.UP_DATE,'yyyy-mm') =
        to_char(w.UP_DATE,'yyyy-mm') and f.MARK = w.MARK
        where to_char(f.UP_DATE,'yyyy') = #{year}
        and f.mark = 1 and w.mark = 1
        group by TO_CHAR(f.UP_DATE, 'yyyy-Q')
        order by year
    </select>

    <select id="getUnitCostYear" resultType="java.util.Map">
        SELECT TO_CHAR(UP_DATE, 'yyyy') YEAR, TO_CHAR(UP_DATE, 'MM') MONTH, ${ccode}
        FROM TF_YWPN_COSTRLFIXED_W
        WHERE TO_CHAR(UP_DATE, 'yyyy') = #{year}
          and MARK = '1'
        ORDER BY MONTH
    </select>

    <select id="getUnitCostSumYear" resultType="map">
        select
        <choose>
            <when test="type == 714">
                nvl(round((sum(JBDF_ONE) + sum(DLDF_ONE)) / nullif(sum(GSL_ONE), 0) * 1000, 4),0) DFCB_ONE,
                nvl(round((sum(OTHERZFY) + sum(PACZFY_ONE) + sum(SYZFY_ONE) +sum(CNZFY) +sum(BCSZFY)) /
                nullif(sum(GSL_ONE), 0) * 1000, 4),0) ZSCLCB_ONE,
                nvl(round(sum(SZYSF_ONE) / nullif(sum(GSL_ONE), 0) * 1000, 4),0) SZYSFCB_ONE,
                nvl(round(sum(ZFY_ONE) / nullif(sum(GSL_ONE), 0) * 1000, 4),0) DWCB_ONE,
            </when>
            <when test="type == 715">
                nvl(round((sum(JBDF_TWO) + sum(DLDF_TWO)) / nullif(sum(GSL_TWO), 0) * 1000, 4) ,0) DFCB_TWO,
                nvl(round(sum(ZZSCLFY_TWO) / nullif(sum(GSL_TWO), 0) * 1000, 4) ,0) ZSCLCB_TWO,
                nvl(round(sum(SZYSF_TWO) / nullif(sum(GSL_TWO), 0) * 1000, 4) ,0) SZYSFCB_TWO,
                nvl(round(sum(ZFY_TWO) / nullif(sum(GSL_TWO), 0) * 1000, 4) ,0) DWCB_TWO,
            </when>
            <when test="type == 716">
                nvl(round(sum(YSF) / nullif(sum(GSL_TOTAL), 0) * 1000, 4) ,0) YSFCB,
                nvl(round((sum(JBDF_TOTAL) + sum(DLDF_TOTAL)) / nullif(sum(GSL_TOTAL), 0) * 1000, 4) ,0) DFCB_TOTAL,
                nvl(round((sum(ZZSCLFY_TWO) + sum(OTHERZFY) + sum(PACZFY_ONE) + sum(SYZFY_ONE) +sum(CNZFY) +sum(BCSZFY))
                / nullif(sum(GSL_TOTAL), 0) * 1000, 4) ,0) ZSCLCB_TOTAL,
                nvl(round(sum(SZYSF_TWO) / nullif(sum(GSL_TOTAL), 0) * 1000, 4) ,0) SZYSFCB_TOTAL,
                nvl(round(sum(ZFY) / nullif(sum(GSL_TOTAL), 0) * 1000, 4) ,0) DWCB_TOTAL,
            </when>
            <when test="type == 718">
                nvl(round(sum(PACZFY_ONE) / nullif(sum(GSL_ONE),0) * 1000 ,4) ,0) PACCB_ONE,
                nvl(round(sum(BCSZFY) / nullif(sum(GSL_ONE),0) * 1000 ,4) ,0) BCSCB_ONE,
                nvl(round(sum(SYZFY_ONE) / nullif(sum(GSL_ONE),0) * 1000 ,4) ,0) SYCB_ONE,
                nvl(round(sum(CNZFY) / nullif(sum(GSL_ONE),0) * 1000 ,4) ,0) CNCB_ONE,
                nvl(round((sum(OTHERZFY) + sum(PACZFY_ONE) + sum(SYZFY_ONE) +sum(CNZFY) +sum(BCSZFY)) /
                nullif(sum(GSL_ONE), 0) * 1000, 4),0) ZSCLCB_ONE,
            </when>
            <when test="type == 719">
                nvl(round(sum(PACZFY_TWO) / nullif(sum(GSL_TWO),0) * 1000 ,4) ,0) PACCB_TWO,
                nvl(round(sum(CNZFY_TWO) / nullif(sum(GSL_TWO),0) * 1000 ,4) ,0) CNCB_TWO,
                nvl(round(sum(PAMZSZFY) / nullif(sum(GSL_TWO),0) * 1000 ,4) ,0) PAMZSCB_TWO,
                nvl(round(sum(YLZFY_TWO) / nullif(sum(GSL_TWO),0) * 1000 ,4) ,0) YLCB_TWO,
                nvl(round(sum(FTZFY) / nullif(sum(GSL_TWO),0) * 1000 ,4) ,0) FTCB_TWO,
                nvl(round(sum(GMSJFHYZFY) / nullif(sum(GSL_TWO),0) * 1000 ,4) ,0) GMSJFHYCB_TWO,
                nvl(round(sum(PAMWNZFY) / nullif(sum(GSL_TWO),0) * 1000 ,4) ,0) PAMWNCB_TWO,
                nvl(round(sum(WNZYF) / nullif(sum(GSL_TWO),0) * 1000 ,4) ,0) WNZYCB_TWO,
                nvl(round(sum(ZZSCLFY_TWO) / nullif(sum(GSL_TWO), 0) * 1000, 4) ,0) ZSCLCB_TWO,
            </when>
            <when test="type == 720">
                nvl(round(sum(ZZSCLFY_ONE) / nullif(sum(GSL_ONE), 0) * 1000, 4),0) ZSCLCB_ONE,
                nvl(round(sum(ZZSCLFY_TWO) / nullif(sum(GSL_TWO), 0) * 1000, 4) ,0) ZSCLCB_TWO,
                nvl(round((sum(ZZSCLFY_TWO) + sum(OTHERZFY) + sum(PACZFY_ONE) + sum(SYZFY_ONE) +sum(CNZFY) +sum(BCSZFY))
                / nullif(sum(GSL_TOTAL), 0) * 1000, 4) ,0) ZSCLCB_TOTAL,
            </when>
        </choose>
        to_char(f.UP_DATE, 'yyyy') year
        from TF_YWPN_COSTRLFIXED_W f
        left join TF_YWPN_COSTRLWATER_W w on to_char(f.UP_DATE, 'yyyy-mm') = to_char(w.UP_DATE, 'yyyy-mm') and f.MARK =
        w.MARK
        where f.MARK = 1
        and to_char(f.UP_DATE, 'yyyy') = #{year}
        group by to_char(f.UP_DATE, 'yyyy')
        order by year
    </select>

    <select id="getUnitCostYearMonth" resultType="java.util.Map">
        SELECT TO_CHAR(UP_DATE, 'yyyy') YEAR, TO_CHAR(UP_DATE, 'yyyy-MM') MONTH, ${ccode}
        FROM TF_YWPN_COSTRLFIXED_W
        WHERE TO_CHAR(UP_DATE, 'yyyy') IN (${year})
          and TO_CHAR(UP_DATE, 'MM') IN (${month})
          and MARK = '1'
        ORDER BY UP_DATE
    </select>
    <select id="getCodeByFId" resultType="map">
        select CCODE, CNAME, CCONTERT
        from TF_YWPN_SYSCHILDCODE_D
        where PCID = #{typeId}
    </select>

    <select id="getGetWater" resultType="com.tofly.xrtygis.custom.entity.dataquery.GetMongWater">
        SELECT TO_CHAR(UP_DATE, 'MM') MONTH, NVL(${value}, 0) GSL
        FROM TF_YWPN_COSTRLWATER_W
        WHERE MARK = '1'
          AND TO_CHAR(UP_DATE, 'yyyy') = #{year}
    </select>
    <select id="getCodeByIds" resultType="java.util.Map">
        select ID,CCODE , CNAME , CCONTERT from TF_YWPN_SYSCHILDCODE_D where
        ID IN
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </select>

    <select id="getIndexName" resultType="string">
        select CNAME from TF_YWPN_SYSCHILDCODE_D where PCID in (684,696,703,706,713,717) and CCODE = #{index}
    </select>


</mapper>
