<?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="cn.cecep.talroad.mapper.analysis.SRaOverRateWaterMapper">

    <resultMap id="BasResultMap" type="cn.cecep.talroad.domain.analysis.SRaOverRateWater">
        <id property="id" column="id"/>
        <result property="factoryId" column="factory_id"/>
        <result property="pointName" column="point_name"/>
        <result property="outletCode" column="outlet_code"/>
        <result property="validDataCount" column="valid_data_count"/>
        <result property="tnOverCount" column="tn_over_count"/>
        <result property="tnOverRate" column="tn_over_rate"/>
        <result property="tpOverCount" column="tp_over_count"/>
        <result property="tpOverRate" column="tp_over_rate"/>
        <result property="codOverCount" column="cod_over_count"/>
        <result property="codOverRate" column="cod_over_rate"/>
        <result property="nh3OverCount" column="nh3_over_count"/>
        <result property="nh3OverRate" column="nh3_over_rate"/>

        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="statisticsTime" column="statistics_time"/>
        <result property="statisticsType" column="statistics_type"/>

    </resultMap>

    <select id="selectOverRateWaterPage" resultType="cn.cecep.talroad.vo.analysis.SRaOverRateWaterVo">
        select
           t1.factory_id,
           t2.factory_name,
           t2.country_Name,
           t4.arguments_name,
           t1.point_name,
           t1.outlet_code,
           t1.valid_data_count,
           t1.cod_over_count,
           t1.cod_over_rate,
           t1.nh3_over_count,
           t1.nh3_over_rate,
           t1.tp_over_count,
           t1.tp_over_rate,
           t1.tn_over_count,
           t1.tn_over_rate,
           t1.statistics_type,
           t1.statistics_time
        from s_ra_over_rate_water t1
        LEFT JOIN pc_factory t2 ON t1.factory_id = t2.id
        left join (
            select
            plf.factory_id, plv.arguments_code, plv.arguments_name
            from pc_label_factory plf
            left join pc_label_value plv on plf.label_id = plv.label_id and plf.label_value = plv.arguments_code
            where plf.label_id = '4'
        ) t4 on t1.factory_id = t4.factory_id
        <where>
            <if test="query.factoryName != null and query.factoryName != ''">
                AND t2.factory_name LIKE CONCAT('%', #{query.factoryName}, '%')
            </if>
            <if test="query.industryCode != null and query.industryCode != ''">
                AND t4.arguments_code = #{query.industryCode}
            </if>
            <if test="query.regionCode != null and query.regionCode != ''">
                AND t2.country_code = #{query.regionCode}
            </if>
            <if test="query.regionCodeList != null and query.regionCodeList.size() > 0">
                AND t2.country_code IN
                <foreach collection="query.regionCodeList" open="(" separator="," close=")" item="item">
                    #{item}
                </foreach>
            </if>
            <if test="query.pointName != null and query.pointName != ''">
                AND t1.point_name LIKE CONCAT('%', #{query.pointName}, '%')
            </if>
            <if test="query.statisticsType != null and query.statisticsType != ''">
                AND t1.statistics_type = #{query.statisticsType}
            </if>
            <if test="query.statisticsTimeStart != null and query.statisticsTimeStart != ''">
                AND t1.statistics_time >= #{query.statisticsTimeStart}
            </if>
            <if test="query.statisticsTimeEnd != null and query.statisticsTimeEnd != ''">
                AND t1.statistics_time &lt;= #{query.statisticsTimeEnd}
            </if>
        </where>
        ORDER BY t1.statistics_time DESC, t1.id
    </select>
    <select id="selectWaterDataByMonth"
        resultType="cn.cecep.talroad.domain.analysis.SRaOverRateWater">


    </select>

</mapper>
