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

    <select id="getTableInfo" resultType="long">
        select ID
        from ${table}
        where MARK = #{mark}
        <if test="mark ==0">
            and to_char(up_date,'yyyy-mm-dd') = to_char(#{update},'yyyy-mm-dd')
        </if>
        <if test="mark == 1">
            and to_char(up_date,'yyyy-mm') = to_char(#{update},'yyyy-mm')
        </if>
    </select>

    <select id="getPriceID" resultType="long">
        select ID
        from TF_YWPN_COSTRLPRICE_W
        where ISNEW = '1'
          and YEAR = to_char(#{date}, 'yyyy')
    </select>

    <select id="simulationCorrection" resultType="map">
        select to_char(w.UP_DATE, 'yyyy-mm') month,
               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,
               round(pac_one, 4)             pac_one,
               round(pac_two, 4)             pac_two,
               round(sy_one, 4)              sy_one,
               round(yl_two, 4)              yl_two,
               round(pam, 4)                 pam,
               round(ft, 4)                  ft,
               round(cn, 4)                  cn,
               round(CN_TWO, 4)              CN_TWO,
               round(gmsjfhy, 4)             gmsjfhy,
               round(pam_wy, 4)              pam_wn,
               round(bcs, 4)                 bcs,
               round(wnzl, 4)                wnzl,
               round(dldl_one, 4)            dldl_one,
               round(dldl_two, 4)            dldl_two,
               round(dldl_total, 4)          dldl_total,
               round(jbdl_one, 4)            jbdl_one,
               round(jbdl_two, 4)            jbdl_two,
               round(jbdl_total, 4)          jbdl_total,
               round(other, 4)               other,
               round(OTHER_ONE, 4)           OTHER_ONE,
               round(OTHER_TWO, 4)           OTHER_TWO,
               round(CN_TWO, 4)              CN_TWO,
               round(CNDH_TWO, 4)            CNDH_TWO,
               round(OTHER_ONE_ZFY, 4)       OTHER_ONE_ZFY,
               round(OTHER_ONE_CB, 4)        OTHER_ONE_CB,
               round(OTHER_TWO_ZFY, 4)       OTHER_TWO_ZFY,
               round(OTHER_TWO_CB, 4)        OTHER_TWO_CB,
               round(OTHER_ONE_DH, 4)        OTHER_ONE_DH,
               round(OTHER_TWO_DH, 4)        OTHER_TWO_DH,
               round(OTHERCB, 4)             OTHERCB,
               round(OTHERZFY, 4)            OTHERZFY,
               round(paczfy_one, 4)          paczfy_one,
               round(paczfy_two, 4)          paczfy_two,
               round(syzfy_one, 4)           syzfy_one,
               round(ylzfy_two, 4)           ylzfy_two,
               round(pamzszfy, 4)            pamzszfy,
               round(ftzfy, 4)               ftzfy,
               round(cnzfy, 4)               cnzfy,
               round(gmsjfhyzfy, 4)          gmsjfhyzfy,
               round(pamwnzfy, 4)            pamwnzfy,
               round(bcszfy, 4)              bcszfy,
               round(wnzyf, 4)               wnzyf,
               round(jbdf_one, 4)            jbdf_one,
               round(jbdf_two, 4)            jbdf_two,
               round(jbdf_total, 4)          jbdf_total,
               round(dldf_one, 4)            dldf_one,
               round(dldf_two, 4)            dldf_two,
               round(dldf_total, 4)          dldf_total,
               round(ysf, 4)                 ysf,
               round(CNZFY_TWO, 4)           CNZFY_TWO,
               round(szysf_one, 4)           szysf_one,
               round(szysf_two, 4)           szysf_two,
               round(szysf_total, 4)         szysf_total,
               round(dfcb_one, 4)            dfcb_one,
               round(dfcb_two, 4)            dfcb_two,
               round(dfcb_total, 4)          dfcb_total,
               round(paccb_one, 4)           paccb_one,
               round(sycb_one, 4)            sycb_one,
               round(cncb_one, 4)            cncb_one,
               round(bcscb_one, 4)           bcscb_one,
               round(zsclcb_one, 4)          zsclcb_one,
               round(paccb_two, 4)           paccb_two,
               round(ylcb_two, 4)            ylcb_two,
               round(pamzscb_two, 4)         pamzscb_two,
               round(ftcb_two, 4)            ftcb_two,
               round(gmsjfhycb_two, 4)       gmsjfhycb_two,
               round(pamwncb_two, 4)         pamwncb_two,
               round(wnzycb_two, 4)          wnzycb_two,
               round(zsclcb_two, 4)          zsclcb_two,
               round(zsclcb_total, 4)        zsclcb_total,
               round(ysfcb, 4)               ysfcb,
               round(szysfcb_one, 4)         szysfcb_one,
               round(szysfcb_two, 4)         szysfcb_two,
               round(szysfcb_total, 4)       szysfcb_total,
               round(zfy_one, 4)             zfy_one,
               round(zfy_two, 4)             zfy_two,
               round(CNCB_TWO, 4)            CNCB_TWO,
               round(dwcb_one, 4)            dwcb_one,
               round(dwcb_two, 4)            dwcb_two,
               round(dwcb_total, 4)          dwcb_total,
               round(zzsclfy_one, 4)         zzsclfy_one,
               round(zzsclfy_two, 4)         zzsclfy_two,
               round(zfy, 4)                 zfy,
               round(otherzfy, 4)            otherzfy,
               round(othercb, 4)             othercb,
               round(pacdh_one, 4)           pacdh_one,
               round(pacdh_two, 4)           pacdh_two,
               round(sydh_one, 4)            sydh_one,
               round(yldh_two, 4)            yldh_two,
               round(dh_one, 4)              dh_one,
               round(dh_two, 4)              dh_two,
               round(dh_total, 4)            dh_total,
               round(cndh, 4)                cndh,
               round(gmsjfhydh, 4)           gmsjfhydh,
               round(pamdh, 4)               pamdh,
               round(pam_wydh, 4)            pam_wndh,
               round(wnzldh, 4)              wnzldh,
               round(ftdh, 4)                ftdh,
               round(bcsdh, 4)               bcsdh,
               round(otherdh, 4)             otherdh
        from (TF_YWPN_COSTRLWATER_W w
            left join TF_YWPN_COSTRLFIXED_W f on
                    to_char(w.UP_DATE, 'yyyy-mm') = to_char(f.UP_DATE, 'yyyy-mm') and w.MARK = f.MARK)
                 left join TF_YWPN_COSTRLUNIT_W u
                           on to_char(w.UP_DATE, 'yyyy-mm') = to_char(u.UP_DATE, 'yyyy-mm') and w.MARK = u.MARK
        where w.MARK = 1
          and to_char(w.UP_DATE, 'yyyy-mm') = #{month}
    </select>

    <select id="simulationCorrectionYear" resultType="map">
        select extract(YEAR FROM w.UP_DATE)                                                         year,
               round(sum(CN_TWO), 4)                                                                cn_two,
               round(sum(CNZFY_TWO), 4)                                                             cnzfy_two,
               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,
               round(sum(wspsl), 4)                                                                 wspsl,
               round(((sum(GSL_TOTAL) + sum(GSL_QBJ) - sum(SSL_TOTAL)) / nullif(sum(GSL_TOTAL) + sum(GSL_QBJ), 0)) *
                     100, 2)                                                                        cxc,
               round(((sum(GSL_TOTAL) + sum(GSL_QBJ) - sum(SSL_TOTAL) - sum(WSPSL)) /
                      nullif(sum(GSL_TOTAL) + sum(GSL_QBJ), 0)) * 100, 2)                           lsl,
               round(sum(pac_one), 4)                                                               pac_one,
               round(sum(pac_two), 4)                                                               pac_two,
               round(sum(sy_one), 4)                                                                sy_one,
               round(sum(yl_two), 4)                                                                yl_two,
               round(sum(pam), 4)                                                                   pam,
               round(sum(ft), 4)                                                                    ft,
               round(sum(cn), 4)                                                                    cn,
               round(sum(gmsjfhy), 4)                                                               gmsjfhy,
               round(sum(pam_wy), 4)                                                                pam_wn,
               round(sum(bcs), 4)                                                                   bcs,
               round(sum(wnzl), 4)                                                                  wnzl,
               round(sum(dldl_one), 4)                                                              dldl_one,
               round(sum(dldl_two), 4)                                                              dldl_two,
               round(sum(dldl_total), 4)                                                            dldl_total,
               round(sum(jbdl_one), 4)                                                              jbdl_one,
               round(sum(jbdl_two), 4)                                                              jbdl_two,
               round(sum(jbdl_total), 4)                                                            jbdl_total,
               round(sum(other), 4)                                                                 other,
               round(sum(OTHER_ONE), 4)                                                             OTHER_ONE,
               round(sum(OTHER_TWO), 4)                                                             OTHER_TWO,
               round(sum(paczfy_one), 4)                                                            paczfy_one,
               round(sum(paczfy_two), 4)                                                            paczfy_two,
               round(sum(syzfy_one), 4)                                                             syzfy_one,
               round(sum(ylzfy_two), 4)                                                             ylzfy_two,
               round(sum(pamzszfy), 4)                                                              pamzszfy,
               round(sum(ftzfy), 4)                                                                 ftzfy,
               round(sum(cnzfy), 4)                                                                 cnzfy,
               round(sum(gmsjfhyzfy), 4)                                                            gmsjfhyzfy,
               round(sum(pamwnzfy), 4)                                                              pamwnzfy,
               round(sum(bcszfy), 4)                                                                bcszfy,
               round(sum(wnzyf), 4)                                                                 wnzyf,
               round(sum(jbdf_one), 4)                                                              jbdf_one,
               round(sum(jbdf_two), 4)                                                              jbdf_two,
               round(sum(jbdf_total), 4)                                                            jbdf_total,
               round(sum(dldf_one), 4)                                                              dldf_one,
               round(sum(dldf_two), 4)                                                              dldf_two,
               round(sum(dldf_total), 4)                                                            dldf_total,
               round(sum(ysf), 4)                                                                   ysf,
               round(sum(szysf_one), 4)                                                             szysf_one,
               round(sum(szysf_two), 4)                                                             szysf_two,
               round(sum(szysf_total), 4)                                                           szysf_total,
               round(((sum(JBDF_ONE) + sum(DLDF_ONE)) / nullif(sum(GSL_ONE), 0)) * 1000, 5)         dfcb_one,
               round(((sum(JBDF_TWO) + sum(DLDF_TWO)) / nullif(sum(GSL_TWO), 0)) * 1000, 5)         dfcb_two,
               round(((sum(JBDF_TOTAL) + sum(DLDF_TOTAL)) / nullif(sum(GSL_TOTAL), 0)) * 1000, 5)   dfcb_total,
               round((sum(PACZFY_ONE) / nullif(sum(GSL_ONE), 0)) * 1000, 5)                         paccb_one,
               round((sum(SYZFY_ONE) / nullif(sum(GSL_ONE), 0)) * 1000, 5)                          sycb_one,
               round((sum(CNZFY) / nullif(sum(GSL_ONE), 0)) * 1000, 5)                              cncb_one,
               round((sum(CNZFY_TWO) / nullif(sum(GSL_TWO), 0)) * 1000, 5)                          cncb_two,
               round((sum(BCSZFY) / nullif(sum(GSL_ONE), 0)) * 1000, 5)                             bcscb_one,
               round((sum(ZZSCLFY_ONE) / nullif(sum(GSL_ONE), 0)) * 1000, 5)                        zsclcb_one,
               round((sum(PACZFY_TWO) / nullif(sum(GSL_TWO), 0)) * 1000, 5)                         paccb_two,
               round((sum(YLZFY_TWO) / nullif(sum(GSL_TWO), 0)) * 1000, 5)                          ylcb_two,
               round((sum(PAMZSZFY) / nullif(sum(GSL_TWO), 0)) * 1000, 5)                           pamzscb_two,
               round((sum(FTZFY) / nullif(sum(GSL_TWO), 0)) * 1000, 5)                              ftcb_two,
               round((sum(GMSJFHYZFY) / nullif(sum(GSL_TWO), 0)) * 1000, 5)                         gmsjfhycb_two,
               round((sum(PAMWNZFY) / nullif(sum(GSL_TWO), 0)) * 1000, 5)                           pamwncb_two,
               round((sum(WNZYF) / nullif(sum(GSL_TWO), 0)) * 1000, 5)                              wnzycb_two,
               round((sum(ZZSCLFY_TWO) / nullif(sum(GSL_TWO), 0)) * 1000, 5)                        zsclcb_two,
               round(((sum(ZZSCLFY_ONE) + sum(ZZSCLFY_TWO)) / nullif(sum(GSL_TOTAL), 0)) * 1000, 5) zsclcb_total,
               round((sum(YSF) / nullif(sum(GSL_ONE), 0)) * 1000, 5)                                ysfcb,
               round((sum(SZYSF_ONE) / nullif(sum(GSL_ONE), 0)) * 1000, 5)                          szysfcb_one,
               round((sum(SZYSF_TWO) / nullif(sum(GSL_TWO), 0)) * 1000, 5)                          szysfcb_two,
               round((sum(SZYSF_TOTAL) / nullif(sum(GSL_TOTAL), 0)) * 1000, 5)                      szysfcb_total,
               round(sum(ZFY_ONE), 4)                                                               zfy_one,
               round(sum(ZFY_TWO), 4)                                                               zfy_two,
               round((sum(ZFY_ONE) / nullif(sum(GSL_TOTAL), 0)) * 1000, 5)                          dwcb_one,
               round((sum(ZFY_TWO) / nullif(sum(GSL_TOTAL), 0)) * 1000, 5)                          dwcb_two,
               round((sum(ZFY) / nullif(sum(GSL_TOTAL), 0)) * 1000, 5)                              dwcb_total,
               round(sum(zzsclfy_one), 4)                                                           zzsclfy_one,
               round(sum(zzsclfy_two), 4)                                                           zzsclfy_two,
               round(sum(ZFY), 4)                                                                   zfy,
               round(sum(otherzfy), 4)                                                              otherzfy,
               round(sum(OTHER_ONE_ZFY), 4)                                                         OTHER_ONE_ZFY,
               round(sum(OTHER_TWO_ZFY), 4)                                                         OTHER_TWO_ZFY,
               round(sum(OTHER) / nullif(sum(GSL_ONE) * 10, 0), 5)                                  othercb,
               round(sum(OTHER_ONE_ZFY) / nullif(sum(GSL_ONE) * 10, 0), 5)                          other_one_cb,
               round(sum(OTHER_TWO_ZFY) / nullif(sum(GSL_TWO) * 10, 0), 5)                          other_two_cb,
               round(sum(PAC_ONE) / nullif(sum(GSL_ONE) * 10, 0), 5)                                pacdh_one,
               round(sum(PAC_TWO) / nullif(sum(GSL_TWO) * 10, 0), 5)                                pacdh_two,
               round(sum(SY_ONE) / nullif(sum(GSL_ONE) * 10, 0), 5)                                 sydh_one,
               round(sum(YL_TWO) / nullif(sum(GSL_TWO) * 10, 0), 5)                                 yldh_two,
               round(sum(DLDL_ONE) / nullif(sum(GSL_ONE) * 10, 0), 5)                               dh_one,
               round(sum(DLDL_TWO) / nullif(sum(GSL_TWO) * 10, 0), 5)                               dh_two,
               round(sum(DLDL_TOTAL) / nullif(sum(GSL_TOTAL) * 10, 0), 5)                           dh_total,
               round(sum(CN) / nullif(sum(GSL_ONE) * 10, 0), 5)                                     cndh,
               round(sum(CN_TWO) / nullif(sum(GSL_TWO) * 10, 0), 5)                                 cndh_two,
               round(sum(GMSJFHY) / nullif(sum(GSL_TWO) * 10, 0), 5)                                gmsjfhydh,
               round(sum(PAM) / nullif(sum(GSL_TWO) * 10, 0), 5)                                    pamdh,
               round(sum(PAM_WY) / nullif(sum(GSL_TWO) * 10, 0), 5)                                 pam_wndh,
               round(sum(GMSJFHY) / nullif(sum(GSL_TWO) * 10, 0), 5)                                wnzldh,
               round(sum(FT) / nullif(sum(GSL_TWO) * 10, 0), 5)                                     ftdh,
               round(sum(BCS) / nullif(sum(GSL_ONE) * 10, 0), 5)                                    bcsdh,
               round(sum(OTHER) / nullif(sum(GSL_ONE) * 10, 0), 5)                                  otherdh,
               round(sum(OTHER_ONE) / nullif(sum(GSL_ONE) * 10, 0), 5)                              other_one_dh,
               round(sum(OTHER_TWO) / nullif(sum(GSL_TWO) * 10, 0), 5)                              other_two_dh
        from (TF_YWPN_COSTRLWATER_W w
                 left join TF_YWPN_COSTRLFIXED_W f on
                extract(year from w.UP_DATE) = extract(year from f.UP_DATE) and w.MARK = f.MARK)
        where w.MARK = 1
          and extract(year from w.UP_DATE) = #{year}
        group by extract(YEAR FROM w.UP_DATE)
    </select>

    <select id="getMonthPlanYear" resultType="map">
        select substr(w.MONTH, 1, 4)                                                                year,
               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,
               round(sum(wspsl), 4)                                                                 wspsl,
               round(((sum(GSL_TOTAL) + sum(GSL_QBJ) - sum(SSL_TOTAL)) / nullif(sum(GSL_TOTAL) + sum(GSL_QBJ), 0)) *
                     100, 2)                                                                        cxc,
               round(((sum(GSL_TOTAL) + sum(GSL_QBJ) - sum(SSL_TOTAL) - sum(WSPSL)) /
                      nullif(sum(GSL_TOTAL) + sum(GSL_QBJ), 0)) * 100, 2)                           lsl,
               round(sum(pac_one), 4)                                                               pac_one,
               round(sum(pac_two), 4)                                                               pac_two,
               round(sum(sy_one), 4)                                                                sy_one,
               round(sum(yl_two), 4)                                                                yl_two,
               round(sum(pam), 4)                                                                   pam,
               round(sum(ft), 4)                                                                    ft,
               round(sum(cn), 4)                                                                    cn,
               round(sum(CN_TWO), 4)                                                                CN_TWO,
               round(sum(gmsjfhy), 4)                                                               gmsjfhy,
               round(sum(pam_wn), 4)                                                                pam_wn,
               round(sum(bcs), 4)                                                                   bcs,
               round(sum(wnzl), 4)                                                                  wnzl,
               round(sum(dldl_one), 4)                                                              dldl_one,
               round(sum(dldl_two), 4)                                                              dldl_two,
               round(sum(dldl_total), 4)                                                            dldl_total,
               round(sum(jbdl_one), 4)                                                              jbdl_one,
               round(sum(jbdl_two), 4)                                                              jbdl_two,
               round(sum(jbdl_total), 4)                                                            jbdl_total,
               round(sum(other), 4)                                                                 other,
               round(sum(OTHER_ONE), 4)                                                             OTHER_ONE,
               round(sum(OTHER_TWO), 4)                                                             OTHER_TWO,
               round(sum(paczfy_one), 4)                                                            paczfy_one,
               round(sum(paczfy_two), 4)                                                            paczfy_two,
               round(sum(syzfy_one), 4)                                                             syzfy_one,
               round(sum(ylzfy_two), 4)                                                             ylzfy_two,
               round(sum(pamzszfy), 4)                                                              pamzszfy,
               round(sum(ftzfy), 4)                                                                 ftzfy,
               round(sum(cnzfy), 4)                                                                 cnzfy,
               round(sum(CNZFY_TWO), 4)                                                             CNZFY_TWO,
               round(sum(gmsjfhyzfy), 4)                                                            gmsjfhyzfy,
               round(sum(pamwnzfy), 4)                                                              pamwnzfy,
               round(sum(bcszfy), 4)                                                                bcszfy,
               round(sum(wnzyf), 4)                                                                 wnzyf,
               round(sum(jbdf_one), 4)                                                              jbdf_one,
               round(sum(jbdf_two), 4)                                                              jbdf_two,
               round(sum(jbdf_total), 4)                                                            jbdf_total,
               round(sum(dldf_one), 4)                                                              dldf_one,
               round(sum(dldf_two), 4)                                                              dldf_two,
               round(sum(dldf_total), 4)                                                            dldf_total,
               round(sum(ysf), 4)                                                                   ysf,
               round(sum(szysf_one), 4)                                                             szysf_one,
               round(sum(szysf_two), 4)                                                             szysf_two,
               round(sum(szysf_total), 4)                                                           szysf_total,
               round(((sum(JBDF_ONE) + sum(DLDF_ONE)) / nullif(sum(GSL_ONE), 0)) * 1000, 5)         dfcb_one,
               round(((sum(JBDF_TWO) + sum(DLDF_TWO)) / nullif(sum(GSL_TWO), 0)) * 1000, 5)         dfcb_two,
               round(((sum(JBDF_TOTAL) + sum(DLDF_TOTAL)) / nullif(sum(GSL_TOTAL), 0)) * 1000, 5)   dfcb_total,
               round((sum(PACZFY_ONE) / nullif(sum(GSL_ONE), 0)) * 1000, 5)                         paccb_one,
               round((sum(SYZFY_ONE) / nullif(sum(GSL_ONE), 0)) * 1000, 5)                          sycb_one,
               round((sum(CNZFY) / nullif(sum(GSL_ONE), 0)) * 1000, 5)                              cncb_one,
               round((sum(BCSZFY) / nullif(sum(GSL_ONE), 0)) * 1000, 5)                             bcscb_one,
               round((sum(ZZSCLFY_ONE) / nullif(sum(GSL_ONE), 0)) * 1000, 5)                        zsclcb_one,
               round((sum(PACZFY_TWO) / nullif(sum(GSL_TWO), 0)) * 1000, 5)                         paccb_two,
               round((sum(YLZFY_TWO) / nullif(sum(GSL_TWO), 0)) * 1000, 5)                          ylcb_two,
               round((sum(PAMZSZFY) / nullif(sum(GSL_TWO), 0)) * 1000, 5)                           pamzscb_two,
               round((sum(FTZFY) / nullif(sum(GSL_TWO), 0)) * 1000, 5)                              ftcb_two,
               round((sum(GMSJFHYZFY) / nullif(sum(GSL_TWO), 0)) * 1000, 5)                         gmsjfhycb_two,
               round((sum(PAMWNZFY) / nullif(sum(GSL_TWO), 0)) * 1000, 5)                           pamwncb_two,
               round((sum(WNZYF) / nullif(sum(GSL_TWO), 0)) * 1000, 5)                              wnzycb_two,
               round((sum(ZZSCLFY_TWO) / nullif(sum(GSL_TWO), 0)) * 1000, 5)                        zsclcb_two,
               round(((sum(ZZSCLFY_ONE) + sum(ZZSCLFY_TWO)) / nullif(sum(GSL_TOTAL), 0)) * 1000, 5) zsclcb_total,
               round((sum(YSF) / nullif(sum(GSL_ONE), 0)) * 1000, 5)                                ysfcb,
               round((sum(SZYSF_ONE) / nullif(sum(GSL_ONE), 0)) * 1000, 5)                          szysfcb_one,
               round((sum(SZYSF_TWO) / nullif(sum(GSL_TWO), 0)) * 1000, 5)                          szysfcb_two,
               round((sum(SZYSF_TOTAL) / nullif(sum(GSL_TOTAL), 0)) * 1000, 5)                      szysfcb_total,
               round(sum(ZFY_ONE), 4)                                                               zfy_one,
               round(sum(ZFY_TWO), 4)                                                               zfy_two,
               round((sum(ZFY_ONE) / nullif(sum(GSL_TOTAL), 0)) * 1000, 5)                          dwcb_one,
               round((sum(ZFY_TWO) / nullif(sum(GSL_TOTAL), 0)) * 1000, 5)                          dwcb_two,
               round((sum(ZFY) / nullif(sum(GSL_TOTAL), 0)) * 1000, 5)                              dwcb_total,
               round(sum(zzsclfy_one), 4)                                                           zzsclfy_one,
               round(sum(zzsclfy_two), 4)                                                           zzsclfy_two,
               round(sum(ZFY), 4)                                                                   zfy,
               round(sum(otherzfy), 4)                                                              otherzfy,
               round(sum(OTHER_ONE_ZFY), 4)                                                         OTHER_ONE_ZFY,
               round(sum(OTHER_TWO_ZFY), 4)                                                         OTHER_TWO_ZFY,
               round(sum(OTHER) / nullif(sum(GSL_ONE) * 10, 0), 5)                                  othercb,
               round(sum(OTHER_ONE_ZFY) / nullif(sum(GSL_ONE) * 10, 0), 5)                          other_one_cb,
               round(sum(OTHER_TWO_ZFY) / nullif(sum(GSL_TWO) * 10, 0), 5)                          other_two_cb,
               round(sum(PAC_ONE) / nullif(sum(ZSL_ONE) * 10, 0), 5)                                pacdh_one,
               round(sum(PAC_TWO) / nullif(sum(ZSL_TWO) * 10, 0), 5)                                pacdh_two,
               round(sum(SY_ONE) / nullif(sum(ZSL_ONE) * 10, 0), 5)                                 sydh_one,
               round(sum(YL_TWO) / nullif(sum(ZSL_TWO) * 10, 0), 5)                                 yldh_two,
               round(sum(DLDL_ONE) / nullif(sum(ZSL_ONE) * 10, 0), 5)                               dh_one,
               round(sum(DLDL_TWO) / nullif(sum(ZSL_TWO) * 10, 0), 5)                               dh_two,
               round(sum(DLDL_TOTAL) / nullif(sum(ZSL_TOTAL) * 10, 0), 5)                           dh_total,
               round(sum(CN) / nullif(sum(ZSL_ONE) * 10, 0), 5)                                     cndh,
               round(sum(CN_TWO) / nullif(sum(ZSL_TWO) * 10, 0), 5)                                 cndh_two,
               round(sum(GMSJFHY) / nullif(sum(ZSL_TWO) * 10, 0), 5)                                gmsjfhydh,
               round(sum(PAM) / nullif(sum(ZSL_TWO) * 10, 0), 5)                                    pamdh,
               round(sum(PAM_WN) / nullif(sum(ZSL_TWO) * 10, 0), 5)                                 pam_wndh,
               round(sum(GMSJFHY) / nullif(sum(ZSL_TWO) * 10, 0), 5)                                wnzldh,
               round(sum(FT) / nullif(sum(ZSL_TWO) * 10, 0), 5)                                     ftdh,
               round(sum(BCS) / nullif(sum(ZSL_ONE) * 10, 0), 5)                                    bcsdh,
               round(sum(OTHER) / nullif(sum(ZSL_ONE) * 10, 0), 5)                                  otherdh,
               round(sum(OTHER_ONE) / nullif(sum(ZSL_ONE) * 10, 0), 5)                              other_one_dh,
               round(sum(OTHER_TWO) / nullif(sum(ZSL_TWO) * 10, 0), 5)                              other_two_dh
        from TF_YWPN_COSTBGWATER_W w
                 left join TF_YWPN_COSTBGFIXED_W f on
            substr(w.MONTH, 1, 4) = substr(f.MOUTH, 1, 4)
                 left join TF_YWPN_COSTBGINDEX_W i
                           on substr(i.MONTH, 1, 4) = substr(w.MONTH, 1, 4)
        where substr(w.MONTH, 1, 4) = #{year}
        group by substr(w.MONTH, 1, 4)
    </select>

    <select id="getMonthPlan" resultType="map">
        SELECT w.MONTH,
               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,
               round(CN_TWO, 4)                              CN_TWO,
               round(pac_one, 4)                             pac_one,
               round(pac_two, 4)                             pac_two,
               round(sy_one, 4)                              sy_one,
               round(yl_two, 4)                              yl_two,
               round(pam, 4)                                 pam,
               round(ft, 4)                                  ft,
               round(cn, 4)                                  cn,
               round(gmsjfhy, 4)                             gmsjfhy,
               round(pam_wn, 4)                              pam_wn,
               round(bcs, 4)                                 bcs,
               round(wnzl, 4)                                wnzl,
               round(dldl_one, 4)                            dldl_one,
               round(dldl_two, 4)                            dldl_two,
               round(dldl_total, 4)                          dldl_total,
               round(jbdl_one, 4)                            jbdl_one,
               round(jbdl_two, 4)                            jbdl_two,
               round(jbdl_total, 4)                          jbdl_total,
               round(other, 4)                               other,
               round(paczfy_one, 4)                          paczfy_one,
               round(paczfy_two, 4)                          paczfy_two,
               round(syzfy_one, 4)                           syzfy_one,
               round(ylzfy_two, 4)                           ylzfy_two,
               round(pamzszfy, 4)                            pamzszfy,
               round(ftzfy, 4)                               ftzfy,
               round(cnzfy, 4)                               cnzfy,
               round(gmsjfhyzfy, 4)                          gmsjfhyzfy,
               round(pamwnzfy, 4)                            pamwnzfy,
               round(bcszfy, 4)                              bcszfy,
               round(wnzyf, 4)                               wnzyf,
               round(jbdf_one, 4)                            jbdf_one,
               round(jbdf_two, 4)                            jbdf_two,
               round(jbdf_total, 4)                          jbdf_total,
               round(dldf_one, 4)                            dldf_one,
               round(dldf_two, 4)                            dldf_two,
               round(dldf_total, 4)                          dldf_total,
               round(ysf, 4)                                 ysf,
               round(szysf_one, 4)                           szysf_one,
               round(szysf_two, 4)                           szysf_two,
               round(szysf_total, 4)                         szysf_total,
               round(dfcb_one, 4)                            dfcb_one,
               round(dfcb_two, 4)                            dfcb_two,
               round(dfcb_total, 4)                          dfcb_total,
               round(paccb_one, 4)                           paccb_one,
               round(sycb_one, 4)                            sycb_one,
               round(cncb_one, 4)                            cncb_one,
               round(bcscb_one, 4)                           bcscb_one,
               round(zsclcb_one, 4)                          zsclcb_one,
               round(paccb_two, 4)                           paccb_two,
               round(ylcb_two, 4)                            ylcb_two,
               round(pamzscb_two, 4)                         pamzscb_two,
               round(ftcb_two, 4)                            ftcb_two,
               round(gmsjfhycb_two, 4)                       gmsjfhycb_two,
               round(pamwncb_two, 4)                         pamwncb_two,
               round(wnzycb_two, 4)                          wnzycb_two,
               round(zsclcb_two, 4)                          zsclcb_two,
               round(zsclcb_total, 4)                        zsclcb_total,
               round(ysfcb, 4)                               ysfcb,
               round(szysfcb_one, 4)                         szysfcb_one,
               round(szysfcb_two, 4)                         szysfcb_two,
               round(szysfcb_total, 4)                       szysfcb_total,
               round(zfy_one, 4)                             zfy_one,
               round(CNZFY_TWO, 4)                           CNZFY_TWO,
               round(zfy_two, 4)                             zfy_two,
               round(dwcb_one, 4)                            dwcb_one,
               round(dwcb_two, 4)                            dwcb_two,
               round(dwcb_total, 4)                          dwcb_total,
               round(zzsclfy_one, 4)                         zzsclfy_one,
               round(zzsclfy_two, 4)                         zzsclfy_two,
               round(zfy, 4)                                 zfy,
               round(otherzfy, 4)                            otherzfy,
               round(othercb, 4)                             othercb,
               round(CNCB_TWO, 4)                            CNCB_TWO,
               round(pacdh_one, 4)                           pacdh_one,
               round(pacdh_two, 4)                           pacdh_two,
               round(sydh_one, 4)                            sydh_one,
               round(yldh_two, 4)                            yldh_two,
               round(dh_one, 4)                              dh_one,
               round(dh_two, 4)                              dh_two,
               round(dh_total, 4)                            dh_total,
               round(CN / (nullif(ZSL_ONE, 0) * 10), 4)      cndh,
               round(CN_TWO / (nullif(ZSL_TWO, 0) * 10), 4)  cndh_two,
               round(GMSJFHY / (nullif(ZSL_TWO, 0) * 10), 4) gmsjfhydh,
               round(PAM / (nullif(ZSL_TWO, 0) * 10), 4)     pamdh,
               round(PAM_WN / (nullif(ZSL_TWO, 0) * 10), 4)  pam_wndh,
               round(WNZL / (nullif(ZSL_TWO, 0) * 10), 4)    wnzldh,
               round(FT / (nullif(ZSL_TWO, 0) * 10), 4)      ftdh,
               round(BCS / (nullif(ZSL_ONE, 0) * 10), 4)     bcsdh,
               round(OTHERDH, 4)                             OTHERDH,
               round(OTHER_ONE_DH, 4)                        OTHER_ONE_DH,
               round(OTHER_TWO_DH, 4)                        OTHER_TWO_DH,
               round(OTHER_ONE, 4)                           OTHER_ONE,
               round(OTHER_TWO, 4)                           OTHER_TWO,
               round(OTHER_ONE_ZFY, 4)                       OTHER_ONE_ZFY,
               round(OTHER_TWO_ZFY, 4)                       OTHER_TWO_ZFY,
               round(OTHER_ONE_CB, 4)                        OTHER_ONE_CB,
               round(OTHER_TWO_CB, 4)                        OTHER_TWO_CB
        FROM TF_YWPN_COSTBGWATER_W w
                 full join TF_YWPN_COSTBGINDEX_W i on w.MONTH = i.MONTH
                 full join TF_YWPN_COSTBGUNIT_W u on w.MONTH = u.MONTH
                 LEFT JOIN TF_YWPN_COSTBGFIXED_W b ON w.MONTH = b.MOUTH
        where w.MONTH = #{month}
    </select>

    <select id="countWater" resultType="long">
        SELECT count(*)
        FROM TF_YWPN_COSTRLWATER_W
        WHERE to_char(up_date, 'yyyy-mm') = #{month}
          AND mark = 0
    </select>

    <select id="getWaterInfo" resultType="com.tofly.xrtygis.entity.Costrlwater">
        select 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,
        round(pac_one,4)pac_one,
        round(pac_two,4)pac_two,
        round(sy_one,4)sy_one,
        round(yl_two,4)yl_two,
        round(pam,4)pam,
        round(ft,4)ft,
        round(cn,4)cn,
        round(gmsjfhy,4)gmsjfhy,
        round(pam_wy,4)pam_wn,
        round(bcs,4)bcs,
        round(wnzl,4)wnzl,
        round(dldl_one,4)dldl_one,
        round(dldl_two,4)dldl_two,
        round(dldl_total,4)dldl_total,
        round(jbdl_one,4)jbdl_one,
        round(jbdl_two,4)jbdl_two,
        round(jbdl_total,4)jbdl_total,
        round(mark,4)mark,
        round(other,4)other,
        round(OTHER_ONE,4)other_one,
        round(OTHER_TWO,4)other_two
        from TF_YWPN_COSTRLWATER_W
        where MARK = #{mark}
        <if test="mark == 0">
            and to_char(up_date,'yyyy-mm-dd') = to_char(#{update},'yyyy-mm-dd')
        </if>
        <if test="mark == 1">
            and to_char(up_date,'yyyy-mm') = to_char(#{update},'yyyy-mm')
        </if>
    </select>

    <select id="getWaterInfoSum" resultType="com.tofly.xrtygis.custom.entity.dto.WaterInfoDto">
        select sum(GSL_ONE)    gslOne,
               sum(GSL_TWO)    gslTwo,
               sum(GSL_TOTAL)  gslTotal,
               sum(SSL_TOTAL)  ssl,
               sum(WSPSL)      wspsl,
               sum(GSL_QBJ)    gslQbj,
               sum(JBDL_ONE)   jbdlOne,
               sum(JBDL_TWO)   jbdlTwo,
               sum(JBDL_TOTAL) jbdlTotal
        from TF_YWPN_COSTRLWATER_W
        where MARK = '0'
          and to_char(UP_DATE, 'yyyy-mm-dd') between to_char(add_months(#{date}, -1), 'yyyy-mm-') || #{start} and to_char(#{date}, 'yyyy-mm-') || #{end}
    </select>

    <select id="getWater" resultType="com.tofly.xrtygis.entity.Costrlwater">
        select *
        from TF_YWPN_COSTRLWATER_W
        where MARK = #{mark}
          and to_char(UP_DATE, 'yyyy-mm-dd') = to_char(#{date}, 'yyyy-mm-dd')
    </select>
</mapper>