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

    <resultMap type="cn.cecep.talroad.domain.BMainHazardousSolidWasteFa" id="BMainHazardousSolidWasteFaResult">
        <result property="id"    column="id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="solidWasteType"    column="solid_waste_type"    />
        <result property="facilityName"    column="facility_name"    />
        <result property="facilityCode"    column="facility_code"    />
        <result property="facilityType"    column="facility_type"    />
        <result property="lon"    column="lon"    />
        <result property="lat"    column="lat"    />
        <result property="polluteTechnicalRequirements"    column="pollute_technical_requirements"    />
    </resultMap>


    <sql id="selectBMainHazardousSolidWasteFaVo">
        select id, factory_id, solid_waste_type, facility_name, facility_code, facility_type, lon, lat, pollute_technical_requirements from b_main_hazardous_solid_waste_fa
    </sql>

    <select id="selectBMainHazardousSolidWasteFaList" parameterType="cn.cecep.talroad.domain.BMainHazardousSolidWasteFa" resultMap="BMainHazardousSolidWasteFaResult">
        <include refid="selectBMainHazardousSolidWasteFaVo"/>
        <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="facilityName != null  and facilityName != ''"> and facility_name like concat('%', #{facilityName}, '%')</if>
            <if test="facilityCode != null  and facilityCode != ''"> and facility_code = #{facilityCode}</if>
            <if test="facilityType != null  and facilityType != ''"> and facility_type = #{facilityType}</if>
            <if test="lon != null  and lon != ''"> and lon = #{lon}</if>
            <if test="lat != null  and lat != ''"> and lat = #{lat}</if>
            <if test="polluteTechnicalRequirements != null  and polluteTechnicalRequirements != ''"> and pollute_technical_requirements = #{polluteTechnicalRequirements}</if>
        </where>
    </select>

    <select id="selectListAndFactory" resultType="cn.cecep.talroad.vo.BMainHazardousSolidWasteFaVo">
        SELECT
        bmhswf.*,
        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
        pc_factory pf
        LEFT JOIN  b_main_hazardous_solid_waste_fa bmhswfON pf.ID = bmhswf.factory_id
        <if test="solidWasteType != null and solidWasteType != ''">
            AND bmhswf.solid_waste_type LIKE concat('%',#{solidWasteType,jdbcType=VARCHAR},'%')
        </if>
        <where>
            <if test="factoryIdList != null and factoryIdList.size() != 0">
                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>
