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

    <resultMap type="cn.cecep.talroad.domain.BStatTableZxbgGasEmissionStatistics" id="BStatTableZxbgGasEmissionStatisticsResult">
        <result property="id"    column="id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="zxbgType"    column="zxbg_type"    />
        <result property="zxbgPeriod"    column="zxbg_period"    />
        <result property="zxbgPollutantType"    column="zxbg_pollutant_type"    />
        <result property="pollutantName"    column="pollutant_name"    />
        <result property="facilityName"    column="facility_name"    />
        <result property="facilitiesCode"    column="facilities_code"    />
        <result property="monitoringTime"    column="monitoring_time"    />
        <result property="monitoringNumber"    column="Monitoring_number"    />
        <result property="emissionConcentration"    column="emission_concentration"    />
        <result property="monitoringResultsHour"    column="monitoring_results_hour"    />
        <result property="monitoringFoldsHour"    column="monitoring_folds_hour"    />
        <result property="isExceeded"    column="is_exceeded"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>


    <sql id="selectBStatTableZxbgGasEmissionStatisticsVo">
        select id, factory_id, zxbg_type, zxbg_period, zxbg_pollutant_type, pollutant_name, facility_name, facilities_code, monitoring_time, Monitoring_number, emission_concentration, monitoring_results_hour, monitoring_folds_hour, is_exceeded, remark, create_time from b_stat_table_zxbg_gas_emission_statistics
    </sql>

    <select id="selectBStatTableZxbgGasEmissionStatisticsList" parameterType="cn.cecep.talroad.domain.BStatTableZxbgGasEmissionStatistics" resultMap="BStatTableZxbgGasEmissionStatisticsResult">
        <include refid="selectBStatTableZxbgGasEmissionStatisticsVo"/>
        <where>
            <if test="factoryId != null  and factoryId != ''"> and factory_id = #{factoryId}</if>
            <if test="zxbgType != null  and zxbgType != ''"> and zxbg_type = #{zxbgType}</if>
            <if test="zxbgPeriod != null  and zxbgPeriod != ''"> and zxbg_period = #{zxbgPeriod}</if>
            <if test="zxbgPollutantType != null  and zxbgPollutantType != ''"> and zxbg_pollutant_type = #{zxbgPollutantType}</if>
            <if test="pollutantName != null  and pollutantName != ''"> and pollutant_name like concat('%', #{pollutantName}, '%')</if>
            <if test="facilityName != null  and facilityName != ''"> and facility_name like concat('%', #{facilityName}, '%')</if>
            <if test="facilitiesCode != null  and facilitiesCode != ''"> and facilities_code = #{facilitiesCode}</if>
            <if test="monitoringTime != null  and monitoringTime != ''"> and monitoring_time = #{monitoringTime}</if>
            <if test="monitoringNumber != null "> and Monitoring_number = #{monitoringNumber}</if>
            <if test="emissionConcentration != null  and emissionConcentration != ''"> and emission_concentration = #{emissionConcentration}</if>
            <if test="monitoringResultsHour != null  and monitoringResultsHour != ''"> and monitoring_results_hour = #{monitoringResultsHour}</if>
            <if test="monitoringFoldsHour != null  and monitoringFoldsHour != ''"> and monitoring_folds_hour = #{monitoringFoldsHour}</if>
            <if test="isExceeded != null  and isExceeded != ''"> and is_exceeded = #{isExceeded}</if>
        </where>
    </select>

    <select id="selectListAndFactory" resultMap="BStatTableZxbgGasEmissionStatisticsResult">
        SELECT
        zxbg.*,
        pf.factory_name,
        pf.country_name,
        pf.license_man_type,
        pf.poll_dis_license_code,
        pf.industrial_park_name,
        pf.industrial_park_code,
        pf.industry_permission_name,
        pf.river_basin
        FROM
        (select * from b_stat_table_zxbg_gas_emission_statistics
        <where>
            <if test="zxbgAirType != null  and zxbgAirType != ''"> and zxbg_pollutant_type = #{zxbgAirType}</if>
            <if test="zxbgPollutant != null  and zxbgPollutant != ''"> and pollutant_name like concat('%', #{zxbgPollutant}, '%')</if>
            <if test="zxbgType != null  and zxbgType != ''"> and zxbg_type = #{zxbgType}</if>
            <if test="zxbgPeriod != null  and zxbgPeriod != ''"> and zxbg_period  like concat('%', #{zxbgPeriod}, '%')</if>
        </where>
        ) zxbg
        right JOIN pc_factory pf ON pf.ID = zxbg.factory_id
        <where>
            <if test="factoryIdList != null and factoryIdList.size() != 0">
                and 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>
