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

    <resultMap type="cn.cecep.talroad.domain.PcControlRequirements" id="PcControlRequirementsResult">
        <result property="id"    column="id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="outletId"    column="outlet_id"    />
        <result property="pollutantId"    column="pollutant_id"    />
        <result property="pollutantStandardName"    column="pollutant_standard_name"    />
        <result property="emissionStandardConcentrationLim"    column="emission_standard_concentration_lim"    />
        <result property="emissionStandardConcentrationUnit"    column="emission_standard_concentration_unit"    />
        <result property="emissionStandardRateLim"    column="emission_standard_rate_lim"    />
        <result property="approvalRequirements"    column="approval_requirements"    />
        <result property="permissibleConcentrationLimHour"    column="permissible_concentration_lim_hour"    />
        <result property="permissibleConcentrationLimDay"    column="permissible_concentration_lim_day"    />
        <result property="permissibleRateLim"    column="permissible_rate_lim"    />
        <result property="permissibleLimFirst"    column="permissible_lim_first"    />
        <result property="permissibleLimSecond"    column="permissible_lim_second"    />
        <result property="permissibleLimThird"    column="permissible_lim_third"    />
        <result property="permissibleLimFourth"    column="permissible_lim_fourth"    />
        <result property="permissibleLimSfifth"    column="permissible_lim_sfifth"    />
        <result property="commitmentEmissionLim"    column="Commitment_emission_lim"    />
        <result property="monitoringFacilities"    column="monitoring_facilities"    />
        <result property="whetherAutoMonitorConn"    column="whether_auto_monitor_conn"    />
        <result property="autoMonitorName"    column="auto_monitor_name"    />
        <result property="autoMonitorAddress"    column="auto_monitor_address"    />
        <result property="whetherAutoMonitorRequire"    column="whether_auto_monitor_require"    />
        <result property="manualMonitorNumber"    column="manual_monitor_number"    />
        <result property="manualMonitorFrequency"    column="manual_monitor_frequency"    />
        <result property="manualMonitorMethod"    column="manual_monitor_method"    />
        <result property="otherInformation"    column="other_information"    />
        <result property="pollutantName"    column="pollutant_name"    />
        <result property="pollutionPreventionMeasures"    column="pollution_prevention_measures"    />
        <result property="commitmentEmissionPromise"    column="commitment_emission_promise"    />
    </resultMap>


    <sql id="selectPcControlRequirementsVo">
        select id, factory_id, outlet_id, pollutant_id, pollutant_standard_name, emission_standard_concentration_lim, emission_standard_concentration_unit, emission_standard_rate_lim, approval_requirements, permissible_concentration_lim_hour, permissible_concentration_lim_day, permissible_rate_lim, permissible_lim_first, permissible_lim_second, permissible_lim_third, permissible_lim_fourth, permissible_lim_sfifth, Commitment_emission_lim, monitoring_facilities, whether_auto_monitor_conn, auto_monitor_name, auto_monitor_address, whether_auto_monitor_require, manual_monitor_number, manual_monitor_frequency, manual_monitor_method, other_information,pollutant_name,pollution_prevention_measures,commitment_emission_promise from pc_control_requirements
    </sql>

    <select id="selectPcControlRequirementsList" parameterType="cn.cecep.talroad.domain.PcControlRequirements" resultMap="PcControlRequirementsResult">
        <include refid="selectPcControlRequirementsVo"/>
        <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="pollutantId != null  and pollutantId != ''"> and pollutant_id = #{pollutantId}</if>
            <if test="pollutantStandardName != null  and pollutantStandardName != ''"> and pollutant_standard_name like concat('%', #{pollutantStandardName}, '%')</if>
            <if test="emissionStandardConcentrationLim != null  and emissionStandardConcentrationLim != ''"> and emission_standard_concentration_lim = #{emissionStandardConcentrationLim}</if>
            <if test="emissionStandardConcentrationUnit != null  and emissionStandardConcentrationUnit != ''"> and emission_standard_concentration_unit = #{emissionStandardConcentrationUnit}</if>
            <if test="emissionStandardRateLim != null  and emissionStandardRateLim != ''"> and emission_standard_rate_lim = #{emissionStandardRateLim}</if>
            <if test="approvalRequirements != null  and approvalRequirements != ''"> and approval_requirements = #{approvalRequirements}</if>
            <if test="permissibleConcentrationLimHour != null  and permissibleConcentrationLimHour != ''"> and permissible_concentration_lim_hour = #{permissibleConcentrationLimHour}</if>
            <if test="permissibleConcentrationLimDay != null  and permissibleConcentrationLimDay != ''"> and permissible_concentration_lim_day = #{permissibleConcentrationLimDay}</if>
            <if test="permissibleRateLim != null  and permissibleRateLim != ''"> and permissible_rate_lim = #{permissibleRateLim}</if>
            <if test="permissibleLimFirst != null  and permissibleLimFirst != ''"> and permissible_lim_first = #{permissibleLimFirst}</if>
            <if test="permissibleLimSecond != null  and permissibleLimSecond != ''"> and permissible_lim_second = #{permissibleLimSecond}</if>
            <if test="permissibleLimThird != null  and permissibleLimThird != ''"> and permissible_lim_third = #{permissibleLimThird}</if>
            <if test="permissibleLimFourth != null  and permissibleLimFourth != ''"> and permissible_lim_fourth = #{permissibleLimFourth}</if>
            <if test="permissibleLimSfifth != null  and permissibleLimSfifth != ''"> and permissible_lim_sfifth = #{permissibleLimSfifth}</if>
            <if test="commitmentEmissionLim != null  and commitmentEmissionLim != ''"> and Commitment_emission_lim = #{commitmentEmissionLim}</if>
            <if test="monitoringFacilities != null  and monitoringFacilities != ''"> and monitoring_facilities = #{monitoringFacilities}</if>
            <if test="whetherAutoMonitorConn != null  and whetherAutoMonitorConn != ''"> and whether_auto_monitor_conn = #{whetherAutoMonitorConn}</if>
            <if test="autoMonitorName != null  and autoMonitorName != ''"> and auto_monitor_name like concat('%', #{autoMonitorName}, '%')</if>
            <if test="autoMonitorAddress != null  and autoMonitorAddress != ''"> and auto_monitor_address = #{autoMonitorAddress}</if>
            <if test="whetherAutoMonitorRequire != null  and whetherAutoMonitorRequire != ''"> and whether_auto_monitor_require = #{whetherAutoMonitorRequire}</if>
            <if test="manualMonitorNumber != null  and manualMonitorNumber != ''"> and manual_monitor_number = #{manualMonitorNumber}</if>
            <if test="manual monitorFrequency != null  and manual monitorFrequency != ''"> and manual monitor_frequency = #{manual monitorFrequency}</if>
            <if test="manual monitorMethod != null  and manual monitorMethod != ''"> and manual monitor_method = #{manual monitorMethod}</if>
            <if test="otherInformation != null  and otherInformation != ''"> and other_information = #{otherInformation}</if>
        </where>
    </select>

    <select id="selectLabelRequirements" resultType="cn.cecep.talroad.vo.PcControlRequirementsVo">
        SELECT
            factory_id,
            bmapa.pollutant_id,
            pp.poll_name as pollutantName,
            commitment_emission_lim
        FROM
            pc_control_requirements bmapa
                LEFT JOIN pc_pollutant pp ON pp.ID = bmapa.pollutant_id
    </select>
    <select id="selectLabelOnlineRequirements" resultType="cn.cecep.talroad.vo.PcControlRequirementsVo">
        SELECT
            con.factory_id,
            con.pollutant_id,
            con.outlet_id
        FROM
            pc_outlet AS po
                LEFT JOIN pc_control_requirements AS con ON con.outlet_id = po.ID
        WHERE
            con.monitoring_facilities = '自动'
          AND po.pollutant_type != '4' AND po.pollutant_type != '3'
    </select>
    <select id="selectLabelOnlineOutPoll" resultType="cn.cecep.talroad.vo.PcControlRequirementsVo">
        SELECT
            fpo.outlet_id,
            fpo.pollutant_id ,
            po.parent_outlet_id as id
        FROM
            pc_outlet AS po
                LEFT JOIN pc_factory_pollutant AS fpo ON fpo.outlet_id = po.ID
        WHERE
            po.pollutant_type ='4' and po.parent_outlet_id is not null
    </select>
    <select id="selectPwxkGasOrg" resultType="cn.cecep.talroad.vo.PcControlRequirementsVo$PwxkGasOrg">
        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.outlet_types,
            t2.outlet_lat,
            t2.outlet_lon,
            t2.exhaust_funnel_hight,
            t2.exhaust_funnel_inner,
            t2.exhaust_gas_temperature,
            t3.pollutant_name,
            t3.pollutant_standard_name,
            t3.emission_standard_concentration_lim,
            t3.emission_standard_concentration_unit,
            t3.emission_standard_rate_lim,
            t3.approval_requirements,
            t3.permissible_concentration_lim_hour,
            t3.permissible_concentration_lim_day,
            t3.permissible_rate_lim,
            t3.permissible_lim_first,
            t3.permissible_lim_second,
            t3.permissible_lim_third,
            t3.permissible_lim_fourth,
            t3.permissible_lim_sfifth,
            t3.commitment_emission_lim,
            t3.monitoring_facilities,
            t3.whether_auto_monitor_conn,
            t3.auto_monitor_name,
            t3.auto_monitor_address,
            t3.whether_auto_monitor_require,
            t3.manual_monitor_number,
            t3.manual_monitor_frequency,
            t3.manual_monitor_method,
            t3.other_information
        FROM
            pc_factory t1
        LEFT JOIN pc_outlet t2 ON t2.factory_id = t1."id"
            AND t2.pollutant_type = '1'
            AND t2.pollutant_outlet_type = '1'
            <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.outletTypes != null and query.outletTypes != ''">
                AND t2.outlet_types = #{query.outletTypes}
            </if>
        LEFT JOIN pc_control_requirements t3 ON t3.outlet_id = t2.id
            <if test="query.pollutantStandardName != null and query.pollutantStandardName != ''">
                AND t3.pollutant_standard_name LIKE concat('%', #{query.pollutantStandardName}, '%')
            </if>
            <if test="query.pollutantNames != null and query.pollutantNames.size() > 0">
                AND t3.pollutant_name IN
                <foreach collection="query.pollutantNames" open="(" separator="," close=")" item="item">
                    #{item}
                </foreach>
            </if>
            <if test="query.monitoringFacilities != null and query.monitoringFacilities != ''">
                AND t3.monitoring_facilities = #{query.monitoringFacilities}
            </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", t3.pollutant_id, t3.id
    </select>
    <select id="selectPwxkGasNoOrg" resultType="cn.cecep.talroad.vo.PcControlRequirementsVo$PwxkGasNoOrg">
        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.production_process,
            t3.pollutant_name,
            t2.pollution_prevention_measures,
            t3.pollutant_standard_name,
            t3.permissible_concentration_lim_hour,
            t3.permissible_concentration_lim_day,
            t3.emission_standard_concentration_unit,
            t3.permissible_lim_first,
            t3.permissible_lim_second,
            t3.permissible_lim_third,
            t3.permissible_lim_fourth,
            t3.permissible_lim_sfifth,
            t3.commitment_emission_promise,
            t3.monitoring_facilities,
            t3.whether_auto_monitor_conn,
            t3.auto_monitor_name,
            t3.auto_monitor_address,
            t3.whether_auto_monitor_require,
            t3.manual_monitor_number,
            t3.manual_monitor_frequency,
            t3.manual_monitor_method,
            t3.other_information
        FROM
            pc_factory t1
        LEFT JOIN pc_outlet t2 ON t2.factory_id = t1."id"
            AND t2.pollutant_type = '1'
            AND t2.pollutant_outlet_type = '2'
            <if test="query.outletCode != null and query.outletCode != ''">
                AND t2.outlet_code LIKE concat('%', #{query.outletCode}, '%')
            </if>
        LEFT JOIN pc_control_requirements t3 ON t3.outlet_id = t2.id
            <if test="query.pollutantStandardName != null and query.pollutantStandardName != ''">
                AND t3.pollutant_standard_name LIKE concat('%', #{query.pollutantStandardName}, '%')
            </if>
            <if test="query.pollutantNames != null and query.pollutantNames.size() > 0">
                AND t3.pollutant_name IN
                <foreach collection="query.pollutantNames" open="(" separator="," close=")" item="item">
                    #{item}
                </foreach>
            </if>
            <if test="query.monitoringFacilities != null and query.monitoringFacilities != ''">
                AND t3.monitoring_facilities = #{query.monitoringFacilities}
            </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", t3.pollutant_id, t3.id
    </select>
    <select id="selectPwxkWaterDirect"
            resultType="cn.cecep.talroad.vo.PcControlRequirementsVo$PwxkWaterDirect">
        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.outlet_types,
            t2.outlet_lat,
            t2.outlet_lon,
            t2.direction_drainage,
            t2.discharge_law,
            t2.intermittent_emission_period,
            t2.receiving_water_name,
            t2.receiving_water_objective,
            t2.receiving_water_lon,
            t2.receiving_water_lat,

            t3.pollutant_name,
            t3.pollutant_standard_name,
            t3.emission_standard_concentration_lim,
            t3.approval_requirements,
            t3.commitment_emission_lim,
            t3.permissible_concentration_lim_water,
            t3.emission_standard_concentration_unit,
            t3.permissible_lim_first,
            t3.permissible_lim_second,
            t3.permissible_lim_third,
            t3.permissible_lim_fourth,
            t3.permissible_lim_sfifth,
            t3.commitment_emission_promise,
            t3.monitoring_facilities,
            t3.whether_auto_monitor_conn,
            t3.auto_monitor_name,
            t3.auto_monitor_address,
            t3.whether_auto_monitor_require,
            t3.manual_monitor_number,
            t3.manual_monitor_frequency,
            t3.manual_monitor_method,
            t3.other_information
        FROM
            pc_factory t1
        LEFT JOIN pc_outlet t2 ON t2.factory_id = t1."id"
            AND t2.pollutant_type = '2'
            AND t2.emissions_form = '直接排放'
            <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.outletTypes != null and query.outletTypes != ''">
                and t2.outlet_types = #{query.outletTypes}
            </if>
            <if test="query.directionDrainage != null and query.directionDrainage.size() > 0">
                and t2.direction_drainage IN
                <foreach collection="query.directionDrainage" open="(" separator="," close=")" item="item">
                    #{item}
                </foreach>
            </if>
            <if test="query.dischargeLaw != null and query.dischargeLaw.size() > 0">
                and t2.discharge_law IN
                <foreach collection="query.dischargeLaw" 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>
        LEFT JOIN pc_control_requirements t3 ON t3.outlet_id = t2.id
            <if test="query.pollutantStandardName != null and query.pollutantStandardName != ''">
                AND t3.pollutant_standard_name LIKE concat('%', #{query.pollutantStandardName}, '%')
            </if>
            <if test="query.pollutantNames != null and query.pollutantNames.size() > 0">
                AND t3.pollutant_name IN
                <foreach collection="query.pollutantNames" open="(" separator="," close=")" item="item">
                    #{item}
                </foreach>
            </if>
            <if test="query.monitoringFacilities != null and query.monitoringFacilities != ''">
                AND t3.monitoring_facilities = #{query.monitoringFacilities}
            </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", t3.pollutant_id, t3.id
    </select>
    <select id="selectPwxkWaterIndirect"
            resultType="cn.cecep.talroad.vo.PcControlRequirementsVo$PwxkWaterIndirect">
        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.outlet_types,
            t2.outlet_lat,
            t2.outlet_lon,
            t2.direction_drainage,
            t2.discharge_law,
            t2.intermittent_emission_period,
            t2.treatment_plant_accepted_name,

            t3.pollutant_name,
            t3.pollutant_standard_name,
            t3.emission_standard_concentration_lim,
            t3.approval_requirements,
            t3.commitment_emission_lim,
            t3.permissible_concentration_lim_water,
            t3.emission_standard_concentration_unit,
            t3.permissible_lim_first,
            t3.permissible_lim_second,
            t3.permissible_lim_third,
            t3.permissible_lim_fourth,
            t3.permissible_lim_sfifth,
            t3.commitment_emission_promise,
            t3.monitoring_facilities,
            t3.whether_auto_monitor_conn,
            t3.auto_monitor_name,
            t3.auto_monitor_address,
            t3.whether_auto_monitor_require,
            t3.manual_monitor_number,
            t3.manual_monitor_frequency,
            t3.manual_monitor_method,
            t3.other_information
        FROM
            pc_factory t1
        LEFT JOIN pc_outlet t2 ON t2.factory_id = t1."id"
            AND t2.pollutant_type = '2'
            AND t2.emissions_form = '间接排放'
            <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.outletTypes != null and query.outletTypes != ''">
                and t2.outlet_types = #{query.outletTypes}
            </if>
            <if test="query.directionDrainage != null and query.directionDrainage.size() > 0">
                and t2.direction_drainage IN
                <foreach collection="query.directionDrainage" open="(" separator="," close=")" item="item">
                    #{item}
                </foreach>
            </if>
            <if test="query.dischargeLaw != null and query.dischargeLaw.size() > 0">
                and t2.discharge_law IN
                <foreach collection="query.dischargeLaw" open="(" separator="," close=")" item="item">
                    #{item}
                </foreach>
            </if>
            <if test="query.treatmentPlantAcceptedName != null and query.treatmentPlantAcceptedName != ''">
                and t2.treatment_plant_accepted_name like concat('%', #{query.treatmentPlantAcceptedName}, '%')
            </if>
        LEFT JOIN pc_control_requirements t3 ON t3.outlet_id = t2.id
            <if test="query.pollutantStandardName != null and query.pollutantStandardName != ''">
                AND t3.pollutant_standard_name LIKE concat('%', #{query.pollutantStandardName}, '%')
            </if>
            <if test="query.pollutantNames != null and query.pollutantNames.size() > 0">
                AND t3.pollutant_name IN
                <foreach collection="query.pollutantNames" open="(" separator="," close=")" item="item">
                    #{item}
                </foreach>
            </if>
            <if test="query.monitoringFacilities != null and query.monitoringFacilities != ''">
                AND t3.monitoring_facilities = #{query.monitoringFacilities}
            </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", t3.pollutant_id, t3.id
    </select>
</mapper>
