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

    <resultMap type="cn.cecep.talroad.domain.BStatTableZxbgPflWater" id="BStatTableZxbgPflWaterResult">
        <result property="id"    column="id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="zxbgType"    column="zxbg_type"    />
        <result property="zxbgPeriod"    column="zxbg_period"    />
        <result property="zxbgOutletCode"    column="zxbg_outlet_code"    />
        <result property="zxbgOutletName"    column="zxbg_outlet_name"    />
        <result property="zxbgPollutant"    column="zxbg_pollutant"    />
        <result property="zxbgDischargeYear"    column="zxbg_discharge_year"    />
        <result property="zxbgDischargeActual"    column="zxbg_discharge_actual"    />
        <result property="createTime"    column="create_time"    />
        <result property="isDelete"    column="is_delete"    />
        <result property="zxbgOutletId"    column="zxbg_outlet_id"    />
        <result property="zxbgEmissionType"    column="zxbg_emission_type"    />
    </resultMap>


    <sql id="selectBStatTableZxbgPflWaterVo">
        select id, factory_id, zxbg_type, zxbg_period, zxbg_outlet_code, zxbg_outlet_name, zxbg_pollutant, zxbg_discharge_year, zxbg_discharge_actual, create_time, is_delete, zxbg_outlet_id, zxbg_emission_type from b_stat_table_zxbg_pfl_water
    </sql>

    <select id="selectBStatTableZxbgPflWaterList" parameterType="cn.cecep.talroad.domain.BStatTableZxbgPflWater" resultMap="BStatTableZxbgPflWaterResult">
        <include refid="selectBStatTableZxbgPflWaterVo"/>
        <where>
            <if test="factoryId != null  and factoryId != ''"> and factory_id = #{factoryId}</if>
            <if test="zxbgType != null  and zxbgType != ''"> and zxbg_type = #{zxbgType}</if>
            <if test="zxbgPeriod != null  and zxbgPeriod != ''"> and zxbg_period = #{zxbgPeriod}</if>
            <if test="zxbgOutletCode != null  and zxbgOutletCode != ''"> and zxbg_outlet_code = #{zxbgOutletCode}</if>
            <if test="zxbgOutletName != null  and zxbgOutletName != ''"> and zxbg_outlet_name like concat('%', #{zxbgOutletName}, '%')</if>
            <if test="zxbgPollutant != null  and zxbgPollutant != ''"> and zxbg_pollutant = #{zxbgPollutant}</if>
            <if test="zxbgDischargeYear != null  and zxbgDischargeYear != ''"> and zxbg_discharge_year = #{zxbgDischargeYear}</if>
            <if test="zxbgDischargeActual != null  and zxbgDischargeActual != ''"> and zxbg_discharge_actual = #{zxbgDischargeActual}</if>
            <if test="isDelete != null  and isDelete != ''"> and is_delete = #{isDelete}</if>
            <if test="zxbgOutletId != null  and zxbgOutletId != ''"> and zxbg_outlet_id = #{zxbgOutletId}</if>
            <if test="zxbgEmissionType != null  and zxbgEmissionType != ''"> and zxbg_emission_type = #{zxbgEmissionType}</if>
        </where>
    </select>

    <select id="selectListAndFactory" resultType="cn.cecep.talroad.domain.BStatTableZxbgPflWater">
        SELECT
        zxbg.*,
        pf.factory_name,
        pf.country_name,
        pf.license_man_type,
        pf.poll_dis_license_code,
        pf.industrial_park_name,
        pf.industrial_park_code,
        pf.industry_permission_name,
        pf.river_basin
        FROM
        (select * from b_stat_table_zxbg_pfl_water
        <where>
            <if test="zxbgPollutant != null  and zxbgPollutant != ''"> and zxbg_pollutant like concat('%', #{zxbgPollutant}, '%')</if>
            <if test="zxbgEmissionType != null  and zxbgEmissionType != ''"> and zxbg_emission_type = #{zxbgEmissionType}</if>
            <if test="zxbgType != null  and zxbgType != ''"> and zxbg_type = #{zxbgType}</if>
            <if test="zxbgPeriod != null  and zxbgPeriod != ''"> and zxbg_period  like concat('%', #{zxbgPeriod}, '%')</if>
        </where>
        ) zxbg
        right JOIN pc_factory pf ON pf.ID = zxbg.factory_id
        <where>
            <if test="factoryIdList != null and factoryIdList.size() != 0">
                and pf.id
                <foreach collection="factoryIdList" close=")" open=" IN (" separator="," item="item">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
        </where>
        ORDER BY pf.order_num, pf.id
    </select>
</mapper>
