<?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.playlet.system.mapper.PlayletUserTaskMapper">

    <resultMap type="PlayletUserTask" id="PlayletUserTaskResult">
        <result property="id" column="id"/>
        <result property="taskId" column="task_id"/>
        <result property="userId" column="user_id"/>
        <result property="userTaskState" column="user_task_state"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateBy" column="update_by"/>
        <result property="remark" column="remark"/>
        <result property="taskStartTime" column="task_start_time"/>
        <result property="taskEndTime" column="task_end_time"/>
    </resultMap>

    <sql id="selectPlayletUserTaskVo">
        select id,
               task_id,
               user_id,
               user_task_state,
               create_time,
               update_time,
               create_by,
               update_by,
               remark,
               task_start_time,
               task_end_time
        from playlet_user_task
    </sql>

    <select id="selectPlayletUserTaskList" parameterType="PlayletUserTask" resultMap="PlayletUserTaskResult">
        <include refid="selectPlayletUserTaskVo"/>
        <where>
            <if test="taskId != null ">and task_id = #{taskId}</if>
            <if test="userId != null ">and user_id = #{userId}</if>
            <if test="userTaskState != null ">and user_task_state = #{userTaskState}</if>
            <if test="taskStartTime != null ">and task_start_time = #{taskStartTime}</if>
            <if test="taskEndTime != null ">and task_end_time = #{taskEndTime}</if>
        </where>
    </select>

    <select id="selectPlayletUserTaskById" parameterType="Long" resultMap="PlayletUserTaskResult">
        <include refid="selectPlayletUserTaskVo"/>
        where id = #{id}
    </select>

    <insert id="insertPlayletUserTask" parameterType="PlayletUserTask" useGeneratedKeys="true" keyProperty="id">
        insert into playlet_user_task
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskId != null">task_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="userTaskState != null">user_task_state,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null">remark,</if>
            <if test="taskStartTime != null">task_start_time,</if>
            <if test="taskEndTime != null">task_end_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskId != null">#{taskId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="userTaskState != null">#{userTaskState},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null">#{remark},</if>
            <if test="taskStartTime != null">#{taskStartTime},</if>
            <if test="taskEndTime != null">#{taskEndTime},</if>
        </trim>
    </insert>

    <update id="updatePlayletUserTask" parameterType="PlayletUserTask">
        update playlet_user_task
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userTaskState != null">user_task_state = #{userTaskState},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="taskStartTime != null">task_start_time = #{taskStartTime},</if>
            <if test="taskEndTime != null">task_end_time = #{taskEndTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePlayletUserTaskById" parameterType="Long">
        delete
        from playlet_user_task
        where id = #{id}
    </delete>

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

</mapper>