<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tofly.xrtygis.custom.mapper.WaterCostMapper">

    <select id="budgetByMonth" resultType="com.tofly.xrtygis.custom.entity.vo.WaterVo">
        select water.MONTH,
               nvl(SY_ONE, 0)      syOne,
               nvl(PAC_ONE, 0)     pacOne,
               nvl(YL_TWO, 0)      ylTwo,
               nvl(PAC_TWO, 0)     pacTwo,
               nvl(PAM, 0)         pam,
               nvl(FT, 0)          ft,
               nvl(CN, 0)          cn,
               nvl(GMSJFHY, 0)     gmsjfhy,
               nvl(PAM_WN, 0)      pamWy,
               nvl(BCS, 0)         bcs,
               nvl(WNZL, 0)        wnzl,
               nvl(DLDL_ONE, 0)    dldlOne,
               nvl(DLDL_TWO, 0)    dldlTwo,
               nvl(DLDL_TOTAL, 0)  dldlTotal,
               nvl(GSL_ONE, 0)     gslOne,
               nvl(GSL_TWO, 0)     gslTwo,
               nvl(GSL_QBJ, 0)     gslQbj,
               nvl(GSL_TOTAL, 0)   gslTotal,
               nvl(ZSL_ONE, 0)     zslOne,
               nvl(ZSL_TWO, 0)     zslTwo,
               nvl(ZSL_TOTAL, 0)   zslTotal,
               nvl(ZSL_HQSK, 0)    ZslHqsk,
               nvl(WSPSL, 0)       wspsl,
               ZYSL_ONE            zyslOne,
               ZYSL_TWO            zyslTwo,
               ZYSL_TOTAL          zyslTotal,
               JBDL_ONE            jbdlOne,
               JBDL_TWO            jbdlTwo,
               JBDL_TOTAL          jbdlTotal,
               nvl(SSL_TOTAL, 0)   sslTotal,
               nvl(ZYSLL_ONE, 0)   zysllOne,
               nvl(ZYSLL_TWO, 0)   zysllTwo,
               nvl(ZYSLL_TOTAL, 0) zysllTotal,
               nvl(CXC, 0)         cxc,
               nvl(LSL, 0)         lsl,
               nvl(OTHER, 0)       other
        from TF_YWPN_COSTBGWATER_W water
                 full join TF_YWPN_COSTBGINDEX_W ind on water.MONTH = ind.MONTH
        where ind.MONTH = #{month}
    </select>

    <select id="financeByMonth" resultType="com.tofly.xrtygis.custom.entity.vo.WaterVo">
        select ID,
               to_char(UP_DATE, 'yyyy-mm-dd') month,
               SY_ONE                         syOne,
               PAC_ONE                        pacOne,
               YL_TWO                         ylTwo,
               PAC_TWO                        pacTwo,
               PAM                            pam,
               FT                             ft,
               CN                             cn,
               GMSJFHY                        gmsjfhy,
               PAM_WY                         pamWy,
               BCS                            bcs,
               WNZL                           wnzl,
               JBDL_ONE                       jbdlOne,
               JBDL_TWO                       jbdlTwo,
               JBDL_TOTAL                     jbdlTotal,
               DLDL_ONE                       dldlOne,
               DLDL_TWO                       dldlTwo,
               DLDL_TOTAL                     dldlTotal,
               GSL_ONE                        gslOne,
               GSL_TWO                        gslTwo,
               GSL_QBJ                        gslQbj,
               GSL_TOTAL                      gslTotal,
               ZSL_ONE                        zslOne,
               ZSL_TWO                        zslTwo,
               ZSL_TOTAL                      zslTotal,
               ZSL_HQSK                       zslHqsk,
               WSPSL                          wspsl,
               ZYSL_ONE                       zyslOne,
               ZYSL_TWO                       zyslTwo,
               ZYSL_TOTAL                     zyslTotal,
               SSL_TOTAL                      sslTotal,
               ZYSLL_ONE                      zysllOne,
               ZYSLL_TWO                      zysllTwo,
               ZYSLL_TOTAL                    zysllTotal,
               CXC                            cxc,
               LSL                            lsl,
               OTHER                          other,
               MARK
        from TF_YWPN_COSTRLWATER_W
        where MARK = '1'
          and to_char(UP_DATE, 'yyyy-mm') = #{month}


    </select>

    <select id="realWaterCost" resultType="com.tofly.xrtygis.custom.entity.vo.WaterVo">
        select sum(SY_ONE)                                                           syOne,
               sum(PAC_ONE)                                                          pacOne,
               sum(YL_TWO)                                                           ylTwo,
               sum(PAC_TWO)                                                          pacTwo,
               sum(PAM)                                                              pam,
               sum(FT)                                                               ft,
               sum(CN)                                                               cn,
               sum(GMSJFHY)                                                          gmsjfhy,
               sum(PAM_WY)                                                           pamWy,
               sum(BCS)                                                              bcs,
               sum(WNZL)                                                             wnzl,
               sum(JBDL_ONE)                                                         jbdlOne,
               sum(JBDL_TWO)                                                         jbdlTwo,
               sum(JBDL_TOTAL)                                                       jbdlTotal,
               sum(DLDL_ONE)                                                         dldlOne,
               sum(DLDL_TWO)                                                         dldlTwo,
               sum(DLDL_TOTAL)                                                       dldlTotal,
               sum(GSL_ONE)                                                          gslOne,
               sum(GSL_TWO)                                                          gslTwo,
               sum(GSL_QBJ)                                                          gslQbj,
               sum(GSL_TOTAL)                                                        gslTotal,
               sum(ZSL_ONE)                                                          zslOne,
               sum(ZSL_TWO)                                                          zslTwo,
               sum(ZSL_TOTAL)                                                        zslTotal,
               sum(ZSL_HQSK)                                                         zslHqsk,
               sum(WSPSL)                                                            wspsl,
               sum(SSL_TOTAL)                                                        sslTotal,
               sum(ZYSL_ONE)                                                         zyslOne,
               sum(ZYSL_TWO)                                                         zyslTwo,
               sum(ZYSL_TOTAL)                                                       zyslTotal,
               trunc((nvl(sum(ZYSL_ONE), 0) / nullif(sum(ZSL_ONE), 0) * 100), 2)     zysllOne,
               trunc((nvl(sum(ZYSL_TWO), 0) / nullif(sum(ZSL_TWO), 0) * 100), 2)     zysllTwo,
               trunc((nvl(sum(ZYSL_TOTAL), 0) / nullif(sum(ZSL_TOTAL), 0) * 100), 2) zysllTotal,
               trunc(((nvl(sum(GSL_TOTAL), 0) +
                       nvl(sum(GSL_QBJ), 0) -
                       nvl(sum(SSL_TOTAL), 0)) /
                      nullif(sum(GSL_TOTAL), 0) *
                      100), 4)                                                       cxc,
               trunc(((nvl(sum(GSL_TOTAL), 0) +
                       nvl(sum(GSL_QBJ), 0) -
                       nvl(sum(SSL_TOTAL), 0) -
                       nvl(sum(WSPSL), 0)) / nullif(sum(GSL_TOTAL), 0) * 100), 4)    lsl,
               sum(OTHER)                                                            other
        from TF_YWPN_COSTRLWATER_W
        where to_char(UP_DATE, 'yyyy-mm') = #{month}
          and mark = 0
        group by to_char(UP_DATE, 'yyyy-mm')
    </select>

    <select id="viewWater" resultType="com.tofly.xrtygis.custom.entity.vo.WaterVo">
        select
        ID,
        MARK,
        nvl(SY_ONE,0) syOne,
        ZYSL_ONE zyslOne,
        ZYSL_TWO zyslTwo,
        ZYSL_TOTAL zyslTotal,
        nvl(PAC_ONE,0) pacOne,
        nvl(YL_TWO,0) ylTwo,
        nvl(PAC_TWO,0) pacTwo,
        nvl(PAM,0) pam,
        nvl(FT,0) ft,
        nvl(CN,0) cn,
        nvl(GMSJFHY,0) gmsjfhy,
        nvl(PAM_WY,0) pamWy,
        nvl(BCS,0) bcs,
        nvl(WNZL,0) wnzl,
        nvl(JBDL_ONE, 0) jbdlOne,
        nvl(JBDL_TWO, 0) jbdlTwo,
        nvl(JBDL_TOTAL, 0) jbdlTotal,
        nvl(DLDL_ONE,0) dldlOne,
        nvl(DLDL_TWO,0) dldlTwo,
        nvl(DLDL_TOTAL,0) dldlTotal,
        nvl(GSL_ONE,0) gslOne,
        nvl(GSL_TWO,0) gslTwo,
        nvl(GSL_QBJ,0) gslQbj,
        nvl(GSL_TOTAL,0) gslTotal,
        nvl(ZSL_ONE,0) zslOne,
        nvl(ZSL_TWO,0) zslTwo,
        nvl(ZSL_TOTAL,0) zslTotal,
        nvl(ZSL_HQSK,0) zslHqsk,
        nvl(WSPSL,0) wspsl,
        nvl(SSL_TOTAL,0) sslTotal,
        nvl(ZYSLL_ONE,0) zysllOne,
        nvl(ZYSLL_TWO,0) zysllTwo,
        nvl(ZYSLL_TOTAL,0) zysllTotal,
        nvl(OTHER,0) other ,
        nvl(CXC,0) cxc,
        nvl(LSL,0) lsl,
        to_char(UP_DATE,'yyyy-mm-dd') month
        from TF_YWPN_COSTRLWATER_W
        where MARK = '0'
        <if test="month != null ">
            and to_char(UP_DATE, 'yyyy-mm') = #{month}
        </if>
        <if test="month == null">
            and to_char(UP_DATE,'yyyy-mm') between to_char(add_months(sysdate,-1),'yyyy-mm') and
            to_char(sysdate,'yyyy-mm')
        </if>
        order by month
    </select>

    <select id="getInfoByDay" resultType="long">
        select ID
        from ${name}
        where MARK = #{mark}
          and to_char(up_date, 'yyyy-mm-dd') = #{day}
    </select>
</mapper>