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

    <resultMap type="cn.cecep.talroad.domain.BMainPollDisWaterOout" id="BMainPollDisWaterOoutResult">
        <result property="ooutId"    column="oout_id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="pollDisId"    column="poll_dis_id"    />
        <result property="pollutantsType"    column="pollutants_type"    />
        <result property="pollutantsTotalFrist"    column="pollutants_total_frist"    />
        <result property="pollutantsTotalSecond"    column="pollutants_total_second"    />
        <result property="pollutantsTotalThird"    column="pollutants_total_third"    />
        <result property="pollutantsTotalFourth"    column="pollutants_total_fourth"    />
        <result property="pollutantsTotalFifth"    column="pollutants_total_fifth"    />
        <result property="outletCode"    column="outlet_code"    />
        <result property="outletName"    column="outlet_name"    />
        <result property="outletUseTotal"    column="outlet_use_total"    />
        <result property="pollutantsMgRate"    column="pollutants_mg_rate"    />
    </resultMap>


    <sql id="selectBMainPollDisWaterOoutVo">
        select oout_id, factory_id, poll_dis_id, pollutants_type, pollutants_total_frist, pollutants_total_second, pollutants_total_third, pollutants_total_fourth, pollutants_total_fifth, outlet_code, outlet_name, outlet_use_total, pollutants_mg_rate from b_main_poll_dis_water_oout
    </sql>

    <select id="selectBMainPollDisWaterOoutList" parameterType="cn.cecep.talroad.domain.BMainPollDisWaterOout" resultMap="BMainPollDisWaterOoutResult">
        <include refid="selectBMainPollDisWaterOoutVo"/>
        <where>
            <if test="factoryId != null  and factoryId != ''"> and factory_id = #{factoryId}</if>
            <if test="pollDisId != null  and pollDisId != ''"> and poll_dis_id = #{pollDisId}</if>
            <if test="pollutantsType != null  and pollutantsType != ''"> and pollutants_type = #{pollutantsType}</if>
            <if test="pollutantsTotalFrist != null  and pollutantsTotalFrist != ''"> and pollutants_total_frist = #{pollutantsTotalFrist}</if>
            <if test="pollutantsTotalSecond != null  and pollutantsTotalSecond != ''"> and pollutants_total_second = #{pollutantsTotalSecond}</if>
            <if test="pollutantsTotalThird != null  and pollutantsTotalThird != ''"> and pollutants_total_third = #{pollutantsTotalThird}</if>
            <if test="pollutantsTotalFourth != null  and pollutantsTotalFourth != ''"> and pollutants_total_fourth = #{pollutantsTotalFourth}</if>
            <if test="pollutantsTotalFifth != null  and pollutantsTotalFifth != ''"> and pollutants_total_fifth = #{pollutantsTotalFifth}</if>
            <if test="outletCode != null  and outletCode != ''"> and outlet_code = #{outletCode}</if>
            <if test="outletName != null  and outletName != ''"> and outlet_name like concat('%', #{outletName}, '%')</if>
            <if test="outletUseTotal != null  and outletUseTotal != ''"> and outlet_use_total = #{outletUseTotal}</if>
            <if test="pollutantsMgRate != null  and pollutantsMgRate != ''"> and pollutants_mg_rate = #{pollutantsMgRate}</if>
        </where>
    </select>
    <select id="selectPollutantGroupList" resultType="cn.cecep.talroad.vo.analysis.PollDisPollutantGroupVO">
        SELECT round (avg(cast (substr (pollutants_mg_rate, position ( '-' IN pollutants_mg_rate )) as DECIMAL)), 2 ) AS pollutants_mg_rate,
               pollutants_type
        FROM
            b_main_poll_dis_water_oout
        WHERE
            pollutants_mg_rate != '/'
          and factory_id = #{factoryId}
          AND poll_dis_id = #{licenseId}
          AND outlet_code = #{outletCode}

        GROUP BY
            pollutants_type
    </select>

</mapper>
