<!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.UnitMapper">

    <select id="selectFinance" resultType="map">
        select id,
        to_char(UP_DATE, 'yyyy-mm-dd') month,
        round(PACDH_ONE, 4) PACDH_ONE,
        round(PACDH_TWO, 4) PACDH_TWO,
        round(SYDH_ONE, 4) SYDH_ONE,
        round(CNDH_TWO, 4) CNDH_TWO,
        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(OTHERDH, 4) OTHERDH,
        round(OTHER_ONE_DH, 4) OTHER_ONE_DH,
        round(OTHER_TWO_DH, 4) OTHER_TWO_DH
        from TF_YWPN_COSTRLUNIT_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="selectReal" resultType="map">
        select
        round(sum(PAC_ONE) / (nullif(sum(ZSL_ONE),0) * 10),4) pacdh_one,
        round(sum(PAC_TWO) / (nullif(sum(ZSL_TWO),0) * 10),4) pacdh_two,
        round(sum(SY_ONE) / (nullif(sum(ZSL_ONE),0) * 10),4) sydh_one,
        round(sum(YL_TWO) / (nullif(sum(ZSL_TWO),0) * 10),4) yldh_two,
        round(sum(CN_TWO) / (nullif(sum(ZSL_TWO),0) * 10),4) cndh_two,
        round(sum(DLDL_ONE) / (nullif(sum(ZSL_ONE),0) * 10),4) dh_one,
        round(sum(DLDL_TWO) / (nullif(sum(ZSL_TWO),0) * 10),4) dh_two,
        round(sum(DLDL_TOTAL) / (nullif(sum(ZSL_TOTAL),0) * 10),4) dh_total,
        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(OTHER_TWO) / (nullif(sum(ZSL_TWO),0) * 10),4) otherTwoDh
        from TF_YWPN_COSTRLWATER_W
        where
        MARK = '0'
        <if test="start != null and end != null">
            and to_char(UP_DATE,'yyyy-mm-dd') between #{start} and #{end}
        </if>
    </select>

    <select id="viewReals" resultType="map">
        select id,
        to_char(UP_DATE, 'yyyy-mm-dd') month,
        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(CNDH_TWO, 4) CNDH_TWO,
        round(DH_TWO, 4) DH_TWO,
        round(DH_TOTAL, 4) DH_TOTAL,
        round(OTHERDH, 4) OTHERDH,
        round(OTHER_ONE_DH, 4) OTHER_ONE_DH,
        round(OTHER_TWO_DH, 4) OTHER_TWO_DH
        from TF_YWPN_COSTRLUNIT_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="selectPlan" resultType="map">
        select MONTH,
        round(PACDH_ONE, 4) PACDH_ONE,
        round(SYDH_ONE, 4) SYDH_ONE,
        round(PACDH_TWO, 4) PACDH_TWO,
        round(YLDH_TWO, 4) YLDH_TWO,
        round(DH_ONE, 4) DH_ONE,
        round(CNDH_TWO, 4) CNDH_TWO,
        round(DH_TWO, 4) DH_TWO,
        round(DH_TOTAL) DH_TOTAL,
        round(OTHERDH, 4) OTHERDH,
        round(OTHER_ONE_DH, 4) OTHER_ONE_DH,
        round(OTHER_TWO_DH, 4) OTHER_TWO_DH
        from TF_YWPN_COSTBGUNIT_W
        <where>
            <if test="month != null">
                MONTH = #{month}
            </if>
            <if test="month == null">
                month = to_char(sysdate,'yyyy-mm')
            </if>
        </where>
    </select>

</mapper>