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

    <resultMap type="cn.cecep.talroad.domain.BStatTableZxbgHdGtBasic" id="BStatTableZxbgHdGtBasicResult">
        <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="scale"    column="scale"    />
        <result property="runTime"    column="run_time"    />
        <result property="powerGeneration"    column="power_generation"    />
        <result property="heatSupply"    column="heat_supply"    />
        <result property="actualRunningTime"    column="actual_running_time"    />
        <result property="averageLoadRatio"    column="average_load_ratio"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>


    <sql id="selectBStatTableZxbgHdGtBasicVo">
        select id, factory_id, zxbg_type, zxbg_period, unit_name, scale, run_time, power_generation, heat_supply, actual_running_time, average_load_ratio, remark, create_time from b_stat_table_zxbg_hd_gt_basic
    </sql>

    <select id="selectBStatTableZxbgHdGtBasicList" parameterType="cn.cecep.talroad.domain.BStatTableZxbgHdGtBasic" resultMap="BStatTableZxbgHdGtBasicResult">
        <include refid="selectBStatTableZxbgHdGtBasicVo"/>
        <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="scale != null  and scale != ''"> and scale = #{scale}</if>
            <if test="runTime != null  and runTime != ''"> and run_time = #{runTime}</if>
            <if test="powerGeneration != null  and powerGeneration != ''"> and power_generation = #{powerGeneration}</if>
            <if test="heatSupply != null  and heatSupply != ''"> and heat_supply = #{heatSupply}</if>
            <if test="actualRunningTime != null  and actualRunningTime != ''"> and actual_running_time = #{actualRunningTime}</if>
            <if test="averageLoadRatio != null  and averageLoadRatio != ''"> and average_load_ratio = #{averageLoadRatio}</if>
        </where>
    </select>

    <select id="selectListAndFactory" resultMap="BStatTableZxbgHdGtBasicResult">
        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_basic
        <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>
