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

    <resultMap type="cn.cecep.talroad.domain.BStatTableZxbgHdFuelAnalysis" id="BStatTableZxbgHdFuelAnalysisResult">
        <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="productionUnit"    column="production_unit"    />
        <result property="fuelName"    column="fuel_name"    />
        <result property="usage"    column="usage"    />
        <result property="ashContent"    column="ash_content"    />
        <result property="sulfur"    column="sulfur"    />
        <result property="volatileContent"    column="volatile_content"    />
        <result property="caloricValue"    column="caloric_value"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>


    <sql id="selectBStatTableZxbgHdFuelAnalysisVo">
        select id, factory_id, zxbg_type, zxbg_period, production_unit, fuel_name, usage, ash_content, sulfur, volatile_content, caloric_value, remark, create_time from b_stat_table_zxbg_hd_fuel_analysis
    </sql>

    <select id="selectBStatTableZxbgHdFuelAnalysisList" parameterType="cn.cecep.talroad.domain.BStatTableZxbgHdFuelAnalysis" resultMap="BStatTableZxbgHdFuelAnalysisResult">
        <include refid="selectBStatTableZxbgHdFuelAnalysisVo"/>
        <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="productionUnit != null  and productionUnit != ''"> and production_unit = #{productionUnit}</if>
            <if test="fuelName != null  and fuelName != ''"> and fuel_name like concat('%', #{fuelName}, '%')</if>
            <if test="usage != null  and usage != ''"> and usage = #{usage}</if>
            <if test="ashContent != null  and ashContent != ''"> and ash_content = #{ashContent}</if>
            <if test="sulfur != null  and sulfur != ''"> and sulfur = #{sulfur}</if>
            <if test="volatileContent != null  and volatileContent != ''"> and volatile_content = #{volatileContent}</if>
            <if test="caloricValue != null  and caloricValue != ''"> and caloric_value = #{caloricValue}</if>
        </where>
    </select>

    <select id="selectListAndFactory" resultMap="BStatTableZxbgHdFuelAnalysisResult">
        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_hd_fuel_analysis
        <where>
            <if test="productionUnit != null  and productionUnit != ''"> and production_unit  like concat('%', #{productionUnit}, '%')</if>
            <if test="fuelName != null  and fuelName != ''"> and fuel_name like concat('%', #{fuelName}, '%')</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>
