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

    <resultMap type="cn.cecep.talroad.domain.BStatTableZxbgPflAirOverproof" id="BStatTableZxbgPflAirOverproofResult">
        <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="zxbgOutletCode"    column="zxbg_outlet_code"    />
        <result property="zxbgPollutant"    column="zxbg_pollutant"    />
        <result property="zxbgDischargeTrue"    column="zxbg_discharge_true"    />
        <result property="zxbgDischargeActual"    column="zxbg_discharge_actual"    />
        <result property="createTime"    column="create_time"    />
        <result property="isDelete"    column="is_delete"    />
        <result property="zxbgProCode"    column="zxbg_pro_code"    />
        <result property="overStartTime"    column="over_start_time"    />
        <result property="overEndTime"    column="over_end_time"    />
        <result property="overRemark"    column="over_remark"    />
        <result property="overUnit"    column="over_unit"    />
    </resultMap>


    <sql id="selectBStatTableZxbgPflAirOverproofVo">
        select id, factory_id, zxbg_type, zxbg_period, zxbg_outlet_code, zxbg_pollutant, zxbg_discharge_true, zxbg_discharge_actual, create_time, is_delete, zxbg_pro_code, over_start_time, over_end_time, over_remark, over_unit from b_stat_table_zxbg_pfl_air_overproof
    </sql>

    <select id="selectBStatTableZxbgPflAirOverproofList" parameterType="cn.cecep.talroad.domain.BStatTableZxbgPflAirOverproof" resultMap="BStatTableZxbgPflAirOverproofResult">
        <include refid="selectBStatTableZxbgPflAirOverproofVo"/>
        <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="zxbgOutletCode != null  and zxbgOutletCode != ''"> and zxbg_outlet_code = #{zxbgOutletCode}</if>
            <if test="zxbgPollutant != null  and zxbgPollutant != ''"> and zxbg_pollutant = #{zxbgPollutant}</if>
            <if test="zxbgDischargeTrue != null  and zxbgDischargeTrue != ''"> and zxbg_discharge_true = #{zxbgDischargeTrue}</if>
            <if test="zxbgDischargeActual != null  and zxbgDischargeActual != ''"> and zxbg_discharge_actual = #{zxbgDischargeActual}</if>
            <if test="isDelete != null  and isDelete != ''"> and is_delete = #{isDelete}</if>
            <if test="zxbgProCode != null  and zxbgProCode != ''"> and zxbg_pro_code = #{zxbgProCode}</if>
            <if test="overStartTime != null  and overStartTime != ''"> and over_start_time = #{overStartTime}</if>
            <if test="overEndTime != null  and overEndTime != ''"> and over_end_time = #{overEndTime}</if>
            <if test="overRemark != null  and overRemark != ''"> and over_remark = #{overRemark}</if>
            <if test="overUnit != null  and overUnit != ''"> and over_unit = #{overUnit}</if>
        </where>
    </select>

    <select id="selectListAndFactory" resultType="cn.cecep.talroad.domain.BStatTableZxbgPflAirOverproof">
        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_pfl_air_overproof
        <where>
            <if test="zxbgPollutant != null  and zxbgPollutant != ''"> and zxbg_pollutant like concat('%', #{zxbgPollutant}, '%')</if>
            <if test="overRemark != null  and overRemark != ''"> and over_remark like concat('%', #{overRemark}, '%') </if>
            <if test="overStartTime != null  and overStartTime != ''"> and over_start_time >= CAST(concat(#{overStartTime},':00:00') AS timestamp)</if>
            <if test="overEndTime != null  and overEndTime != ''"> and over_end_time &lt;=  CAST(concat(#{overEndTime},':59:59') AS timestamp)</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>
