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

    <resultMap type="cn.cecep.talroad.domain.BStatTableZxbgHdGtInvestment" id="BStatTableZxbgHdGtInvestmentResult">
        <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="governanceType"    column="governance_type"    />
        <result property="startTime"    column="start_time"    />
        <result property="productionTime"    column="production_time"    />
        <result property="plannedInvestment"    column="planned_investment"    />
        <result property="cycleCompleteInvestment"    column="cycle_complete_investment"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>


    <sql id="selectBStatTableZxbgHdGtInvestmentVo">
        select id, factory_id, zxbg_type, zxbg_period, unit_name, governance_type, start_time, production_time, planned_investment, cycle_complete_investment,  create_time from b_stat_table_zxbg_hd_gt_investment
    </sql>

    <select id="selectBStatTableZxbgHdGtInvestmentList" parameterType="cn.cecep.talroad.domain.BStatTableZxbgHdGtInvestment" resultMap="BStatTableZxbgHdGtInvestmentResult">
        <include refid="selectBStatTableZxbgHdGtInvestmentVo"/>
        <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="governanceType != null  and governanceType != ''"> and governance_type = #{governanceType}</if>
            <if test="startTime != null  and startTime != ''"> and start_time = #{startTime}</if>
            <if test="productionTime != null  and productionTime != ''"> and production_time = #{productionTime}</if>
            <if test="plannedInvestment != null  and plannedInvestment != ''"> and planned_investment = #{plannedInvestment}</if>
            <if test="cycleCompleteInvestment != null  and cycleCompleteInvestment != ''"> and cycle_complete_investment = #{cycleCompleteInvestment}</if>
        </where>
    </select>

    <select id="selectListAndFactory" resultMap="BStatTableZxbgHdGtInvestmentResult">
        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_investment
        <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>
