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

    <resultMap type="PlayletTask" id="PlayletTaskResult">
        <result property="id" column="id"/>
        <result property="taskId" column="task_id"/>
        <result property="name" column="name"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="platformType" column="platform_type"/>
        <result property="rule" column="rule"/>
        <result property="contributeStartTime" column="contribute_start_time"/>
        <result property="contributeEndTime" column="contribute_end_time"/>
        <result property="askFor" column="ask_for"/>
        <result property="totalBonus" column="total_bonus"/>
        <result property="awardDescribe" column="award_describe"/>
        <result property="state" column="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"/>
    </resultMap>

    <sql id="selectPlayletTaskVo">
        select id,
               task_id,
               name,
               start_time,
               end_time,
               platform_type,
               rule,
               contribute_start_time,
               contribute_end_time,
               ask_for,
               total_bonus,
               award_describe,
               state,
               create_time,
               update_time,
               create_by,
               update_by,
               remark
        from playlet_task
    </sql>

    <select id="selectPlayletTaskList" parameterType="PlayletTask" resultMap="PlayletTaskResult">
        <include refid="selectPlayletTaskVo"/>
        <where>
            <if test="taskId != null  and taskId != ''">and task_id = #{taskId}</if>
            <if test="name != null  and name != ''">and name like concat('%', #{name}, '%')</if>
            <if test="startTime != null ">and start_time = #{startTime}</if>
            <if test="endTime != null ">and end_time = #{endTime}</if>
            <if test="platformType != null ">and platform_type = #{platformType}</if>
            <if test="rule != null  and rule != ''">and rule = #{rule}</if>
            <if test="contributeStartTime != null ">and contribute_start_time = #{contributeStartTime}</if>
            <if test="contributeEndTime != null ">and contribute_end_time = #{contributeEndTime}</if>
            <if test="askFor != null  and askFor != ''">and ask_for = #{askFor}</if>
            <if test="totalBonus != null ">and total_bonus = #{totalBonus}</if>
            <if test="awardDescribe != null  and awardDescribe != ''">and award_describe = #{awardDescribe}</if>
            <if test="state != null ">and state = #{state}</if>
        </where>
    </select>

    <select id="selectPlayletTaskListByUser" parameterType="PlayletTask" resultMap="PlayletTaskResult">
        select
        playlet_task.`id`,
        playlet_task.`task_id`,
        playlet_task.`start_time`,
        playlet_task.`end_time`,
        playlet_task.`platform_type`,
        playlet_task.`rule`,
        playlet_task.`contribute_start_time`,
        playlet_task.`contribute_end_time`,
        playlet_task.`ask_for`,
        playlet_task.`total_bonus`,
        playlet_task.`award_describe`,
        playlet_task.`state`,
        playlet_task.`create_time`,
        playlet_task.`update_time`,
        playlet_task.`create_by`,
        playlet_task.`update_by`,
        playlet_task.`remark`
        from playlet_task right join playlet_user_task on playlet_task.`id` = playlet_user_task.`task_id`
        <where>
            playlet_user_task.`user_id` = #{userId}
            <if test="taskId != null  and taskId != ''">and playlet_task.`task_id` = #{taskId}</if>
            <if test="name != null  and name != ''">and playlet_task.`name` like concat('%', #{name}, '%')</if>
            <if test="startTime != null ">and playlet_task.`start_time` = #{startTime}</if>
            <if test="endTime != null ">and playlet_task.`end_time` = #{endTime}</if>
            <if test="platformType != null ">and playlet_task.`platform_type` = #{platformType}</if>
            <if test="rule != null  and rule != ''">and playlet_task.`rule` = #{rule}</if>
            <if test="contributeStartTime != null ">and playlet_task.`contribute_start_time` = #{contributeStartTime}</if>
            <if test="contributeEndTime != null ">and playlet_task.`contribute_end_time` = #{contributeEndTime}</if>
            <if test="askFor != null  and askFor != ''">and playlet_task.`ask_for` = #{askFor}</if>
            <if test="totalBonus != null ">and playlet_task.`total_bonus` = #{totalBonus}</if>
            <if test="awardDescribe != null  and awardDescribe != ''">and playlet_task.`award_describe` = #{awardDescribe}</if>
            <if test="state != null ">and playlet_task.`state` = #{state}</if>
        </where>
    </select>

    <select id="selectPlayletTaskById" parameterType="Long" resultMap="PlayletTaskResult">
        <include refid="selectPlayletTaskVo"/>
        where id = #{id}
    </select>

    <insert id="insertPlayletTask" parameterType="PlayletTask" useGeneratedKeys="true" keyProperty="id">
        insert into playlet_task
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskId != null and taskId != ''">task_id,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="platformType != null">platform_type,</if>
            <if test="rule != null and rule != ''">rule,</if>
            <if test="contributeStartTime != null">contribute_start_time,</if>
            <if test="contributeEndTime != null">contribute_end_time,</if>
            <if test="askFor != null and askFor != ''">ask_for,</if>
            <if test="totalBonus != null">total_bonus,</if>
            <if test="awardDescribe != null and awardDescribe != ''">award_describe,</if>
            <if test="state != null">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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskId != null and taskId != ''">#{taskId},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="platformType != null">#{platformType},</if>
            <if test="rule != null and rule != ''">#{rule},</if>
            <if test="contributeStartTime != null">#{contributeStartTime},</if>
            <if test="contributeEndTime != null">#{contributeEndTime},</if>
            <if test="askFor != null and askFor != ''">#{askFor},</if>
            <if test="totalBonus != null">#{totalBonus},</if>
            <if test="awardDescribe != null and awardDescribe != ''">#{awardDescribe},</if>
            <if test="state != null">#{state},</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>
        </trim>
    </insert>

    <update id="updatePlayletTask" parameterType="PlayletTask">
        update playlet_task
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskId != null and taskId != ''">task_id = #{taskId},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="platformType != null">platform_type = #{platformType},</if>
            <if test="rule != null and rule != ''">rule = #{rule},</if>
            <if test="contributeStartTime != null">contribute_start_time = #{contributeStartTime},</if>
            <if test="contributeEndTime != null">contribute_end_time = #{contributeEndTime},</if>
            <if test="askFor != null and askFor != ''">ask_for = #{askFor},</if>
            <if test="totalBonus != null">total_bonus = #{totalBonus},</if>
            <if test="awardDescribe != null and awardDescribe != ''">award_describe = #{awardDescribe},</if>
            <if test="state != null">state = #{state},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePlayletTaskById" parameterType="Long">
        delete
        from playlet_task
        where id = #{id}
    </delete>

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

</mapper>