<?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.moka.gdtauto.mapper.TencentAssetDramaMapper">

    <!-- 批量插入或更新短剧资产 -->
    <insert id="batchInsertOrUpdate" parameterType="java.util.List">
        INSERT INTO tencent_asset_drama (
            job_number,
            account_id,
            marketing_asset_id,
            marketing_asset_name,
            marketing_asset_type,
            created_time,
            is_deleted,
            properties
        )
        VALUES
        <foreach collection="dramas" item="item" separator=",">
            (
                #{item.jobNumber},
                #{item.accountId},
                #{item.marketingAssetId},
                #{item.marketingAssetName},
                #{item.marketingAssetType},
                #{item.createdTime},
                #{item.isDeleted},
                #{item.properties}
            )
        </foreach>
        ON DUPLICATE KEY UPDATE
            marketing_asset_name = VALUES(marketing_asset_name),
            marketing_asset_type = VALUES(marketing_asset_type),
            created_time = VALUES(created_time),
            is_deleted = VALUES(is_deleted),
            properties = VALUES(properties),
            update_time = CURRENT_TIMESTAMP
    </insert>

    <!-- randomNewAsset --> 
    <select id="randomNewAsset">
        SELECT * FROM (
            SELECT * FROM tencent_asset_drama
            WHERE job_number = #{jobNumber}
            ORDER BY marketing_asset_id DESC
            LIMIT #{best}
        ) AS temp_table
        ORDER BY RAND()
        LIMIT #{rand}
    </select>
</mapper>
