<?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.ruoyi.jarvis.mapper.BatchPublishTaskMapper">
    
    <resultMap type="com.ruoyi.jarvis.domain.BatchPublishTask" id="BatchPublishTaskResult">
        <result property="id"    column="id"    />
        <result property="taskName"    column="task_name"    />
        <result property="originalMessage"    column="original_message"    />
        <result property="totalProducts"    column="total_products"    />
        <result property="selectedProducts"    column="selected_products"    />
        <result property="targetAccounts"    column="target_accounts"    />
        <result property="status"    column="status"    />
        <result property="successCount"    column="success_count"    />
        <result property="failCount"    column="fail_count"    />
        <result property="commonParams"    column="common_params"    />
        <result property="createUserId"    column="create_user_id"    />
        <result property="createUserName"    column="create_user_name"    />
        <result property="createTime"    column="create_time"    />
        <result property="completeTime"    column="complete_time"    />
    </resultMap>

    <sql id="selectBatchPublishTaskVo">
        select id, task_name, original_message, total_products, selected_products, target_accounts, 
               status, success_count, fail_count, common_params, create_user_id, create_user_name, 
               create_time, complete_time 
        from batch_publish_task
    </sql>

    <select id="selectBatchPublishTaskList" parameterType="com.ruoyi.jarvis.domain.BatchPublishTask" resultMap="BatchPublishTaskResult">
        <include refid="selectBatchPublishTaskVo"/>
        <where>  
            <if test="taskName != null  and taskName != ''"> and task_name like concat('%', #{taskName}, '%')</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="createUserId != null "> and create_user_id = #{createUserId}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectBatchPublishTaskById" parameterType="Long" resultMap="BatchPublishTaskResult">
        <include refid="selectBatchPublishTaskVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertBatchPublishTask" parameterType="com.ruoyi.jarvis.domain.BatchPublishTask" useGeneratedKeys="true" keyProperty="id">
        insert into batch_publish_task
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskName != null and taskName != ''">task_name,</if>
            <if test="originalMessage != null">original_message,</if>
            <if test="totalProducts != null">total_products,</if>
            <if test="selectedProducts != null">selected_products,</if>
            <if test="targetAccounts != null">target_accounts,</if>
            <if test="status != null">status,</if>
            <if test="successCount != null">success_count,</if>
            <if test="failCount != null">fail_count,</if>
            <if test="commonParams != null">common_params,</if>
            <if test="createUserId != null">create_user_id,</if>
            <if test="createUserName != null">create_user_name,</if>
            <if test="createTime != null">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskName != null and taskName != ''">#{taskName},</if>
            <if test="originalMessage != null">#{originalMessage},</if>
            <if test="totalProducts != null">#{totalProducts},</if>
            <if test="selectedProducts != null">#{selectedProducts},</if>
            <if test="targetAccounts != null">#{targetAccounts},</if>
            <if test="status != null">#{status},</if>
            <if test="successCount != null">#{successCount},</if>
            <if test="failCount != null">#{failCount},</if>
            <if test="commonParams != null">#{commonParams},</if>
            <if test="createUserId != null">#{createUserId},</if>
            <if test="createUserName != null">#{createUserName},</if>
            <if test="createTime != null">#{createTime},</if>
        </trim>
    </insert>

    <update id="updateBatchPublishTask" parameterType="com.ruoyi.jarvis.domain.BatchPublishTask">
        update batch_publish_task
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskName != null and taskName != ''">task_name = #{taskName},</if>
            <if test="status != null">status = #{status},</if>
            <if test="successCount != null">success_count = #{successCount},</if>
            <if test="failCount != null">fail_count = #{failCount},</if>
            <if test="completeTime != null">complete_time = #{completeTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBatchPublishTaskById" parameterType="Long">
        delete from batch_publish_task where id = #{id}
    </delete>

</mapper>

