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" +
            "               gsl_one,\n" +
            "               gsl_two,\n" +
            "               gsl_qbj,\n" +
            "               gsl_total,\n" +
            "               zsl_one,\n" +
            "               zsl_two,\n" +
            "               zsl_hqsk,\n" +
            "               zsl_total,\n" +
            "               ssl_total,\n" +
            "               zysl_one,\n" +
            "               zysl_two,\n" +
            "               zysl_total,\n" +
            "               zysll_one,\n" +
            "               zysll_two,\n" +
            "               zysll_total,\n" +
            "               wspsl,\n" +
            "               cxc,\n" +
            "               lsl\n" +
            "        from TF_YWPN_COSTBGWATER_W\n" +
            "        where YEAR_ID = #{id}" +
            "        order by month")
    List<Map<String, Object>> getWaterInfo(@Param("id") Long id);

    /**
     * 总和
     *
     * @param id id
     * @return list
     */
    @Select(" select sum(gsl_one) gsl_one,\n" +
            "               sum(gsl_two) gsl_two,\n" +
            "               sum(gsl_qbj) gsl_qbj,\n" +
            "               sum(gsl_total) gsl_total,\n" +
            "               sum(zsl_one) zsl_one,\n" +
            "               sum(zsl_two) zsl_two,\n" +
            "               sum(zsl_hqsk) zsl_hqsk,\n" +
            "               sum(zsl_total) zsl_total,\n" +
            "               sum(ssl_total) ssl_total,\n" +
            "               sum(zysl_one) zysl_one,\n" +
            "               sum(zysl_two) zysl_two,\n" +
            "               sum(zysl_total) zysl_total,\n" +
            "               sum(wspsl) wspsl,\n" +
            "               round(sum(ZYSL_ONE) / nullif(sum(ZSL_ONE),0) * 100,3) zysll_one,\n" +
            "               round(sum(ZYSL_TWO) / nullif(sum(ZSL_TWO),0) * 100,3) zysll_two,\n" +
            "               round(sum(ZYSL_TOTAL) / nullif(sum(ZSL_TOTAL),0) * 100,3) zysll_total,\n" +
            "               round((sum(GSL_TOTAL) + sum(GSL_QBJ) - sum(SSL_TOTAL)) / nullif(sum(GSL_TOTAL),0) * 100,3) cxc,\n" +
            "               round((sum(GSL_TOTAL) + sum(GSL_QBJ) - sum(SSL_TOTAL) - sum(WSPSL)) / nullif(sum(GSL_TOTAL),0) * 100,3) 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" +
            "               pac_one,\n" +
            "               pac_two,\n" +
            "               sy_one,\n" +
            "               yl_two,\n" +
            "               pam,\n" +
            "               ft,\n" +
            "               cn,\n" +
            "               gmsjfhy,\n" +
            "               pam_wn,\n" +
            "               bcs,\n" +
            "               wnzl,\n" +
            "               dldl_one,\n" +
            "               dldl_two,\n" +
            "               dldl_total,\n" +
            "               other,\n" +
            "               jbdl_one,\n" +
            "               jbdl_two,\n" +
            "               jbdl_total\n" +
            "        from TF_YWPN_COSTBGINDEX_W\n" +
            "        where YEAR_ID = #{id}" +
            "        order by month")
    List<Map<String, Object>> getIndexInfo(@Param("id") Long id);

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

    @Select("select dfcb_one,\n" +
            "               MOUTH month," +
            "               dfcb_two,\n" +
            "               dfcb_total,\n" +
            "               paccb_one,\n" +
            "               sycb_one,\n" +
            "               cncb_one,\n" +
            "               bcscb_one,\n" +
            "               zsclcb_one,\n" +
            "               paccb_two,\n" +
            "               ylcb_two,\n" +
            "               pamzscb_two,\n" +
            "               ftcb_two,\n" +
            "               gmsjfhycb_two,\n" +
            "               pamwncb_two,\n" +
            "               wnzycb_two,\n" +
            "               zsclcb_two,\n" +
            "               zsclcb_total,\n" +
            "               ysfcb,\n" +
            "               szysfcb_one,\n" +
            "               szysfcb_two,\n" +
            "               szysfcb_total,\n" +
            "               dwcb_one,\n" +
            "               dwcb_two,\n" +
            "               dwcb_total,\n" +
            "               othercb\n" +
            "        from TF_YWPN_COSTBGFIXED_W\n" +
            "        where YEAR_ID = #{id}" +
            "        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,3) DFCB_ONE,\n" +
            "                round((sum(JBDF_TWO) + sum(DLDF_TWO) ) / nullif(sum(GSL_TWO),0) * 1000,3) DFCB_TWO,\n" +
            "                round((sum(JBDF_TOTAL) + sum(DLDF_TOTAL) ) / nullif(sum(GSL_TOTAL),0) * 1000,3) DFCB_TOTAL,\n" +
            "                round(sum(PACZFY_ONE) / nullif(sum(GSL_ONE),0) * 1000,3) PACCB_ONE,\n" +
            "                round(sum(SYZFY_ONE) / nvl(sum(GSL_ONE),0) * 1000,3) SYCB_ONE,\n" +
            "                round(sum(BCSZFY) / nullif(sum(GSL_ONE),0) * 1000,3) BCSCB_ONE,\n" +
            "                round(sum(CNZFY) / nullif(sum(GSL_ONE),0) * 1000,3) CNCB_ONE,\n" +
            "                round(sum(ZZSCLFY_ONE) / nullif(sum(GSL_ONE),0) * 1000,3) ZSCLCB_ONE,\n" +
            "                round(sum(PACZFY_TWO) / nullif(sum(GSL_TWO),0) * 1000,3) PACCB_TWO,\n" +
            "                round(sum(YLZFY_TWO) / nullif(sum(GSL_TWO),0) * 1000,3) YLCB_TWO,\n" +
            "                round(sum(PAMZSZFY) / nullif(sum(GSL_TWO),0) * 1000,3) PAMZSCB_TWO,\n" +
            "                round(sum(GMSJFHYZFY) / nullif(sum(GSL_TWO),0) * 1000,3) GMSJFHYCB_TWO,\n" +
            "                round(sum(PAMWNZFY) / nullif(sum(GSL_TWO),0) * 1000,3) PAMWNCB_TWO,\n" +
            "                round(sum(FTZFY) / nullif(sum(GSL_TWO),0) * 1000,3) FTCB_TWO,\n" +
            "                round(sum(WNZYF) / nullif(sum(GSL_TWO),0) * 1000,3) WNZYCB_TWO,\n" +
            "                round(sum(ZZSCLFY_TWO) / decode(sum(GSL_TWO),0,null,sum(GSL_TWO)) * 1000,3) ZSCLCB_TWO,\n" +
            "                round((sum(ZZSCLFY_ONE) + sum(ZZSCLFY_TWO)) / nullif(sum(GSL_TOTAL),0) * 1000,3) ZSCLCB_TOTAL,\n" +
            "                round(sum(YSF) / nullif(sum(GSL_TOTAL),0) * 1000,3) YSFCB,\n" +
            "                round(sum(SZYSF_ONE) / nullif(sum(GSL_ONE),0) * 1000,3) SZYSFCB_ONE,\n" +
            "                round(sum(SZYSF_TWO) / nullif(sum(GSL_TWO),0) * 1000,3) SZYSFCB_TWO,\n" +
            "                round(sum(SZYSF_TOTAL) / nullif(sum(GSL_TOTAL),0) * 1000,3) SZYSFCB_TOTAL,\n" +
            "                round(sum(ZFY_ONE) / nullif(sum(GSL_TOTAL),0) * 1000,3) DWCB_ONE,\n" +
            "                round(sum(ZFY_TWO) / nullif(sum(GSL_TOTAL),0) * 1000,3)DWCB_TWO,\n" +
            "                round(sum(ZFY) / nullif(sum(GSL_TOTAL),0) * 1000,3) DWCB_TOTAL,\n" +
            "                round(sum(OTHERZFY) / nullif(sum(GSL_TOTAL),0) * 1000,3) OTHERCB\n" +
            "        from TF_YWPN_COSTBGFIXED_W f,TF_YWPN_COSTBGWATER_W w\n" +
            "        where f.MOUTH = w.MONTH 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 sum(paczfy_one)  paczfy_one,\n" +
            "               sum(paczfy_two)  paczfy_two,\n" +
            "               sum(syzfy_one)   syzfy_one,\n" +
            "               sum(ylzfy_two)   ylzfy_two,\n" +
            "               sum(pamzszfy)    pamzszfy,\n" +
            "               sum(ftzfy)       ftzfy,\n" +
            "               sum(cnzfy)       cnzfy,\n" +
            "               sum(gmsjfhyzfy)  gmsjfhyzfy,\n" +
            "               sum(pamwnzfy)    pamwnzfy,\n" +
            "               sum(bcszfy)      bcszfy,\n" +
            "               sum(wnzyf)       wnzyf,\n" +
            "               sum(jbdf_one)    jbdf_one,\n" +
            "               sum(jbdf_two)    jbdf_two,\n" +
            "               sum(jbdf_total)  jbdf_total,\n" +
            "               sum(dldf_one)    dldf_one,\n" +
            "               sum(dldf_two)    dldf_two,\n" +
            "               sum(dldf_total)  dldf_total,\n" +
            "               sum(ysf)         ysf,\n" +
            "               sum(szysf_one)   szysf_one,\n" +
            "               sum(szysf_two)   szysf_two,\n" +
            "               sum(szysf_total) szysf_total,\n" +
            "               sum(zfy_one)     zfy_one,\n" +
            "               sum(zfy_two)     zfy_two,\n" +
            "               sum(zzsclfy_one) zzsclfy_one,\n" +
            "               sum(zzsclfy_two) zzsclfy_two,\n" +
            "               sum(zfy)         zfy,\n" +
            "               sum(otherzfy)    otherzfy\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), 5)      pacdh_one,\n" +
            "       round(sum(PAC_TWO) / (nullif(sum(ZSL_TWO), 0)* 10), 5)      pacdh_two,\n" +
            "       round(sum(SY_ONE) / (nullif(sum(ZSL_ONE), 0)* 10), 5)       sydh_one,\n" +
            "       round(sum(YL_TWO) / (nullif(sum(ZSL_TWO), 0)* 10), 5)       yldh_two,\n" +
            "       round(sum(DLDL_ONE) / (nullif(sum(ZSL_ONE), 0)* 10), 5)     dh_one,\n" +
            "       round(sum(DLDL_TWO) / (nullif(sum(ZSL_TWO), 0)* 10), 5)     dh_two,\n" +
            "       round(sum(DLDL_TOTAL) / (nullif(sum(ZSL_TOTAL), 0)* 10), 5) dh_total\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);

}
