<?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.gpsboot.mapper.fill.FillMonthMapper">

    <resultMap id="fillMonthMap" type="com.tofly.pojo.fill.FillMonth">
        <id property="id" column="ID"/>
        <result property="recordTime" column="RECORD_TIME"/>
        <result property="issue" column="ISSUE"/>
        <result property="fillDept" column="FILL_DEPT"/>
        <result property="belongStationId" column="BELONG_STATION_ID"/>
        <result property="phone" column="PHONE"/>
        <result property="monthDealWq" column="MONTH_DEAL_WQ"/>
        <result property="maxDayDealWq" column="MAX_DAY_DEAL_WQ"/>
        <result property="monthEc" column="MONTH_EC"/>
        <result property="loadRate" column="LOAD_RATE"/>
        <result property="spDesignScale" column="SP_DESIGN_SCALE"/>
        <result property="monthDirectCost" column="MONTH_DIRECT_COST"/>
        <result property="dayNormalOperation" column="DAY_NORMAL_OPERATION"/>
        <result property="reachLetDay" column="REACH_LET_DAY"/>
        <result property="notReachSource" column="NOT_REACH_SOURCE"/>
        <result property="exceedItem" column="EXCEED_ITEM"/>
        <result property="cs" column="CS"/>
        <result property="mainCs" column="MAIN_CS"/>
        <result property="totalCs" column="TOTAL_CS"/>
        <result property="activeCsRate" column="ACTIVE_CS_RATE"/>
        <result property="pr" column="PR"/>
        <result property="mainPr" column="MAIN_PR"/>
        <result property="totalPr" column="TOTAL_PR"/>
        <result property="activePrRate" column="ACTIVE_PR_RATE"/>
        <result property="da" column="DA"/>
        <result property="mainDa" column="MAIN_DA"/>
        <result property="totalDa" column="TOTAL_DA"/>
        <result property="activeDaRate" column="ACTIVE_DA_RATE"/>
        <result property="monthDsPc" column="MONTH_DS_PC"/>
        <result property="pcCutRate" column="PC_CUT_RATE"/>
        <result property="monthPc" column="MONTH_PC"/>
        <result property="landUr" column="LAND_UR"/>
        <result property="bmUr" column="BM_UR"/>
        <result property="ictUr" column="ICT_UR"/>
        <result property="otherUr" column="OTHER_UR"/>
        <result property="uwUr" column="UW_UR"/>
        <result property="codCr" column="COD_CR"/>
        <result property="bod5" column="BOD5"/>
        <result property="nh3n" column="NH3N"/>
        <result property="ss" column="SS"/>
        <result property="tn" column="TN"/>
        <result property="tp" column="TP"/>
        <result property="ph" column="PH"/>
        <result property="codCrOut" column="COD_CR_OUT"/>
        <result property="bod5Out" column="BOD5_OUT"/>
        <result property="nh3nOut" column="NH3N_OUT"/>
        <result property="ssOut" column="SS_OUT"/>
        <result property="tnOut" column="TN_OUT"/>
        <result property="tpOut" column="TP_OUT"/>
        <result property="phOut" column="PH_OUT"/>
        <result property="note" column="NOTE"/>
        <result property="fillTime" column="FILL_TIME"/>
        <result property="fillUser" column="FILL_USER"/>
        <result property="updateTime" column="UPDATE_TIME"/>
        <result property="updateUser" column="UPDATE_USER"/>
        <result property="auditUser" column="AUDIT_USER"/>
        <result property="auditState" column="AUDIT_STATE"/>
        <result property="auditTime" column="AUDIT_TIME"/>
        <result property="auditNote" column="AUDIT_NOTE"/>
        <result property="report" column="REPORT"/>
        <result property="reportTime" column="REPORT_TIME"/>
        <result property="state" column="STATE"/>
        <association property="notReachSourceName" column="NOT_REACH_SOURCE" select="getNotReachSourceName"/>
        <association property="csName" column="CS" select="getReportName"/>
        <association property="mainCsName" column="MAIN_CS" select="getMainCsName"/>
        <association property="prName" column="PR" select="getReportName"/>
        <association property="mainPrName" column="MAIN_PR" select="getMainPrName"/>
        <association property="daName" column="DA" select="getReportName"/>
        <association property="mainDaName" column="MAIN_DA" select="getMainDaName"/>
        <association property="stateName" column="STATE" select="getStateName"/>
        <association property="reportName" column="REPORT" select="getReportName"/>
        <association property="auditStateName" column="AUDIT_STATE" select="getAuditStateName"/>
        <association property="auditUserName" column="AUDIT_USER" select="com.tofly.gpsboot.mapper.plan.HydrantrecordMapper.getRealName"/>
        <association property="fillDeptName" column="FILL_DEPT" select="com.tofly.gpsboot.mapper.fill.FillEcMapper.getDName"/>
        <association property="belongStationName" column="BELONG_STATION_ID" select="getBelongStationName"/>
        <association property="fillUserName" column="FILL_USER" select="com.tofly.gpsboot.mapper.plan.HydrantrecordMapper.getRealName"/>
        <association property="updateUserName" column="UPDATE_USER" select="com.tofly.gpsboot.mapper.plan.HydrantrecordMapper.getRealName"/>
        <association property="belongDeptId" column="BELONG_STATION_ID" select="getBelongDeptId"/>
        <association property="belongDeptName" column="BELONG_STATION_ID" select="getBelongDeptName"/>
    </resultMap>

    <select id="getBelongDeptId" resultType="Long">
        select DEPT_ID
        from tf_dept_sewage
        where SEWAGE_STATION_ID = #{belongStationId}
    </select>
    <select id="getBelongDeptName" resultType="string">
        select a.NAME
        from tf_smpn_department_x a
        left join tf_dept_sewage b on a.ID = b.DEPT_ID
        where b.SEWAGE_STATION_ID = #{belongStationId}
    </select>
    <select id="getNotReachSourceName" resultType="string">
        select CNAME
        from TF_YWPN_SYSCHILDCODE_D
        where PCID = 50900
          and ID = #{notReachSource}
    </select>
    <select id="getMainCsName" resultType="string">
        select CNAME
        from TF_YWPN_SYSCHILDCODE_D
        where PCID = 51000
          and ID = #{mainCs}
    </select>
    <select id="getMainPrName" resultType="string">
        select CNAME
        from TF_YWPN_SYSCHILDCODE_D
        where PCID = 52000
          and ID = #{mainPr}
    </select>
    <select id="getMainDaName" resultType="string">
        select CNAME
        from TF_YWPN_SYSCHILDCODE_D
        where PCID = 53000
          and ID = #{mainDa}
    </select>

    <select id="getBelongStationName"  resultType="java.lang.String">
        select name belongStationName
        from tf_ywpn_monitor_stationsiteinfo_w
        where id = #{belongStationId}
    </select>

    <select id="getAuditStateName" resultType="string">
        SELECT case #{auditState} when '0' then '未审核' when '1' then '通过' when '2' then '不通过' when '3' then '不可审核'end
    </select>

    <select id="getReportName" resultType="string">
        SELECT case #{report} when '0' then '否' when '1' then '是' end
    </select>
    <select id="getStateName" resultType="string">
        SELECT case #{state} when '0' then '未上报' when '1' then '待审核' when '2' then '完成' end
    </select>

    <select id="getFillMonthPage" resultMap="fillMonthMap">
        select * from tf_fill_month_w
        where  1=1
        <if test="dto.fillDept != null ">
            and fill_Dept = #{dto.fillDept}
        </if>
        <if test="dto.id != null ">
            and id = #{dto.id}
        </if>
        <if test="dto.fillUser != null">
            and fill_User = #{dto.fillUser}
        </if>
        <if test="dto.auditUser != null">
            and audit_User = #{dto.auditUser}
        </if>
        <if test="dto.auditState != null and dto.auditState !=''">
            and audit_state = #{dto.auditState}
        </if>
        <if test="dto.report != null and dto.report !=''">
            and report = #{dto.report}
        </if>
        <if test="dto.belongStationIds != null and dto.belongStationIds != ''  ">
            AND CONVERT(varchar(100), BELONG_STATION_ID) in
            <foreach item="nodeCodestr" collection="dto.belongStationIds.split(',')" open="(" separator="," close=")">
                #{nodeCodestr}
            </foreach>
        </if>
        <if test="dto.state != null and dto.state !=''">
            and state = #{dto.state}
        </if>
        <if test="dto.startTime != null and dto.endTime != null">
            and RECORD_TIME between #{dto.startTime} and #{dto.endTime}
        </if>
        <if test="dto.monthSel != null and dto.monthSel !=''">
            and CONVERT(VARCHAR(7),RECORD_TIME, 120) = #{dto.monthSel}
        </if>
    </select>

    <select id="getStationDeptList" resultType="com.tofly.pojo.fill.FillVo">
        select a.id belongStationId,a.name sewageStationName,b.id belongDeptId,b.name belongDeptName
        from tf_ywpn_monitor_stationsiteinfo_w a
        left join tf_dept_sewage c on a.ID = c.SEWAGE_STATION_ID
        left join tf_smpn_department_x b on b.id = c.DEPT_ID
        where  1=1 and a.del_flag = '0'
        <if test="sewageIds != null">
            AND a.id in
            <foreach item="item" index="index" collection="sewageIds" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        order by a.id
    </select>

<!--    <select id="getIndexValDay" resultType="com.tofly.pojo.fill.FillVo">-->
<!--        select  CONVERT(VARCHAR(100), e.RECORD_TIME, 20) RECORD_TIME,-->
<!--                e.BELONG_STATION_ID BELONG_STATION_ID,-->
<!--                (select g.DEPT_ID from tf_dept_sewage g where g.SEWAGE_STATION_ID = e.BELONG_STATION_ID) belong_dept_id,-->
<!--                (select h.NAME from tf_smpn_department_x h left join tf_dept_sewage g on h.ID = g.DEPT_ID where g.SEWAGE_STATION_ID = e.BELONG_STATION_ID) belong_dept_name,-->
<!--                f.name sewage_station_name,-->
<!--                ISNULL(a.ELECTRO, 0) ELECTRO,-->
<!--                ISNULL(b.DAY_SLUDGE_DEHYDRATION, 0) DAY_SLUDGE_DEHYDRATION,-->
<!--                ISNULL(b.DAY_SLUDGE_TRANSFER, 0) DAY_SLUDGE_TRANSFER,-->
<!--                ISNULL(b.SLUDGE_WATER_CUT_RATE, 0) SLUDGE_WATER_CUT_RATE,-->
<!--                ISNULL(d.DAY_INTO_WATER, 0) DAY_INTO_WATER,-->
<!--                ISNULL(d.DAY_OUT_WATER, 0) DAY_OUT_WATER,-->
<!--                ISNULL(e.COD_CR, 0) COD_CR,-->
<!--                ISNULL(e.BOD5, 0) BOD5,-->
<!--                ISNULL(e.NH3N, 0) NH3N,-->
<!--                ISNULL(e.SS, 0) SS,-->
<!--                ISNULL(e.TN, 0) TN,-->
<!--                ISNULL(e.TP, 0) TP,-->
<!--                ISNULL(e.PH, 0) PH,-->
<!--                ISNULL(e.COD_CR_OUT, 0) COD_CR_OUT,-->
<!--                ISNULL(e.BOD5_OUT, 0) BOD5_OUT,-->
<!--                ISNULL(e.NH3N_OUT, 0) NH3N_OUT,-->
<!--                ISNULL(e.SS_OUT, 0) SS_OUT,-->
<!--                ISNULL(e.TN_OUT, 0) TN_OUT,-->
<!--                ISNULL(e.TP_OUT, 0) TP_OUT,-->
<!--                ISNULL(e.PH_OUT, 0) PH_OUT-->
<!--        from tf_fill_water_w e-->
<!--        left join tf_fill_sludge_deal_w b on e.BELONG_STATION_ID = b.BELONG_STATION_ID-->
<!--        left join tf_fill_sludge_Transfer_w c on e.BELONG_STATION_ID = c.BELONG_STATION_ID-->
<!--        left join tf_fill_stc_w d on e.BELONG_STATION_ID = d.BELONG_STATION_ID-->
<!--        left join tf_fill_ec_w a on e.BELONG_STATION_ID = a.BELONG_STATION_ID-->
<!--        left join tf_ywpn_monitor_stationsiteinfo_w f on f.ID = e.BELONG_STATION_ID-->
<!--        WHERE-->
<!--            1=1-->
<!--        <if test="startDate != null and endDate != null">-->
<!--            AND CONVERT(VARCHAR(100), a.RECORD_TIME, 20) between #{startDate} and #{endDate}-->
<!--        </if>-->
<!--        <if test="belongSewageId != null">-->
<!--            AND f.ID = #{belongSewageId}-->
<!--        </if>-->
<!--        ORDER BY RECORD_TIME-->
<!--    </select>-->

<!--    <select id="getIndexValMonth" resultType="com.tofly.pojo.fill.FillVo">-->
<!--        select  datename(yyyy,a.RECORD_TIME) + '-' + datename(m,a.RECORD_TIME) RECORD_TIME,-->
<!--                a.BELONG_STATION_ID BELONG_STATION_ID,-->
<!--                f.name sewage_station_name,-->
<!--                ISNULL(SUM ( convert(decimal(18, 5), a.ELECTRO) ), 0) ELECTRO,-->
<!--                ISNULL(SUM ( convert(decimal(18, 5), b.DAY_SLUDGE_DEHYDRATION) ), 0) DAY_SLUDGE_DEHYDRATION,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), b.DAY_SLUDGE_TRANSFER) ) / COUNT(*),2) ELSE 0 END DAY_SLUDGE_TRANSFER,-->
<!--                ISNULL(SUM ( convert(decimal(18, 5), b.SLUDGE_WATER_CUT_RATE) ), 0) SLUDGE_WATER_CUT_RATE,-->
<!--                ISNULL(SUM ( convert(decimal(18, 5), d.DAY_INTO_WATER) ), 0) DAY_INTO_WATER,-->
<!--                ISNULL(SUM ( convert(decimal(18, 5), d.DAY_OUT_WATER) ), 0) DAY_OUT_WATER,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.COD_CR) ) / COUNT(*),2) ELSE 0 END COD_CR,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.BOD5) ) / COUNT(*),2) ELSE 0 END BOD5,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.NH3N) ) / COUNT(*),2) ELSE 0 END NH3N,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.SS) ) / COUNT(*),2) ELSE 0 END SS,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.TN) ) / COUNT(*),2) ELSE 0 END TN,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.TP) ) / COUNT(*),2) ELSE 0 END TP,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.PH) ) / COUNT(*),2) ELSE 0 END PH,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.COD_CR_OUT) ) / COUNT(*),2) ELSE 0 END COD_CR_OUT,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.BOD5_OUT) ) / COUNT(*),2) ELSE 0 END BOD5_OUT,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.NH3N_OUT) ) / COUNT(*),2) ELSE 0 END NH3N_OUT,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.SS_OUT) ) / COUNT(*),2) ELSE 0 END SS_OUT,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.PH_OUT) ) / COUNT(*),2) ELSE 0 END PH_OUT,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.TN_OUT) ) / COUNT(*),2) ELSE 0 END TN_OUT,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.TP_OUT) ) / COUNT(*),2) ELSE 0 END TP_OUT-->
<!--        from tf_fill_ec_w a-->
<!--        left join tf_fill_sludge_deal_w b on a.BELONG_STATION_ID = b.BELONG_STATION_ID-->
<!--        left join tf_fill_sludge_Transfer_w c on a.BELONG_STATION_ID = c.BELONG_STATION_ID-->
<!--        left join tf_fill_stc_w d on a.BELONG_STATION_ID = d.BELONG_STATION_ID-->
<!--        left join tf_fill_water_w e on a.BELONG_STATION_ID = e.BELONG_STATION_ID-->
<!--        left join tf_ywpn_monitor_stationsiteinfo_w f on a.BELONG_STATION_ID = f.ID-->
<!--        WHERE-->
<!--            1=1-->
<!--        <if test="startMonth != null and endMonth != null">-->
<!--            AND datename(yyyy,a.RECORD_TIME) + '-' + datename(m,a.RECORD_TIME) between #{startMonth} and #{endMonth}-->
<!--        </if>-->
<!--        GROUP BY datename(yyyy,a.RECORD_TIME) + '-' + datename(m,a.RECORD_TIME), a.BELONG_STATION_ID, f.name-->
<!--        ORDER BY RECORD_TIME-->
<!--    </select>-->

<!--    <select id="getIndexValYear" resultType="com.tofly.pojo.fill.FillVo">-->
<!--        select  datename(yyyy,a.RECORD_TIME) RECORD_TIME,-->
<!--                a.BELONG_STATION_ID BELONG_STATION_ID,-->
<!--                f.name sewage_station_name,-->
<!--                ISNULL(SUM ( convert(decimal(18, 5), a.ELECTRO) ), 0) ELECTRO,-->
<!--                ISNULL(SUM ( convert(decimal(18, 5), b.DAY_SLUDGE_DEHYDRATION) ), 0) DAY_SLUDGE_DEHYDRATION,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), b.DAY_SLUDGE_TRANSFER) ) / COUNT(*),2) ELSE 0 END DAY_SLUDGE_TRANSFER,-->
<!--                ISNULL(SUM ( convert(decimal(18, 5), b.SLUDGE_WATER_CUT_RATE) ), 0) SLUDGE_WATER_CUT_RATE,-->
<!--                ISNULL(SUM ( convert(decimal(18, 5), d.DAY_INTO_WATER) ), 0) DAY_INTO_WATER,-->
<!--                ISNULL(SUM ( convert(decimal(18, 5), d.DAY_OUT_WATER) ), 0) DAY_OUT_WATER,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.COD_CR) ) / COUNT(*),2) ELSE 0 END COD_CR,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.BOD5) ) / COUNT(*),2) ELSE 0 END BOD5,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.NH3N) ) / COUNT(*),2) ELSE 0 END NH3N,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.SS) ) / COUNT(*),2) ELSE 0 END SS,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.TN) ) / COUNT(*),2) ELSE 0 END TN,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.TP) ) / COUNT(*),2) ELSE 0 END TP,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.PH) ) / COUNT(*),2) ELSE 0 END PH,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.COD_CR_OUT) ) / COUNT(*),2) ELSE 0 END COD_CR_OUT,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.BOD5_OUT) ) / COUNT(*),2) ELSE 0 END BOD5_OUT,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.NH3N_OUT) ) / COUNT(*),2) ELSE 0 END NH3N_OUT,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.SS_OUT) ) / COUNT(*),2) ELSE 0 END SS_OUT,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.PH_OUT) ) / COUNT(*),2) ELSE 0 END PH_OUT,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.TN_OUT) ) / COUNT(*),2) ELSE 0 END TN_OUT,-->
<!--                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), e.TP_OUT) ) / COUNT(*),2) ELSE 0 END TP_OUT-->
<!--        from tf_fill_ec_w a-->
<!--        left join tf_fill_sludge_deal_w b on a.BELONG_STATION_ID = b.BELONG_STATION_ID-->
<!--        left join tf_fill_sludge_Transfer_w c on a.BELONG_STATION_ID = c.BELONG_STATION_ID-->
<!--        left join tf_fill_stc_w d on a.BELONG_STATION_ID = d.BELONG_STATION_ID-->
<!--        left join tf_fill_water_w e on a.BELONG_STATION_ID = e.BELONG_STATION_ID-->
<!--        left join tf_ywpn_monitor_stationsiteinfo_w f on a.BELONG_STATION_ID = f.ID-->
<!--        WHERE-->
<!--            1=1-->
<!--        <if test="startYear != null and endYear != null">-->
<!--            AND datename(yyyy,a.RECORD_TIME) between #{startYear} and #{endYear}-->
<!--        </if>-->
<!--        GROUP BY datename(yyyy,a.RECORD_TIME), a.BELONG_STATION_ID, f.name-->
<!--        ORDER BY RECORD_TIME-->
<!--    </select>-->
    <select id="getIndexValYear" resultMap="fillMonthMap">
        select  datename(yyyy,RECORD_TIME) scada_Time,
                BELONG_STATION_ID,
                ISNULL(SUM ( convert(decimal(18, 5), MONTH_DEAL_WQ) ), 0) MONTH_DEAL_WQ,
                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), MAX_DAY_DEAL_WQ) ) / COUNT(*),2) ELSE 0 END MAX_DAY_DEAL_WQ,
                ISNULL(SUM ( convert(decimal(18, 5), MONTH_EC) ), 0) MONTH_EC,
                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), LOAD_RATE) ) / COUNT(*),2) ELSE 0 END LOAD_RATE,
                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), SP_DESIGN_SCALE) ) / COUNT(*),2) ELSE 0 END SP_DESIGN_SCALE,
                ISNULL(SUM ( convert(decimal(18, 5), MONTH_DIRECT_COST) ), 0) MONTH_DIRECT_COST,
                ISNULL(SUM ( convert(decimal(18, 5), DAY_NORMAL_OPERATION) ), 0) DAY_NORMAL_OPERATION,
                ISNULL(SUM ( convert(decimal(18, 5), REACH_LET_DAY) ), 0) REACH_LET_DAY,
                ISNULL(SUM ( convert(decimal(18, 5), TOTAL_CS) ), 0) TOTAL_CS,
                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), ACTIVE_CS_RATE) ) / COUNT(*),2) ELSE 0 END ACTIVE_CS_RATE,
                ISNULL(SUM ( convert(decimal(18, 5), TOTAL_PR) ), 0) TOTAL_PR,
                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), ACTIVE_PR_RATE) ) / COUNT(*),2) ELSE 0 END ACTIVE_PR_RATE,
                ISNULL(SUM ( convert(decimal(18, 5), TOTAL_PR) ), 0) TOTAL_DA,
                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), ACTIVE_DA_RATE) ) / COUNT(*),2) ELSE 0 END ACTIVE_DA_RATE,
                ISNULL(SUM ( convert(decimal(18, 5), MONTH_DS_PC) ), 0) MONTH_DS_PC,
                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), PC_CUT_RATE) ) / COUNT(*),2) ELSE 0 END PC_CUT_RATE,
                ISNULL(SUM ( convert(decimal(18, 5), MONTH_PC) ), 0) MONTH_PC,
                ISNULL(SUM ( convert(decimal(18, 5), LAND_UR) ), 0) LAND_UR,
                ISNULL(SUM ( convert(decimal(18, 5), BM_UR) ), 0) BM_UR,
                ISNULL(SUM ( convert(decimal(18, 5), ICT_UR) ), 0) ICT_UR,
                ISNULL(SUM ( convert(decimal(18, 5), OTHER_UR) ), 0) OTHER_UR,
                ISNULL(SUM ( convert(decimal(18, 5), UW_UR) ), 0) UW_UR,
                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), COD_CR) ) / COUNT(*),2) ELSE 0 END COD_CR,
                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), BOD5) ) / COUNT(*),2) ELSE 0 END BOD5,
                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), NH3N) ) / COUNT(*),2) ELSE 0 END NH3N,
                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), SS) ) / COUNT(*),2) ELSE 0 END SS,
                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), TN) ) / COUNT(*),2) ELSE 0 END TN,
                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), TP) ) / COUNT(*),2) ELSE 0 END TP,
                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), PH) ) / COUNT(*),2) ELSE 0 END PH,
                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), COD_CR_OUT) ) / COUNT(*),2) ELSE 0 END COD_CR_OUT,
                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), BOD5_OUT) ) / COUNT(*),2) ELSE 0 END BOD5_OUT,
                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), NH3N_OUT) ) / COUNT(*),2) ELSE 0 END NH3N_OUT,
                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), SS_OUT) ) / COUNT(*),2) ELSE 0 END SS_OUT,
                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), PH_OUT) ) / COUNT(*),2) ELSE 0 END PH_OUT,
                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), TN_OUT) ) / COUNT(*),2) ELSE 0 END TN_OUT,
                case WHEN(ISNULL(COUNT(*), 0)) != 0 THEN round(SUM( convert(decimal(18, 5), TP_OUT) ) / COUNT(*),2) ELSE 0 END TP_OUT
        from tf_fill_month_w
        WHERE
        1=1
        <if test="startYear != null and endYear != null">
            AND datename(yyyy,RECORD_TIME) between #{startYear} and #{endYear}
        </if>
        <if test="sewageIds != null">
            AND BELONG_STATION_ID in
            <foreach item="item" index="index" collection="sewageIds" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        GROUP BY datename(yyyy,RECORD_TIME), BELONG_STATION_ID
        ORDER BY scada_Time
    </select>

</mapper>
