<?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="itemId" column="item_id"/>
        <result property="peopleNumber" column="people_number"/>
        <result property="commissionRate" column="commission_rate"/>
        <result property="recommendLabel" column="recommend_label"/>
        <result property="taskUrl" column="task_url"/>
        <result property="taskDiskUrl" column="task_disk_url"/>
        <result property="totalBonus" column="total_bonus"/>
        <result property="videoCount" column="video_count"/>
        <result property="playCount" column="play_count"/>
        <result property="starCount" column="star_count"/>
        <result property="commentCount" column="comment_count"/>
        <result property="baseBonus" column="base_bonus"/>
        <result property="taskContent" column="task_content"/>
        <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"/>
        <result property="dyStatus" column="dy_status"  />
        <result property="ksStatus" column="ks_status"  />
        <result property="dspStatus" column="dsp_status"  />
    </resultMap>

    <sql id="selectPlayletTaskVo">
        select id,
               task_id,
               name,
               item_id,
               people_number,
               commission_rate,
               recommend_label,
               task_url,
               task_disk_url,
               start_time,
               end_time,
               platform_type,
               base_bonus,
               total_bonus,
               state,
               ks_status,
               dy_status,
               dsp_status,
               task_content,
               comment_count,
               star_count,
               play_count,
               video_count,
               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="state != null ">and state = #{state}</if>
            <if test="ksStatus != null ">and ks_status = #{ksStatus}</if>
            <if test="dyStatus != null ">and dy_status = #{dyStatus}</if>
            <if test="dspStatus != null ">and dsp_status = #{dspStatus}</if>
        </where>
    </select>

    <select id="selectPlayletTaskListByUser" parameterType="PlayletTask" resultMap="PlayletTaskResult">
        select
        playlet_task.id,
        playlet_task.task_id,
        playlet_task.name,
        playlet_task.item_id,
        playlet_task.ks_status,
        playlet_task.dy_status,
        playlet_task.dsp_status,
        playlet_task.people_number,
        playlet_task.commission_rate,
        playlet_task.recommend_label,
        playlet_task.task_url,
        playlet_task.task_disk_url,
        playlet_task.start_time,
        playlet_task.end_time,
        playlet_task.platform_type,
        playlet_task.base_bonus,
        playlet_task.total_bonus,
        playlet_task.state,
        playlet_task.task_content,
        playlet_task.comment_count,
        playlet_task.star_count,
        playlet_task.play_count,
        playlet_task.video_count,
        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="totalBonus != null ">and playlet_task.`total_bonus` = #{totalBonus}</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="itemId != null and itemId != ''">item_id,</if>
            <if test="peopleNumber != null and peopleNumber != ''">people_number,</if>
            <if test="commissionRate != null and commissionRate != ''">commission_rate,</if>
            <if test="recommendLabel != null and recommendLabel != ''">recommend_label,</if>
            <if test="taskUrl != null and taskUrl != ''">task_url,</if>
            <if test="taskDiskUrl != null and taskDiskUrl != ''">task_disk_url,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="platformType != null">platform_type,</if>
            <if test="baseBonus != null">base_bonus,</if>
            <if test="totalBonus != null">total_bonus,</if>
            <if test="state != null">state,</if>
            <if test="taskContent != null">task_content,</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="ksStatus != null">ks_status,</if>
            <if test="dyStatus != null">dy_status,</if>
            <if test="dspStatus != null">dsp_status,</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="itemId != null and itemId != ''">#{itemId},</if>
            <if test="peopleNumber != null and peopleNumber != ''">#{peopleNumber},</if>
            <if test="commissionRate != null and commissionRate != ''">#{commissionRate},</if>
            <if test="recommendLabel != null and recommendLabel != ''">#{recommendLabel},</if>
            <if test="taskUrl != null and taskUrl != ''">#{taskUrl},</if>
            <if test="taskDiskUrl != null and taskDiskUrl != ''">#{taskDiskUrl},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="platformType != null">#{platformType},</if>
            <if test="baseBonus != null">#{baseBonus},</if>
            <if test="totalBonus != null">#{totalBonus},</if>
            <if test="state != null">#{state},</if>
            <if test="taskContent != null">#{taskContent},</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="ksStatus != null">#{ksStatus},</if>
            <if test="dyStatus != null">#{dyStatus},</if>
            <if test="dspStatus != null">#{dspStatus},</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="itemId != null and itemId != ''">item_id = #{itemId},</if>
            <if test="peopleNumber != null and peopleNumber != ''">people_number = #{peopleNumber},</if>
            <if test="commissionRate != null and commissionRate != ''">commission_rate = #{commissionRate},</if>
            <if test="recommendLabel != null and recommendLabel != ''">recommend_label = #{recommendLabel},</if>
            <if test="taskUrl != null and taskUrl != ''">task_url = #{taskUrl},</if>
            <if test="taskDiskUrl != null and taskDiskUrl != ''">task_disk_url = #{taskDiskUrl},</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="baseBonus != null">base_bonus = #{baseBonus},</if>
            <if test="totalBonus != null">total_bonus = #{totalBonus},</if>
            <if test="state != null">state = #{state},</if>
            <if test="taskContent != null">task_content = #{taskContent},</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="ksStatus != null">ks_status = #{ksStatus},</if>
            <if test="dyStatus != null">dy_status = #{dyStatus},</if>
            <if test="dspStatus != null">dsp_status = #{dspStatus},</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>