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

    <resultMap id="costbgwaterMap" type="com.tofly.xrtygis.entity.Costbgwater">
        <id property="id" column="ID"/>
        <result property="yearId" column="YEAR_ID"/>
        <result property="month" column="MONTH"/>
        <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="createTime" column="CREATE_TIME"/>
        <result property="createUser" column="CREATE_USER"/>
        <association property="createUserName" column="CREATE_USER"
                     select="com.tofly.xrtygis.mapper.IFileMapper.getUserName"/>
    </resultMap>
    <select id="selectPlanYearData" resultType="java.util.Map">
        SELECT SUBSTR(MONTH, 1, 4) MONTH,
               nvl(SUM(GSL_ONE), 0)     GSL_ONE,
               nvl(SUM(GSL_TWO), 0)     GSL_TWO,
               nvl(SUM(GSL_QBJ), 0)     GSL_QBJ,
               nvl(SUM(GSL_TOTAL), 0)   GSL_TOTAL,
               nvl(SUM(ZSL_ONE), 0)     ZSL_ONE,
               nvl(SUM(ZSL_TWO), 0)     ZSL_TWO,
               nvl(SUM(ZSL_HQSK), 0)    ZSL_HQSK,
               nvl(SUM(ZSL_TOTAL), 0)   ZSL_TOTAL,
               nvl(SUM(SSL_TOTAL), 0)   SSL_TOTAL,
               nvl(SUM(ZYSL_ONE), 0)    ZYSL_ONE,
               nvl(SUM(ZYSL_TWO), 0)    ZYSL_TWO,
               nvl(SUM(ZYSL_TOTAL), 0)  ZYSL_TOTAL,
               nvl(SUM(ZYSLL_ONE), 0)   ZYSLL_ONE,
               nvl(SUM(ZYSLL_TWO), 0)   ZYSLL_TWO,
               nvl(SUM(ZYSLL_TOTAL), 0) ZYSLL_TOTAL,
               nvl(SUM(WSPSL), 0)       WSPSL,
               nvl(SUM(CXC), 0)         CXC,
               nvl(SUM(LSL), 0)         LSL
        FROM (SELECT SUBSTR(MONTH, 1, 4) MONTH,
                     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,
                     CXC,
                     LSL
              FROM TF_YWPN_COSTBGWATER_W
              WHERE SUBSTR(MONTH, 1, 4) IN (${startYear}))
        GROUP BY MONTH
        ORDER BY MONTH ASC
    </select>
    <select id="selectPlanMonthByYearData" resultType="java.util.Map">
        SELECT *
        FROM TF_YWPN_COSTBGWATER_W
        WHERE SUBSTR(MONTH, 1, 4) = #{year}
        ORDER BY MONTH ASC
    </select>

    <select id="selectPlanMonthData" resultType="java.util.Map">
        SELECT *
        FROM TF_YWPN_COSTBGWATER_W
        WHERE SUBSTR(MONTH, 1, 4) IN (${year})
          and SUBSTR(MONTH, -2) IN (${month})
        ORDER BY MONTH ASC
    </select>


    <sql id="realityDataResult">
        UP_DATE
        ,
               nvl(SUM(GSL_ONE)    ,0) GSL_ONE,
               nvl(SUM(GSL_TWO)    ,0) GSL_TWO,
               nvl(SUM(GSL_QBJ)    ,0) GSL_QBJ,
               nvl(SUM(GSL_TOTAL)  ,0) GSL_TOTAL,
               nvl(SUM(ZSL_ONE)    ,0) ZSL_ONE,
               nvl(SUM(ZSL_TWO)    ,0) ZSL_TWO,
               nvl(SUM(ZSL_HQSK)   ,0) ZSL_HQSK,
               nvl(SUM(ZSL_TOTAL)  ,0) ZSL_TOTAL,
               nvl(SUM(SSL_TOTAL)  ,0) SSL_TOTAL,
               nvl(SUM(ZYSL_ONE)   ,0) ZYSL_ONE,
               nvl(SUM(ZYSL_TWO)   ,0) ZYSL_TWO,
               nvl(SUM(ZYSL_TOTAL) ,0) ZYSL_TOTAL,
               nvl(SUM(ZYSLL_ONE)  ,0) ZYSLL_ONE,
               nvl(SUM(ZYSLL_TWO)  ,0) ZYSLL_TWO,
               nvl(SUM(ZYSLL_TOTAL),0) ZYSLL_TOTAL,
               nvl(SUM(WSPSL)      ,0) WSPSL,
               nvl(SUM(CXC)        ,0) CXC,
               nvl(SUM(LSL)        ,0) LSL
    </sql>
    <sql id="realityData">
        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,
        CXC,
        LSL
    </sql>

    <select id="selectRealityYearData" resultType="java.util.Map">
        SELECT
        <include refid="realityDataResult"></include>
        FROM (
        SELECT
        TO_CHAR(UP_DATE,'yyyy') UP_DATE,
        <include refid="realityData"></include>
        FROM TF_YWPN_COSTRLWATER_W
        WHERE TO_CHAR(UP_DATE, 'yyyy') IN (${startYear})
        and MARK = '1')
        GROUP BY UP_DATE ORDER BY UP_DATE ASC
    </select>
    <select id="selectRealityMonthByYearData" resultType="java.util.Map">
        SELECT
        <include refid="realityDataResult"></include>
        FROM (
        SELECT
        TO_CHAR(UP_DATE, 'yyyy-MM') UP_DATE,
        <include refid="realityData"></include>
        FROM TF_YWPN_COSTRLWATER_W
        WHERE TO_CHAR(UP_DATE, 'yyyy') = #{year} and MARK = '1'
        )
        GROUP BY UP_DATE ORDER BY UP_DATE ASC
    </select>
    <select id="selectRealityMonthData" resultType="java.util.Map">
        SELECT
        <include refid="realityDataResult"></include>
        FROM (
        SELECT
        TO_CHAR(UP_DATE, 'yyyy-MM') UP_DATE,
        <include refid="realityData"></include>
        FROM TF_YWPN_COSTRLWATER_W
        WHERE TO_CHAR(UP_DATE, 'yyyy') IN (${year})
        and TO_CHAR(UP_DATE, 'MM') IN (${month})
        and MARK = '1' )
        GROUP BY UP_DATE ORDER BY UP_DATE ASC
    </select>
    <select id="selectPlanProduceYearData" resultType="java.util.Map">
        SELECT MONTH,
            nvl(SUM (PAC_ONE), 0 ) PAC_ONE,
            nvl(SUM (PAC_TWO), 0 ) PAC_TWO,
            nvl(SUM (SY_ONE), 0 ) SY_ONE,
            nvl(SUM (YL_TWO), 0 ) YL_TWO,
            nvl(SUM (PAM), 0 ) PAM,
            nvl(SUM (FT), 0 ) FT,
            nvl(SUM (CN), 0 ) CN,
            nvl(SUM (GMSJFHY), 0 ) GMSJFHY,
            nvl(SUM (PAM_WN), 0 ) PAM_WN,
            nvl(SUM (BCS), 0 ) BCS,
            nvl(SUM (WNZL), 0 ) WNZL,
            nvl(SUM (DLDL_ONE), 0 ) DLDL_ONE,
            nvl(SUM (DLDL_TWO), 0 ) DLDL_TWO,
            nvl(SUM (DLDL_TOTAL), 0 ) DLDL_TOTAL
        FROM (SELECT SUBSTR(MONTH, 1, 4)
            MONTH, PAC_ONE, PAC_TWO, SY_ONE, YL_TWO, PAM, FT, CN, GMSJFHY, PAM_WN, BCS, WNZL, DLDL_ONE, DLDL_TWO, DLDL_TOTAL
            FROM TF_YWPN_COSTBGINDEX_W
            WHERE SUBSTR(MONTH, 1, 4) IN (${startYear}) )
        GROUP BY MONTH
        ORDER BY MONTH ASC
    </select>
    <select id="selectPlanProduceMonthByYear" resultType="java.util.Map">
        SELECT *
        FROM TF_YWPN_COSTBGINDEX_W
        WHERE SUBSTR(MONTH, 1, 4) = #{year}
        ORDER BY MONTH ASC
    </select>
    <select id="selectPlanProduceMonthData" resultType="java.util.Map">
        SELECT *
        FROM TF_YWPN_COSTBGINDEX_W
        WHERE SUBSTR(MONTH, 1, 4) IN (${year})
          and SUBSTR(MONTH, -2) IN (${month})
        ORDER BY MONTH ASC
    </select>
    <sql id="produceMaterialsRealityRsult">
        UP_DATE
        ,
        nvl(SUM(PAC_ONE)   ,0)  PAC_ONE,
        nvl(SUM(PAC_TWO)   ,0)  PAC_TWO,
        nvl(SUM(SY_ONE)    ,0)  SY_ONE,
        nvl(SUM(YL_TWO)    ,0)  YL_TWO,
        nvl(SUM(PAM)       ,0)  PAM,
        nvl(SUM(FT)        ,0)  FT,
        nvl(SUM(CN)        ,0)  CN,
        nvl(SUM(GMSJFHY)   ,0)  GMSJFHY,
        nvl(SUM(PAM_WY)    ,0)  PAM_WN,
        nvl(SUM(BCS)       ,0)  BCS,
        nvl(SUM(WNZL)      ,0)  WNZL,
        nvl(SUM(DLDL_ONE)  ,0)  DLDL_ONE,
        nvl(SUM(DLDL_TWO)  ,0)  DLDL_TWO,
        nvl(SUM(DLDL_TOTAL),0)  DLDL_TOTAL,
        nvl(SUM(JBDL_ONE)  ,0)  JBDL_ONE,
        nvl(SUM(JBDL_TWO)  ,0)  JBDL_TWO,
        nvl(SUM(JBDL_TOTAL),0)  JBDL_TOTAL
    </sql>
    <sql id="produceMaterialsRealityData">
        PAC_ONE
        ,
        PAC_TWO,
        SY_ONE,
        YL_TWO,
        PAM,
        FT,
        CN,
        GMSJFHY,
        PAM_WY,
        BCS,
        WNZL,
        DLDL_ONE,
        DLDL_TWO,
        DLDL_TOTAL,
        JBDL_ONE,
        JBDL_TWO,
        JBDL_TOTAL
    </sql>
    <select id="selectRealityProduceYearData" resultType="java.util.Map">
        SELECT
        <include refid="produceMaterialsRealityRsult"></include>
        FROM (
        SELECT
        TO_CHAR(UP_DATE,'yyyy') UP_DATE ,
        <include refid="produceMaterialsRealityData"></include>
        FROM TF_YWPN_COSTRLWATER_W
        WHERE MARK = '1' and TO_CHAR(UP_DATE, 'yyyy') IN (${startYear}))
        GROUP BY UP_DATE ORDER BY UP_DATE ASC
    </select>
    <select id="selectRealityProduceMonthByYear" resultType="java.util.Map">
        SELECT
        <include refid="produceMaterialsRealityRsult"></include>
        FROM (
        SELECT
        TO_CHAR(UP_DATE, 'yyyy-MM') UP_DATE,
        <include refid="produceMaterialsRealityData"></include>
        FROM TF_YWPN_COSTRLWATER_W
        WHERE TO_CHAR(UP_DATE, 'yyyy') = #{year} and MARK = '1'
        )
        GROUP BY UP_DATE ORDER BY UP_DATE ASC
    </select>
    <select id="selectRealityProduceMonthData" resultType="java.util.Map">
        SELECT
        <include refid="produceMaterialsRealityRsult"></include>
        FROM (
        SELECT
        TO_CHAR(UP_DATE, 'yyyy-MM') UP_DATE,
        <include refid="produceMaterialsRealityData"></include>
        FROM TF_YWPN_COSTRLWATER_W
        WHERE TO_CHAR(UP_DATE, 'yyyy') IN (${year})
        and TO_CHAR(UP_DATE, 'MM') IN (${month}) and MARK = '1'
        )
        GROUP BY UP_DATE ORDER BY UP_DATE ASC
    </select>
    <sql id="costPlanReslut">
        b
        .
        MONTH
        ,
               b.PAC_ONE * p.PACDJ                                     PAC_ONE,
               b.PAC_TWO * p.PACDJ                                     PAC_TWO,
               b.SY_ONE * p.SYDJ                                       SY_ONE,
               b.YL_TWO * p.YLDJ                                       YL_TWO,
               b.PAM * p.PAM_ZSDJ                                      PAM,
               b.FT * p.FTDJ                                           FT,
               b.CN * p.CNDJ                                           CN,
               b.GMSJFHY * p.GMSJFHYDJ                                 GMSJFHY,
               b.PAM_WN * p.PAM_WNDJ                                   PAM_WN,
               b.BCS * p.BCSDJ                                         BCS,
               b.WNZL * p.WNZYDJ                                       WNZL,
               b.DLDL_ONE * p.DLDDJ_ONE                                DLDL_ONE,
               b.DLDL_TWO * p.DLDDJ_TWO                                DLDL_TWO,
               (b.DLDL_ONE * p.DLDDJ_ONE) + (b.DLDL_TWO * p.DLDDJ_TWO) DLDL_TOTAL
    </sql>
    <select id="selectPlanCostYearData" resultType="java.util.Map">
        <!--        SELECT-->
        <!--        <include refid="costPlanReslut"></include>-->
        <!--        FROM TF_YWPN_COSTBGPRICE_W p-->
        <!--        LEFT JOIN (SELECT MONTH, SUM (PAC_ONE) PAC_ONE, SUM (PAC_TWO) PAC_TWO, SUM (SY_ONE)-->
        <!--        SY_ONE, SUM (YL_TWO) YL_TWO, SUM (PAM) PAM, SUM (FT) FT, SUM (CN) CN, SUM (GMSJFHY) GMSJFHY, SUM (PAM_WN)-->
        <!--        PAM_WN,-->
        <!--        SUM (BCS) BCS, SUM (WNZL) WNZL, SUM (DLDL_ONE) DLDL_ONE, SUM (DLDL_TWO) DLDL_TWO, SUM (DLDL_TOTAL) DLDL_TOTAL-->
        <!--        FROM-->
        <!--        (SELECT SUBSTR(MONTH, 1, 4) MONTH-->
        <!--        , PAC_ONE, PAC_TWO, SY_ONE, YL_TWO, PAM, FT, CN, GMSJFHY, PAM_WN, BCS, WNZL, DLDL_ONE, DLDL_TWO, DLDL_TOTAL-->
        <!--        FROM TF_YWPN_COSTBGINDEX_W-->
        <!--        WHERE SUBSTR(MONTH, 1, 4) <![CDATA[ >= ]]> #{startYear}-->
        <!--        and SUBSTR(MONTH, 1, 4) <![CDATA[ <= ]]> #{endYear}) GROUP BY MONTH) b ON p.YEAR = b.MONTH WHERE p.SNEW = '1'-->
        <!--        ORDER BY b.MONTH ASC-->
        SELECT MONTH, <include refid="realityCostYearData"></include> FROM (SELECT
        SUBSTR(MOUTH, 1, 4) MONTH,
        <include refid="realityCostReslut"></include>
        FROM TF_YWPN_COSTBGFIXED_W WHERE SUBSTR(MOUTH, 1, 4) IN (${startYear})
        ) GROUP BY MONTH ORDER BY MONTH ASC
    </select>
    <select id="selectPlanCostMonthByYear" resultType="java.util.Map">
        <!--        SELECT-->
        <!--        <include refid="costPlanReslut"></include>-->
        <!--        FROM TF_YWPN_COSTBGPRICE_W p-->
        <!--        LEFT JOIN (SELECT SUBSTR(MONTH, 1, 4) YEAR, MONTH, PAC_ONE, PAC_TWO, SY_ONE, YL_TWO, PAM, FT, CN, GMSJFHY,-->
        <!--        PAM_WN, BCS, WNZL, DLDL_ONE, DLDL_TWO, DLDL_TOTAL-->
        <!--        FROM TF_YWPN_COSTBGINDEX_W-->
        <!--        WHERE SUBSTR(MONTH, 1, 4) = #{year}) b ON p.YEAR = b.YEAR WHERE p.SNEW = '1' ORDER BY b.MONTH ASC-->
        SELECT
        MOUTH MONTH,
        <include refid="realityCostReslut"></include>
        FROM TF_YWPN_COSTBGFIXED_W WHERE SUBSTR(MOUTH, 1, 4) = #{year} ORDER BY MONTH ASC
    </select>
    <select id="selectPlanCostMonthData" resultType="java.util.Map">
        <!--        SELECT-->
        <!--        <include refid="costPlanReslut"></include>-->
        <!--        FROM-->
        <!--        TF_YWPN_COSTBGPRICE_W p LEFT JOIN (SELECT SUBSTR(MONTH, 1, 4) YEAR , MONTH-->
        <!--        ,PAC_ONE,PAC_TWO,SY_ONE,YL_TWO,PAM,FT,CN,GMSJFHY,PAM_WN,BCS,WNZL,DLDL_ONE,DLDL_TWO,DLDL_TOTAL FROM-->
        <!--        TF_YWPN_COSTBGINDEX_W-->
        <!--        WHERE SUBSTR(MONTH, 1, 4) <![CDATA[ >= ]]> #{startYearStr}-->
        <!--        and SUBSTR(MONTH, 1, 4) <![CDATA[ <= ]]> #{endYearStr}-->
        <!--        and SUBSTR(MONTH, -2) = #{monthStr} ) b ON p.YEAR = b.YEAR WHERE p.SNEW = '1' ORDER BY b.MONTH ASC-->
        SELECT MOUTH MONTH,
        <include refid="realityCostReslut"></include>
        FROM TF_YWPN_COSTBGFIXED_W WHERE SUBSTR(MOUTH, 1, 4) IN (${year})
        and SUBSTR(MOUTH, -2) IN (${month}) ORDER BY MONTH ASC
    </select>

    <sql id="costRealityReslut">
        b
        .
        UP_DATE
        ,
        b.PAC_ONE*p.PACDJ PAC_ONE,
        b.PAC_TWO*p.PACDJ PAC_TWO,
        b.SY_ONE*p.SYDJ SY_ONE,
        b.YL_TWO*p.YLDJ YL_TWO,
        b.PAM*p.PAM_ZSDJ PAM ,
        b.FT* p.FTDJ FT,
        b.CN * p.CNDJ CN,
        b.GMSJFHY * p.GMSJFHYDJ GMSJFHY,
        b.PAM_WN * p.PAM_WNDJ PAM_WN ,
        b.BCS * p.BCSDJ BCS,
        b.WNZL * p.WNZYDJ WNZL,
        b.DLDL_ONE * p.DLDDJ_ONE DLDL_ONE,
        b.DLDL_TWO * p.DLDDJ_TWO DLDL_TWO,
        (b.DLDL_ONE * p.DLDDJ_ONE) + (b.DLDL_TWO * p.DLDDJ_TWO) DLDL_TOTAL
    </sql>
    <sql id="realityCostReslut">
        PACZFY_ONE
        ,PACZFY_TWO,SYZFY_ONE,YLZFY_TWO,
               PAMZSZFY,FTZFY,CNZFY,GMSJFHYZFY,PAMWNZFY,BCSZFY,WNZYF,JBDF_ONE,JBDF_TWO,JBDF_TOTAL,
               DLDF_ONE,DLDF_TWO,DLDF_TOTAL,YSF,SZYSF_ONE,SZYSF_TWO,SZYSF_TOTAL,DFCB_ONE,DFCB_TWO,
               DFCB_TOTAL,PACCB_ONE,SYCB_ONE,CNCB_ONE,BCSCB_ONE,ZSCLCB_ONE,PACCB_TWO,YLCB_TWO,
               PAMZSCB_TWO,FTCB_TWO,GMSJFHYCB_TWO,PAMWNCB_TWO,WNZYCB_TWO,ZSCLCB_TWO,ZSCLCB_TOTAL,
               YSFCB,SZYSFCB_ONE,SZYSFCB_TWO,SZYSFCB_TOTAL,ZFY_ONE,ZFY_TWO,DWCB_ONE,DWCB_TWO,DWCB_TOTAL,
               ZZSCLFY_ONE,ZZSCLFY_TWO,ZFY
    </sql>
    <sql id="realityCostYearData">
        nvl
        (SUM(PACZFY_ONE)    ,0) PACZFY_ONE,
        nvl(SUM(PACZFY_TWO)    ,0) PACZFY_TWO,
        nvl(SUM(SYZFY_ONE)     ,0) SYZFY_ONE,
        nvl(SUM(YLZFY_TWO)     ,0) YLZFY_TWO,
        nvl(SUM(PAMZSZFY)      ,0) PAMZSZFY,
        nvl(SUM(FTZFY)         ,0) FTZFY,
        nvl(SUM(CNZFY)         ,0) CNZFY,
        nvl(SUM(GMSJFHYZFY)    ,0) GMSJFHYZFY,
        nvl(SUM(PAMWNZFY)      ,0) PAMWNZFY,
        nvl(SUM(BCSZFY)        ,0) BCSZFY,
        nvl(SUM(WNZYF)         ,0) WNZYF,
        nvl(SUM(JBDF_ONE)      ,0) JBDF_ONE,
        nvl(SUM(JBDF_TWO)      ,0) JBDF_TWO,
        nvl(SUM(JBDF_TOTAL)    ,0) JBDF_TOTAL,
        nvl(SUM(DLDF_ONE)      ,0) DLDF_ONE,
        nvl(SUM(DLDF_TWO)      ,0) DLDF_TWO,
        nvl(SUM(DLDF_TOTAL)    ,0) DLDF_TOTAL,
        nvl(SUM(YSF)           ,0) YSF,
        nvl(SUM(SZYSF_ONE)     ,0) SZYSF_ONE,
        nvl(SUM(SZYSF_TWO)     ,0) SZYSF_TWO,
        nvl(SUM(SZYSF_TOTAL)   ,0) SZYSF_TOTAL,
        nvl(SUM(DFCB_ONE)      ,0) DFCB_ONE,
        nvl(SUM(DFCB_TWO)      ,0) DFCB_TWO,
        nvl(SUM(DFCB_TOTAL)    ,0) DFCB_TOTAL,
        nvl(SUM(PACCB_ONE)     ,0) PACCB_ONE,
        nvl(SUM(SYCB_ONE)      ,0) SYCB_ONE,
        nvl(SUM(CNCB_ONE)      ,0) CNCB_ONE,
        nvl(SUM(BCSCB_ONE)     ,0) BCSCB_ONE,
        nvl(SUM(ZSCLCB_ONE)    ,0) ZSCLCB_ONE,
        nvl(SUM(PACCB_TWO)     ,0) PACCB_TWO,
        nvl(SUM(YLCB_TWO)      ,0) YLCB_TWO,
        nvl(SUM(PAMZSCB_TWO)   ,0) PAMZSCB_TWO,
        nvl(SUM(FTCB_TWO)      ,0) FTCB_TWO,
        nvl(SUM(GMSJFHYCB_TWO) ,0) GMSJFHYCB_TWO,
        nvl(SUM(PAMWNCB_TWO)   ,0) PAMWNCB_TWO,
        nvl(SUM(WNZYCB_TWO)    ,0) WNZYCB_TWO,
        nvl(SUM(ZSCLCB_TWO)    ,0) ZSCLCB_TWO,
        nvl(SUM(ZSCLCB_TOTAL)  ,0) ZSCLCB_TOTAL,
        nvl(SUM(YSFCB)         ,0) YSFCB,
        nvl(SUM(SZYSFCB_ONE)   ,0) SZYSFCB_ONE,
        nvl(SUM(SZYSFCB_TWO)   ,0) SZYSFCB_TWO,
        nvl(SUM(SZYSFCB_TOTAL) ,0) SZYSFCB_TOTAL,
        nvl(SUM(ZFY_ONE)       ,0) ZFY_ONE,
        nvl(SUM(ZFY_TWO)       ,0) ZFY_TWO,
        nvl(SUM(DWCB_ONE)      ,0) DWCB_ONE,
        nvl(SUM(DWCB_TWO)      ,0) DWCB_TWO,
        nvl(SUM(DWCB_TOTAL)    ,0) DWCB_TOTAL,
        nvl(SUM(ZZSCLFY_ONE)   ,0) ZZSCLFY_ONE,
        nvl(SUM(ZZSCLFY_TWO)   ,0) ZZSCLFY_TWO,
        nvl(SUM(ZFY)           ,0) ZFY
    </sql>
    <select id="selectRealityCostYearData" resultType="java.util.Map">
        <!--        SELECT-->
        <!--        <include refid="costRealityReslut"></include>-->
        <!--        FROM TF_YWPN_COSTRLPRICE_W p-->
        <!--        LEFT JOIN (SELECT UP_DATE,-->
        <!--        SUM(PAC_ONE) PAC_ONE,-->
        <!--        SUM(PAC_TWO) PAC_TWO,-->
        <!--        SUM(SY_ONE) SY_ONE,-->
        <!--        SUM(YL_TWO) YL_TWO,-->
        <!--        SUM(PAM) PAM,-->
        <!--        SUM(FT) FT,-->
        <!--        SUM(CN) CN,-->
        <!--        SUM(GMSJFHY) GMSJFHY,-->
        <!--        SUM(PAM_WY) PAM_WN,-->
        <!--        SUM(BCS) BCS,-->
        <!--        SUM(WNZL) WNZL,-->
        <!--        SUM(DLDL_ONE) DLDL_ONE,-->
        <!--        SUM(DLDL_TWO) DLDL_TWO,-->
        <!--        SUM(DLDL_TOTAL) DLDL_TOTAL,-->
        <!--        SUM(JBDL_ONE) JBDL_ONE,-->
        <!--        SUM(JBDL_TWO) JBDL_TWO,-->
        <!--        SUM(JBDL_TOTAL) JBDL_TOTAL-->
        <!--        FROM (SELECT TO_CHAR(UP_DATE, 'yyyy') UP_DATE,-->
        <!--        PAC_ONE,-->
        <!--        PAC_TWO,-->
        <!--        SY_ONE,-->
        <!--        YL_TWO,-->
        <!--        PAM,-->
        <!--        FT,-->
        <!--        CN,-->
        <!--        GMSJFHY,-->
        <!--        PAM_WY,-->
        <!--        BCS,-->
        <!--        WNZL,-->
        <!--        DLDL_ONE,-->
        <!--        DLDL_TWO,-->
        <!--        DLDL_TOTAL,-->
        <!--        JBDL_ONE,-->
        <!--        JBDL_TWO,-->
        <!--        JBDL_TOTAL-->
        <!--        FROM TF_YWPN_COSTRLWATER_W-->
        <!--        WHERE MARK = '1'-->
        <!--        AND TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ >= ]]> #{startYear}-->
        <!--        and TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ <= ]]> #{endYear})-->
        <!--        GROUP BY UP_DATE) b ON p.YEAR = b.UP_DATE WHERE p.ISNEW = '1' ORDER BY b.UP_DATE ASC-->
        SELECT UP_DATE, <include refid="realityCostYearData"></include> FROM (SELECT
        TO_CHAR(UP_DATE,'yyyy') UP_DATE ,
        <include refid="realityCostReslut"></include>
        FROM TF_YWPN_COSTRLFIXED_W WHERE TO_CHAR(UP_DATE,'yyyy') IN (${startYear})
        and MARK='1') GROUP BY UP_DATE ORDER BY UP_DATE ASC
    </select>
    <select id="selectRealityCostMonthByYear" resultType="java.util.Map">
        SELECT
        TO_CHAR(UP_DATE,'yyyy-MM') UP_DATE,
        <include refid="realityCostReslut"></include>
        FROM TF_YWPN_COSTRLFIXED_W WHERE TO_CHAR(UP_DATE,'yyyy') = #{year} and MARK = '1' ORDER BY UP_DATE ASC
    </select>

    <select id="selectRealityCostMonthData" resultType="java.util.Map">
        <!--        SELECT-->
        <!--        <include refid="costRealityReslut"></include>-->
        <!--        FROM TF_YWPN_COSTRLPRICE_W p-->
        <!--        LEFT JOIN (SELECT TO_CHAR(UP_DATE, 'yyyy') YEAR,-->
        <!--        TO_CHAR(UP_DATE, 'yyyy-MM') UP_DATE,-->
        <!--        PAC_ONE,-->
        <!--        PAC_TWO,-->
        <!--        SY_ONE,-->
        <!--        YL_TWO,-->
        <!--        PAM,-->
        <!--        FT,-->
        <!--        CN,-->
        <!--        GMSJFHY,-->
        <!--        PAM_WY PAM_WN,-->
        <!--        BCS,-->
        <!--        WNZL,-->
        <!--        DLDL_ONE,-->
        <!--        DLDL_TWO,-->
        <!--        DLDL_TOTAL,-->
        <!--        JBDL_ONE,-->
        <!--        JBDL_TWO,-->
        <!--        JBDL_TOTAL-->
        <!--        FROM TF_YWPN_COSTRLWATER_W-->
        <!--        WHERE TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ >= ]]> #{startYearStr}-->
        <!--        and TO_CHAR(UP_DATE, 'yyyy') <![CDATA[ <= ]]> #{endYearStr}-->
        <!--        and TO_CHAR(UP_DATE, 'MM') = #{monthStr}-->
        <!--        and MARK = '1') b ON p.YEAR = b.YEAR WHERE p.ISNEW = '1' ORDER BY b.UP_DATE ASC-->
        SELECT TO_CHAR(UP_DATE,'yyyy-MM') UP_DATE,
        <include refid="realityCostReslut"></include>
        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 ASC
    </select>

    <sql id="priceReslut">
        YEAR,TO_CHAR(UP_DATE , 'yyyy-MM') CREATE_TIME,
        PACDJ,YLDJ,PAM_ZSDJ,PAM_WNDJ,FTDJ,CNDJ,GMSJFHYDJ,SYDJ,DLDDJ_ONE,DLDDJ_TWO,WNZYDJ,YSFDJ,SZYSDJ,BCSDJ,OTHERDJ
    </sql>

    <select id="selectPlanPriceYearData" resultType="java.util.Map">
<!--        SELECT-->
<!--        <include refid="priceReslut"></include>-->
<!--        FROM TF_YWPN_COSTBGPRICE_W-->
<!--        WHERE YEAR IN  (${startYear}) and SNEW = '1'-->
<!--        ORDER BY CREATE_TIME ASC-->
<!--由于在单价计划值中没有使用SNEW这一字段标识单价是否最新单价，所以只能使用以下方式查询年度单价数据-->
        SELECT
        <include refid="priceReslut"></include>
        FROM TF_YWPN_COSTBGPRICE_W WHERE ID IN ( SELECT
        MAX(ID)
        FROM TF_YWPN_COSTBGPRICE_W
        WHERE YEAR IN (${startYear})
        GROUP BY YEAR)
    </select>
    <select id="selectPlanPriceMonthByYear" resultType="java.util.Map">
        SELECT
        <include refid="priceReslut"></include>
        FROM TF_YWPN_COSTBGPRICE_W WHERE ID IN
        (SELECT MAX(ID) FROM (SELECT ID,TO_CHAR(UP_DATE , 'yyyy-MM') UP_DATE FROM TF_YWPN_COSTBGPRICE_W WHERE
        YEAR = #{year}) GROUP BY UP_DATE)
        AND YEAR = #{year}
        ORDER BY UP_DATE ASC
<!--        SELECT <include refid="priceReslut"></include> FROM TF_YWPN_COSTBGPRICE_W WHERE-->
<!--        YEAR = #{year}-->
<!--        ORDER BY CREATE_TIME ASC-->
    </select>
    <select id="selectPlanPriceMonthData" resultType="java.util.Map">
        SELECT
        <include refid="priceReslut"></include>
        FROM TF_YWPN_COSTBGPRICE_W WHERE ID IN
        (SELECT MAX(ID) FROM (SELECT ID, YEAR,TO_CHAR(UP_DATE , 'yyyy-MM') UP_DATE FROM TF_YWPN_COSTBGPRICE_W
        WHERE YEAR IN (${year}) and
        TO_CHAR(UP_DATE,'MM') IN (${month}) ) GROUP BY UP_DATE)
        AND YEAR IN (${year})
        ORDER BY UP_DATE ASC
<!--        SELECT <include refid="priceReslut"></include>-->
<!--        FROM TF_YWPN_COSTBGPRICE_W-->
<!--        WHERE YEAR IN (${year}) and-->
<!--        TO_CHAR(CREATE_TIME,'MM') IN (${month})-->
<!--        ORDER BY CREATE_TIME ASC-->
    </select>

    <select id="selectRealityPriceYearData" resultType="java.util.Map">
<!--        SELECT-->
<!--        <include refid="priceReslut"></include>-->
<!--        FROM TF_YWPN_COSTRLPRICE_W-->
<!--        WHERE TO_CHAR(CREATE_TIME,'yyyy') IN (${startYear})-->
<!--        and ISNEW = '1' ORDER BY CREATE_TIME ASC-->

        SELECT
        <include refid="priceReslut"></include>
        FROM TF_YWPN_COSTRLPRICE_W
        WHERE YEAR IN (${startYear})
        and ISNEW = '1' ORDER BY UP_DATE ASC
    </select>
    <select id="selectRealityPriceMonthByYear" resultType="java.util.Map">
        SELECT
        <include refid="priceReslut"></include>
        FROM
        TF_YWPN_COSTRLPRICE_W WHERE ID IN (SELECT MAX(ID) FROM (SELECT ID,TO_CHAR(UP_DATE , 'yyyy-MM') UP_DATE
        FROM TF_YWPN_COSTRLPRICE_W WHERE
        YEAR = #{year} ) GROUP BY UP_DATE)
        AND YEAR = #{year}
        ORDER BY UP_DATE ASC
<!--        SELECT <include refid="priceReslut"></include> FROM TF_YWPN_COSTRLPRICE_W WHERE-->
<!--        YEAR = #{year}-->
<!--        ORDER BY CREATE_TIME ASC-->
    </select>
    <select id="selectRealityPriceMonthData" resultType="java.util.Map">
        SELECT
        <include refid="priceReslut"></include>
        FROM
        TF_YWPN_COSTRLPRICE_W WHERE ID IN
        (SELECT MAX(ID) FROM (SELECT ID, YEAR,TO_CHAR(UP_DATE , 'yyyy-MM') UP_DATE FROM TF_YWPN_COSTRLPRICE_W
        WHERE YEAR IN (${year}) and
        TO_CHAR(UP_DATE,'MM') IN (${month}) )
        GROUP BY UP_DATE)
        AND YEAR IN (${year})
        ORDER BY UP_DATE ASC
<!--        SELECT <include refid="priceReslut"></include>-->
<!--        FROM TF_YWPN_COSTRLPRICE_W-->
<!--        WHERE YEAR IN (${year}) and-->
<!--        TO_CHAR(CREATE_TIME,'MM') IN (${month})-->
<!--        ORDER BY CREATE_TIME ASC-->
    </select>

    <select id="selectPriceMonthByYear" resultType="java.util.Map">
        SELECT
        <include refid="priceReslut"></include>
        FROM
        ${tableName} WHERE ID IN (SELECT MAX(ID) FROM (SELECT ID , YEAR FROM ${tableName}
        WHERE
        TO_CHAR(CREATE_TIME,'yyyy') IN
        <foreach collection="fileterYear" item="fileteryear" open="(" close=")" separator=",">
            #{fileteryear}
        </foreach>
        and TO_CHAR(CREATE_TIME,'MM') <![CDATA[ <= ]]> #{monthStr} ) GROUP BY YEAR)
        ORDER BY YEAR ASC
    </select>
    <select id="getProduceDataYearPlan" resultMap="costbgwaterMap">
        SELECT MONTH,
          nvl(SUM (GSL_ONE)    ,0) GSL_ONE,
          nvl(SUM (GSL_TWO)    ,0) GSL_TWO,
          nvl(SUM (GSL_QBJ)    ,0) GSL_QBJ,
          nvl(SUM (GSL_TOTAL)  ,0) GSL_TOTAL,
          nvl(SUM (ZSL_ONE)    ,0) ZSL_ONE,
          nvl(SUM (ZSL_TWO)    ,0) ZSL_TWO,
          nvl(SUM (ZSL_HQSK)   ,0) ZSL_HQSK,
          nvl(SUM (ZSL_TOTAL)  ,0) ZSL_TOTAL,
          nvl(SUM (SSL_TOTAL)  ,0) SSL_TOTAL,
          nvl(SUM (ZYSL_ONE)   ,0) ZYSL_ONE,
          nvl(SUM (ZYSL_TWO)   ,0) ZYSL_TWO,
          nvl(SUM (ZYSL_TOTAL) ,0) ZYSL_TOTAL, 
          nvl(SUM (ZYSLL_ONE)  ,0) ZYSLL_ONE,
          nvl(SUM (ZYSLL_TWO)  ,0) ZYSLL_TWO,
          nvl(SUM (ZYSLL_TOTAL),0) ZYSLL_TOTAL,
          nvl(SUM (WSPSL)      ,0) WSPSL,
          nvl(SUM (CXC)        ,0) CXC,
          nvl(SUM (LSL)        ,0) LSL
        FROM (SELECT SUBSTR(MONTH, 1, 4) MONTH, 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, CXC, LSL
            FROM TF_YWPN_COSTBGWATER_W WHERE SUBSTR(MONTH, 1, 4) IN (${startYear}) )
        GROUP BY MONTH
    </select>
    <select id="egtProduceDataMonthByYaerPlan" resultMap="costbgwaterMap">
        SELECT MONTH, 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,
            CXC,
            LSL
        FROM TF_YWPN_COSTBGWATER_W
        WHERE SUBSTR(MONTH, 1, 4) = #{year}
    </select>

    <select id="getProduceDataMonthPlan" resultMap="costbgwaterMap">
        SELECT MONTH, 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,
            CXC,
            LSL
        FROM TF_YWPN_COSTBGWATER_W
        WHERE SUBSTR(MONTH , 1 , 4) IN (${year})
          and SUBSTR(MONTH , -2) IN (${month})
    </select>


</mapper>
