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

    <resultMap type="cn.cecep.talroad.domain.BStatTableZxbgGasEmissionSpeed" id="BStatTableZxbgGasEmissionSpeedResult">
        <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="outletCode"    column="outlet_code"    />
        <result property="outletName"    column="outlet_name"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
        <result property="pollutantName"    column="pollutant_name"    />
        <result property="pollutantCode"    column="pollutant_code"    />
        <result property="emissionConcentration"    column="emission_concentration"    />
        <result property="effectivelyHour"    column="effectively_hour"    />
        <result property="detectionMinHour"    column="detection_min_hour"    />
        <result property="detectionMaxHour"    column="detection_max_hour"    />
        <result property="detectionAvgHour"    column="detection_avg_hour"    />
        <result property="exceededData"    column="exceeded_data"    />
        <result property="exceededRate"    column="exceeded_rate"    />
        <result property="exceededCause"    column="exceeded_cause"    />
    </resultMap>


    <sql id="selectBStatTableZxbgGasEmissionSpeedVo">
        select id, factory_id, zxbg_type, zxbg_period, outlet_code, outlet_name, remark, create_time, pollutant_name, pollutant_code, emission_concentration, effectively_hour, detection_min_hour, detection_max_hour, detection_avg_hour, exceeded_data, exceeded_rate, exceeded_cause from b_stat_table_zxbg_gas_emission_speed
    </sql>

    <select id="selectBStatTableZxbgGasEmissionSpeedList" parameterType="cn.cecep.talroad.domain.BStatTableZxbgGasEmissionSpeed" resultMap="BStatTableZxbgGasEmissionSpeedResult">
        <include refid="selectBStatTableZxbgGasEmissionSpeedVo"/>
        <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="outletCode != null  and outletCode != ''"> and outlet_code = #{outletCode}</if>
            <if test="outletName != null  and outletName != ''"> and outlet_name like concat('%', #{outletName}, '%')</if>
            <if test="pollutantName != null  and pollutantName != ''"> and pollutant_name like concat('%', #{pollutantName}, '%')</if>
            <if test="pollutantCode != null  and pollutantCode != ''"> and pollutant_code = #{pollutantCode}</if>
            <if test="emissionConcentration != null  and emissionConcentration != ''"> and emission_concentration = #{emissionConcentration}</if>
            <if test="effectivelyHour != null  and effectivelyHour != ''"> and effectively_hour = #{effectivelyHour}</if>
            <if test="detectionMinHour != null  and detectionMinHour != ''"> and detection_min_hour = #{detectionMinHour}</if>
            <if test="detectionMaxHour != null  and detectionMaxHour != ''"> and detection_max_hour = #{detectionMaxHour}</if>
            <if test="detectionAvgHour != null  and detectionAvgHour != ''"> and detection_avg_hour = #{detectionAvgHour}</if>
            <if test="exceededData != null  and exceededData != ''"> and exceeded_data = #{exceededData}</if>
            <if test="exceededRate != null  and exceededRate != ''"> and exceeded_rate = #{exceededRate}</if>
            <if test="exceededCause != null  and exceededCause != ''"> and exceeded_cause = #{exceededCause}</if>
        </where>
    </select>

    <select id="selectListAndFactory" resultMap="BStatTableZxbgGasEmissionSpeedResult">
        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_speed
        <where>
            <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>
