<!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,
               round(SY_ONE, 4)      syOne,
               round(PAC_ONE, 4)     pacOne,
               round(YL_TWO, 4)      ylTwo,
               round(PAC_TWO, 4)     pacTwo,
               round(PAM, 4)         pam,
               round(FT, 4)          ft,
               round(CN, 4)          cn,
               round(CN_TWO, 4)      cnTwo,
               round(GMSJFHY, 4)     gmsjfhy,
               round(PAM_WN, 4)      pamWy,
               round(BCS, 4)         bcs,
               round(WNZL, 4)        wnzl,
               round(DLDL_ONE, 4)    dldlOne,
               round(DLDL_TWO, 4)    dldlTwo,
               round(DLDL_TOTAL, 4)  dldlTotal,
               round(GSL_ONE, 4)     gslOne,
               round(GSL_TWO, 4)     gslTwo,
               round(GSL_QBJ, 4)     gslQbj,
               round(GSL_TOTAL, 4)   gslTotal,
               round(ZSL_ONE, 4)     zslOne,
               round(ZSL_TWO, 4)     zslTwo,
               round(ZSL_TOTAL, 4)   zslTotal,
               round(ZSL_HQSK, 4)    ZslHqsk,
               round(WSPSL, 4)       wspsl,
               round(ZYSL_ONE, 4)    zyslOne,
               round(ZYSL_TWO, 4)    zyslTwo,
               round(ZYSL_TOTAL, 4)  zyslTotal,
               round(JBDL_ONE, 4)    jbdlOne,
               round(JBDL_TWO, 4)    jbdlTwo,
               round(JBDL_TOTAL, 4)  jbdlTotal,
               round(SSL_TOTAL, 4)   sslTotal,
               round(ZYSLL_ONE, 4)   zysllOne,
               round(ZYSLL_TWO, 4)   zysllTwo,
               round(ZYSLL_TOTAL, 4) zysllTotal,
               round(CXC, 4)         cxc,
               round(LSL, 4)         lsl,
               round(OTHER, 4)       other,
               round(OTHER_ONE, 4)   otherOne,
               round(OTHER_TWO, 4)   otherTwo
        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,
               round(SY_ONE, 4)               syOne,
               round(PAC_ONE, 4)              pacOne,
               round(YL_TWO, 4)               ylTwo,
               round(PAC_TWO, 4)              pacTwo,
               round(PAM, 4)                  pam,
               round(FT, 4)                   ft,
               round(CN, 4)                   cn,
               round(GMSJFHY, 4)              gmsjfhy,
               round(PAM_WY, 4)               pamWy,
               round(BCS, 4)                  bcs,
               round(WNZL, 4)                 wnzl,
               round(JBDL_ONE, 4)             jbdlOne,
               round(JBDL_TWO, 4)             jbdlTwo,
               round(JBDL_TOTAL, 4)           jbdlTotal,
               round(DLDL_ONE, 4)             dldlOne,
               round(DLDL_TWO, 4)             dldlTwo,
               round(DLDL_TOTAL, 4)           dldlTotal,
               round(GSL_ONE, 4)              gslOne,
               round(GSL_TWO, 4)              gslTwo,
               round(GSL_QBJ, 4)              gslQbj,
               round(GSL_TOTAL, 4)            gslTotal,
               round(ZSL_ONE, 4)              zslOne,
               round(ZSL_TWO, 4)              zslTwo,
               round(ZSL_TOTAL, 4)            zslTotal,
               round(ZSL_HQSK, 4)             zslHqsk,
               round(WSPSL, 4)                wspsl,
               round(ZYSL_ONE, 4)             zyslOne,
               round(ZYSL_TWO, 4)             zyslTwo,
               round(ZYSL_TOTAL, 4)           zyslTotal,
               round(SSL_TOTAL, 4)            sslTotal,
               round(ZYSLL_ONE, 4)            zysllOne,
               round(ZYSLL_TWO, 4)            zysllTwo,
               round(ZYSLL_TOTAL, 4)          zysllTotal,
               round(CN_TWO, 4)               cnTwo,
               round(CXC, 4)                  cxc,
               round(LSL, 4)                  lsl,
               round(OTHER, 4)                other,
               round(OTHER_ONE, 4)            otherOne,
               round(OTHER_TWO, 4)            otherTwo,
               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 round(sum(SY_ONE), 4)                                                               syOne,
               round(sum(PAC_ONE), 4)                                                              pacOne,
               round(sum(YL_TWO), 4)                                                               ylTwo,
               round(sum(PAC_TWO), 4)                                                              pacTwo,
               round(sum(PAM), 4)                                                                  pam,
               round(sum(FT), 4)                                                                   ft,
               round(sum(CN), 4)                                                                   cn,
               round(sum(CN_TWO), 4)                                                               cnTwo,
               round(sum(GMSJFHY), 4)                                                              gmsjfhy,
               round(sum(PAM_WY), 4)                                                               pamWy,
               round(sum(BCS), 4)                                                                  bcs,
               round(sum(WNZL), 4)                                                                 wnzl,
               round(sum(JBDL_ONE), 4)                                                             jbdlOne,
               round(sum(JBDL_TWO), 4)                                                             jbdlTwo,
               round(sum(JBDL_TOTAL), 4)                                                           jbdlTotal,
               round(sum(DLDL_ONE), 4)                                                             dldlOne,
               round(sum(DLDL_TWO), 4)                                                             dldlTwo,
               round(sum(DLDL_TOTAL), 4)                                                           dldlTotal,
               round(sum(GSL_ONE), 4)                                                              gslOne,
               round(sum(GSL_TWO), 4)                                                              gslTwo,
               round(sum(GSL_QBJ), 4)                                                              gslQbj,
               round(sum(GSL_TOTAL), 4)                                                            gslTotal,
               round(sum(ZSL_ONE), 4)                                                              zslOne,
               round(sum(ZSL_TWO), 4)                                                              zslTwo,
               round(sum(ZSL_TOTAL), 4)                                                            zslTotal,
               round(sum(ZSL_HQSK), 4)                                                             zslHqsk,
               round(sum(WSPSL), 4)                                                                wspsl,
               round(sum(SSL_TOTAL), 4)                                                            sslTotal,
               round(sum(ZYSL_ONE), 4)                                                             zyslOne,
               round(sum(ZYSL_TWO), 4)                                                             zyslTwo,
               round(sum(ZYSL_TOTAL), 4)                                                           zyslTotal,
               round((nvl(sum(ZYSL_ONE), 0) / nullif(sum(ZSL_ONE), 0) * 100), 2)                   zysllOne,
               round((nvl(sum(ZYSL_TWO), 0) / nullif(sum(ZSL_TWO), 0) * 100), 2)                   zysllTwo,
               round((nvl(sum(ZYSL_TOTAL), 0) / nullif(sum(ZSL_TOTAL), 0) * 100), 2)               zysllTotal,
               round(((nvl(sum(GSL_TOTAL), 0) +
                       nvl(sum(GSL_QBJ), 0) -
                       nvl(sum(SSL_TOTAL), 0)) /
                      nullif((sum(GSL_TOTAL) + sum(GSL_QBJ)), 0) *
                      100), 2)                                                                     cxc,
               round(((nvl(sum(GSL_TOTAL), 0) +
                       nvl(sum(GSL_QBJ), 0) -
                       nvl(sum(SSL_TOTAL), 0) -
                       nvl(sum(WSPSL), 0)) / nullif((sum(GSL_TOTAL) + sum(GSL_QBJ)), 0) * 100), 4) lsl,
               sum(OTHER)                                                                          other,
               sum(OTHER_ONE)                                                                      otherOne,
               sum(OTHER_TWO)                                                                      otherTwo
        from TF_YWPN_COSTRLWATER_W
        where to_char(UP_DATE, 'yyyy-mm-dd') between #{start} and #{end}
          and mark = 0
    </select>

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

    <select id="sumWaterCost" resultType="map">
        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(wspsl)      wspsl,
               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_wy,
               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,
               sum(other)      other
        from TF_YWPN_COSTRLWATER_W
        where MARK = 0
          and to_char(UP_DATE, 'yyyy-mm-dd') between #{start} and #{end}
    </select>

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