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

    <resultMap type="cn.cecep.talroad.domain.BMainHazardousSolidWaste" id="BMainHazardousSolidWasteResult">
        <result property="id"    column="id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="solidWasteType"    column="solid_waste_type"    />
        <result property="solidWasteName"    column="solid_waste_name"    />
        <result property="solidWasteCode"    column="solid_waste_code"    />
        <result property="hazardousCharacteristics"    column="hazardous_characteristics"    />
        <result property="category"    column="category"    />
        <result property="physicalCharacteristics"    column="physical_characteristics"    />
        <result property="productionLink"    column="production_link"    />
        <result property="whereAbouts"    column="where_abouts"    />
        <result property="remark"    column="remark"    />
    </resultMap>


    <sql id="selectBMainHazardousSolidWasteVo">
        select id, factory_id, solid_waste_type, solid_waste_name, solid_waste_code, hazardous_characteristics, category, physical_characteristics, production_link, where_abouts, remark from b_main_hazardous_solid_waste
    </sql>

    <select id="selectBMainHazardousSolidWasteList" parameterType="cn.cecep.talroad.domain.BMainHazardousSolidWaste" resultMap="BMainHazardousSolidWasteResult">
        <include refid="selectBMainHazardousSolidWasteVo"/>
        <where>
            <if test="factoryId != null  and factoryId != ''"> and factory_id = #{factoryId}</if>
            <if test="solidWasteType != null  and solidWasteType != ''"> and solid_waste_type = #{solidWasteType}</if>
            <if test="solidWasteName != null  and solidWasteName != ''"> and solid_waste_name like concat('%', #{solidWasteName}, '%')</if>
            <if test="solidWasteCode != null  and solidWasteCode != ''"> and solid_waste_code = #{solidWasteCode}</if>
            <if test="hazardousCharacteristics != null  and hazardousCharacteristics != ''"> and hazardous_characteristics = #{hazardousCharacteristics}</if>
            <if test="category != null  and category != ''"> and category = #{category}</if>
            <if test="physicalCharacteristics != null  and physicalCharacteristics != ''"> and physical_characteristics = #{physicalCharacteristics}</if>
            <if test="productionLink != null  and productionLink != ''"> and production_link = #{productionLink}</if>
            <if test="whereAbouts != null  and whereAbouts != ''"> and where_abouts = #{whereAbouts}</if>
        </where>
    </select>

    <select id="selectListAndFactory" resultType="cn.cecep.talroad.vo.BMainHazardousSolidWasteVo">
        SELECT
        bmhsw.*,
        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_hazardous_solid_waste bmhsw
        Right JOIN pc_factory pf ON pf.ID = bmhsw.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>
