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

    <resultMap type="cn.cecep.talroad.domain.BMainPollDisEmlRecord" id="BMainPollDisEmlRecordResult">
        <result property="emlId"    column="eml_id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="pollDisId"    column="poll_dis_id"    />
        <result property="othersInformation"    column="others_information"    />
        <result property="mainContent"    column="main_content"    />
        <result property="reportingFrequency"    column="reporting_frequency"    />
    </resultMap>


    <sql id="selectBMainPollDisEmlRecordVo">
        select eml_id, factory_id, poll_dis_id, others_information, main_content, reporting_frequency from b_main_poll_dis_eml_record
    </sql>

    <select id="selectBMainPollDisEmlRecordList" parameterType="cn.cecep.talroad.domain.BMainPollDisEmlRecord" resultMap="BMainPollDisEmlRecordResult">
        <include refid="selectBMainPollDisEmlRecordVo"/>
        <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="othersInformation != null  and othersInformation != ''"> and others_information = #{othersInformation}</if>
            <if test="mainContent != null  and mainContent != ''"> and main_content = #{mainContent}</if>
            <if test="reportingFrequency != null  and reportingFrequency != ''"> and reporting_frequency = #{reportingFrequency}</if>
        </where>
    </select>

    <select id="selectListAndFactory" resultType="cn.cecep.talroad.vo.BMainPollDisEmlRecordVo">
        SELECT
        bmpder.*,
        pf.factory_name,
        pf.city_code,
        pf.city_name,
        pf.country_code,
        pf.country_name,
        pf.license_man_type,
        pf.poll_dis_license_code,
        pf.usc_code,
        pf.ins_fram_code,
        pf.whether_local_park,
        pf.industrial_park_name,
        pf.industrial_park_code,
        pf.industry_permission_name,
        pf.river_basin
        FROM
        b_main_poll_dis_eml_record bmpder
        Right JOIN pc_factory pf ON pf.ID = bmpder.factory_id
        <where>
            <if test="collection != null and collection.size() != 0">
                pf.id
                <foreach collection="collection" close=")" open=" IN (" separator="," item="item">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
        </where>
        ORDER BY pf.order_num, pf.id
    </select>
</mapper>
