<?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="com.zehong.system.mapper.TInvestmentMapper">
    
    <resultMap type="TInvestment" id="TInvestmentResult">
        <result property="id"    column="id"    />
        <result property="investmentName"    column="investment_name"    />
        <result property="investmentYear"    column="investment_year"    />
        <result property="investmentFunds"    column="investment_funds"    />
        <result property="investmentType"    column="investment_type"    />
        <result property="income"    column="income"    />
        <result property="drawType"    column="draw_type"    />
        <result property="timeUnit"    column="time_unit"    />
        <result property="evaluate"    column="evaluate"    />
        <result property="projectName"    column="project_name"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectTInvestmentVo">
        select id, investment_name, investment_year, investment_funds, investment_type, income, draw_type, time_unit, evaluate, project_name, create_time, update_time from t_investment
    </sql>

    <select id="selectTInvestmentList" parameterType="TInvestment" resultMap="TInvestmentResult">
        <include refid="selectTInvestmentVo"/>
        <where>  
            <if test="investmentName != null  and investmentName != ''"> and investment_name like concat('%', #{investmentName}, '%')</if>
            <if test="investmentYear != null  and investmentYear != ''"> and investment_year = #{investmentYear}</if>
            <if test="investmentFunds != null  and investmentFunds != ''"> and investment_funds = #{investmentFunds}</if>
            <if test="investmentType != null  and investmentType != ''"> and investment_type = #{investmentType}</if>
            <if test="income != null  and income != ''"> and income = #{income}</if>
            <if test="drawType != null  and drawType != ''"> and draw_type = #{drawType}</if>
            <if test="timeUnit != null  and timeUnit != ''"> and time_unit = #{timeUnit}</if>
            <if test="evaluate != null  and evaluate != ''"> and evaluate = #{evaluate}</if>
            <if test="projectName != null  and projectName != ''"> and project_name like concat('%', #{projectName}, '%')</if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
        </where>
    </select>
    
    <select id="selectTInvestmentById" parameterType="Long" resultMap="TInvestmentResult">
        <include refid="selectTInvestmentVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTInvestment" parameterType="TInvestment" useGeneratedKeys="true" keyProperty="id">
        insert into t_investment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="investmentName != null">investment_name,</if>
            <if test="investmentYear != null">investment_year,</if>
            <if test="investmentFunds != null">investment_funds,</if>
            <if test="investmentType != null">investment_type,</if>
            <if test="income != null">income,</if>
            <if test="drawType != null">draw_type,</if>
            <if test="timeUnit != null">time_unit,</if>
            <if test="evaluate != null">evaluate,</if>
            <if test="projectName != null">project_name,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="investmentName != null">#{investmentName},</if>
            <if test="investmentYear != null">#{investmentYear},</if>
            <if test="investmentFunds != null">#{investmentFunds},</if>
            <if test="investmentType != null">#{investmentType},</if>
            <if test="income != null">#{income},</if>
            <if test="drawType != null">#{drawType},</if>
            <if test="timeUnit != null">#{timeUnit},</if>
            <if test="evaluate != null">#{evaluate},</if>
            <if test="projectName != null">#{projectName},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateTInvestment" parameterType="TInvestment">
        update t_investment
        <trim prefix="SET" suffixOverrides=",">
            <if test="investmentName != null">investment_name = #{investmentName},</if>
            <if test="investmentYear != null">investment_year = #{investmentYear},</if>
            <if test="investmentFunds != null">investment_funds = #{investmentFunds},</if>
            <if test="investmentType != null">investment_type = #{investmentType},</if>
            income = #{income},
            <if test="drawType != null">draw_type = #{drawType},</if>
            time_unit = #{timeUnit},
            project_name = #{projectName},
            <if test="evaluate != null">evaluate = #{evaluate},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTInvestmentById" parameterType="Long">
        delete from t_investment where id = #{id}
    </delete>

    <delete id="deleteTInvestmentByIds" parameterType="String">
        delete from t_investment where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>