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

    <!-- 随机获取一个创意图片：按normalCnt降序取前100，再随机取1个 -->
    <select id="selectOneCreativeImage" resultType="com.moka.gdtauto.entity.OssFile">
        SELECT * FROM (
            SELECT * FROM oss_file
            WHERE business_type = 1
              AND file_type = 'image'
            <if test="excludeIds != null and excludeIds.size() > 0">
              AND id NOT IN
              <foreach collection="excludeIds" item="id" open="(" separator="," close=")">
                  #{id}
              </foreach>
            </if>
            ORDER BY normal_cnt DESC
            LIMIT 20
        ) t
        ORDER BY RAND()
        LIMIT 1
    </select>

    <!-- 随机获取一个创意视频：按normalCnt降序取前100，再随机取1个 -->
    <select id="selectOneCreativeVideo" resultType="com.moka.gdtauto.entity.OssFile">
        SELECT * FROM (
            SELECT * FROM oss_file
            WHERE business_type = 1
              AND file_type = 'video'
            <if test="excludeIds != null and excludeIds.size() > 0">
              AND id NOT IN
              <foreach collection="excludeIds" item="id" open="(" separator="," close=")">
                  #{id}
              </foreach>
            </if>
            ORDER BY normal_cnt DESC
            LIMIT 20
        ) t
        ORDER BY RAND()
        LIMIT 1
    </select>

</mapper>
