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

    <resultMap type="cn.cecep.talroad.domain.BStatTableZxbgWrzlTotal" id="BStatTableZxbgWrzlTotalResult">
        <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="zxbgPollutant"    column="zxbg_pollutant"    />
        <result property="pollutionControlFacilityCode"    column="pollution_control_facility_code"    />
        <result property="pollutionControlFacilityName"    column="pollution_control_facility_name"    />
        <result property="processParameter"    column="process_parameter"    />
        <result property="amount"    column="amount"    />
        <result property="unit"    column="unit"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>


    <sql id="selectBStatTableZxbgWrzlTotalVo">
        select id, factory_id, zxbg_type, zxbg_period, zxbg_pollutant, pollution_control_facility_code, pollution_control_facility_name, process_parameter, amount, unit, remark, create_time from b_stat_table_zxbg_wrzl_total
    </sql>

    <select id="selectBStatTableZxbgWrzlTotalList" parameterType="cn.cecep.talroad.domain.BStatTableZxbgWrzlTotal" resultMap="BStatTableZxbgWrzlTotalResult">
        <include refid="selectBStatTableZxbgWrzlTotalVo"/>
        <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="zxbgPollutant != null  and zxbgPollutant != ''"> and zxbg_pollutant = #{zxbgPollutant}</if>
            <if test="pollutionControlFacilityCode != null  and pollutionControlFacilityCode != ''"> and pollution_control_facility_code = #{pollutionControlFacilityCode}</if>
            <if test="pollutionControlFacilityName != null  and pollutionControlFacilityName != ''"> and pollution_control_facility_name like concat('%', #{pollutionControlFacilityName}, '%')</if>
            <if test="processParameter != null  and processParameter != ''"> and process_parameter = #{processParameter}</if>
            <if test="amount != null  and amount != ''"> and amount = #{amount}</if>
            <if test="unit != null  and unit != ''"> and unit = #{unit}</if>
        </where>
    </select>

    <select id="selectListAndFactory" resultMap="BStatTableZxbgWrzlTotalResult">
        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_wrzl_total
        <where>
            <if test="processParameter != null  and processParameter != ''"> and process_parameter like concat('%',#{processParameter}, '%')</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>

    <select id="selectByPeriodAndTypeAndRecords"
            resultMap="BStatTableZxbgWrzlTotalResult">
        select id,
        factory_id,
        zxbg_type,
        zxbg_period,
        zxbg_pollutant,
        pollution_control_facility_code,
        pollution_control_facility_name,
        process_parameter,
        amount,
        unit,
        remark,
        create_time
        from b_stat_table_zxbg_wrzl_total
        WHERE zxbg_type = #{type,jdbcType=VARCHAR}
        AND zxbg_period = #{period,jdbcType=VARCHAR}
        AND zxbg_pollutant = #{pollutant,jdbcType=VARCHAR}
        AND factory_id IN
        <foreach collection="factoryIds" separator="," item="item" close=")" open="(">
            #{item,jdbcType=VARCHAR}
        </foreach>
    </select>

    <select id="selectFactoryIdsListByPeriod" resultType="java.lang.String">
        select factory_id
        from b_stat_table_zxbg_wrzl_total
        WHERE zxbg_type = #{type,jdbcType=VARCHAR}
        AND zxbg_period = #{period,jdbcType=VARCHAR}
        AND zxbg_pollutant = #{pollutant,jdbcType=VARCHAR}
    </select>
</mapper>
