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

    <resultMap type="cn.cecep.talroad.domain.BStatTableZxbgWaterEmission" id="BStatTableZxbgWaterEmissionResult">
        <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="createTime"    column="create_time"    />
        <result property="remark"    column="remark"    />
        <result property="outletCode"    column="outlet_code"    />
        <result property="pollutantName"    column="pollutant_name"    />
        <result property="monitoringFacilities"    column="monitoring_facilities"    />
        <result property="facilityName"    column="facility_name"    />
        <result property="emissionConcentration"    column="emission_concentration"    />
        <result property="effectivelyDay"    column="effectively_day"    />
        <result property="detectionMinDay"    column="detection_min_day"    />
        <result property="detectionMaxDay"    column="detection_max_day"    />
        <result property="detectionAvgDay"    column="detection_avg_day"    />
        <result property="exceededData"    column="exceeded_data"    />
        <result property="exceededRate"    column="exceeded_rate"    />
        <result property="actualEmissions"    column="actual_emissions"    />
        <result property="instrumentName"    column="instrument_name"    />
        <result property="samplingMethod"    column="sampling_method"    />
        <result property="manualMethod"    column="manual_method"    />
    </resultMap>


    <sql id="selectBStatTableZxbgWaterEmissionVo">
        select id, factory_id, zxbg_type, zxbg_period, zxbg_pollutant_type, create_time, remark, outlet_code, pollutant_name, monitoring_facilities, facility_name, emission_concentration, effectively_day, detection_min_day, detection_max_day, detection_avg_day, exceeded_data, exceeded_rate, actual_emissions, instrument_name, sampling_method, manual_method from b_stat_table_zxbg_water_emission
    </sql>

    <select id="selectBStatTableZxbgWaterEmissionList" parameterType="cn.cecep.talroad.domain.BStatTableZxbgWaterEmission" resultMap="BStatTableZxbgWaterEmissionResult">
        <include refid="selectBStatTableZxbgWaterEmissionVo"/>
        <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="outletCode != null  and outletCode != ''"> and outlet_code = #{outletCode}</if>
            <if test="pollutantName != null  and pollutantName != ''"> and pollutant_name like concat('%', #{pollutantName}, '%')</if>
            <if test="monitoringFacilities != null  and monitoringFacilities != ''"> and monitoring_facilities = #{monitoringFacilities}</if>
            <if test="facilityName != null  and facilityName != ''"> and facility_name like concat('%', #{facilityName}, '%')</if>
            <if test="emissionConcentration != null  and emissionConcentration != ''"> and emission_concentration = #{emissionConcentration}</if>
            <if test="effectivelyDay != null  and effectivelyDay != ''"> and effectively_day = #{effectivelyDay}</if>
            <if test="detectionMinDay != null  and detectionMinDay != ''"> and detection_min_day = #{detectionMinDay}</if>
            <if test="detectionMaxDay != null  and detectionMaxDay != ''"> and detection_max_day = #{detectionMaxDay}</if>
            <if test="detectionAvgDay != null  and detectionAvgDay != ''"> and detection_avg_day = #{detectionAvgDay}</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="actualEmissions != null  and actualEmissions != ''"> and actual_emissions = #{actualEmissions}</if>
            <if test="instrumentName != null  and instrumentName != ''"> and instrument_name like concat('%', #{instrumentName}, '%')</if>
            <if test="samplingMethod != null  and samplingMethod != ''"> and sampling_method = #{samplingMethod}</if>
            <if test="manualMethod != null  and manualMethod != ''"> and manual_method = #{manualMethod}</if>
        </where>
    </select>

    <select id="selectListAndFactory" resultMap="BStatTableZxbgWaterEmissionResult">
        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_water_emission
        <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>
            <if test="zxbgName != null  and zxbgName != ''"> and zxbg_name like concat('%', #{zxbgName}, '%')</if>
            <if test="zxbgParam != null  and zxbgParam != ''"> and zxbg_param like concat('%', #{zxbgParam}, '%')</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>
