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

    <resultMap type="cn.cecep.talroad.domain.BStatTableZxbgGtFuel" id="BStatTableZxbgGtFuelResult">
        <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="recordContent"    column="record_content"    />
        <result property="name"    column="name"    />
        <result property="specificInformation"    column="specific_information"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>


    <sql id="selectBStatTableZxbgGtFuelVo">
        select id, factory_id, zxbg_type, zxbg_period, record_content, name, specific_information,remark, create_time from b_stat_table_zxbg_gt_fuel
    </sql>

    <select id="selectBStatTableZxbgGtFuelList" parameterType="cn.cecep.talroad.domain.BStatTableZxbgGtFuel" resultMap="BStatTableZxbgGtFuelResult">
        <include refid="selectBStatTableZxbgGtFuelVo"/>
        <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="recordContent != null  and recordContent != ''"> and record_content = #{recordContent}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="specificInformation != null  and specificInformation != ''"> and specific_information = #{specificInformation}</if>
        </where>
    </select>

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