<?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.CostrlwaterMapper">

    <resultMap id="costrlwaterMap" type="com.tofly.xrtygis.entity.Costrlwater">
        <id property="id" column="ID"/>
        <result property="upDate" column="UP_DATE"/>
        <result property="gslOne" column="GSL_ONE"/>
        <result property="gslTwo" column="GSL_TWO"/>
        <result property="gslQbj" column="GSL_QBJ"/>
        <result property="gslTotal" column="GSL_TOTAL"/>
        <result property="zslOne" column="ZSL_ONE"/>
        <result property="zslTwo" column="ZSL_TWO"/>
        <result property="zslHqsk" column="ZSL_HQSK"/>
        <result property="zslTotal" column="ZSL_TOTAL"/>
        <result property="sslTotal" column="SSL_TOTAL"/>
        <result property="zyslOne" column="ZYSL_ONE"/>
        <result property="zyslTwo" column="ZYSL_TWO"/>
        <result property="zyslTotal" column="ZYSL_TOTAL"/>
        <result property="zysllOne" column="ZYSLL_ONE"/>
        <result property="zysllTwo" column="ZYSLL_TWO"/>
        <result property="zysllTotal" column="ZYSLL_TOTAL"/>
        <result property="wspsl" column="WSPSL"/>
        <result property="cxc" column="CXC"/>
        <result property="lsl" column="LSL"/>
        <result property="pacOne" column="PAC_ONE"/>
        <result property="pacTwo" column="PAC_TWO"/>
        <result property="syOne" column="SY_ONE"/>
        <result property="ylTwo" column="YL_TWO"/>
        <result property="pam" column="PAM"/>
        <result property="ft" column="FT"/>
        <result property="cn" column="CN"/>
        <result property="gmsjfhy" column="GMSJFHY"/>
        <result property="pamWy" column="PAM_WY"/>
        <result property="bcs" column="BCS"/>
        <result property="wnzl" column="WNZL"/>
        <result property="dldlOne" column="DLDL_ONE"/>
        <result property="dldlTwo" column="DLDL_TWO"/>
        <result property="dldlTotal" column="DLDL_TOTAL"/>
        <result property="jbdlOne" column="JBDL_ONE"/>
        <result property="jbdlTwo" column="JBDL_TWO"/>
        <result property="jbdlTotal" column="JBDL_TOTAL"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="mark" column="MARK"/>
        <result property="other" column="OTHER"/>
        <result property="otherOne" column="OTHER_ONE"/>
        <result property="otherTwo" column="OTHER_TWO"/>
        <association property="createUserName" column="CREATE_USER"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
    </resultMap>
    <!--<![CDATA[ >= ]]>  <![CDATA[ <= ]]>-->
    <!--    GSL_ONE,GSL_TWO,GSL_QBJ,GSL_TOTAL,
                   ZSL_ONE,ZSL_TWO,ZSL_HQSK,ZSL_TOTAL,SSL_TOTAL,ZYSL_ONE,ZYSL_TWO,ZYSL_TOTAL,ZYSLL_ONE,ZYSLL_TWO,ZYSLL_TOTAL,WSPSL-->
    <select id="getWaterDataMonth" resultType="java.util.Map">
        SELECT TO_CHAR(UP_DATE, 'yyyy')    YEAR,
               TO_CHAR(UP_DATE, 'yyyy-MM') UP_DATE,
               TO_CHAR(UP_DATE, 'MM')      MONTH,
               ${typet}
        FROM TF_YWPN_COSTRLWATER_W
        WHERE MARK = '1'
          AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ <= ]]> #{endYear}
          AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ >= ]]> #{startYear}
        ORDER BY UP_DATE
    </select>

    <select id="getWaterDataQuarter" resultType="java.util.Map">
        SELECT SUBSTR(UP_DATE, 1, 4) YEAR, UP_DATE MONTH, ${sumType}
        FROM (SELECT TO_CHAR(UP_DATE, 'yyyy-Q') UP_DATE,
                     ${typet}
              FROM TF_YWPN_COSTRLWATER_W
              WHERE MARK = '1'
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ <= ]]> #{endYear}
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ >= ]]> #{startYear})
        GROUP BY UP_DATE
        ORDER BY UP_DATE
    </select>
    <!--SUM(GSL_ONE) GSL_ONE , SUM(GSL_TWO) GSL_TWO, SUM(GSL_QBJ) GSL_QBJ, SUM(GSL_TOTAL) GSL_TOTAL,
                   SUM(ZSL_ONE) ZSL_ONE,  SUM(ZSL_TWO) ZSL_TWO, SUM(ZSL_HQSK) ZSL_HQSK, SUM(ZSL_TOTAL) ZSL_TOTAL,
                   SUM(SSL_TOTAL) SSL_TOTAL, SUM(ZYSL_ONE) ZYSL_ONE, SUM(ZYSL_TWO) ZYSL_TWO, SUM(ZYSL_TOTAL) ZYSL_TOTAL,
                   SUM(ZYSLL_ONE) ZYSLL_ONE, SUM(ZYSLL_TWO) ZYSLL_TWO, SUM(ZYSLL_TOTAL) ZYSLL_TOTAL, SUM(WSPSL) WSPSL-->
    <select id="getWaterDataYear" resultType="java.util.Map">
        SELECT UP_DATE YEAR, ${sumType}
        FROM (SELECT TO_CHAR(UP_DATE, 'yyyy') UP_DATE,
                     ${typet}
              FROM TF_YWPN_COSTRLWATER_W
              WHERE MARK = '1'
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ <= ]]> #{endYear}
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ >= ]]> #{startYear})
        GROUP BY UP_DATE
        ORDER BY UP_DATE
    </select>

    <select id="sumWaterData" resultType="double">
        select
        <choose>
            <when test="type == 632">
                round(sum(GSL_ONE),4) GSL_ONE
            </when>
            <when test="type == 633">
                round(sum(GSL_TWO),4) GSL_TWO
            </when>
            <when test="type == 634">
                round(sum(GSL_QBJ),4) GSL_QBJ
            </when>

            <when test="type == 635">
                round(sum(GSL_TOTAL),4) GSL_TOTAL
            </when>
            <when test="type == 636">
                round(sum(ZSL_ONE),4) ZSL_ONE
            </when>
            <when test="type == 637">
                round(sum(ZSL_TWO),4) ZSL_TWO
            </when>
            <when test="type == 638">
                round(sum(ZSL_HQSK),4) ZSL_HQSK
            </when>
            <when test="type == 639">
                round(sum(ZSL_TOTAL),4) ZSL_TOTAL
            </when>
            <when test="type == 640">
                round(sum(SSL_TOTAL),4) SSL_TOTAL
            </when>
            <when test="type == 641">
                round(sum(ZYSL_ONE),4) ZYSL_ONE
            </when>
            <when test="type == 642">
                round(sum(ZYSL_TWO),4) ZYSL_TWO
            </when>
            <when test="type == 643">
                round(sum(ZYSL_TOTAL),4) ZYSL_TOTAL
            </when>
            <when test="type == 644">
                round(sum(ZYSL_ONE) / nullif(sum(ZSL_ONE),0) * 100,4) ZYSLL_ONE
            </when>
            <when test="type == 645">
                round(sum(ZYSL_TWO) / nullif(sum(ZSL_TWO),0) * 100,4) ZYSLL_TWO
            </when>
            <when test="type == 646">
                round(sum(ZYSL_TOTAL) / nullif(sum(ZSL_TOTAL),0) * 100,4) ZYSLL_TOTAL
            </when>
            <when test="type == 647">
                round(sum(WSPSL),4) WSPSL
            </when>
            <otherwise/>
        </choose>
        from TF_YWPN_COSTRLWATER_W
        WHERE MARK = '1'
        AND TO_CHAR(UP_DATE, 'yyyy') = #{year}
    </select>

    <select id="quaWaterData" resultType="map">
        select
        <choose>
            <when test="type == 632">
                round(sum(GSL_ONE),4) val,
            </when>
            <when test="type == 633">
                round(sum(GSL_TWO),4) val,
            </when>
            <when test="type == 634">
                round(sum(GSL_QBJ),4) val,
            </when>

            <when test="type == 635">
                round(sum(GSL_TOTAL),4) val,
            </when>
            <when test="type == 636">
                round(sum(ZSL_ONE),4) val,
            </when>
            <when test="type == 637">
                round(sum(ZSL_TWO),4) val,
            </when>
            <when test="type == 638">
                round(sum(ZSL_HQSK),4) val,
            </when>
            <when test="type == 639">
                round(sum(ZSL_TOTAL),4) val,
            </when>
            <when test="type == 640">
                round(sum(SSL_TOTAL),4) val,
            </when>
            <when test="type == 641">
                round(sum(ZYSL_ONE),4) val,
            </when>
            <when test="type == 642">
                round(sum(ZYSL_TWO),4) val,
            </when>
            <when test="type == 643">
                round(sum(ZYSL_TOTAL),4) val,
            </when>
            <when test="type == 644">
                round(sum(ZYSL_ONE) / nullif(sum(ZSL_ONE),0) * 100,4) val,
            </when>
            <when test="type == 645">
                round(sum(ZYSL_TWO) / nullif(sum(ZSL_TWO),0) * 100,4) val,
            </when>
            <when test="type == 646">
                round(sum(ZYSL_TOTAL) / nullif(sum(ZSL_TOTAL),0) * 100,4) val,
            </when>
            <when test="type == 647">
                round(sum(WSPSL),4) val,
            </when>
            <otherwise/>
        </choose>
        TO_CHAR(UP_DATE, 'yyyy-Q') year
        from TF_YWPN_COSTRLWATER_W
        WHERE MARK = '1'
        AND TO_CHAR(UP_DATE, 'yyyy') =#{year}
        group by TO_CHAR(UP_DATE, 'yyyy-Q')
        ORDER BY year
    </select>

    <select id="getElectricityDataMonth" resultType="java.util.Map">
        SELECT TO_CHAR(UP_DATE, 'yyyy')    YEAR,
               TO_CHAR(UP_DATE, 'yyyy-MM') UP_DATE,
               TO_CHAR(UP_DATE, 'MM')      MONTH,
               ${typet}
        FROM ${tableName}
        WHERE MARK = '1'
          AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ <= ]]> #{endYear}
          AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ >= ]]> #{startYear}
        ORDER BY UP_DATE
    </select>

    <select id="getElectricityDataQuarter" resultType="java.util.Map">
        SELECT SUBSTR(UP_DATE, 1, 4) YEAR, UP_DATE MONTH, ${sumType}
        FROM (SELECT TO_CHAR(UP_DATE, 'yyyy-Q') UP_DATE, ${typet}
              FROM ${tableName}
              WHERE MARK = '1'
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ <= ]]> #{endYear}
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ >= ]]> #{startYear})
        GROUP BY UP_DATE
        ORDER BY UP_DATE
    </select>

    <select id="getElectricityDataYear" resultType="java.util.Map">
        SELECT UP_DATE YEAR, ${sumType}
        FROM (SELECT TO_CHAR(UP_DATE, 'yyyy') UP_DATE, ${typet}
              FROM ${tableName}
              WHERE MARK = '1'
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ <= ]]> #{endYear}
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ >= ]]> #{startYear})
        GROUP BY UP_DATE
        ORDER BY UP_DATE
    </select>

    <select id="sumElectricQuantity" resultType="double">
        select
        <choose>
            <when test="type == 651">
                round(sum(DLDL_ONE),4) val
            </when>
            <when test="type == 652">
                round(sum(DLDL_TWO),4) val
            </when>
            <when test="type == 653">
                round(sum(DLDL_TOTAL),4) val
            </when>
            <when test="type == 654">
                round(sum(DLDL_ONE) / (nullif(sum(ZSL_ONE),0) * 10),4) val
            </when>
            <when test="type == 655">
                round(sum(DLDL_TWO) / (nullif(sum(ZSL_TWO),0) * 10),4) val
            </when>
            <when test="type == 656">
                round(sum(DLDL_TOTAL) / (nullif(sum(ZSL_TOTAL),0) * 10),4) val
            </when>
            <otherwise/>
        </choose>
        from TF_YWPN_COSTRLWATER_W
        where MARK = 1
        and to_char(UP_DATE, 'yyyy') = #{year}
    </select>

    <select id="quaElectricQuantity" resultType="map">
        select
        <choose>
            <when test="type == 651">
                round(sum(DLDL_ONE),4) val,
            </when>
            <when test="type == 652">
                round(sum(DLDL_TWO),4) val,
            </when>
            <when test="type == 653">
                round(sum(DLDL_TOTAL),4) val,
            </when>
            <when test="type == 654">
                round(sum(DLDL_ONE) / (nullif(sum(ZSL_ONE),0) * 10),4) val,
            </when>
            <when test="type == 655">
                round(sum(DLDL_TWO) / (nullif(sum(ZSL_TWO),0) * 10),4) val,
            </when>
            <when test="type == 656">
                round(sum(DLDL_TOTAL) / (nullif(sum(ZSL_TOTAL),0) * 10),4) val,
            </when>
            <otherwise/>
        </choose>
        to_char(UP_DATE,'yyyy-Q') year
        from TF_YWPN_COSTRLWATER_W
        where MARK = 1
        and to_char(UP_DATE, 'yyyy') = #{year}
        group by to_char(UP_DATE,'yyyy-Q')
        order by year
    </select>

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

    <select id="getMaterialsDataQuarter" resultType="java.util.Map">
        SELECT SUBSTR(UP_DATE, 1, 4) YEAR, UP_DATE MONTH, ${sumType}
        FROM (SELECT TO_CHAR(UP_DATE, 'yyyy-Q') UP_DATE, ${typet}
              FROM TF_YWPN_COSTRLUNIT_W
              WHERE MARK = '1'
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ <= ]]> #{endYear}
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ >= ]]> #{startYear})
        GROUP BY UP_DATE
        ORDER BY UP_DATE
    </select>

    <select id="getMaterialsDataQuarterTest" resultType="map">
        SELECT
        <if test="type.contains('658')">
            round(sum(cn) / (nullif(sum(ZSL_ONE),0) * 10),4) cndh,
        </if>
        <if test="type.contains('659')">
            round(sum(GMSJFHY) / (nullif(sum(ZSL_TWO),0) * 10),4) gmsjdh,
        </if>
        <if test="type.contains('660')">
            round(sum(PAM) / (nullif(sum(ZSL_TWO),0) * 10),4) pamdh,
        </if>
        <if test="type.contains('661')">
            round(sum(PAM_WY) / (nullif(sum(ZSL_TWO),0) * 10),4) pamwndh,
        </if>
        <if test="type.contains('662')">
            round(sum(WNZL) / (nullif(sum(ZSL_TWO),0) * 10),4) wnzydh,
        </if>
        <if test="type.contains('663')">
            round(sum(FT) / (nullif(sum(ZSL_TWO),0) * 10),4) ftdh,
        </if>
        <if test="type.contains('664')">
            round(sum(BCS) / (nullif(sum(ZSL_ONE),0) * 10),4) bcsdh,
        </if>
        <if test="type.contains('1017')">
            round(sum(cn_two) / (nullif(sum(ZSL_TWO),0) * 10),4) cndh_two,
        </if>
        <if test="type.contains('1021')">
            round(sum(OTHER) / (nullif(sum(ZSL_ONE),0) * 10),4) otherdh,
        </if>
        <if test="type.contains('1022')">
            round(sum(OTHER_ONE) / (nullif(sum(ZSL_ONE),0) * 10),4) other_one_dh,
        </if>
        <if test="type.contains('1023')">
            round(sum(OTHER_TWO) / (nullif(sum(ZSL_TWO),0) * 10),4) other_two_dh,
        </if>
        <if test="type.contains('665')">
            round(sum(PAC_ONE) / (nullif(sum(ZSL_ONE),0) * 10),4) pacdh_one,
        </if>
        <if test="type.contains('666')">
            round(sum(PAC_TWO) / (nullif(sum(ZSL_TWO),0) * 10),4) pacdh_two,
        </if>
        <if test="type.contains('667')">
            round(sum(SY_ONE) / (nullif(sum(ZSL_ONE),0) * 10),4) sydh_one,
        </if>
        <if test="type.contains('668')">
            round(sum(YL_TWO) / (nullif(sum(ZSL_TWO),0) * 10),4) yldh_two,
        </if>
        TO_CHAR(UP_DATE, 'yyyy-Q') MONTH,
        TO_CHAR(UP_DATE, 'yyyy') YEAR
        FROM TF_YWPN_COSTRLWATER_W
        WHERE MARK = '1'
        AND TO_CHAR(UP_DATE, 'yyyy-Q') between #{endYear} and #{startYear}
        group by TO_CHAR(UP_DATE, 'yyyy-Q'),TO_CHAR(UP_DATE, 'yyyy')
        ORDER BY month
    </select>

    <select id="getMaterialsDataYear" resultType="java.util.Map">
        SELECT UP_DATE YEAR, ${sumType}
        FROM (SELECT TO_CHAR(UP_DATE, 'yyyy') UP_DATE, ${typet}
              FROM TF_YWPN_COSTRLUNIT_W
              WHERE MARK = '1'
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ <= ]]> #{endYear}
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ >= ]]> #{startYear})
        GROUP BY UP_DATE
        ORDER BY UP_DATE
    </select>

    <select id="getMaterialsDataYearTest" resultType="map">
        SELECT
        <if test="type.contains('658')">
            round(sum(cn) / (nullif(sum(ZSL_ONE),0) * 10),4) cndh,
        </if>
        <if test="type.contains('659')">
            round(sum(GMSJFHY) / (nullif(sum(ZSL_TWO),0) * 10),4) gmsjdh,
        </if>
        <if test="type.contains('660')">
            round(sum(PAM) / (nullif(sum(ZSL_TWO),0) * 10),4) pamdh,
        </if>
        <if test="type.contains('661')">
            round(sum(PAM_WY) / (nullif(sum(ZSL_TWO),0) * 10),4) pamwndh,
        </if>
        <if test="type.contains('662')">
            round(sum(WNZL) / (nullif(sum(ZSL_TWO),0) * 10),4) wnzydh,
        </if>
        <if test="type.contains('663')">
            round(sum(FT) / (nullif(sum(ZSL_TWO),0) * 10),4) ftdh,
        </if>
        <if test="type.contains('664')">
            round(sum(BCS) / (nullif(sum(ZSL_ONE),0) * 10),4) bcsdh,
        </if>
        <if test="type.contains('1017')">
            round(sum(cn_two) / (nullif(sum(ZSL_TWO),0) * 10),4) cndh_two,
        </if>
        <if test="type.contains('1021')">
            round(sum(OTHER) / (nullif(sum(ZSL_ONE),0) * 10),4) otherdh,
        </if>
        <if test="type.contains('1022')">
            round(sum(OTHER_ONE) / (nullif(sum(ZSL_ONE),0) * 10),4) other_one_dh,
        </if>
        <if test="type.contains('1023')">
            round(sum(OTHER_TWO) / (nullif(sum(ZSL_TWO),0) * 10),4) other_two_dh,
        </if>
        <if test="type.contains('665')">
            round(sum(PAC_ONE) / (nullif(sum(ZSL_ONE),0) * 10),4) pacdh_one,
        </if>
        <if test="type.contains('666')">
            round(sum(PAC_TWO) / (nullif(sum(ZSL_TWO),0) * 10),4) pacdh_two,
        </if>
        <if test="type.contains('667')">
            round(sum(SY_ONE) / (nullif(sum(ZSL_ONE),0) * 10),4) sydh_one,
        </if>
        <if test="type.contains('668')">
            round(sum(YL_TWO) / (nullif(sum(ZSL_TWO),0) * 10),4) yldh_two,
        </if>
        TO_CHAR(UP_DATE, 'yyyy') year
        FROM TF_YWPN_COSTRLWATER_W
        WHERE MARK = '1'
        AND TO_CHAR(UP_DATE, 'yyyy') between #{endYear} and #{startYear}
        group by TO_CHAR(UP_DATE, 'yyyy')
        ORDER BY year
    </select>

    <select id="sumMaterialsDataYearTest" resultType="double">
        SELECT
        <choose>
            <when test="type == 1022">
                round(sum(OTHER_ONE) / (nullif(sum(ZSL_ONE),0) * 10),4) val
            </when>
            <when test="type == 1023">
                round(sum(OTHER_TWO) / (nullif(sum(ZSL_ONE),0) * 10),4) val
            </when>
            <when test="type == 1021">
                round(sum(OTHER) / (nullif(sum(ZSL_ONE),0) * 10),4) val
            </when>
            <when test="type == 658">
                round(sum(cn) / (nullif(sum(ZSL_ONE),0) * 10),4) val
            </when>
            <when test="type == 659">
                round(sum(GMSJFHY) / (nullif(sum(ZSL_TWO),0) * 10),4) val
            </when>
            <when test="type == 660">
                round(sum(PAM) / (nullif(sum(ZSL_TWO),0) * 10),4) val
            </when>
            <when test="type == 661">
                round(sum(PAM_WY) / (nullif(sum(ZSL_TWO),0) * 10),4) val
            </when>
            <when test="type == 662">
                round(sum(WNZL) / (nullif(sum(ZSL_TWO),0) * 10),4) val
            </when>
            <when test="type == 663">
                round(sum(FT) / (nullif(sum(ZSL_TWO),0) * 10),4) val
            </when>
            <when test="type == 664">
                round(sum(BCS) / (nullif(sum(ZSL_ONE),0) * 10),4) val
            </when>
            <when test="type == 1017">
                round(sum(cn_two) / (nullif(sum(ZSL_TWO),0) * 10),4) val
            </when>
            <when test="type == 665">
                round(sum(PAC_ONE) / (nullif(sum(ZSL_ONE),0) * 10),4) val
            </when>
            <when test="type == 666">
                round(sum(PAC_TWO) / (nullif(sum(ZSL_TWO),0) * 10),4) val
            </when>
            <when test="type == 667">
                round(sum(SY_ONE) / (nullif(sum(ZSL_ONE),0) * 10),4) val
            </when>
            <when test="type == 668">
                round(sum(YL_TWO) / (nullif(sum(ZSL_TWO),0) * 10),4) val
            </when>
            <otherwise/>
        </choose>
        FROM TF_YWPN_COSTRLWATER_W
        WHERE MARK = '1'
        AND TO_CHAR(UP_DATE, 'yyyy') = #{startYear}
    </select>

    <select id="quaMaterialsDataYearTest" resultType="map">
        SELECT
        <choose>
            <when test="type == 1022">
                round(sum(OTHER_ONE) / (nullif(sum(ZSL_ONE),0) * 10),4) val,
            </when>
            <when test="type == 1023">
                round(sum(OTHER_TWO) / (nullif(sum(ZSL_ONE),0) * 10),4) val,
            </when>
            <when test="type == 1021">
                round(sum(OTHER) / (nullif(sum(ZSL_ONE),0) * 10),4) val,
            </when>
            <when test="type == 658">
                round(sum(cn) / (nullif(sum(ZSL_ONE),0) * 10),4) val,
            </when>
            <when test="type == 659">
                round(sum(GMSJFHY) / (nullif(sum(ZSL_TWO),0) * 10),4) val,
            </when>
            <when test="type == 660">
                round(sum(PAM) / (nullif(sum(ZSL_TWO),0) * 10),4) val,
            </when>
            <when test="type == 661">
                round(sum(PAM_WY) / (nullif(sum(ZSL_TWO),0) * 10),4) val,
            </when>
            <when test="type == 662">
                round(sum(WNZL) / (nullif(sum(ZSL_TWO),0) * 10),4) val,
            </when>
            <when test="type == 663">
                round(sum(FT) / (nullif(sum(ZSL_TWO),0) * 10),4) val,
            </when>
            <when test="type == 664">
                round(sum(BCS) / (nullif(sum(ZSL_ONE),0) * 10),4) val,
            </when>
            <when test="type == 1017">
                round(sum(cn_two) / (nullif(sum(ZSL_TWO),0) * 10),4) val,
            </when>
            <when test="type == 665">
                round(sum(PAC_ONE) / (nullif(sum(ZSL_ONE),0) * 10),4) val,
            </when>
            <when test="type == 666">
                round(sum(PAC_TWO) / (nullif(sum(ZSL_TWO),0) * 10),4) val,
            </when>
            <when test="type == 667">
                round(sum(SY_ONE) / (nullif(sum(ZSL_ONE),0) * 10),4) val,
            </when>
            <when test="type == 668">
                round(sum(YL_TWO) / (nullif(sum(ZSL_TWO),0) * 10),4) val,
            </when>
            <otherwise/>
        </choose>
        to_char(UP_DATE,'yyyy-Q') year
        FROM TF_YWPN_COSTRLWATER_W
        WHERE MARK = '1'
        AND TO_CHAR(UP_DATE, 'yyyy') = #{year}
        group by to_char(UP_DATE,'yyyy-Q')
    </select>

    <select id="getPriceDataMonth" resultType="java.util.Map">
        SELECT YEAR, TO_CHAR(UP_DATE, 'yyyy-MM') CRET_TIME, TO_CHAR(UP_DATE, 'MM') MONTH, ${typet}
        FROM TF_YWPN_COSTRLPRICE_W
        WHERE ID IN (
            SELECT MAX(ID)
            FROM (SELECT ID
                       , TO_CHAR(UP_DATE
                    , 'yyyy-MM') CRET_TIME
                       , YEAR
                  FROM TF_YWPN_COSTRLPRICE_W
                  WHERE YEAR <![CDATA[ >= ]]> #{startYear}
                    and YEAR <![CDATA[ <= ]]> #{endYear})
            GROUP BY CRET_TIME, YEAR)
        ORDER BY UP_DATE ASC
    </select>
    <select id="getPriceDataQuarter" resultType="java.util.Map">
        SELECT YEAR, TO_CHAR(UP_DATE, 'yyyy-Q') MONTH, ${typet}
        FROM TF_YWPN_COSTRLPRICE_W
        WHERE ID IN (SELECT MAX(ID)
                     FROM (SELECT ID
                                , YEAR
                                , TO_CHAR(UP_DATE
                             , 'yyyy-Q') quarter
                           FROM TF_YWPN_COSTRLPRICE_W
                           WHERE YEAR <![CDATA[ >= ]]> #{startYear}
                             and YEAR <![CDATA[ <= ]]> #{endYear})
                     GROUP BY quarter, YEAR)
        ORDER BY UP_DATE
    </select>
    <select id="getPriceDataYear" resultType="java.util.Map">
        SELECT YEAR, TO_CHAR(UP_DATE, 'yyyy-MM') CRET_TIME, ${typet}
        FROM TF_YWPN_COSTRLPRICE_W
        WHERE YEAR <![CDATA[ >= ]]> #{startYear}
          and YEAR <![CDATA[ <= ]]> #{endYear}
          and ISNEW = '1'
        ORDER BY UP_DATE
    </select>

    <select id="getProduceDataYearReality" resultMap="costrlwaterMap2">
        SELECT UP_DATE,
               round(SUM(GSL_ONE), 4)                                                                               GSL_ONE,
               round(SUM(GSL_TWO), 4)                                                                               GSL_TWO,
               round(SUM(GSL_QBJ), 4)                                                                               GSL_QBJ,
               round(SUM(GSL_TOTAL), 4)                                                                             GSL_TOTAL,
               round(SUM(ZSL_ONE), 4)                                                                               ZSL_ONE,
               round(SUM(ZSL_TWO), 4)                                                                               ZSL_TWO,
               round(SUM(ZSL_HQSK), 4)                                                                              ZSL_HQSK,
               round(SUM(ZSL_TOTAL), 4)                                                                             ZSL_TOTAL,
               round(SUM(SSL_TOTAL), 4)                                                                             SSL_TOTAL,
               round(SUM(ZYSL_ONE), 4)                                                                              ZYSL_ONE,
               round(SUM(ZYSL_TWO), 4)                                                                              ZYSL_TWO,
               round(SUM(ZYSL_TOTAL), 4)                                                                            ZYSL_TOTAL,
               round((SUM(ZYSL_ONE) / nullif(sum(ZSL_ONE), 0)) * 100, 2)                                            ZYSLL_ONE,
               round((SUM(ZYSL_TWO) / nullif(sum(ZSL_TWO), 0)) * 100, 2)                                            ZYSLL_TWO,
               round((SUM(ZYSL_TOTAL) / nullif(sum(ZSL_TOTAL), 0)) * 100, 2)                                        ZYSLL_TOTAL,
               SUM(WSPSL)                                                                                           WSPSL,
               round(((sum(GSL_TOTAL) + sum(GSL_QBJ) - sum(SSL_TOTAL)) / (sum(GSL_QBJ) + sum(GSL_TOTAL))) * 100, 2) CXC,
               round(((sum(GSL_TOTAL) + sum(GSL_QBJ) - sum(SSL_TOTAL) - sum(WSPSL)) / (sum(GSL_QBJ) + sum(GSL_TOTAL))) *
                     100, 2)                                                                                        LSL
        FROM (SELECT TO_CHAR(UP_DATE, 'yyyy') UP_DATE,
                     GSL_ONE,
                     GSL_TWO,
                     GSL_QBJ,
                     GSL_TOTAL,
                     ZSL_ONE,
                     ZSL_TWO,
                     ZSL_HQSK,
                     ZSL_TOTAL,
                     SSL_TOTAL,
                     ZYSL_ONE,
                     ZYSL_TWO,
                     ZYSL_TOTAL,
                     WSPSL
              FROM TF_YWPN_COSTRLWATER_W
              WHERE TO_CHAR(UP_DATE, 'yyyy') IN (${startYear})
                and MARK = '1')
        GROUP BY UP_DATE
        order by UP_DATE
    </select>
    <select id="getProduceDataMonthByYearReality" resultMap="costrlwaterMap2">
        SELECT TO_CHAR(UP_DATE, 'yyyy-MM') UP_DATE,
               round(GSL_ONE, 4)           GSL_ONE,
               round(GSL_TWO, 4)           GSL_TWO,
               round(GSL_QBJ, 4)           GSL_QBJ,
               round(GSL_TOTAL, 4)         GSL_TOTAL,
               round(ZSL_ONE, 4)           ZSL_ONE,
               round(ZSL_TWO, 4)           ZSL_TWO,
               round(ZSL_HQSK, 4)          ZSL_HQSK,
               round(ZSL_TOTAL, 4)         ZSL_TOTAL,
               round(SSL_TOTAL, 4)         SSL_TOTAL,
               round(ZYSL_ONE, 4)          ZYSL_ONE,
               round(ZYSL_TWO, 4)          ZYSL_TWO,
               round(ZYSL_TOTAL, 4)        ZYSL_TOTAL,
               round(ZYSLL_ONE, 4)         ZYSLL_ONE,
               round(ZYSLL_TWO, 4)         ZYSLL_TWO,
               round(ZYSLL_TOTAL, 4)       ZYSLL_TOTAL,
               round(WSPSL, 4)             WSPSL,
               round(CXC, 4)               CXC,
               round(LSL, 4)               LSL
        FROM TF_YWPN_COSTRLWATER_W
        WHERE TO_CHAR(UP_DATE, 'yyyy') = #{year}
          and MARK = '1'
        order by UP_DATE
    </select>
    <select id="getProduceDataMonthReality" resultMap="costrlwaterMap2">
        SELECT TO_CHAR(UP_DATE, 'yyyy-MM')
                                     UP_DATE,
               round(GSL_ONE, 4)     GSL_ONE,
               round(GSL_TWO, 4)     GSL_TWO,
               round(GSL_QBJ, 4)     GSL_QBJ,
               round(GSL_TOTAL, 4)   GSL_TOTAL,
               round(ZSL_ONE, 4)     ZSL_ONE,
               round(ZSL_TWO, 4)     ZSL_TWO,
               round(ZSL_HQSK, 4)    ZSL_HQSK,
               round(ZSL_TOTAL, 4)   ZSL_TOTAL,
               round(SSL_TOTAL, 4)   SSL_TOTAL,
               round(ZYSL_ONE, 4)    ZYSL_ONE,
               round(ZYSL_TWO, 4)    ZYSL_TWO,
               round(ZYSL_TOTAL, 4)  ZYSL_TOTAL,
               round(ZYSLL_ONE, 4)   ZYSLL_ONE,
               round(ZYSLL_TWO, 4)   ZYSLL_TWO,
               round(ZYSLL_TOTAL, 4) ZYSLL_TOTAL,
               round(WSPSL, 4)       WSPSL,
               round(CXC, 4)         CXC,
               round(LSL, 4)         LSL
        FROM TF_YWPN_COSTRLWATER_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="getQuarterDataOffer" resultType="java.util.Map">
        SELECT QUARTER,
               SUBSTR(QUARTER, -1)  NUM,
               round(SUM(ONE), 4)   ONE,
               round(SUM(TWO), 4)   TWO,
               round(SUM(TOTAL), 4) TOTAL
        FROM (SELECT TO_CHAR(UP_DATE, 'yyyy-Q') QUARTER, GSL_ONE ONE, GSL_TWO TWO, GSL_TOTAL TOTAL
              FROM TF_YWPN_COSTRLWATER_W
              WHERE TO_CHAR(UP_DATE, 'yyyy') = #{year}
                and MARK = '1')
        GROUP BY QUARTER
        ORDER BY QUARTER
    </select>
    <select id="getMonthDataOffer" resultType="java.util.Map">
        SELECT TO_CHAR(UP_DATE, 'yyyy') YEAR,
               TO_CHAR(UP_DATE, 'MM')   MONTH,
               round(GSL_ONE, 4)        ONE,
               round(GSL_TWO, 4)        TWO,
               round(GSL_TOTAL, 4)      TOTAL
        FROM TF_YWPN_COSTRLWATER_W
        WHERE TO_CHAR(UP_DATE, 'yyyy') = #{year}
          and TO_CHAR(UP_DATE, 'MM') = #{month}
          and MARK = '1'
    </select>
    <select id="getYearDataOffer" resultType="java.util.Map">
        SELECT TO_CHAR(UP_DATE, 'yyyy') YEAR,
               TO_CHAR(UP_DATE, 'MM')   MONTH,
               round(GSL_ONE, 4)        ONE,
               round(GSL_TWO, 4)        TWO,
               round(GSL_TOTAL, 4)      TOTAL
        FROM TF_YWPN_COSTRLWATER_W
        WHERE TO_CHAR(UP_DATE, 'yyyy') = #{year}
          and MARK = '1'
        ORDER BY MONTH
    </select>

    <resultMap id="costrlwaterMap2" type="com.tofly.xrtygis.custom.entity.dataquery.WaterReality">
        <id property="id" column="ID"/>
        <result property="upDate" column="UP_DATE"/>
        <result property="gslOne" column="GSL_ONE"/>
        <result property="gslTwo" column="GSL_TWO"/>
        <result property="gslQbj" column="GSL_QBJ"/>
        <result property="gslTotal" column="GSL_TOTAL"/>
        <result property="zslOne" column="ZSL_ONE"/>
        <result property="zslTwo" column="ZSL_TWO"/>
        <result property="zslHqsk" column="ZSL_HQSK"/>
        <result property="zslTotal" column="ZSL_TOTAL"/>
        <result property="sslTotal" column="SSL_TOTAL"/>
        <result property="zyslOne" column="ZYSL_ONE"/>
        <result property="zyslTwo" column="ZYSL_TWO"/>
        <result property="zyslTotal" column="ZYSL_TOTAL"/>
        <result property="zysllOne" column="ZYSLL_ONE"/>
        <result property="zysllTwo" column="ZYSLL_TWO"/>
        <result property="zysllTotal" column="ZYSLL_TOTAL"/>
        <result property="wspsl" column="WSPSL"/>
        <result property="cxc" column="CXC"/>
        <result property="lsl" column="LSL"/>
        <result property="pacOne" column="PAC_ONE"/>
        <result property="pacTwo" column="PAC_TWO"/>
        <result property="syOne" column="SY_ONE"/>
        <result property="ylTwo" column="YL_TWO"/>
        <result property="pam" column="PAM"/>
        <result property="ft" column="FT"/>
        <result property="cn" column="CN"/>
        <result property="gmsjfhy" column="GMSJFHY"/>
        <result property="pamWy" column="PAM_WY"/>
        <result property="bcs" column="BCS"/>
        <result property="wnzl" column="WNZL"/>
        <result property="dldlOne" column="DLDL_ONE"/>
        <result property="dldlTwo" column="DLDL_TWO"/>
        <result property="dldlTotal" column="DLDL_TOTAL"/>
        <result property="jbdlOne" column="JBDL_ONE"/>
        <result property="jbdlTwo" column="JBDL_TWO"/>
        <result property="jbdlTotal" column="JBDL_TOTAL"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="mark" column="MARK"/>
    </resultMap>

    <select id="getWaterDataMonthTwo" resultType="java.util.Map">
        SELECT TO_CHAR(UP_DATE, 'yyyy')    YEAR,
               TO_CHAR(UP_DATE, 'yyyy-MM') UP_DATE,
               TO_CHAR(UP_DATE, 'MM')      MONTH,
               round(${typet}, 4)          reslutData
        FROM TF_YWPN_COSTRLWATER_W
        WHERE MARK = '1'
          AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ <= ]]> #{endYear}
          AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ >= ]]> #{startYear}
        ORDER BY UP_DATE
    </select>
    <select id="getWaterDataQuarterTwo" resultType="java.util.Map">
        SELECT SUBSTR(UP_DATE, 1, 4) YEAR, UP_DATE MONTH, round(SUM(${typet}), 4) reslutData
        FROM (SELECT TO_CHAR(UP_DATE, 'yyyy-Q') UP_DATE,
                     ${typet}
              FROM TF_YWPN_COSTRLWATER_W
              WHERE MARK = '1'
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ <= ]]> #{endYear}
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ >= ]]> #{startYear})
        GROUP BY UP_DATE
        ORDER BY UP_DATE
    </select>
    <select id="getWaterDataYearTwo" resultType="java.util.Map">
        SELECT UP_DATE YEAR, round(SUM(${typet}), 4) reslutData
        FROM (SELECT TO_CHAR(UP_DATE, 'yyyy') UP_DATE,
                     ${typet}
              FROM TF_YWPN_COSTRLWATER_W
              WHERE MARK = '1'
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ <= ]]> #{endYear}
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ >= ]]> #{startYear})
        GROUP BY UP_DATE
        ORDER BY UP_DATE
    </select>
    <select id="getElectricityDataMonthTwo" resultType="java.util.Map">
        SELECT TO_CHAR(UP_DATE, 'yyyy')    YEAR,
               TO_CHAR(UP_DATE, 'yyyy-MM') UP_DATE,
               TO_CHAR(UP_DATE, 'MM')      MONTH,
               round(${typet}, 4)          reslutData
        FROM ${tableName}
        WHERE MARK = '1'
          AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ <= ]]> #{endYear}
          AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ >= ]]> #{startYear}
        ORDER BY UP_DATE
    </select>
    <select id="getElectricityDataQuarterTwo" resultType="java.util.Map">
        SELECT SUBSTR(UP_DATE, 1, 4) YEAR, UP_DATE MONTH, round(SUM(${typet}), 4) reslutData
        FROM (SELECT TO_CHAR(UP_DATE, 'yyyy-Q') UP_DATE, nvl(${typet}, 0) ${typet}
              FROM ${tableName}
              WHERE MARK = '1'
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ <= ]]> #{endYear}
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ >= ]]> #{startYear})
        GROUP BY UP_DATE
        ORDER BY UP_DATE
    </select>
    <select id="getElectricityDataYearTwo" resultType="java.util.Map">
        SELECT UP_DATE YEAR, round(SUM(${typet}), 4) reslutData
        FROM (SELECT TO_CHAR(UP_DATE, 'yyyy') UP_DATE, nvl(${typet}, 0) ${typet}
              FROM ${tableName}
              WHERE MARK = '1'
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ <= ]]> #{endYear}
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ >= ]]> #{startYear})
        GROUP BY UP_DATE
        ORDER BY UP_DATE
    </select>
    <select id="getMaterialsDataMonthTwo" resultType="java.util.Map">
        SELECT TO_CHAR(UP_DATE, 'yyyy')    YEAR,
               TO_CHAR(UP_DATE, 'yyyy-MM') UP_DATE,
               TO_CHAR(UP_DATE, 'MM')      MONTH,
               round(${typet}, 4)          reslutData
        FROM TF_YWPN_COSTRLUNIT_W
        WHERE MARK = '1'
          AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ <= ]]> #{endYear}
          AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ >= ]]> #{startYear}
        ORDER BY UP_DATE
    </select>
    <select id="getMaterialsDataQuarterTwo" resultType="java.util.Map">
        SELECT SUBSTR(UP_DATE, 1, 4) YEAR, UP_DATE MONTH, round(SUM(${typet}), 4) reslutData
        FROM (SELECT TO_CHAR(UP_DATE, 'yyyy-Q') UP_DATE, ${typet}
              FROM TF_YWPN_COSTRLUNIT_W
              WHERE MARK = '1'
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ <= ]]> #{endYear}
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ >= ]]> #{startYear})
        GROUP BY UP_DATE
        ORDER BY UP_DATE
    </select>
    <select id="getMaterialsDataYearTwo" resultType="java.util.Map">
        SELECT UP_DATE YEAR, round(SUM(${typet}), 4) reslutData
        FROM (SELECT TO_CHAR(UP_DATE, 'yyyy') UP_DATE, ${typet}
              FROM TF_YWPN_COSTRLUNIT_W
              WHERE MARK = '1'
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ <= ]]> #{endYear}
                AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ >= ]]> #{startYear})
        GROUP BY UP_DATE
        ORDER BY UP_DATE
    </select>
    <select id="getPriceDataMonthTwo" resultType="java.util.Map">
        SELECT YEAR, TO_CHAR(UP_DATE, 'yyyy-MM') CRET_TIME, TO_CHAR(UP_DATE, 'MM') MONTH, round(${typet}, 4) reslutData
        FROM TF_YWPN_COSTRLPRICE_W
        WHERE ID IN (
            SELECT MAX(ID)
            FROM (SELECT ID
                       , TO_CHAR(UP_DATE
                    , 'yyyy-MM') UP_DATE
                       , YEAR
                  FROM TF_YWPN_COSTRLPRICE_W
                  WHERE YEAR <![CDATA[ >= ]]> #{startYear}
                    and YEAR <![CDATA[ <= ]]> #{endYear})
            GROUP BY UP_DATE, YEAR)
        ORDER BY UP_DATE ASC
    </select>
    <select id="getPriceDataQuarterTwo" resultType="java.util.Map">
        SELECT YEAR, TO_CHAR(UP_DATE, 'yyyy-Q') MONTH, round(${typet}, 4) reslutData
        FROM TF_YWPN_COSTRLPRICE_W
        WHERE ID IN (SELECT MAX(ID)
                     FROM (SELECT ID
                                , YEAR
                                , TO_CHAR(UP_DATE
                             , 'yyyy-Q') quarter
                           FROM TF_YWPN_COSTRLPRICE_W
                           WHERE YEAR <![CDATA[ >= ]]> #{startYear}
                             and YEAR <![CDATA[ <= ]]> #{endYear})
                     GROUP BY quarter, YEAR)
        ORDER BY UP_DATE ASC
    </select>
    <select id="getPriceDataYearTwo" resultType="java.util.Map">
        SELECT YEAR, TO_CHAR(UP_DATE, 'yyyy-MM') CRET_TIME, round(${typet}, 4) reslutData
        FROM TF_YWPN_COSTRLPRICE_W
        WHERE YEAR <![CDATA[ >= ]]> #{startYear}
          and YEAR <![CDATA[ <= ]]> #{endYear}
          and ISNEW = '1'
        ORDER BY UP_DATE ASC
    </select>

</mapper>
