<?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.custom.mapper.DataMonthPlanMapper">

    <!-- *********************制水材料************************* -->

    <select id="getOneMonthActual" resultType="com.tofly.xrtygis.custom.entity.vo.MarkWaterVo">
        select round(GSL_ONE, 4)      gsl,
               round(ZSL_ONE, 4)      zsl,
               round(ZYSL_ONE, 4)     zysl,
               round(ZYSLL_ONE, 4)    zysll,
               round(PACDH_ONE, 4)    pacdh,
               round(SYDH_ONE, 4)     sydh,
               round(DH_ONE, 4)       dh,
               round(PAC_ONE, 4)      pac,
               round(SY_ONE, 4)       sy,
               round(CN, 4)           CN,
               round(CNDH, 4)         cnDh,
               round(BCS, 4)          BCS,
               round(DLDL_ONE, 4)     dldl,
               round(OTHER, 4)        other,
               round(OTHER_ONE, 4)    otherOne,
               round(OTHERDH, 4)      otherdh,
               round(OTHER_ONE_DH, 4) otherOneDh
        from TF_YWPN_COSTRLWATER_W w
                 full join TF_YWPN_COSTRLUNIT_W u
                           on to_char(w.UP_DATE, 'yyyy-mm-dd') = to_char(u.UP_DATE, 'yyyy-mm-dd')
                               and w.MARK = u.MARK
        where w.MARK = '1'
          and to_char(w.UP_DATE, 'yyyy-mm') = #{year}
    </select>

    <select id="getTwoMonthActual" resultType="com.tofly.xrtygis.custom.entity.vo.MarkWaterVo">
        select round(GSL_TWO, 4)      gsl,
               round(ZSL_TWO, 4)      zsl,
               round(ZYSL_TWO, 4)     zysl,
               round(ZYSLL_TWO, 4)    zysll,
               round(PACDH_TWO, 4)    pacdh,
               round(YLDH_TWO, 4)     yldh,
               round(DH_TWO, 4)       dh,
               round(PAC_TWO, 4)      pac,
               round(YL_TWO, 4)       yl,
               round(PAM, 4)          PAM,
               round(FT, 4)           FT,
               round(GMSJFHY, 4)      gmsj,
               round(PAM_WY, 4)       pamwn,
               round(CN_TWO, 4)       cn,
               round(CNDH_TWO, 4)     cnDh,
               round(WNZL, 4)         WNZL,
               round(DLDL_TWO, 4)     dldl,
               round(OTHER_TWO, 4)    otherTwo,
               round(OTHER_TWO_DH, 4) otherTwoDh
        from TF_YWPN_COSTRLWATER_W w
                 full join TF_YWPN_COSTRLUNIT_W u
                           on to_char(w.UP_DATE, 'yyyy-mm-dd') = to_char(u.UP_DATE, 'yyyy-mm-dd')
                               and w.MARK = u.MARK
        where w.MARK = '1'
          and to_char(w.UP_DATE, 'yyyy-mm') = #{year}
    </select>

    <select id="getOneMonthPlan" resultType="com.tofly.xrtygis.custom.entity.vo.MarkWaterVo">
        select round(GSL_ONE, 4)                        gsl,
               round(ZSL_ONE, 4)                        zsl,
               round(ZYSL_ONE, 4)                       zysl,
               round(ZYSLL_ONE, 4)                      zysll,
               round(PACDH_ONE, 4)                      pacdh,
               round(SYDH_ONE, 4)                       sydh,
               round(DH_ONE, 4)                         dh,
               round(PAC_ONE, 4)                        pac,
               round(SY_ONE, 4)                         sy,
               round(CN, 4)                             CN,
               round(CN / (nullif(ZSL_ONE, 0) * 10), 4) cnDh,
               round(BCS, 4)                            BCS,
               round(DLDL_ONE, 4)                       dldl,
               round(OTHER, 4)                          other,
               round(OTHER_ONE, 4)                      otherOne,
               round(OTHERDH, 4)                        otherdh,
               round(OTHER_ONE_DH, 4)                   otherOneDh
        from TF_YWPN_COSTBGWATER_W w,
             TF_YWPN_COSTBGINDEX_W i,
             TF_YWPN_COSTBGUNIT_W u
        where w.MONTH = i.MONTH
          and i.MONTH = u.MONTH
          and w.MONTH = #{year}
    </select>

    <select id="getTwoMonthPlan" resultType="com.tofly.xrtygis.custom.entity.vo.MarkWaterVo">
        select round(GSL_TWO, 4)      gsl,
               round(ZSL_TWO, 4)      zsl,
               round(ZYSL_TWO, 4)     zysl,
               round(ZYSLL_TWO, 4)    zysll,
               round(PACDH_TWO, 4)    pacdh,
               round(YLDH_TWO, 4)     yldh,
               round(DH_TWO, 4)       dh,
               round(PAC_TWO, 4)      pac,
               round(YL_TWO, 4)       yl,
               round(PAM, 4)          PAM,
               round(FT, 4)           FT,
               round(CN_TWO, 4)       cn,
               round(CNDH_TWO, 4)     cnDh,
               round(GMSJFHY, 4)      gmsj,
               round(PAM_WN, 4)       pamwn,
               round(WNZL, 4)         WNZL,
               round(DLDL_TWO, 4)     dldl,
               round(OTHER_TWO, 4)    otherTwo,
               round(OTHER_TWO_DH, 4) otherTwoDh
        from TF_YWPN_COSTBGWATER_W w,
             TF_YWPN_COSTBGINDEX_W i,
             TF_YWPN_COSTBGUNIT_W u
        where w.MONTH = i.MONTH
          and i.MONTH = u.MONTH
          and w.MONTH = #{year}
    </select>

    <select id="getOneMonthPile" resultType="com.tofly.xrtygis.custom.entity.vo.MarkWaterVo">
        select round(sum(GSL_ONE), 4)                                    gsl,
               round(sum(ZSL_ONE), 4)                                    zsl,
               round(sum(ZYSL_ONE), 4)                                   zysl,
               round(sum(ZYSL_ONE) / nullif(sum(ZSL_ONE), 0) * 100, 2)   zysll,
               round(sum(PAC_ONE) / (nullif(sum(ZSL_ONE), 0) * 10), 4)   pacdh,
               round(sum(SY_ONE) / (nullif(sum(ZSL_ONE), 0) * 10), 4)    sydh,
               round(sum(DLDL_ONE) / (nullif(sum(ZSL_ONE), 0) * 10), 4)  dh,
               round(sum(PAC_ONE), 4)                                    pac,
               round(sum(SY_ONE), 4)                                     sy,
               round(sum(CN), 4)                                         cn,
               round(sum(CN) / (nullif(sum(ZSL_ONE), 0) * 10), 4)        cnDh,
               round(sum(BCS), 4)                                        bcs,
               round(sum(DLDL_ONE), 4)                                   dldl,
               round(sum(OTHER), 4)                                      other,
               round(sum(OTHER_ONE), 4)                                  otherOne,
               round(sum(OTHER) / (nullif(sum(ZSL_ONE), 0) * 10), 4)     otherdh,
               round(sum(OTHER_ONE) / (nullif(sum(ZSL_ONE), 0) * 10), 4) otherOneDh
        from TF_YWPN_COSTRLWATER_W w
        where w.MARK = '0'
          and to_char(w.UP_DATE, 'yyyy-mm') = #{year}
    </select>

    <select id="getTwoMonthPile" resultType="com.tofly.xrtygis.custom.entity.vo.MarkWaterVo">
        select round(sum(GSL_TWO), 4)                                    gsl,
               round(sum(ZSL_TWO), 4)                                    zsl,
               round(sum(ZYSL_TWO), 4)                                   zysl,
               round(sum(ZYSL_TWO) / nullif(sum(ZSL_TWO), 0) * 100, 2)   zysll,
               round(sum(PAC_TWO) / (nullif(sum(ZSL_TWO), 0) * 10), 4)   pacdh,
               round(sum(YL_TWO) / (nullif(sum(ZSL_TWO), 0) * 10), 4)    yldh,
               round(sum(DLDL_TWO) / (nullif(sum(ZSL_TWO), 0) * 10), 4)  dh,
               round(sum(PAC_TWO), 4)                                    pac,
               round(sum(YL_TWO), 4)                                     yl,
               round(sum(PAM), 4)                                        pam,
               round(sum(FT), 4)                                         ft,
               round(sum(CN_TWO), 4)                                     cn,
               round(sum(CN_TWO) / (nullif(sum(ZSL_TWO), 0) * 10), 4)    cnDh,
               round(sum(GMSJFHY), 4)                                    gmsj,
               round(sum(PAM_WY), 4)                                     pamwn,
               round(sum(WNZL), 4)                                       wnzl,
               round(sum(DLDL_TWO), 4)                                   dldl,
               round(sum(OTHER_TWO), 4)                                  otherTwo,
               round(sum(OTHER_TWO) / (nullif(sum(ZSL_TWO), 0) * 10), 4) otherTwoDh
        from TF_YWPN_COSTRLWATER_W w
        where w.MARK = '0'
          and to_char(w.UP_DATE, 'yyyy-mm') = #{year}
    </select>

    <select id="getOneInfo" resultType="map">
        select to_char(w.UP_DATE, 'yyyy-mm-dd') day,
               round(GSL_ONE, 4)                gsl,
               round(ZSL_ONE, 4)                zsl,
               round(ZYSL_ONE, 4)               zysl,
               round(ZYSLL_ONE, 4)              zysll,
               round(PACDH_ONE, 4)              pacdh,
               round(SYDH_ONE, 4)               sydh,
               round(DH_ONE, 4)                 dh,
               round(PAC_ONE, 4)                pac,
               round(SY_ONE, 4)                 sy,
               round(CN, 4)                     cn,
               round(CNDH, 4)                   cn_dh,
               round(BCS, 4)                    bcs,
               round(DLDL_ONE, 4)               dldl,
               round(OTHER, 4)                  other,
               round(OTHER_ONE, 4)              other_one,
               round(OTHERDH, 4)                otherdh,
               round(OTHER_ONE_DH, 4)           other_one_dh
        from TF_YWPN_COSTRLWATER_W w,
             TF_YWPN_COSTRLUNIT_W u
        where w.MARK = u.MARK
          and to_char(w.UP_DATE, 'yyyy-mm-dd') = to_char(u.UP_DATE, 'yyyy-mm-dd')
          and w.MARK = '0'
          and to_char(w.UP_DATE, 'yyyy-mm') = #{year}
        order by day
    </select>

    <select id="getTwoInfo" resultType="map">
        select to_char(w.UP_DATE, 'yyyy-mm-dd') day,
               round(GSL_TWO, 4)                gsl,
               round(ZSL_TWO, 4)                zsl,
               round(ZYSL_TWO, 4)               zysl,
               round(ZYSLL_TWO, 4)              zysll,
               round(PACDH_TWO, 4)              pacdh,
               round(YLDH_TWO, 4)               yldh,
               round(DH_TWO, 4)                 dh,
               round(PAC_TWO, 4)                pac,
               round(YL_TWO, 4)                 yl,
               round(PAM, 4)                    PAM,
               round(FT, 4)                     FT,
               round(CN_TWO, 4)                 cn,
               round(CNDH_TWO, 4)               cn_dh,
               round(GMSJFHY, 4)                gmsj,
               round(PAM_WY, 4)                 pamwn,
               round(WNZL, 4)                   WNZL,
               round(DLDL_TWO, 4)               dldl,
               round(OTHER_TWO, 4)              OTHER_TWO,
               round(OTHER_TWO_DH, 4)           OTHER_TWO_DH
        from TF_YWPN_COSTRLWATER_W w,
             TF_YWPN_COSTRLUNIT_W u
        where w.MARK = u.MARK
          and to_char(w.UP_DATE, 'yyyy-mm-dd') = to_char(u.UP_DATE, 'yyyy-mm-dd')
          and w.MARK = '0'
          and to_char(w.UP_DATE, 'yyyy-mm') = #{year}
        order by day
    </select>

    <select id="getMonthActual" resultType="com.tofly.xrtygis.custom.entity.vo.MarkWaterVo">
        select round(GSL_TOTAL, 4)                                         gsl,
               round(ZSL_TOTAL, 4)                                         zsl,
               round(ZYSL_TOTAL, 4)                                        zysl,
               round(ZYSLL_TOTAL, 4)                                       zysll,
               round((PAC_ONE + PAC_TWO) / (nullif(ZSL_TOTAL, 0) * 10), 4) pacdh,
               round(SYDH_ONE, 4)                                          sydh,
               round(DH_TOTAL, 4)                                          dh,
               round(PAC_ONE + PAC_TWO, 4)                                 pac,
               round(SY_ONE, 4)                                            sy,
               round(CN + CN_TWO, 4)                                       CN,
               round((CN + CN_TWO) / (nullif(ZSL_TOTAL, 0) * 10), 4)       cnDh,
               round(BCS, 4)                                               BCS,
               round(DLDL_TOTAL, 4)                                        dldl,
               round(OTHER, 4)                                             other,
               round(OTHER_ONE, 4)                                         otherOne,
               round(OTHERDH, 4)                                           otherdh,
               round(OTHER_ONE_DH, 4)                                      otherOneDh,
               round(YLDH_TWO, 4)                                          yldh,
               round(YL_TWO, 4)                                            yl,
               round(PAM, 4)                                               PAM,
               round(FT, 4)                                                FT,
               round(GMSJFHY, 4)                                           gmsj,
               round(PAM_WY, 4)                                            pamwn,
               round(WNZL, 4)                                              WNZL,
               round(OTHER_TWO, 4)                                         otherTwo,
               round(OTHER_TWO_DH, 4)                                      otherTwoDh
        from TF_YWPN_COSTRLWATER_W w
                 full join TF_YWPN_COSTRLUNIT_W u
                           on to_char(w.UP_DATE, 'yyyy-mm-dd') = to_char(u.UP_DATE, 'yyyy-mm-dd')
                               and w.MARK = u.MARK
        where w.MARK = '1'
          and to_char(w.UP_DATE, 'yyyy-mm') = #{year}
    </select>

    <select id="getMonthPlan" resultType="com.tofly.xrtygis.custom.entity.vo.MarkWaterVo">
        select round(GSL_TOTAL, 4)                                         gsl,
               round(ZSL_TOTAL, 4)                                         zsl,
               round(ZYSL_TOTAL, 4)                                        zysl,
               round(ZYSLL_TOTAL, 4)                                       zysll,
               round((PAC_ONE + PAC_TWO) / (nullif(ZSL_TOTAL, 0) * 10), 4) pacdh,
               round(SYDH_ONE, 4)                                          sydh,
               round(DH_TOTAL, 4)                                          dh,
               round(PAC_ONE + PAC_TWO, 4)                                 pac,
               round(SY_ONE, 4)                                            sy,
               round(CN + CN_TWO, 4)                                       CN,
               round((CN + CN_TWO) / (nullif(ZSL_TOTAL, 0) * 10), 4)       cnDh,
               round(BCS, 4)                                               BCS,
               round(DLDL_TOTAL, 4)                                        dldl,
               round(OTHER, 4)                                             other,
               round(OTHER_ONE, 4)                                         otherOne,
               round(OTHERDH, 4)                                           otherdh,
               round(OTHER_ONE_DH, 4)                                      otherOneDh,
               round(YLDH_TWO, 4)                                          yldh,
               round(YL_TWO, 4)                                            yl,
               round(PAM, 4)                                               PAM,
               round(FT, 4)                                                FT,
               round(GMSJFHY, 4)                                           gmsj,
               round(PAM_WN, 4)                                            pamwn,
               round(WNZL, 4)                                              WNZL,
               round(OTHER_TWO, 4)                                         otherTwo,
               round(OTHER_TWO_DH, 4)                                      otherTwoDh
        from TF_YWPN_COSTBGWATER_W w
                 full join TF_YWPN_COSTBGUNIT_W u
                           on w.MONTH = u.MONTH
                 full join TF_YWPN_COSTBGINDEX_W i on w.MONTH = i.MONTH
        where w.MONTH = #{year}
    </select>
    <select id="getMonthPile" resultType="com.tofly.xrtygis.custom.entity.vo.MarkWaterVo">
        select round(sum(GSL_TOTAL), 4)                                                   gsl,
               round(sum(ZSL_TOTAL), 4)                                                   zsl,
               round(sum(ZYSL_TOTAL), 4)                                                  zysl,
               round(sum(ZYSL_TOTAL) / nullif(sum(ZSL_TOTAL), 0) * 100, 2)                zysll,
               round((sum(PAC_ONE) + sum(PAC_TWO)) / (nullif(sum(ZSL_TOTAL), 0) * 10), 4) pacdh,
               round(sum(SY_ONE) / (nullif(sum(ZSL_ONE), 0) * 10), 4)                     sydh,
               round(sum(DLDL_TOTAL) / (nullif(sum(ZSL_TOTAL), 0) * 10), 4)               dh,
               round(sum(PAC_ONE) + sum(PAC_TWO), 4)                                      pac,
               round(sum(SY_ONE), 4)                                                      sy,
               round(sum(CN) + sum(CN_TWO), 4)                                            CN,
               round((sum(CN) + sum(CN_TWO)) / (nullif(sum(ZSL_TOTAL), 0) * 10), 4)       cnDh,
               round(sum(BCS), 4)                                                         BCS,
               round(sum(DLDL_TOTAL), 4)                                                  dldl,
               round(sum(OTHER), 4)                                                       other,
               round(sum(OTHER_ONE), 4)                                                   otherOne,
               round(sum(OTHER) / (nullif(sum(ZSL_ONE), 0) * 10), 4)                      otherdh,
               round(sum(OTHER_ONE) / (nullif(sum(ZSL_ONE), 0) * 10), 4)                  otherOneDh,
               round(sum(YL_TWO) / (nullif(sum(ZSL_TWO), 0) * 10), 4)                     yldh,
               round(sum(YL_TWO), 4)                                                      yl,
               round(sum(PAM), 4)                                                         PAM,
               round(sum(FT), 4)                                                          FT,
               round(sum(GMSJFHY), 4)                                                     gmsj,
               round(sum(PAM_WY), 4)                                                      pamwn,
               round(sum(WNZL), 4)                                                        WNZL,
               round(sum(OTHER_TWO), 4)                                                   otherTwo,
               round(sum(OTHER_TWO) / (nullif(sum(ZSL_TWO), 0) * 10), 4)                  otherTwoDh
        from TF_YWPN_COSTRLWATER_W w
        where w.MARK = '0'
          and to_char(w.UP_DATE, 'yyyy-mm') = #{year}
    </select>
    <select id="getInfo" resultType="map">
        select to_char(w.UP_DATE, 'yyyy-mm-dd')                            day,
               round(GSL_TOTAL, 4)                                         gsl,
               round(ZSL_TOTAL, 4)                                         zsl,
               round(ZYSL_TOTAL, 4)                                        zysl,
               round(ZYSLL_TOTAL, 4)                                       zysll,
               round((PAC_ONE + PAC_TWO) / (nullif(ZSL_TOTAL, 0) * 10), 4) pacdh,
               round(SYDH_ONE, 4)                                          sydh,
               round(DH_TOTAL, 4)                                          dh,
               round(PAC_ONE + PAC_TWO, 4)                                 pac,
               round(SY_ONE, 4)                                            sy,
               round(CN + CN_TWO, 4)                                       CN,
               round((CN + CN_TWO) / (nullif(ZSL_TOTAL, 0) * 10), 4)       cn_dh,
               round(BCS, 4)                                               BCS,
               round(DLDL_TOTAL, 4)                                        dldl,
               round(OTHER, 4)                                             other,
               round(OTHER_ONE, 4)                                         other_one,
               round(OTHERDH, 4)                                           otherdh,
               round(OTHER_ONE_DH, 4)                                      other_one_dh,
               round(YLDH_TWO, 4)                                          yldh,
               round(YL_TWO, 4)                                            yl,
               round(PAM, 4)                                               PAM,
               round(FT, 4)                                                FT,
               round(GMSJFHY, 4)                                           gmsj,
               round(PAM_WY, 4)                                            pamwn,
               round(WNZL, 4)                                              WNZL,
               round(OTHER_TWO, 4)                                         other_two,
               round(OTHER_TWO_DH, 4)                                      other_two_dh
        from TF_YWPN_COSTRLWATER_W w
                 full join TF_YWPN_COSTRLUNIT_W u
                           on to_char(w.UP_DATE, 'yyyy-mm-dd') = to_char(u.UP_DATE, 'yyyy-mm-dd')
                               and w.MARK = u.MARK
        where w.MARK = '0'
          and to_char(w.UP_DATE, 'yyyy-mm') = #{year}
        order by day
    </select>
</mapper>