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

    <resultMap type="cn.cecep.talroad.domain.BStatTableZxbgSnFuel" id="BStatTableZxbgSnFuelResult">
        <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="parameter"    column="parameter"    />
        <result property="recordTheContent"    column="record_the_content"    />
        <result property="name"    column="name"    />
        <result property="remark"    column="remark"    />
        <result property="type"    column="type"    />
        <result property="usage"    column="usage"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>


    <sql id="selectBStatTableZxbgSnFuelVo">
        select id, factory_id, zxbg_type, zxbg_period, parameter, record_the_content, name, remark, type, usage, create_time from b_stat_table_zxbg_sn_fuel
    </sql>

    <select id="selectBStatTableZxbgSnFuelList" parameterType="cn.cecep.talroad.domain.BStatTableZxbgSnFuel" resultMap="BStatTableZxbgSnFuelResult">
        <include refid="selectBStatTableZxbgSnFuelVo"/>
        <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="parameter != null  and parameter != ''"> and parameter = #{parameter}</if>
            <if test="recordTheContent != null  and recordTheContent != ''"> and record_the_content = #{recordTheContent}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="usage != null  and usage != ''"> and usage = #{usage}</if>
        </where>
    </select>

    <select id="selectListAndFactory" resultMap="BStatTableZxbgSnFuelResult">
        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_sn_fuel
        <where>
            <if test="zxbgParam != null  and zxbgParam != ''"> and parameter like concat('%', #{zxbgParam}, '%')</if>
            <if test="zxbgRecord != null  and zxbgRecord != ''"> and record_the_content like concat('%', #{zxbgRecord}, '%')</if>
            <if test="zxbgName != null  and zxbgName != ''"> and name like concat('%', #{zxbgName}, '%')</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>
