<!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,
        PACDH_ONE,
        PACDH_TWO,
        SYDH_ONE,
        YLDH_TWO,
        DH_ONE,
        DH_TWO,
        DH_TOTAL
        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),5) pacdh_one,
        round(sum(PAC_TWO) / (nullif(sum(ZSL_TWO),0) * 10),5) pacdh_two,
        round(sum(SY_ONE) / (nullif(sum(ZSL_ONE),0) * 10),5) sydh_one,
        round(sum(YL_TWO) / (nullif(sum(ZSL_TWO),0) * 10),5) yldh_two,
        round(sum(DLDL_ONE) / (nullif(sum(ZSL_ONE),0) * 10),5) dh_one,
        round(sum(DLDL_TWO) / (nullif(sum(ZSL_TWO),0) * 10),5) dh_two,
        round(sum(DLDL_TOTAL) / (nullif(sum(ZSL_TOTAL),0) * 10),5) dh_total
        from TF_YWPN_COSTRLWATER_W
        where
        MARK = '0'
        <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>
        group by to_char(UP_DATE,'yyyy-mm')
    </select>

    <select id="viewReals" resultType="map">
        select
        id,
        to_char(UP_DATE,'yyyy-mm-dd') month,
        PACDH_ONE,
        PACDH_TWO,
        SYDH_ONE,
        YLDH_TWO,
        DH_ONE,
        DH_TWO,
        DH_TOTAL
        from TF_YWPN_COSTRLUNIT_W
        where
        MARK = '0'
        <if test="month != null">
            and to_char(UP_DATE,'yyyy-mm')
            between #{month} and #{month}
        </if>
        <if test="month == null">
            and to_char(UP_DATE,'yyyy-mm-dd')
            between to_char(add_months(sysdate,-1),'yyyy-mm') || '-' || #{start} and to_char(sysdate,'yyyy-mm') ||'-' ||
            #{end}
        </if>
        order by UP_DATE
    </select>

    <select id="selectPlan" resultType="map">
        select
        MONTH ,
        PACDH_ONE,
        SYDH_ONE,
        PACDH_TWO,
        YLDH_TWO,
        DH_ONE,
        DH_TWO,
        DH_TOTAL
        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>