<?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.bonus.material.task.mapper.TmTaskAuditLogMapper">
    <resultMap type="com.bonus.material.task.domain.TmTaskAuditLog" id="TmTaskAuditLogResult">
        <result property="id"    column="id"    />
        <result property="taskId"    column="task_id"    />
        <result property="taskType"    column="task_type"    />
        <result property="roleId"    column="role_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectTmTaskAuditLogVo">
        select id, task_id, task_type, role_id, create_by, create_time, update_by, update_time, remark from tm_task_audit_log
    </sql>

    <select id="selectTmTaskAuditLogList" parameterType="com.bonus.material.task.domain.TmTaskAuditLog" resultMap="TmTaskAuditLogResult">
        <include refid="selectTmTaskAuditLogVo"/>
        <where>  
            <if test="taskId != null "> and task_id = #{taskId}</if>
            <if test="taskType != null "> and task_type = #{taskType}</if>
            <if test="roleId != null  and roleId != ''"> and role_id = #{roleId}</if>
        </where>
    </select>

    <select id="selectTmTaskAuditRoleList" parameterType="com.bonus.material.task.domain.TmTaskAuditLog" resultType="java.lang.String">
        select role_id
        from tm_task_audit_log
        <where>
            <if test="taskId != null "> and task_id = #{taskId}</if>
            <if test="taskType != null "> and task_type = #{taskType}</if>
        </where>
    </select>
    
    <select id="selectTmTaskAuditLogById" parameterType="Long" resultMap="TmTaskAuditLogResult">
        <include refid="selectTmTaskAuditLogVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTmTaskAuditLog" parameterType="com.bonus.material.task.domain.TmTaskAuditLog" useGeneratedKeys="true" keyProperty="id">
        insert into tm_task_audit_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskId != null">task_id,</if>
            <if test="taskType != null">task_type,</if>
            <if test="roleId != null">role_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskId != null">#{taskId},</if>
            <if test="taskType != null">#{taskType},</if>
            <if test="roleId != null">#{roleId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateTmTaskAuditLog" parameterType="com.bonus.material.task.domain.TmTaskAuditLog">
        update tm_task_audit_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="taskType != null">task_type = #{taskType},</if>
            <if test="roleId != null">role_id = #{roleId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTmTaskAuditLogById" parameterType="Long">
        delete from tm_task_audit_log where id = #{id}
    </delete>

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