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

    <resultMap type="cn.cecep.talroad.domain.PcOutlet" id="PcOutletResult">
        <result property="id"    column="id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="pollutantType"    column="pollutant_type"    />
        <result property="pollutantOutletType"    column="pollutant_outlet_type"    />
        <result property="emissionsForm"    column="emissions_form"    />
        <result property="whetherOutletRequirements"    column="whether_outlet_requirements"    />
        <result property="productionProcess"    column="production_process"    />
        <result property="outletTypes"    column="outlet_types"    />
        <result property="monitoringPointName"    column="monitoring_point_name"    />
        <result property="manageFacilitiesCode"    column="manage_facilities_code"    />
        <result property="manageFacilitiesName"    column="manage_facilities_name"    />
        <result property="productionFacilitiesCode"    column="production_facilities_code"    />
        <result property="productionFacilitiesName"    column="production_facilities_name"    />
        <result property="outletLon"    column="outlet_lon"    />
        <result property="outletLat"    column="outlet_lat"    />
        <result property="exhaustFunnelHight"    column="exhaust_funnel_hight"    />
        <result property="exhaustFunnelInner"    column="exhaust_funnel_inner"    />
        <result property="exhaustGasTemperature"    column="exhaust_gas_temperature"    />
        <result property="outletCode"    column="outlet_code"    />
        <result property="outletName"    column="outlet_name"    />
        <result property="outletMonitorName"    column="outlet_monitor_name"    />
        <result property="treatmentFacilityProcess"    column="treatment_facility_process"    />
        <result property="videoSurveillance"    column="video_surveillance"    />
        <result property="stationName"    column="station_name"    />
        <result property="stationId"    column="station_id"    />
        <result property="pollutionPreventionMeasures"    column="pollution_prevention_measures"    />
        <result property="sourcesWastewater"    column="sources_wastewater"    />
        <result property="moreDetails"    column="more_details"    />
        <result property="directionDrainage"    column="direction_drainage"    />
        <result property="dischargeLaw"    column="discharge_law"    />
        <result property="intermittentEmissionPeriod"    column="intermittent_emission_period"    />
        <result property="treatmentPlantAcceptedName"    column="treatment_plant_accepted_name"    />
        <result property="approvalDocument"    column="approval_document"    />
        <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"    />
        <result property="mark"    column="mark"    />
        <result property="outletStatus"    column="outlet_status"    />
        <result property="wzzStatus"    column="wzz_status"    />
        <result property="alarmInfo"    column="alarm_info"    />
        <result property="parentOutletId"    column="parent_outlet_id"    />
        <result property="isManualEntry"    column="is_manual_entry"    />
        <result property="isStatus"    column="is_status"    />
    </resultMap>


    <sql id="selectPcOutletVo">
        select id, factory_id, pollutant_type, pollutant_outlet_type, emissions_form, whether_outlet_requirements, production_process, outlet_types, monitoring_point_name, manage_facilities_code, manage_facilities_name, production_facilities_code, production_facilities_name, outlet_lon, outlet_lat, exhaust_funnel_hight, exhaust_funnel_inner, exhaust_gas_temperature, outlet_code, outlet_name, outlet_monitor_name, treatment_facility_process, video_surveillance, station_name, station_id, pollution_prevention_measures, sources_wastewater,more_details,direction_drainage,discharge_law,intermittent_emission_period,treatment_plant_accepted_name,approval_document,receiving_water_name, receiving_water_objective, receiving_water_lon, receiving_water_lat,rivers_outlet_name,rivers_outlet_code, mark, outlet_status, wzz_status, alarm_info ,parent_outlet_id,is_manual_entry,is_status from pc_outlet
    </sql>

    <select id="selectPcOutletList" parameterType="cn.cecep.talroad.domain.PcOutlet" resultMap="PcOutletResult">
        <include refid="selectPcOutletVo"/>
        <where>
            <if test="factoryId != null  and factoryId != ''"> and factory_id = #{factoryId}</if>
            <if test="pollutantType != null  and pollutantType != ''"> and pollutant_type = #{pollutantType}</if>
            <if test="pollutantOutletType != null  and pollutantOutletType != ''"> and pollutant_outlet_type = #{pollutantOutletType}</if>
            <if test="emissionsForm != null  and emissionsForm != ''"> and emissions_form = #{emissionsForm}</if>
            <if test="whetherOutletRequirements != null  and whetherOutletRequirements != ''"> and whether_outlet_requirements = #{whetherOutletRequirements}</if>
            <if test="productionProcess != null  and productionProcess != ''"> and production_process = #{productionProcess}</if>
            <if test="outletTypes != null  and outletTypes != ''"> and outlet_types = #{outletTypes}</if>
            <if test="monitoringPointName != null  and monitoringPointName != ''"> and monitoring_point_name like concat('%', #{monitoringPointName}, '%')</if>
            <if test="manageFacilitiesCode != null  and manageFacilitiesCode != ''"> and manage_facilities_code = #{manageFacilitiesCode}</if>
            <if test="manageFacilitiesName != null  and manageFacilitiesName != ''"> and manage_facilities_name like concat('%', #{manageFacilitiesName}, '%')</if>
            <if test="productionFacilitiesCode != null  and productionFacilitiesCode != ''"> and production_facilities_code = #{productionFacilitiesCode}</if>
            <if test="productionFacilitiesName != null  and productionFacilitiesName != ''"> and production_facilities_name like concat('%', #{productionFacilitiesName}, '%')</if>
            <if test="outletLon != null  and outletLon != ''"> and outlet_lon = #{outletLon}</if>
            <if test="outletLat != null  and outletLat != ''"> and outlet_lat = #{outletLat}</if>
            <if test="exhaustFunnelHight != null  and exhaustFunnelHight != ''"> and exhaust_funnel_hight = #{exhaustFunnelHight}</if>
            <if test="exhaustFunnelInner != null  and exhaustFunnelInner != ''"> and exhaust_funnel_inner = #{exhaustFunnelInner}</if>
            <if test="exhaustGasTemperature != null  and exhaustGasTemperature != ''"> and exhaust_gas_temperature = #{exhaustGasTemperature}</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="outletMonitorName != null  and outletMonitorName != ''"> and outlet_monitor_name like concat('%', #{outletMonitorName}, '%')</if>
            <if test="treatmentFacilityProcess != null  and treatmentFacilityProcess != ''"> and treatment_facility_process = #{treatmentFacilityProcess}</if>
            <if test="videoSurveillance != null  and videoSurveillance != ''"> and video_surveillance = #{videoSurveillance}</if>
            <if test="stationName != null  and stationName != ''"> and station_name like concat('%', #{stationName}, '%')</if>
            <if test="stationId != null  and stationId != ''"> and station_id = #{stationId}</if>
            <if test="pollutionPreventionMeasures != null  and pollutionPreventionMeasures != ''"> and pollution_prevention_measures = #{pollutionPreventionMeasures}</if>
            <if test="sourcesWastewater != null  and sourcesWastewater != ''"> and sources_wastewater = #{sourcesWastewater}</if>
        </where>
        order by outlet_name
    </select>

    <select id="selectMapPoints" resultType="cn.cecep.talroad.vo.MapPointVo">
        select
            pc.monitoring_point_name pointName ,
            pc.outlet_lon pointLng ,
            pc.outlet_lat pointLat
        from
            pc_outlet pc
        where
            pc.factory_id = #{factoryId}
          and pc.pollutant_type = #{pollutantType}
    </select>
    <select id="selectPermitOutletList" resultType="cn.cecep.talroad.domain.PcOutlet">
        --查询废气排口和其监测点位
        select
            outPoint.id,
            outPoint.factory_id,
            outlet.outlet_code,
            outPoint.monitoring_point_name,
            outlet.outlet_name,
            outPoint.mark,
            outPoint.outlet_status,
            outPoint.parent_outlet_id
        from pc_outlet outPoint
                 inner join ( select id,outlet_code,outlet_name
                              from pc_outlet
                              where pollutant_type =  #{pollutantType}
                                and pollutant_outlet_type = #{outletType}
                                and outlet_types in ('1','2'))
            outlet on outPoint.parent_outlet_id = outlet.id
            order by factory_id
    </select>

    <select id="selectPointList" resultMap="PcOutletResult">
        select
            distinct
            id,
            factory_id,
            outlet_types,
            monitoring_point_name,
            mark,
            outlet_status,
            parent_outlet_id
        from pc_outlet
        <where>
            AND monitoring_point_name <![CDATA[ <> ]]> ''
            <if test="factoryId != null  and factoryId != ''"> and factory_id = #{factoryId}</if>
            <if test="pollutantType != null  and pollutantType != ''"> and pollutant_type = #{pollutantType}</if>
            <if test="pollutantOutletType != null  and pollutantOutletType != ''">
                and pollutant_outlet_type = ANY( string_to_array(#{pollutantOutletType}, ',') )
            </if>
            <if test="monitoringPointName != null  and monitoringPointName != ''"> and monitoring_point_name like concat('%', #{monitoringPointName}, '%')</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="outletMonitorName != null  and outletMonitorName != ''"> and outlet_monitor_name like concat('%', #{outletMonitorName}, '%')</if>
            <if test="stationName != null  and stationName != ''"> and station_name like concat('%', #{stationName}, '%')</if>
            <if test="stationId != null  and stationId != ''"> and station_id = #{stationId}</if>
        </where>
        order by factory_id
    </select>

    <select id="selectLabelRequirements" resultMap="PcOutletResult">
        SELECT
            factory_id,
            emissions_form
        FROM
            "pc_outlet"
        WHERE
            pollutant_type='2' and
            emissions_form IS NOT NULL
        GROUP BY
            factory_id,
            emissions_form
    </select>

    <select id="selectLabelReceivingWaterObjective" resultMap="PcOutletResult">
        SELECT
            factory_id,
            receiving_water_objective
        FROM
            "pc_outlet"
        WHERE
            pollutant_type='2' and
            receiving_water_objective IS NOT NULL and receiving_water_objective!='/'
						and receiving_water_objective!=''
        GROUP BY
            factory_id,
            receiving_water_objective
    </select>

    <select id="selectLabeRreceivingWaterName" resultMap="PcOutletResult">
        SELECT
            factory_id,
            receiving_water_name
        FROM
            "pc_outlet"
        WHERE
            pollutant_type='2' and
            receiving_water_name IS NOT NULL
        GROUP BY
            factory_id,
            receiving_water_name
    </select>

    <select id="selectListByOnline" resultType="cn.cecep.talroad.domain.PcOutlet">
        SELECT

            po.monitoring_point_name ,
            po.outlet_name,
            po.id
        FROM
            ( SELECT "id", factory_id FROM pc_label_factory WHERE label_id = '502' AND label_value = '1' ) plf
                INNER JOIN pc_factory pf ON plf.factory_id = pf."id"
                INNER JOIN (
                SELECT
                    t1."id",
                    t1.monitoring_point_name,
                    t1.factory_id,
                    t1.outlet_name
                FROM
                    pc_outlet t1
                WHERE
                    t1.pollutant_type = '4'
                  AND t1.pollutant_outlet_type = '1'
            ) po ON po.factory_id = pf."id"
        <if test="name != null and name.trim() != ''">
                where po.monitoring_point_name like concat('%',#{name,jdbcType=VARCHAR},'%')
        </if>
    </select>
    <select id="selectEmissionsStatPointList" resultType="cn.cecep.talroad.vo.EmissionsStatVo$PointRow">
        select
            t1.outlet_id as "pointId",
            t2.monitoring_point_name as "pointName",
            t1.factory_id,
            t3.factory_name as "factoryName",
            t3.country_code as "regionCode",
            t3.country_name as "regionName",
            t4.arguments_name as "industryName",
            t1.pollutant_type as "pollutantCode",
            t5.poll_name as "pollutantName",
            t1.control_standard,
            t1.control_points
        from base_control_concent_standards t1
        left join pc_outlet t2 on t1.outlet_id = t2.id
        left join pc_factory t3 on t1.factory_id = t3.id
        <!-- 查询所有企业的行业标签值、标签值名称 -->
        left join (
            select
                plf.factory_id, plv.arguments_code, plv.arguments_name
            from pc_label_factory plf
            left join pc_label_value plv on plf.label_id = plv.label_id and plf.label_value = plv.arguments_code
            where plf.label_id = '501'
        ) t4 on t1.factory_id = t4.factory_id
        left join pc_pollutant t5 on t1.pollutant_type = t5.poll_code
        <where>
            and t1.include_calculations = '1'
            <if test="search.pollutantCode != null and search.pollutantCode != ''">
                and t1.pollutant_type = #{search.pollutantCode}
            </if>
            <if test="search.factoryId != null and search.factoryId != ''">
                and t1.factory_id = #{search.factoryId}
            </if>
            <if test="search.factoryName != null and search.factoryName != ''">
                and t3.factory_name ilike concat('%', #{search.factoryName}, '%')
            </if>
            <if test="search.regionCode != null and search.regionCode != ''">
                and t3.country_code = #{search.regionCode}
            </if>
            <if test="search.industryCode != null and search.industryCode != ''">
                and t4.arguments_code = #{search.industryCode}
            </if>
            <if test="search.pointName != null and search.pointName != ''">
                and t2.monitoring_point_name ilike concat('%', #{search.pointName}, '%')
            </if>
            <if test="search.controlPoints != null and search.controlPoints != ''">
                and t1.control_points = #{search.controlPoints}
            </if>
        </where>
        order by t3.country_code, t1.factory_id, t1.outlet_id, t1.pollutant_type
    </select>

    <select id="queryPcOutletGasList" resultType="cn.cecep.talroad.vo.PcOutletGasVO">
        SELECT
            pc_outlet.id as monitoringPointId,
            pc_outlet.monitoring_point_name as monitoringPointName,
            pc_outlet.parent_outlet_id as parentOutletId,
            outlet.outlet_types as outletTypes,
            outlet.outlet_code,
            outlet.outlet_name
        FROM
            pc_outlet
        LEFT JOIN pc_outlet AS outlet
        ON pc_outlet.parent_outlet_id = outlet.id
        <where>
            pc_outlet.factory_id =#{factoryId}
            AND pc_outlet.is_status = '1'
            AND pc_outlet.pollutant_type =#{pcOutletGasQuery.pollutantType}
            AND pc_outlet.pollutant_outlet_type in
            <foreach collection="pollutantOutletTypes" item="pollutantOutletType" open="(" separator="," close=")">
                #{pollutantOutletType}
            </foreach>
            <if test="pcOutletGasQuery.monitoringPointName != null and pcOutletGasQuery.monitoringPointName != ''">
                AND pc_outlet.monitoring_point_name =#{pcOutletGasQuery.monitoringPointName}
            </if>
            <if test="pcOutletGasQuery.outletName != null and pcOutletGasQuery.outletName != ''">
                AND outlet.outlet_name =#{pcOutletGasQuery.outletName}
            </if>
            <if test="pcOutletGasQuery.outletCode != null and pcOutletGasQuery.outletCode != ''">
                AND outlet.outlet_code =#{pcOutletGasQuery.outletCode}
            </if>
            <if test="pcOutletGasQuery.outletTypes != null and pcOutletGasQuery.outletTypes != ''">
                AND outlet.outlet_types =#{pcOutletGasQuery.outletTypes}
            </if>
            <if test="pcOutletGasQuery.monitoringPointId != null and pcOutletGasQuery.monitoringPointId != ''">
                AND pc_outlet.id =#{pcOutletGasQuery.monitoringPointId}
            </if>
        </where>
        order by monitoringPointName asc
    </select>

    <select id="queryGasPEMonitoringPointList" resultType="cn.cecep.talroad.vo.GasPEMonitoringPointVO">
        SELECT
            id as monitoringPointId,
            monitoring_point_name as monitoringPointName,
            outlet_code as outletCode,
            CASE
                WHEN is_manual_entry = '1' THEN
                '1' ELSE'0'
            END as isManualEntry
        FROM
            pc_outlet
        <where>
            pc_outlet.factory_id =#{factoryId}
            AND pollutant_type = '3'
            AND pc_outlet.is_status = '1'
            <if test="gasPEMonitoringPointQuery.monitoringPointName != null and gasPEMonitoringPointQuery.monitoringPointName != ''">
                AND pc_outlet.monitoring_point_name =#{gasPEMonitoringPointQuery.monitoringPointName}
            </if>
        </where>
        order by monitoringPointName asc
    </select>

    <select id="pageAndFactory" resultType="cn.cecep.talroad.domain.analysis.SRaOverWaterPollutionTraceability">
        SELECT
            po.id,
            po.outlet_name,
            po.outlet_code,
            po.monitoring_point_name,
            po.direction_drainage AS drainage_direction,
            po.emissions_form AS emission_method,
            po.discharge_law AS emission_behavior,
            po.intermittent_emission_period ,
            pf.factory_name,
            po.factory_id,
            po.treatment_plant_accepted_name AS receiving_sewage_plant_name,
            po.receiving_water_name AS receiving_water_name,
            po.receiving_water_objective AS receiving_target,
            po.rivers_outlet_name AS estuary_name,
            po.rivers_outlet_code AS estuary_code,
            po.outlet_lon AS outlet_longitude,
            po.outlet_lat AS outlet_latitude ,
            pf1.production_lon AS receiving_sewage_plant_longitude,
            pf1.production_lat AS receiving_sewage_plant_latitude,
            po.receiving_water_lon AS estuary_longitude ,
            po.receiving_water_lat AS estuary_latitude,
            po.alarm_info AS alarm_info
        FROM
            pc_outlet po
                LEFT JOIN pc_factory pf ON pf.id=po.factory_id
                LEFT JOIN pc_factory pf1 ON pf1.factory_name=po.receiving_water_name AND emissions_form='间接排放'
        WHERE po.pollutant_type='2'
        <if test="query.factoryName != null and query.factoryName.trim() != ''">
          AND   pf.factory_name like CONCAT ('%',#{query.factoryName,jdbcType=VARCHAR},'%')
        </if>
        <if test="query.outletName != null  and query.outletName.trim() != ''">
            AND  po.outlet_name like CONCAT ('%',#{query.outletName,jdbcType=VARCHAR},'%')
        </if>
        <if test="query.emissionMethod != null  and query.emissionMethod.trim() != ''">
            AND  po.emissions_form like CONCAT ('%',#{query.emissionMethod,jdbcType=VARCHAR},'%')
        </if>
        <if test="query.drainageDirection != null  and query.drainageDirection.trim() != ''">
            AND  po.direction_drainage like CONCAT ('%',#{query.drainageDirection,jdbcType=VARCHAR},'%')
        </if>
        <if test="query.receivingSewagePlantName != null  and query.receivingSewagePlantName.trim() != ''">
            AND  (po.treatment_plant_accepted_name like CONCAT ('%',#{query.receivingSewagePlantName,jdbcType=VARCHAR},'%')
            OR po.rivers_outlet_name  like CONCAT ('%',#{query.receivingSewagePlantName,jdbcType=VARCHAR},'%') )
        </if>
        <if test="query.estuaryCode != null  and query.estuaryCode.trim() != ''">
            AND  po.rivers_outlet_code like CONCAT ('%',#{query.estuaryCode,jdbcType=VARCHAR},'%')
        </if>
        <if test="query.id != null  and query.id.trim() != ''">
            AND  po.id =#{query.id,jdbcType=VARCHAR}
        </if>
        ORDER BY pf1.production_lon DESC,po.receiving_water_lon DESC, po.id
    </select>
    <select id="queryPcOutletsByPcFactoryId" resultType="java.util.HashMap">
        SELECT id,
        factory_id as factoryId,
        monitoring_point_name as monitorPointName,
        manage_facilities_code as manageFacilitiesCode,
        outlet_status outletStatus
        FROM pc_outlet
        WHERE  1 = 1
        AND pollutant_type = #{pollutantType}
        AND pollutant_outlet_type = #{pollutantOutletType}
        AND factory_id = #{factoryId}
        <if test="monitorPointName != null  and monitorPointName != ''">
            AND  monitoring_point_name like CONCAT ('%',#{monitorPointName,jdbcType=VARCHAR},'%')
        </if>
    </select>

    <select id="selectEnableList" resultMap="PcOutletResult">
        select * from pc_outlet
        where factory_id = #{factoryId} and pollutant_type = '4' AND pollutant_outlet_type = #{pollutantOutletType} and monitoring_point_name=#{portName} and is_status = '1'
    </select>
    <select id="selectEnableOutletList" resultMap="PcOutletResult">
        select * from pc_outlet
        where pollutant_type = '4' AND pollutant_outlet_type = #{pollutantOutletType} and is_status = '1'
    </select>

    <select id="getOutletByPoint" resultType="cn.cecep.talroad.domain.PcOutlet">
        select * from pc_outlet pc inner join
        (select parent_outlet_id from pc_outlet where id = #{stationId}) t1 on pc.id = t1.parent_outlet_id
    </select>

    <select id="selectOnLinePoints" resultType="cn.cecep.talroad.domain.PcOutlet">
        SELECT id,
               factory_id as factoryId,
               outlet_code as outletCode,
               outlet_name as outletName,
               pollutant_outlet_type as  pollutantOutletType
        FROM pc_outlet
        WHERE  1 = 1
          AND pollutant_type = #{pollutantType}
          AND is_status = '1'
          AND factory_id = #{factoryId}
    </select>
    <select id="selectByDevice" resultMap="PcOutletResult">
        select
            o.*
        from
            pc_outlet o
                left join b_main_production_inorg_gas mpig on mpig.factory_id = o.factory_id and mpig.outlet_code = o.outlet_code
        where
            o.pollutant_outlet_type = '2'
          and mpig.corresponding_production_id like concat('%', #{device_id}, '%')
    </select>

    <select id="selectByOnlineAndSource" resultType="cn.cecep.talroad.domain.analysis.SRaWaterPermittedOnline">
        select po.id as monitorId,pot.outlet_code,po.monitoring_point_name as moitorName,pf.factory_name,pf.country_name as districtName,pf.industry_permission_name as industryCategoryName
        ,case when po.pollutant_type='4' then '自动监测' when po.pollutant_type='5' then '手工监测' end monitorType,pot.outlet_types as outletType,pot.source_permission_poll as sourcePermissionPoll
        from pc_outlet as po inner join pc_factory as pf on po.factory_id=pf.id
        left join pc_outlet as pot on po.parent_outlet_id=pot.id
        <where>
             po.is_status='1'
            <if test='lambdaQueryWrapper.type=="1"'>
                and po.source_online='1'
            </if>
            <if test='lambdaQueryWrapper.type=="2"'>
               and po.source_permission='1'
            </if>
            <if test="lambdaQueryWrapper.factoryId != null  and lambdaQueryWrapper.factoryId != ''"> and pf.id = #{lambdaQueryWrapper.factoryId} </if>
            <if test="lambdaQueryWrapper.factoryName != null  and lambdaQueryWrapper.factoryName != ''"> and pf.factory_name like concat('%', #{lambdaQueryWrapper.factoryName}, '%')</if>
            <if test="lambdaQueryWrapper.industryCategoryCode != null  and lambdaQueryWrapper.industryCategoryCode != ''"> and pf.industry_permission_name = #{lambdaQueryWrapper.industryCategoryCode}</if>
            <if test="lambdaQueryWrapper.districtName != null  and lambdaQueryWrapper.districtName != ''"> and pf.country_name like concat('%', #{lambdaQueryWrapper.districtName}, '%')</if>
            <if test="lambdaQueryWrapper.districtCode != null  and lambdaQueryWrapper.districtCode != ''"> and pf.country_code = #{lambdaQueryWrapper.districtCode}</if>
            <if test="lambdaQueryWrapper.outletType != null  and lambdaQueryWrapper.outletType != ''"> and po.outlet_types = #{lambdaQueryWrapper.outletType}</if>
            <if test="lambdaQueryWrapper.moitorName != null  and lambdaQueryWrapper.moitorName != ''"> and po.id = #{lambdaQueryWrapper.moitorName} </if>
            <if test="lambdaQueryWrapper.monitorType != null  and lambdaQueryWrapper.monitorType != ''"> and po.pollutant_type = #{lambdaQueryWrapper.monitorType}</if>
            <if test="lambdaQueryWrapper.pollutantOutletType != null  and lambdaQueryWrapper.pollutantOutletType != ''"> and po.pollutant_outlet_type = #{lambdaQueryWrapper.pollutantOutletType}</if>
            <if test="lambdaQueryWrapper.regionCodes != null and lambdaQueryWrapper.regionCodes.size() != 0">
                and pf.country_code IN
                <foreach collection="lambdaQueryWrapper.regionCodes" separator="," item="item" close=")" open="(">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
        </where>
        order by po.factory_id,po.id asc
    </select>

    <select id="selectBySource" resultType="cn.cecep.talroad.domain.analysis.SRaWaterPermittedOnline">
        select pf.factory_name,pf.country_name as districtName,pf.industry_permission_name as industryCategoryName,po.factory_id
        from pc_outlet as po inner join pc_factory as pf on po.factory_id=pf.id
        <where>
            is_status='1'
            and (po.source_online='1' OR po.source_permission='1')
            <if test="lambdaQueryWrapper.factoryName != null  and lambdaQueryWrapper.factoryName != ''"> and pf.factory_name like concat('%', #{lambdaQueryWrapper.factoryName}, '%')</if>
            <if test="lambdaQueryWrapper.industryCategoryCode != null  and lambdaQueryWrapper.industryCategoryCode != ''"> and pf.industry_permission_name = #{lambdaQueryWrapper.industryCategoryCode}</if>
            <if test="lambdaQueryWrapper.districtName != null  and lambdaQueryWrapper.districtName != ''"> and pf.country_name like concat('%', #{lambdaQueryWrapper.districtName}, '%')</if>
            <if test="lambdaQueryWrapper.districtCode != null  and lambdaQueryWrapper.districtCode != ''"> and pf.country_code = #{lambdaQueryWrapper.districtCode}</if>
<!--            <if test="lambdaQueryWrapper.outletType != null  and lambdaQueryWrapper.outletType != ''"> and po.outlet_types = #{lambdaQueryWrapper.outletType}</if>-->
<!--            <if test="lambdaQueryWrapper.moitorName != null  and lambdaQueryWrapper.moitorName != ''"> and po.monitoring_point_name like concat('%', #{lambdaQueryWrapper.moitorName}, '%')</if>-->
<!--            <if test="lambdaQueryWrapper.monitorType != null  and lambdaQueryWrapper.monitorType != ''"> and po.pollutant_type = #{lambdaQueryWrapper.monitorType}</if>-->
            <if test="lambdaQueryWrapper.pollutantOutletType != null  and lambdaQueryWrapper.pollutantOutletType != ''"> and po.pollutant_outlet_type = #{lambdaQueryWrapper.pollutantOutletType}</if>
            <if test="lambdaQueryWrapper.regionCodes != null and lambdaQueryWrapper.regionCodes.size() != 0">
                and pf.country_code IN
                <foreach collection="lambdaQueryWrapper.regionCodes" separator="," item="item" close=")" open="(">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
        </where>
        group by po.factory_id,pf.factory_name,pf.country_name,pf.industry_permission_name
        order by po.factory_id asc
    </select>

    <select id="sourceOutlets" resultType="java.util.HashMap">
        select po.id as value,po.monitoring_point_name as label from pc_outlet as po
        inner join pc_factory as pf  on pf.id=po.factory_id
        <where>
                        <if test='type=="1"'>
                            and source_online='1'
                        </if>
                        <if test='type=="2"'>
                            and source_permission='1'
                        </if>
            <if test="factoryId != null  and factoryId != ''"> and pf.factory_name =#{factoryId} </if>
            <if test="pollutantOutletType != null  and pollutantOutletType != ''"> and pollutant_outlet_type =#{pollutantOutletType} </if>
            <if test="monitorPointName != null  and monitorPointName != ''"> and monitoring_point_name like concat('%', #{monitorPointName}, '%') </if>
        </where>
    </select>

    <select id="selectContrastPointList" resultType="cn.cecep.talroad.vo.analysis.SRaRealTimeAnalysicComsitMonitorVo">
        select po.id as monitorId,po.monitoring_point_name as monitoringPointName,
        pf.factory_name,pf.industry_permission_name as industryCategoryName
        ,pot.manage_facilities_name as manageFacilitiesName,pot.production_facilities_name as productionFacilitiesName,pot.outlet_name as outletName
        from pc_outlet as po inner join pc_factory as pf on po.factory_id=pf.id
        left join pc_outlet as pot on po.parent_outlet_id=pot.id
        <where>
            po.is_status='1' and po.pollutant_type='4'
            and po.id not in (SELECT monitor_id from s_ra_real_time_analysic_comsit_monitor where comsit_id=#{pcOutlet.comsitId})
            <if test="pcOutlet.monitoringPointName != null  and pcOutlet.monitoringPointName != ''"> and po.monitoring_point_name like concat('%', #{pcOutlet.monitoringPointName}, '%') </if>
            <if test="pcOutlet.industryCategoryName != null  and pcOutlet.industryCategoryName != ''"> and pf.industry_permission_name = #{pcOutlet.industryCategoryName} </if>
            <if test="pcOutlet.factoryName != null  and pcOutlet.factoryName != ''"> and pf.factory_name like concat('%', #{pcOutlet.factoryName}, '%') </if>
            <if test="pcOutlet.manageFacilitiesName != null  and pcOutlet.manageFacilitiesName != ''"> and pot.manage_facilities_name like concat('%', #{pcOutlet.manageFacilitiesName}, '%') </if>
            <if test="pcOutlet.productionFacilitiesName != null  and pcOutlet.productionFacilitiesName != ''"> and pot.production_facilities_name like concat('%', #{pcOutlet.productionFacilitiesName}, '%') </if>
        </where>
        order by po.id asc
    </select>

    <select id="selectPwxkList" resultType="cn.cecep.talroad.vo.PcOutletVo$PwxkGas">
        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,
            t2.more_details
        FROM
            pc_factory t1
            LEFT JOIN pc_outlet t2 ON t2.factory_id = t1."id" AND t2.pollutant_type = '1'
                <if test="query.exhaustFunnelHightStart != null">
                    AND t2.exhaust_funnel_hight::numeric >= #{query.exhaustFunnelHightStart}
                </if>
                <if test="query.exhaustFunnelHightEnd != null">
                    AND t2.exhaust_funnel_hight::numeric &lt;= #{query.exhaustFunnelHightEnd}
                </if>
                <if test="query.exhaustFunnelInnerStart != null">
                    AND t2.exhaust_funnel_inner::numeric >= #{query.exhaustFunnelInnerStart}
                </if>
                <if test="query.exhaustFunnelInnerEnd != null">
                    AND t2.exhaust_funnel_inner::numeric &lt;= #{query.exhaustFunnelInnerEnd}
                </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="selectPwxkWaterDirect" resultType="cn.cecep.talroad.vo.PcOutletVo$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,
            t2.more_details
        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>
        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="selectPwxkWaterIndirect" resultType="cn.cecep.talroad.vo.PcOutletVo$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_lat,
            t2.outlet_lon,
            t2.direction_drainage,
            t2.discharge_law,
            t2.intermittent_emission_period,
            t2.treatment_plant_accepted_name
        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.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>
        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>

    <update id="updateBatchCoordinate" parameterType="java.util.List">
        <foreach collection="list" item="item" index="index" separator=";">
            UPDATE pc_outlet
            <set>
                <if test="item.outletLon != null and item.outletLon != ''">outlet_lon=#{item.outletLon},</if>
                <if test="item.outletLon == null or item.outletLon == ''">outlet_lon = '',</if>
                <if test="item.outletLat != null  and item.outletLat != ''">outlet_lat=#{item.outletLat},</if>
                <if test="item.outletLat == null or item.outletLat == ''">outlet_lat = '',</if>
            </set>
            WHERE id=#{item.id}
        </foreach>
    </update>
</mapper>
