<?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.activiti6.mapper.DbTableHisMapper">

    <resultMap type="com.activiti6.domain.DbTableHis" id="DbTableHisResult">
        <result property="instanceId"    column="instance_id"    />
        <result property="tableId"    column="table_id"    />
        <result property="tableName"    column="table_name"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectDbTableHisVo">
        select instance_id, table_id, table_name, create_by, create_time, update_by, update_time from t_table_his
    </sql>

    <select id="selectDbTableHisList" parameterType="com.activiti6.domain.DbTableHis" resultMap="DbTableHisResult">
        <include refid="selectDbTableHisVo"/>
        <where>
            <if test="instanceId != null  and instanceId != ''"> and instance_id = #{instanceId}</if>
            <if test="tableId != null  and tableId != ''"> and table_id = #{tableId}</if>
            <if test="tableName != null  and tableName != ''"> and table_name like concat('%', #{tableName}, '%')</if>
        </where>
    </select>

    <select id="selectDbTableHisById" parameterType="String" resultMap="DbTableHisResult">
        <include refid="selectDbTableHisVo"/>
        where instance_id = #{instanceId}
        ORDER BY
        create_time DESC LIMIT 1
    </select>

    <insert id="insertDbTableHis" parameterType="com.activiti6.domain.DbTableHis">
        insert into t_table_his
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="instanceId != null  and instanceId != ''">instance_id,</if>
            <if test="tableId != null  and tableId != ''">table_id,</if>
            <if test="tableName != null  and tableName != ''">table_name,</if>
            <if test="createBy != null  and createBy != ''">create_by,</if>
            <if test="createTime != null ">create_time,</if>
            <if test="updateBy != null  and updateBy != ''">update_by,</if>
            <if test="updateTime != null ">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="instanceId != null  and instanceId != ''">#{instanceId},</if>
            <if test="tableId != null  and tableId != ''">#{tableId},</if>
            <if test="tableName != null  and tableName != ''">#{tableName},</if>
            <if test="createBy != null  and createBy != ''">#{createBy},</if>
            <if test="createTime != null ">#{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">#{updateBy},</if>
            <if test="updateTime != null ">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateDbTableHis" parameterType="com.activiti6.domain.DbTableHis">
        update t_table_his
        <trim prefix="SET" suffixOverrides=",">
            <if test="tableId != null  and tableId != ''">table_id = #{tableId},</if>
            <if test="tableName != null  and tableName != ''">table_name = #{tableName},</if>
            <if test="createBy != null  and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null ">create_time = #{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null ">update_time = #{updateTime},</if>
        </trim>
        where instance_id = #{instanceId}
    </update>

    <delete id="deleteDbTableHisById" parameterType="String">
        delete from t_table_his where instance_id = #{instanceId}
    </delete>

    <delete id="deleteDbTableHisByIds" parameterType="String">
        delete from t_table_his where instance_id in
        <foreach item="instanceId" collection="array" open="(" separator="," close=")">
            #{instanceId}
        </foreach>
    </delete>

</mapper>
