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

    <resultMap type="cn.cecep.talroad.domain.BMainProductionInorgGas" id="BMainProductionInorgGasResult">
        <result property="id"    column="id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="licenceMonName"    column="licence_mon_name"    />
        <result property="monitoringType"    column="monitoring_type"    />
        <result property="monitoringInorganization"    column="monitoring_inorganization"    />
        <result property="pollutionPrevention"    column="pollution_prevention"    />
        <result property="pollutionProductionLink"    column="pollution_production_link"    />
        <result property="correspondingProductionCode"    column="corresponding_production_code"    />
        <result property="devId"    column="dev_id"    />
        <result property="correspondingProductionName"    column="corresponding_production_name"    />
        <result property="proFacilityParam"    column="pro_facility_param"    />
        <result property="pollutionType"    column="pollution_type"    />
    </resultMap>


    <sql id="selectBMainProductionInorgGasVo">
        select id, factory_id, licence_mon_name, monitoring_type, monitoring_inorganization, pollution_prevention, pollution_production_link, corresponding_production_code, dev_id, corresponding_production_name, pro_facility_param, pollution_type from b_main_production_inorg_gas
    </sql>

    <select id="selectBMainProductionInorgGasList" parameterType="cn.cecep.talroad.domain.BMainProductionInorgGas" resultMap="BMainProductionInorgGasResult">
        <include refid="selectBMainProductionInorgGasVo"/>
        <where>
            <if test="factoryId != null  and factoryId != ''"> and factory_id = #{factoryId}</if>
            <if test="licenceMonName != null  and licenceMonName != ''"> and licence_mon_name like concat('%', #{licenceMonName}, '%')</if>
            <if test="monitoringType != null  and monitoringType != ''"> and monitoring_type = #{monitoringType}</if>
            <if test="monitoringInorganization != null  and monitoringInorganization != ''"> and monitoring_inorganization = #{monitoringInorganization}</if>
            <if test="pollutionPrevention != null  and pollutionPrevention != ''"> and pollution_prevention = #{pollutionPrevention}</if>
            <if test="pollutionProductionLink != null  and pollutionProductionLink != ''"> and pollution_production_link = #{pollutionProductionLink}</if>
            <if test="correspondingProductionCode != null  and correspondingProductionCode != ''"> and corresponding_production_code = #{correspondingProductionCode}</if>
            <if test="devId != null  and devId != ''"> and dev_id = #{devId}</if>
            <if test="correspondingProductionName != null  and correspondingProductionName != ''"> and corresponding_production_name like concat('%', #{correspondingProductionName}, '%')</if>
            <if test="proFacilityParam != null  and proFacilityParam != ''"> and pro_facility_param = #{proFacilityParam}</if>
            <if test="pollutionType != null  and pollutionType != ''"> and pollution_type = #{pollutionType}</if>
        </where>
    </select>


    <select id="selectDeviceIdByPollutantType"
            resultType="cn.cecep.talroad.data.analyse.task.entity.MainProductDeviceVo">
        SELECT
            bmpog.corresponding_production_id proFacilityId,
            po.id outletId,
            bmpog.id,
            po.outlet_code outletCode
        FROM
            pc_outlet po
                LEFT JOIN b_main_production_inorg_gas bmpog ON po.outlet_code = bmpog.outlet_code  AND po.factory_id = bmpog.factory_id
        WHERE
            po.pollutant_type = #{code}
          AND bmpog.corresponding_production_id IS NOT NULL
        GROUP BY bmpog.corresponding_production_id,po.id,bmpog.id;
    </select>

</mapper>
