<?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.FixedMapper">

    <select id="selectWaterInfo" resultType="com.tofly.xrtygis.entity.Costrlwater">
        select *
        from TF_YWPN_COSTRLWATER_W
        where ROWNUM &lt;= 1
        <if test="mark == 1">
            and to_char(UP_DATE, 'yyyy-mm') = substr(#{date},1,7)
            and mark = #{mark}
        </if>
        <if test="mark == 0">
            and to_char(UP_DATE, 'yyyy-mm-dd') = #{date}
            and mark = #{mark}
        </if>
    </select>

    <select id="viewFixedPlan" resultType="com.tofly.xrtygis.entity.Costbgfixed">
        select 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(CNZFY_TWO, 4) CNZFY_TWO,
        round(CNCB_TWO, 4) CNCB_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(zfy_two, 4) zfy_two,
        round(dwcb_one, 4) dwcb_one,
        round(dwcb_two, 4) dwcb_two,
        round(dwcb_total, 4) dwcb_total,
        create_time,
        round(zzsclfy_one, 4) zzsclfy_one,
        round(zzsclfy_two, 4) zzsclfy_two,
        round(zfy, 4) zfy,
        round(otherzfy, 4) otherzfy,
        round(OTHER_ONE_ZFY, 4) OTHER_ONE_ZFY,
        round(OTHER_TWO_ZFY, 4) OTHER_TWO_ZFY,
        round(othercb, 4) othercb,
        round(OTHER_ONE_CB, 4) OTHER_ONE_CB,
        round(OTHER_TWO_CB, 4) OTHER_TWO_CB
        from TF_YWPN_COSTBGFIXED_W
        where
        <if test="month != null">
            MOUTH = #{month}
        </if>
        <if test="month == null">
            MOUTH = to_char(sysdate,'yyyy-mm')
        </if>
    </select>

    <select id="viewFinance" resultType="com.tofly.xrtygis.entity.Costrlfixed">
        select id,
        to_char(UP_DATE, 'yyyy-mm-dd'),
        round(YSF, 4) YSF,
        round(FTCB_TWO, 4) FTCB_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(CNZFY_TWO, 4) CNZFY_TWO,
        round(CNCB_TWO, 4) CNCB_TWO,
        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(BCSCB_ONE, 4) BCSCB_ONE,
        round(CNCB_ONE, 4) CNCB_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(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(DWCB_ONE, 4) DWCB_ONE,
        round(DWCB_TWO, 4) DWCB_TWO,
        round(DWCB_TOTAL, 4) DWCB_TOTAL,
        round(ZFY_ONE, 4) ZFY_ONE,
        round(ZFY_TWO, 4) ZFY_TWO,
        round(ZFY, 4) ZFY,
        round(PACZFY_ONE, 4) PACZFY_ONE,
        round(SYZFY_ONE, 4) SYZFY_ONE,
        round(PACZFY_TWO, 4) PACZFY_TWO,
        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(SZYSF_TOTAL, 4) SZYSF_TOTAL,
        round(OTHERZFY, 4) OTHERZFY,
        round(OTHER_ONE_ZFY, 4) OTHER_ONE_ZFY,
        round(OTHER_TWO_ZFY, 4) OTHER_TWO_ZFY,
        round(OTHERCB, 4) OTHERCB,
        round(OTHER_ONE_CB, 4) OTHER_ONE_CB,
        round(OTHER_TWO_CB, 4) OTHER_TWO_CB,
        round(DF_ONE_TOTAL, 4) DF_ONE_TOTAL,
        round(DF_TWO_TOTAL, 4) DF_TWO_TOTAL,
        round(DL_ONE_TOTAL, 4) DL_ONE_TOTAL,
        round(DL_TWO_TOTAL, 4) DL_TWO_TOTAL
        from TF_YWPN_COSTRLFIXED_W
        where MARK = '1'
        <if test="month != null">
            and to_char(UP_DATE,'yyyy-mm') = #{month}
        </if>
        <if test="month == null">
            and to_char(UP_DATE,'yyyy-mm') = to_char(sysdate,'yyyy-mm')
        </if>
    </select>

    <select id="viewSumFixed" resultType="map">
        select 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(ZFY_ONE), 4) ZFY_ONE,
        round(sum(ZFY_TWO), 4) ZFY_TWO,
        round(sum(ZFY), 4) ZFY,
        round(sum(CNZFY_TWO), 4) cnzfy_two,
        round(sum(PACZFY_ONE), 4) PACZFY_ONE,
        round(sum(SYZFY_ONE), 4) SYZFY_ONE,
        round(sum(PACZFY_TWO), 4) PACZFY_TWO,
        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(SZYSF_TOTAL), 4) SZYSF_TOTAL,
        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(JBDF_ONE) + sum(DLDF_ONE)) / nullif(sum(GSL_ONE), 0) * 1000, 4) DFCB_ONE,
        round((sum(JBDF_TWO) + sum(DLDF_TWO)) / nullif(sum(GSL_TWO), 0) * 1000, 4) DFCB_TWO,
        round((sum(JBDF_TOTAL) + sum(DLDF_TOTAL)) / nullif(sum(GSL_TOTAL), 0) * 1000, 4) DFCB_TOTAL,
        round(sum(PACZFY_ONE) / nullif(sum(GSL_ONE), 0) * 1000, 4) PACCB_ONE,
        round(sum(SYZFY_ONE) / nullif(sum(GSL_ONE), 0) * 1000, 4) SYCB_ONE,
        round(sum(BCSZFY) / nullif(sum(GSL_ONE), 0) * 1000, 4) BCSCB_ONE,
        round(sum(CNZFY) / nullif(sum(GSL_ONE), 0) * 1000, 4) CNCB_ONE,
        round(sum(CNZFY_TWO) / nullif(sum(GSL_TWO), 0) * 1000, 4) CNCB_TWO,
        round(sum(ZZSCLFY_ONE) / nullif(sum(GSL_ONE), 0) * 1000, 4) ZSCLCB_ONE,
        round(sum(PACZFY_TWO) / nullif(sum(GSL_TWO), 0) * 1000, 4) PACCB_TWO,
        round(sum(YLZFY_TWO) / nullif(sum(GSL_TWO), 0) * 1000, 4) YLCB_TWO,
        round(sum(PAMZSZFY) / nullif(sum(GSL_TWO), 0) * 1000, 4) PAMZSCB_TWO,
        round(sum(GMSJFHYZFY) / nullif(sum(GSL_TWO), 0) * 1000, 4) GMSJFHYCB_TWO,
        round(sum(PAMWNZFY) / nullif(sum(GSL_TWO), 0) * 1000, 4) PAMWNCB_TWO,
        round(sum(FTZFY) / nullif(sum(GSL_TWO), 0) * 1000, 4) FTCB_TWO,
        round(sum(WNZYF) / nullif(sum(GSL_TWO), 0) * 1000, 4) WNZYCB_TWO,
        round(sum(ZZSCLFY_TWO) / decode(sum(GSL_TWO), 0, null, sum(GSL_TWO)) * 1000, 4) ZSCLCB_TWO,
        round((sum(ZZSCLFY_ONE) + sum(ZZSCLFY_TWO)) / nullif(sum(GSL_TOTAL), 0) * 1000, 4) ZSCLCB_TOTAL,
        round(sum(YSF) / nullif(sum(GSL_TOTAL), 0) * 1000, 4) YSFCB,
        round(sum(SZYSF_ONE) / nullif(sum(GSL_ONE), 0) * 1000, 4) SZYSFCB_ONE,
        round(sum(SZYSF_TWO) / nullif(sum(GSL_TWO), 0) * 1000, 4) SZYSFCB_TWO,
        round(sum(SZYSF_TOTAL) / nullif(sum(GSL_TOTAL), 0) * 1000, 4) SZYSFCB_TOTAL,
        round(sum(ZFY_ONE) / nullif(sum(GSL_ONE), 0) * 1000, 4) DWCB_ONE,
        round(sum(ZFY_TWO) / nullif(sum(GSL_TWO), 0) * 1000, 4) DWCB_TWO,
        round(sum(ZFY) / nullif(sum(GSL_TOTAL), 0) * 1000, 4) DWCB_TOTAL,
        round(sum(OTHERZFY) / nullif(sum(GSL_ONE), 0) * 1000, 4) OTHERCB,
        round(sum(OTHER_ONE_ZFY) / nullif(sum(GSL_ONE), 0) * 1000, 4) OTHER_ONE_CB,
        round(sum(OTHER_TWO_ZFY) / nullif(sum(GSL_TWO), 0) * 1000, 4) OTHER_TWO_CB
        from TF_YWPN_COSTRLFIXED_W f
        full join TF_YWPN_COSTRLWATER_W w on to_char(f.UP_DATE, 'yyyy-mm-dd') =
        to_char(w.UP_DATE, 'yyyy-mm-dd') and f.MARK = w.MARK
        where f.MARK = '0'
        <if test="start != null and end != null">
            and to_char(f.UP_DATE,'yyyy-mm-dd') between #{start} and #{end}
        </if>
    </select>

    <select id="viewFixed" resultType="map">
        select id,
        to_char(UP_DATE, 'yyyy-mm-dd') up_date,
        round(YSF, 4) YSF,
        round(SZYSF_ONE, 4) SZYSF_ONE,
        round(SZYSF_TWO, 4) SZYSF_TWO,
        round(OTHERZFY, 4) OTHERZFY,
        round(OTHER_ONE_ZFY, 4) OTHER_ONE_ZFY,
        round(OTHER_TWO_ZFY, 4) OTHER_TWO_ZFY,
        round(OTHERCB, 4) OTHERCB,
        round(OTHER_ONE_CB, 4) OTHER_ONE_CB,
        round(OTHER_TWO_CB, 4) OTHER_TWO_CB,
        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(BCSCB_ONE, 4) BCSCB_ONE,
        round(CNCB_ONE, 4) CNCB_ONE,
        round(CNCB_TWO, 4) CNCB_TWO,
        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(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(DWCB_ONE, 4) DWCB_ONE,
        round(DWCB_TWO, 4) DWCB_TWO,
        round(DWCB_TOTAL, 4) DWCB_TOTAL,
        round(ZFY_ONE, 4) ZFY_ONE,
        round(ZFY_TWO, 4) ZFY_TWO,
        round(ZFY, 4) ZFY,
        round(FTCB_TWO, 4) FTCB_TWO,
        round(PACZFY_ONE, 4) PACZFY_ONE,
        round(SYZFY_ONE, 4) SYZFY_ONE,
        round(PACZFY_TWO, 4) PACZFY_TWO,
        round(YLZFY_TWO, 4) YLZFY_TWO,
        round(PAMZSZFY, 4) PAMZSZFY,
        round(FTZFY, 4) FTZFY,
        round(CNZFY, 4) CNZFY,
        round(CNZFY_TWO, 4) CNZFY_TWO,
        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(SZYSF_TOTAL, 4) SZYSF_TOTAL
        from TF_YWPN_COSTRLFIXED_W
        where MARK = '0'
        <if test="start != null and end != null">
            and to_char(UP_DATE,'yyyy-mm-dd') between #{start} and #{end}
        </if>
        order by up_date
    </select>

    <select id="viewDayFixed" resultType="com.tofly.xrtygis.entity.Costrlfixed">
        select *
        from TF_YWPN_COSTRLFIXED_W
        where ROWNUM = 1
        <if test="mark == 1">
            and to_char(UP_DATE,'yyyy-mm') = to_char(#{date},'yyyy-mm')
            and mark = #{mark}
        </if>
        <if test="mark == 0">
            and to_char(UP_DATE,'yyyy-mm-dd') = #{date}
            and mark = #{mark}
        </if>
    </select>

    <select id="getPriceHistory" resultType="map">
        select id, year,UP_DATE, pacdj, yldj, pam_zsdj, pam_wndj, ftdj, cndj, gmsjfhydj, sydj, dlddj_one, dlddj_two,
        wnzydj,
        ysfdj, szysdj, bcsdj, isnew, create_time, create_user, pac2dj, qbjzgdj, otherdj, jbdldj_one, jbdldj_two,
        (select REAL_NAME from TF_SMPN_USER_X where id = p.CREATE_USER) user_name
        from TF_YWPN_COSTRLPRICE_W p
        where YEAR = #{year}
        <if test="start != null and end != null">
            and to_char(UP_DATE,'yyyy-mm-dd hh24:mi:ss') between #{start} and #{end}
        </if>
        order by create_time desc
    </select>

    <select id="existFinanceIsAllowed" resultType="long">
        select count(*)
        from TF_YWPN_COSTRLFIXED_W
        where MARK = 1
          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="getFillInTheMessage" resultType="map">
        select w.id,
               w.up_date,
               w.gsl_one,
               w.gsl_two,
               w.gsl_qbj,
               w.gsl_total,
               w.zsl_one,
               w.zsl_two,
               w.zsl_hqsk,
               w.zsl_total,
               w.ssl_total,
               w.zysl_one,
               w.zysl_two,
               w.zysl_total,
               w.zysll_one,
               w.zysll_two,
               w.zysll_total,
               w.wspsl,
               w.cxc,
               w.lsl,
               w.pac_one,
               w.pac_two,
               w.sy_one,
               w.yl_two,
               w.pam,
               w.ft,
               w.cn,
               w.gmsjfhy,
               w.pam_wy,
               w.bcs,
               w.wnzl,
               w.dldl_one,
               w.dldl_two,
               w.dldl_total,
               w.jbdl_one,
               w.jbdl_two,
               w.jbdl_total,
               w.create_time,
               w.create_user,
               w.mark,
               w.other,
               w.OTHER_ONE,
               w.OTHER_TWO,
               w.update_time,
               w.cn_two,
               f.id,
               f.up_date,
               f.paczfy_one,
               f.paczfy_two,
               f.syzfy_one,
               f.ylzfy_two,
               f.pamzszfy,
               f.ftzfy,
               f.cnzfy,
               f.gmsjfhyzfy,
               f.pamwnzfy,
               f.bcszfy,
               f.wnzyf,
               f.jbdf_one,
               f.jbdf_two,
               f.jbdf_total,
               f.dldf_one,
               f.dldf_two,
               f.dldf_total,
               f.ysf,
               f.szysf_one,
               f.szysf_two,
               f.szysf_total,
               f.dfcb_one,
               f.dfcb_two,
               f.dfcb_total,
               f.paccb_one,
               f.sycb_one,
               f.cncb_one,
               f.bcscb_one,
               f.zsclcb_one,
               f.paccb_two,
               f.ylcb_two,
               f.pamzscb_two,
               f.ftcb_two,
               f.gmsjfhycb_two,
               f.pamwncb_two,
               f.wnzycb_two,
               f.zsclcb_two,
               f.zsclcb_total,
               f.ysfcb,
               f.szysfcb_one,
               f.szysfcb_two,
               f.szysfcb_total,
               f.zfy_one,
               f.zfy_two,
               f.dwcb_one,
               f.dwcb_two,
               f.dwcb_total,
               f.create_time,
               f.create_user,
               f.mark,
               f.zzsclfy_one,
               f.zzsclfy_two,
               f.zfy,
               f.otherzfy,
               OTHER_ONE_ZFY,
               OTHER_TWO_ZFY,
               f.othercb,
               OTHER_ONE_CB,
               OTHER_TWO_CB,
               f.df_one_total,
               f.df_two_total,
               f.dl_one_total,
               f.dl_two_total,
               f.cnzfy_two,
               f.cncb_two,
               f.update_time
        from TF_YWPN_COSTRLWATER_W w
                 full 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
        where f.MARK = 1
          and to_char(f.UP_DATE, 'yyyy-mm') = #{month}
    </select>

</mapper>