package com.tofly.xrtygis.custom.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface PlanManagementMapper {
    /**
     * 详情
     *
     * @param id id
     * @return list
     */
    @Select("select id,\n" +
            "       month,\n" +
            "       round(gsl_one, 4)     gsl_one,\n" +
            "       round(gsl_two, 4)     gsl_two,\n" +
            "       round(gsl_qbj, 4)     gsl_qbj,\n" +
            "       round(gsl_total, 4)   gsl_total,\n" +
            "       round(zsl_one, 4)     zsl_one,\n" +
            "       round(zsl_two, 4)     zsl_two,\n" +
            "       round(zsl_hqsk, 4)    zsl_hqsk,\n" +
            "       round(zsl_total, 4)   zsl_total,\n" +
            "       round(ssl_total, 4)   ssl_total,\n" +
            "       round(zysl_one, 4)    zysl_one,\n" +
            "       round(zysl_two, 4)    zysl_two,\n" +
            "       round(zysl_total, 4)  zysl_total,\n" +
            "       round(zysll_one, 4)   zysll_one,\n" +
            "       round(zysll_two, 4)   zysll_two,\n" +
            "       round(zysll_total, 4) zysll_total,\n" +
            "       round(wspsl, 4)       wspsl,\n" +
            "       round(cxc, 4)         cxc,\n" +
            "       round(lsl, 4)         lsl\n" +
            "from TF_YWPN_COSTBGWATER_W\n" +
            "where YEAR_ID = #{id}\n" +
            "order by month")
    List<Map<String, Object>> getWaterInfo(@Param("id") Long id);

    /**
     * 总和
     *
     * @param id id
     * @return list
     */
    @Select("select round(sum(gsl_one), 4)                                                                                        gsl_one,\n" +
            "       round(sum(gsl_two), 4)                                                                                        gsl_two,\n" +
            "       round(sum(gsl_qbj), 4)                                                                                        gsl_qbj,\n" +
            "       round(sum(gsl_total), 4)                                                                                      gsl_total,\n" +
            "       round(sum(zsl_one), 4)                                                                                        zsl_one,\n" +
            "       round(sum(zsl_two), 4)                                                                                        zsl_two,\n" +
            "       round(sum(zsl_hqsk), 4)                                                                                       zsl_hqsk,\n" +
            "       round(sum(zsl_total), 4)                                                                                      zsl_total,\n" +
            "       round(sum(ssl_total), 4)                                                                                      ssl_total,\n" +
            "       round(sum(zysl_one), 4)                                                                                       zysl_one,\n" +
            "       round(sum(zysl_two), 4)                                                                                       zysl_two,\n" +
            "       round(sum(zysl_total), 4)                                                                                     zysl_total,\n" +
            "       round(sum(wspsl), 4)                                                                                          wspsl,\n" +
            "       round(sum(ZYSL_ONE) / nullif(sum(ZSL_ONE), 0) * 100, 2)                                                       zysll_one,\n" +
            "       round(sum(ZYSL_TWO) / nullif(sum(ZSL_TWO), 0) * 100, 2)                                                       zysll_two,\n" +
            "       round(sum(ZYSL_TOTAL) / nullif(sum(ZSL_TOTAL), 0) * 100, 2)                                                   zysll_total,\n" +
            "       round((sum(GSL_TOTAL) + sum(GSL_QBJ) - sum(SSL_TOTAL)) / (nullif(sum(GSL_TOTAL), 0) + sum(GSL_QBJ)) * 100,\n" +
            "             2)                                                                                                      cxc,\n" +
            "       round((sum(GSL_TOTAL) + sum(GSL_QBJ) - sum(SSL_TOTAL) - sum(WSPSL)) /\n" +
            "             (nullif(sum(GSL_TOTAL), 0) + sum(GSL_QBJ)) * 100, 2)                                                    lsl\n" +
            "from TF_YWPN_COSTBGWATER_W\n" +
            "where YEAR_ID = #{id}")
    Map<String, Object> getWaterSum(@Param("id") Long id);

    /**
     * 总耗信息
     *
     * @param id id
     * @return list
     */
    @Select("select id,\n" +
            "       year_id,\n" +
            "       month,\n" +
            "       round(pac_one, 4)    pac_one,\n" +
            "       round(pac_two, 4)    pac_two,\n" +
            "       round(sy_one, 4)     sy_one,\n" +
            "       round(yl_two, 4)     yl_two,\n" +
            "       round(pam, 4)        pam,\n" +
            "       round(ft, 4)         ft,\n" +
            "       round(cn, 4)         cn,\n" +
            "       round(cn_two, 4)     cn_two,\n" +
            "       round(gmsjfhy, 4)    gmsjfhy,\n" +
            "       round(pam_wn, 4)     pam_wn,\n" +
            "       round(bcs, 4)        bcs,\n" +
            "       round(wnzl, 4)       wnzl,\n" +
            "       round(dldl_one, 4)   dldl_one,\n" +
            "       round(dldl_two, 4)   dldl_two,\n" +
            "       round(dldl_total, 4) dldl_total,\n" +
            "       round(other, 4)      other,\n" +
            "       round(jbdl_one, 4)   jbdl_one,\n" +
            "       round(jbdl_two, 4)   jbdl_two,\n" +
            "       round(other_one, 4)   other_one,\n" +
            "       round(other_two, 4)   other_two,\n" +
            "       round(jbdl_total, 4) jbdl_total\n" +
            "from TF_YWPN_COSTBGINDEX_W\n" +
            "where YEAR_ID = #{id}\n" +
            "order by month")
    List<Map<String, Object>> getIndexInfo(@Param("id") Long id);

    /**
     * 获得总耗总和
     *
     * @param id id
     * @return map
     */
    @Select("select round(sum(pac_one), 4)    pac_one,\n" +
            "       round(sum(pac_two), 4)    pac_two,\n" +
            "       round(sum(sy_one), 4)     sy_one,\n" +
            "       round(sum(yl_two), 4)     yl_two,\n" +
            "       round(sum(pam), 4)        pam,\n" +
            "       round(sum(ft), 4)         ft,\n" +
            "       round(sum(cn), 4)         cn,\n" +
            "       round(sum(cn_two), 4)     cn_two,\n" +
            "       round(sum(gmsjfhy), 4)    gmsjfhy,\n" +
            "       round(sum(pam_wn), 4)     pam_wn,\n" +
            "       round(sum(bcs), 4)        bcs,\n" +
            "       round(sum(wnzl), 4)       wnzl,\n" +
            "       round(sum(dldl_one), 4)   dldl_one,\n" +
            "       round(sum(dldl_two), 4)   dldl_two,\n" +
            "       round(sum(dldl_total), 4) dldl_total,\n" +
            "       round(sum(other), 4)      other,\n" +
            "       round(sum(other_one), 4)  other_one,\n" +
            "       round(sum(other_two), 4)  other_two,\n" +
            "       round(sum(jbdl_one), 4)   jbdl_one,\n" +
            "       round(sum(jbdl_two), 4)   jbdl_two,\n" +
            "       round(sum(jbdl_total), 4) jbdl_total\n" +
            "from TF_YWPN_COSTBGINDEX_W\n" +
            "where YEAR_ID = #{id}")
    Map<String, Object> getIndexSum(@Param("id") Long id);

    @Select("select MOUTH                   month,\n" +
            "       round(dfcb_one, 4)      dfcb_one,\n" +
            "       round(dfcb_two, 4)      dfcb_two,\n" +
            "       round(dfcb_total, 4)    dfcb_total,\n" +
            "       round(paccb_one, 4)     paccb_one,\n" +
            "       round(sycb_one, 4)      sycb_one,\n" +
            "       round(cncb_one, 4)      cncb_one,\n" +
            "       round(cncb_two, 4)      cncb_two,\n" +
            "       round(bcscb_one, 4)     bcscb_one,\n" +
            "       round(zsclcb_one, 4)    zsclcb_one,\n" +
            "       round(paccb_two, 4)     paccb_two,\n" +
            "       round(ylcb_two, 4)      ylcb_two,\n" +
            "       round(pamzscb_two, 4)   pamzscb_two,\n" +
            "       round(ftcb_two, 4)      ftcb_two,\n" +
            "       round(gmsjfhycb_two, 4) gmsjfhycb_two,\n" +
            "       round(pamwncb_two, 4)   pamwncb_two,\n" +
            "       round(wnzycb_two, 4)    wnzycb_two,\n" +
            "       round(zsclcb_two, 4)    zsclcb_two,\n" +
            "       round(zsclcb_total, 4)  zsclcb_total,\n" +
            "       round(ysfcb, 4)         ysfcb,\n" +
            "       round(szysfcb_one, 4)   szysfcb_one,\n" +
            "       round(szysfcb_two, 4)   szysfcb_two,\n" +
            "       round(szysfcb_total, 4) szysfcb_total,\n" +
            "       round(dwcb_one, 4)      dwcb_one,\n" +
            "       round(dwcb_two, 4)      dwcb_two,\n" +
            "       round(dwcb_total, 4)    dwcb_total,\n" +
            "       round(OTHERCB, 4)       othercb,\n" +
            "       round(other_one_cb, 4)  other_one_cb,\n" +
            "       round(other_two_cb, 4)  other_two_cb\n" +
            "from TF_YWPN_COSTBGFIXED_W\n" +
            "where YEAR_ID = #{id}\n" +
            "order by month")
    List<Map<String, Object>> getFixedInfo(@Param("id") Long id);

    @Select("select round((sum(JBDF_ONE) + sum(DLDF_ONE)) / nullif(sum(GSL_ONE), 0) * 1000, 4)         DFCB_ONE,\n" +
            "       round((sum(JBDF_TWO) + sum(DLDF_TWO)) / nullif(sum(GSL_TWO), 0) * 1000, 4)         DFCB_TWO,\n" +
            "       round((sum(JBDF_TOTAL) + sum(DLDF_TOTAL)) / nullif(sum(GSL_TOTAL), 0) * 1000, 4)   DFCB_TOTAL,\n" +
            "       round(sum(PACZFY_ONE) / nullif(sum(GSL_ONE), 0) * 1000, 4)                         PACCB_ONE,\n" +
            "       round(sum(SYZFY_ONE) / nvl(sum(GSL_ONE), 0) * 1000, 4)                             SYCB_ONE,\n" +
            "       round(sum(BCSZFY) / nullif(sum(GSL_ONE), 0) * 1000, 4)                             BCSCB_ONE,\n" +
            "       round(sum(CNZFY) / nullif(sum(GSL_ONE), 0) * 1000, 4)                              CNCB_ONE,\n" +
            "       round(sum(CNZFY_TWO) / nullif(sum(GSL_TWO), 0) * 1000, 4)                          CNCB_TWO,\n" +
            "       round(sum(ZZSCLFY_ONE) / nullif(sum(GSL_ONE), 0) * 1000, 4)                        ZSCLCB_ONE,\n" +
            "       round(sum(PACZFY_TWO) / nullif(sum(GSL_TWO), 0) * 1000, 4)                         PACCB_TWO,\n" +
            "       round(sum(YLZFY_TWO) / nullif(sum(GSL_TWO), 0) * 1000, 4)                          YLCB_TWO,\n" +
            "       round(sum(PAMZSZFY) / nullif(sum(GSL_TWO), 0) * 1000, 4)                           PAMZSCB_TWO,\n" +
            "       round(sum(GMSJFHYZFY) / nullif(sum(GSL_TWO), 0) * 1000, 4)                         GMSJFHYCB_TWO,\n" +
            "       round(sum(PAMWNZFY) / nullif(sum(GSL_TWO), 0) * 1000, 4)                           PAMWNCB_TWO,\n" +
            "       round(sum(FTZFY) / nullif(sum(GSL_TWO), 0) * 1000, 4)                              FTCB_TWO,\n" +
            "       round(sum(WNZYF) / nullif(sum(GSL_TWO), 0) * 1000, 4)                              WNZYCB_TWO,\n" +
            "       round(sum(ZZSCLFY_TWO) / decode(sum(GSL_TWO), 0, null, sum(GSL_TWO)) * 1000, 4)    ZSCLCB_TWO,\n" +
            "       round((sum(ZZSCLFY_ONE) + sum(ZZSCLFY_TWO)) / nullif(sum(GSL_TOTAL), 0) * 1000, 4) ZSCLCB_TOTAL,\n" +
            "       round(sum(YSF) / nullif(sum(GSL_TOTAL), 0) * 1000, 4)                              YSFCB,\n" +
            "       round(sum(SZYSF_ONE) / nullif(sum(GSL_ONE), 0) * 1000, 4)                          SZYSFCB_ONE,\n" +
            "       round(sum(SZYSF_TWO) / nullif(sum(GSL_TWO), 0) * 1000, 4)                          SZYSFCB_TWO,\n" +
            "       round(sum(SZYSF_TOTAL) / nullif(sum(GSL_TOTAL), 0) * 1000, 4)                      SZYSFCB_TOTAL,\n" +
            "       round(sum(ZFY_ONE) / nullif(sum(GSL_ONE), 0) * 1000, 4)                            DWCB_ONE,\n" +
            "       round(sum(ZFY_TWO) / nullif(sum(GSL_TWO), 0) * 1000, 4)                            DWCB_TWO,\n" +
            "       round(sum(ZFY) / nullif(sum(GSL_TOTAL), 0) * 1000, 4)                              DWCB_TOTAL,\n" +
            "       round(sum(OTHERZFY) / nullif(sum(GSL_ONE), 0) * 1000, 4)                           OTHERCB,\n" +
            "       round(sum(OTHER_ONE_ZFY) / nullif(sum(GSL_ONE), 0) * 1000, 4)                      OTHER_ONE_CB,\n" +
            "       round(sum(OTHER_TWO_ZFY) / nullif(sum(GSL_TWO), 0) * 1000, 4)                      OTHER_TWO_CB\n" +
            "from TF_YWPN_COSTBGFIXED_W f,\n" +
            "     TF_YWPN_COSTBGWATER_W w\n" +
            "where f.MOUTH = w.MONTH\n" +
            "  and f.YEAR_ID = #{id}")
    Map<String, Object> getFixedSum(@Param("id") Long id);

    @Select("select sum(JBDF_ONE)   JBDF_ONE,\n" +
            "               sum(JBDF_TWO)   JBDF_TWO,\n" +
            "               sum(JBDF_TOTAL) JBDF_TOTAL\n" +
            "        from TF_YWPN_COSTBGFIXED_W\n" +
            "        where substr(MOUTH, 1, 4) = #{year}")
    Map<String, Object> getElectricityBillSum(@Param("year") String year);

    @Select(" select round(sum(paczfy_one), 4)  paczfy_one,\n" +
            "       round(sum(paczfy_two), 4)  paczfy_two,\n" +
            "       round(sum(syzfy_one), 4)   syzfy_one,\n" +
            "       round(sum(ylzfy_two), 4)   ylzfy_two,\n" +
            "       round(sum(pamzszfy), 4)    pamzszfy,\n" +
            "       round(sum(ftzfy), 4)       ftzfy,\n" +
            "       round(sum(cnzfy), 4)       cnzfy,\n" +
            "       round(sum(gmsjfhyzfy), 4)  gmsjfhyzfy,\n" +
            "       round(sum(pamwnzfy), 4)    pamwnzfy,\n" +
            "       round(sum(bcszfy), 4)      bcszfy,\n" +
            "       round(sum(wnzyf), 4)       wnzyf,\n" +
            "       round(sum(jbdf_one), 4)    jbdf_one,\n" +
            "       round(sum(jbdf_two), 4)    jbdf_two,\n" +
            "       round(sum(jbdf_total), 4)  jbdf_total,\n" +
            "       round(sum(dldf_one), 4)    dldf_one,\n" +
            "       round(sum(dldf_two), 4)    dldf_two,\n" +
            "       round(sum(dldf_total), 4)  dldf_total,\n" +
            "       round(sum(ysf), 4)         ysf,\n" +
            "       round(sum(szysf_one), 4)   szysf_one,\n" +
            "       round(sum(szysf_two), 4)   szysf_two,\n" +
            "       round(sum(szysf_total), 4) szysf_total,\n" +
            "       round(sum(zfy_one), 4)     zfy_one,\n" +
            "       round(sum(zfy_two), 4)     zfy_two,\n" +
            "       round(sum(zzsclfy_one), 4) zzsclfy_one,\n" +
            "       round(sum(zzsclfy_two), 4) zzsclfy_two,\n" +
            "       round(sum(zfy), 4)         zfy,\n" +
            "       round(sum(otherzfy), 4)    otherzfy,\n" +
            "       round(sum(OTHER_ONE_ZFY), 4)    OTHER_ONE_ZFY,\n" +
            "       round(sum(OTHER_TWO_ZFY), 4)    OTHER_TWO_ZFY,\n" +
            "       round(sum(cnzfy_two), 4)   cnzfy_two\n" +
            "from TF_YWPN_COSTBGFIXED_W\n" +
            "where substr(MOUTH, 1, 4) = #{year}")
    Map<String, Object> getExpenseSum(@Param("year") String year);

    @Select("select round(sum(PAC_ONE) / (nullif(sum(ZSL_ONE), 0) * 10), 4)      pacdh_one,\n" +
            "       round(sum(PAC_TWO) / (nullif(sum(ZSL_TWO), 0) * 10), 4)      pacdh_two,\n" +
            "       round(sum(SY_ONE) / (nullif(sum(ZSL_ONE), 0) * 10), 4)       sydh_one,\n" +
            "       round(sum(YL_TWO) / (nullif(sum(ZSL_TWO), 0) * 10), 4)       yldh_two,\n" +
            "       round(sum(DLDL_ONE) / (nullif(sum(ZSL_ONE), 0) * 10), 4)     dh_one,\n" +
            "       round(sum(DLDL_TWO) / (nullif(sum(ZSL_TWO), 0) * 10), 4)     dh_two,\n" +
            "       round(sum(DLDL_TOTAL) / (nullif(sum(ZSL_TOTAL), 0) * 10), 4) dh_total,\n" +
            "       round(sum(OTHER) / (nullif(sum(ZSL_ONE), 0) * 10), 4) otherdh,\n" +
            "       round(sum(CN_TWO) / (nullif(sum(ZSL_TWO), 0) * 10), 4) cndh_two\n" +
            "from TF_YWPN_COSTBGWATER_W w,\n" +
            "     TF_YWPN_COSTBGINDEX_W i\n" +
            "where w.MONTH = i.MONTH\n" +
            "  and substr(w.MONTH, 1, 4) = #{year}")
    Map<String, Object> getUnitSum(@Param("year") String year);


    @Select("select id,\n" +
            "       year_id,\n" +
            "       month,\n" +
            "       round(pacdh_one, 4) pacdh_one,\n" +
            "       round(pacdh_two, 4) pacdh_two,\n" +
            "       round(sydh_one, 4)  sydh_one,\n" +
            "       round(yldh_two, 4)  yldh_two,\n" +
            "       round(dh_one, 4)    dh_one,\n" +
            "       round(dh_two, 4)    dh_two,\n" +
            "       round(dh_total, 4)  dh_total,\n" +
            "       round(otherdh, 4)  otherdh,\n" +
            "       round(cndh_two, 4)  cndh_two\n" +
            "from TF_YWPN_COSTBGUNIT_W\n" +
            "where YEAR_ID = #{id}\n" +
            "order by MONTH")
    List<Map<String, Object>> getUnit(@Param("id") Long id);

}
