<?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.BatchPublishItemMapper">
    
    <resultMap type="com.ruoyi.jarvis.domain.BatchPublishItem" id="BatchPublishItemResult">
        <result property="id"    column="id"    />
        <result property="taskId"    column="task_id"    />
        <result property="skuid"    column="skuid"    />
        <result property="productName"    column="product_name"    />
        <result property="targetAccount"    column="target_account"    />
        <result property="accountRemark"    column="account_remark"    />
        <result property="subAccount"    column="sub_account"    />
        <result property="status"    column="status"    />
        <result property="productId"    column="product_id"    />
        <result property="productStatus"    column="product_status"    />
        <result property="outerId"    column="outer_id"    />
        <result property="publishPrice"    column="publish_price"    />
        <result property="errorMessage"    column="error_message"    />
        <result property="execLog"    column="exec_log"    />
        <result property="publishTime"    column="publish_time"    />
        <result property="delaySeconds"    column="delay_seconds"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectBatchPublishItemVo">
        select id, task_id, skuid, product_name, target_account, account_remark, sub_account, status, 
               product_id, product_status, outer_id, publish_price, error_message, exec_log,
               publish_time, delay_seconds, create_time 
        from batch_publish_item
    </sql>

    <select id="selectBatchPublishItemList" parameterType="com.ruoyi.jarvis.domain.BatchPublishItem" resultMap="BatchPublishItemResult">
        <include refid="selectBatchPublishItemVo"/>
        <where>  
            <if test="taskId != null "> and task_id = #{taskId}</if>
            <if test="skuid != null  and skuid != ''"> and skuid = #{skuid}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="targetAccount != null  and targetAccount != ''"> and target_account = #{targetAccount}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectBatchPublishItemById" parameterType="Long" resultMap="BatchPublishItemResult">
        <include refid="selectBatchPublishItemVo"/>
        where id = #{id}
    </select>

    <select id="selectBatchPublishItemByTaskId" parameterType="Long" resultMap="BatchPublishItemResult">
        <include refid="selectBatchPublishItemVo"/>
        where task_id = #{taskId}
        order by create_time asc
    </select>
        
    <insert id="insertBatchPublishItem" parameterType="com.ruoyi.jarvis.domain.BatchPublishItem" useGeneratedKeys="true" keyProperty="id">
        insert into batch_publish_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskId != null">task_id,</if>
            <if test="skuid != null">skuid,</if>
            <if test="productName != null">product_name,</if>
            <if test="targetAccount != null">target_account,</if>
            <if test="accountRemark != null">account_remark,</if>
            <if test="subAccount != null">sub_account,</if>
            <if test="status != null">status,</if>
            <if test="productId != null">product_id,</if>
            <if test="productStatus != null">product_status,</if>
            <if test="outerId != null">outer_id,</if>
            <if test="publishPrice != null">publish_price,</if>
            <if test="errorMessage != null">error_message,</if>
            <if test="publishTime != null">publish_time,</if>
            <if test="delaySeconds != null">delay_seconds,</if>
            <if test="createTime != null">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskId != null">#{taskId},</if>
            <if test="skuid != null">#{skuid},</if>
            <if test="productName != null">#{productName},</if>
            <if test="targetAccount != null">#{targetAccount},</if>
            <if test="accountRemark != null">#{accountRemark},</if>
            <if test="subAccount != null">#{subAccount},</if>
            <if test="status != null">#{status},</if>
            <if test="productId != null">#{productId},</if>
            <if test="productStatus != null">#{productStatus},</if>
            <if test="outerId != null">#{outerId},</if>
            <if test="publishPrice != null">#{publishPrice},</if>
            <if test="errorMessage != null">#{errorMessage},</if>
            <if test="publishTime != null">#{publishTime},</if>
            <if test="delaySeconds != null">#{delaySeconds},</if>
            <if test="createTime != null">#{createTime},</if>
        </trim>
    </insert>

    <insert id="batchInsertBatchPublishItem" parameterType="java.util.List">
        insert into batch_publish_item
        (task_id, skuid, product_name, target_account, account_remark, status, publish_price, delay_seconds, create_time
        <if test="list != null and list.size() > 0 and list[0].subAccount != null">
            , sub_account
        </if>
        )
        values
        <foreach collection="list" item="item" separator=",">
            (#{item.taskId}, #{item.skuid}, #{item.productName}, #{item.targetAccount}, #{item.accountRemark}, 
             #{item.status}, #{item.publishPrice}, #{item.delaySeconds}, #{item.createTime}
            <if test="list != null and list.size() > 0 and list[0].subAccount != null">
                , #{item.subAccount}
            </if>
            )
        </foreach>
    </insert>

    <update id="updateBatchPublishItem" parameterType="com.ruoyi.jarvis.domain.BatchPublishItem">
        update batch_publish_item
        <trim prefix="SET" suffixOverrides=",">
            <if test="status != null">status = #{status},</if>
            <if test="productId != null">product_id = #{productId},</if>
            <if test="productStatus != null">product_status = #{productStatus},</if>
            <if test="outerId != null">outer_id = #{outerId},</if>
            <if test="errorMessage != null">error_message = #{errorMessage},</if>
            <if test="execLog != null">exec_log = #{execLog},</if>
            <if test="publishTime != null">publish_time = #{publishTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBatchPublishItemById" parameterType="Long">
        delete from batch_publish_item where id = #{id}
    </delete>

</mapper>

