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

    <resultMap type="cn.cecep.talroad.domain.BStatTableZxbgHdGtFuel" id="BStatTableZxbgHdGtFuelResult">
        <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="unitName"    column="unit_name"    />
        <result property="unitType"    column="unit_type"    />
        <result property="fuelConsumption"    column="fuel_consumption"    />
        <result property="fuelConsumptionUnits"    column="fuel_consumption_units"    />
        <result property="coalConsumption"    column="coal_consumption"    />
        <result property="coalConsumptionUnits"    column="coal_consumption_units"    />
        <result property="ashProduction"    column="ash_production"    />
        <result property="ashProductionUits"    column="ash_production_uits"    />
        <result property="slagProduction"    column="slag_production"    />
        <result property="slagProductionUnits"    column="slag_production_units"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>


    <sql id="selectBStatTableZxbgHdGtFuelVo">
        select id, factory_id, zxbg_type, zxbg_period, unit_name, unit_type, fuel_consumption, fuel_consumption_units, coal_consumption, coal_consumption_units, ash_production, ash_production_uits, slag_production, slag_production_units, create_time from b_stat_table_zxbg_hd_gt_fuel
    </sql>

    <select id="selectBStatTableZxbgHdGtFuelList" parameterType="cn.cecep.talroad.domain.BStatTableZxbgHdGtFuel" resultMap="BStatTableZxbgHdGtFuelResult">
        <include refid="selectBStatTableZxbgHdGtFuelVo"/>
        <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="unitName != null  and unitName != ''"> and unit_name like concat('%', #{unitName}, '%')</if>
            <if test="unitType != null  and unitType != ''"> and unit_type = #{unitType}</if>
            <if test="fuelConsumption != null  and fuelConsumption != ''"> and fuel_consumption = #{fuelConsumption}</if>
            <if test="fuelConsumptionUnits != null  and fuelConsumptionUnits != ''"> and fuel_consumption_units = #{fuelConsumptionUnits}</if>
            <if test="coalConsumption != null  and coalConsumption != ''"> and coal_consumption = #{coalConsumption}</if>
            <if test="coalConsumptionUnits != null  and coalConsumptionUnits != ''"> and coal_consumption_units = #{coalConsumptionUnits}</if>
            <if test="ashProduction != null  and ashProduction != ''"> and ash_production = #{ashProduction}</if>
            <if test="ashProductionUits != null  and ashProductionUits != ''"> and ash_production_uits = #{ashProductionUits}</if>
            <if test="slagProduction != null  and slagProduction != ''"> and slag_production = #{slagProduction}</if>
            <if test="slagProductionUnits != null  and slagProductionUnits != ''"> and slag_production_units = #{slagProductionUnits}</if>
        </where>
    </select>

    <select id="selectListAndFactory" resultMap="BStatTableZxbgHdGtFuelResult">
        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_gt_fuel
        <where>
            <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>
