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

    <resultMap type="cn.cecep.talroad.domain.SupermonitorDrainOutlet" id="SupermonitorDrainOutletResult">
        <result property="id"    column="id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="outletId"    column="outlet_id"    />
        <result property="outletType"    column="outlet_type"    />
        <result property="outletCode"    column="outlet_code"    />
        <result property="outletName"    column="outlet_name"    />
        <result property="approvalDocument"    column="approval_document"    />
        <result property="otherInformation"    column="other_information"    />
        <result property="lon"    column="lon"    />
        <result property="lat"    column="lat"    />
        <result property="drainageTo"    column="drainage_to"    />
        <result property="emissionsLaws"    column="emissions_laws"    />
        <result property="intermittentEmissionPeriod"    column="intermittent_emission_period"    />
        <result property="receivingWaterName"    column="receiving_water_name"    />
        <result property="receivingWaterObjective"    column="receiving_water_objective"    />
        <result property="receivingWaterLon"    column="receiving_water_lon"    />
        <result property="receivingWaterLat"    column="receiving_water_lat"    />
        <result property="riversOutletName"    column="rivers_outlet_name"    />
        <result property="riversOutletCode"    column="rivers_outlet_code"    />
    </resultMap>


    <sql id="selectSupermonitorDrainOutletVo">
        select id, factory_id, outlet_id, outlet_type, outlet_code, outlet_name, approval_document, other_information, lon, lat, drainage_to, emissions_laws, intermittent_emission_period, receiving_water_name, receiving_water_objective, receiving_water_lon, receiving_water_lat,rivers_outlet_name,rivers_outlet_code from m_supermonitor_drain_outlet
    </sql>

    <select id="selectSupermonitorDrainOutletList" parameterType="cn.cecep.talroad.domain.SupermonitorDrainOutlet" resultMap="SupermonitorDrainOutletResult">
        <include refid="selectSupermonitorDrainOutletVo"/>
        <where>
            <if test="factoryId != null  and factoryId != ''"> and factory_id = #{factoryId}</if>
            <if test="outletId != null  and outletId != ''"> and outlet_id = #{outletId}</if>
            <if test="outletType != null  and outletType != ''"> and outlet_type = #{outletType}</if>
            <if test="outletCode != null  and outletCode != ''"> and outlet_code = #{outletCode}</if>
            <if test="outletName != null  and outletName != ''"> and outlet_name like concat('%', #{outletName}, '%')</if>
            <if test="approvalDocument != null  and approvalDocument != ''"> and approval_document = #{approvalDocument}</if>
            <if test="otherInformation != null  and otherInformation != ''"> and other_information = #{otherInformation}</if>
            <if test="lon != null  and lon != ''"> and lon = #{lon}</if>
            <if test="lat != null  and lat != ''"> and lat = #{lat}</if>
            <if test="drainageTo != null  and drainageTo != ''"> and drainage_to = #{drainageTo}</if>
            <if test="emissionsLaws != null  and emissionsLaws != ''"> and emissions_laws = #{emissionsLaws}</if>
            <if test="intermittentEmissionPeriod != null  and intermittentEmissionPeriod != ''"> and intermittent_emission_period = #{intermittentEmissionPeriod}</if>
            <if test="receivingWaterName != null  and receivingWaterName != ''"> and receiving_water_name like concat('%', #{receivingWaterName}, '%')</if>
            <if test="receivingWaterObjective != null  and receivingWaterObjective != ''"> and receiving_water_objective = #{receivingWaterObjective}</if>
            <if test="receivingWaterLon != null  and receivingWaterLon != ''"> and receiving_water_lon = #{receivingWaterLon}</if>
            <if test="receivingWaterLat != null  and receivingWaterLat != ''"> and receiving_water_lat = #{receivingWaterLat}</if>
        </where>
    </select>
    <select id="selectRhPwxkList" resultType="cn.cecep.talroad.vo.SupermonitorDrainOutletVo$PwxkRh">
        SELECT
            t1.poll_dis_license_code,
            t1.factory_name,
            t1.license_man_type,
            t1.country_name,
            t1.river_basin,
            t1.industrial_park_name,
            t1.industrial_park_code,
            t1.industry_permission_name,
            t2.outlet_code,
            t2.outlet_name,
            t2.rivers_outlet_name,
            t2.rivers_outlet_code,
            t2.approval_document,
            t2.other_information
        FROM
            pc_factory t1
            LEFT JOIN m_supermonitor_drain_outlet t2 ON t2.factory_id = t1."id" AND t2.outlet_type = '1'
            <if test="query.riversOutletName != null and query.riversOutletName != ''">
                and t2.rivers_outlet_name like concat('%', #{query.riversOutletName}, '%')
            </if>
            <if test="query.riversOutletCode != null and query.riversOutletCode != ''">
                and t2.rivers_outlet_code like concat('%', #{query.riversOutletCode}, '%')
            </if>
        WHERE t1.id IN
            <foreach collection="factoryIds" open="(" separator="," close=")" item="item">
                #{item}
            </foreach>
        ORDER BY t1.order_num, t1."id", t2.outlet_code, t2.id
    </select>
    <select id="selectYsPwxkList" resultType="cn.cecep.talroad.vo.SupermonitorDrainOutletVo$PwxkYs">
        SELECT
            t1.poll_dis_license_code,
            t1.factory_name,
            t1.license_man_type,
            t1.country_name,
            t1.river_basin,
            t1.industrial_park_name,
            t1.industrial_park_code,
            t1.industry_permission_name,
            t2.outlet_code,
            t2.outlet_name,
            t2.lon,
            t2.lon,
            t2.drainage_to,
            t2.emissions_laws,
            t2.intermittent_emission_period,
            t2.receiving_water_name,
            t2.receiving_water_objective,
            t2.receiving_water_lon,
            t2.receiving_water_lat,
            t2.other_information
        FROM
            pc_factory t1
            LEFT JOIN m_supermonitor_drain_outlet t2 ON t2.factory_id = t1."id" AND t2.outlet_type = '2'
            <if test="query.outletCode != null and query.outletCode != ''">
                and t2.outlet_code like concat('%', #{query.outletCode}, '%')
            </if>
            <if test="query.outletName != null and query.outletName != ''">
                and t2.outlet_name like concat('%', #{query.outletName}, '%')
            </if>
            <if test="query.drainageTo != null and query.drainageTo.size() > 0">
                and t2.drainage_to IN
                <foreach collection="query.drainageTo" open="(" separator="," close=")" item="item">
                    #{item}
                </foreach>
            </if>
            <if test="query.emissionsLaws != null and query.emissionsLaws.size() > 0">
                and t2.emissions_laws IN
                <foreach collection="query.emissionsLaws" open="(" separator="," close=")" item="item">
                    #{item}
                </foreach>
            </if>
            <if test="query.receivingWaterName != null and query.receivingWaterName != ''">
                and t2.receiving_water_name like concat('%', #{query.receivingWaterName}, '%')
            </if>
            <if test="query.receivingWaterObjective != null and query.receivingWaterObjective != ''">
                and t2.receiving_water_objective like concat('%', #{query.receivingWaterObjective}, '%')
            </if>
        WHERE t1.id IN
            <foreach collection="factoryIds" open="(" separator="," close=")" item="item">
                #{item}
            </foreach>
        ORDER BY t1.order_num, t1."id", t2.outlet_code, t2.id
    </select>

</mapper>
