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

    <resultMap type="cn.cecep.talroad.domain.BMainAllowablePollutionWater" id="BMainAllowablePollutionWaterResult">
        <result property="id"    column="id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="pollDisId"    column="poll_dis_id"    />
        <result property="pollutionCategory"    column="pollution_category"    />
        <result property="applyFrist"    column="apply_frist"    />
        <result property="applySecond"    column="apply_second"    />
        <result property="applyThird"    column="apply_third"    />
        <result property="applyFourth"    column="apply_fourth"    />
        <result property="applyFifth"    column="apply_fifth"    />
        <result property="applyDischargeLimitingValue"    column="apply_discharge_limiting_value"    />
        <result property="pollName"    column="poll_name"    />
    </resultMap>


    <sql id="selectBMainAllowablePollutionWaterVo">
        select bmapw.id, factory_id, poll_dis_id, pollution_category, apply_frist, apply_second, apply_third, apply_fourth, apply_fifth, apply_discharge_limiting_value, pp.poll_name from b_main_allowable_pollution_water bmapw
    </sql>

    <select id="selectBMainAllowablePollutionWaterList" parameterType="cn.cecep.talroad.domain.BMainAllowablePollutionWater" resultMap="BMainAllowablePollutionWaterResult">
        <include refid="selectBMainAllowablePollutionWaterVo"/>
        <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="pollutionCategory != null  and pollutionCategory != ''"> and pollution_category = #{pollutionCategory}</if>
            <if test="applyFrist != null  and applyFrist != ''"> and apply_frist = #{applyFrist}</if>
            <if test="applySecond != null  and applySecond != ''"> and apply_second = #{applySecond}</if>
            <if test="applyThird != null  and applyThird != ''"> and apply_third = #{applyThird}</if>
            <if test="applyFourth != null  and applyFourth != ''"> and apply_fourth = #{applyFourth}</if>
            <if test="applyFifth != null  and applyFifth != ''"> and apply_fifth = #{applyFifth}</if>
            <if test="applyDischargeLimitingValue != null  and applyDischargeLimitingValue != ''"> and apply_discharge_limiting_value = #{applyDischargeLimitingValue}</if>
        </where>
    </select>

    <select id="selectLabelWater" resultType="cn.cecep.talroad.domain.BMainAllowablePollutionAir">
        SELECT
            bmapa.ID,
            factory_id,
            pollution_category,
            pp.poll_name,
            apply_frist as totalFrist
        FROM
            b_main_allowable_pollution_water bmapa
                LEFT JOIN pc_pollutant pp ON pp.ID = bmapa.pollution_category
    </select>

    <select id="selectBMainAllowablePollutionWaterPageList" resultMap="BMainAllowablePollutionWaterResult">
        <include refid="selectBMainAllowablePollutionWaterVo" />
        LEFT JOIN pc_pollutant pp ON bmapw.pollution_category = pp.poll_code
        ${ew.customSqlSegment}
    </select>
</mapper>
