<?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="cn.com.ctop.common.module.mapper.MaterialCutFrameMapper">

    <select id="getListByVideoSignature" resultType="cn.com.ctop.common.module.entity.MaterialCutFrame">
        select a.signature,
       (select frame.url
        from ctop_material_cut_frame frame
        where frame.signature = a.signature
        order by id desc
        limit 1) as 'url',
       (select frame.image_index
        from ctop_material_cut_frame frame
        where frame.signature = a.signature
        order by id desc
        limit 1) as 'image_index',
       (select frame.id
        from ctop_material_cut_frame frame
        where frame.signature = a.signature
        order by id desc
        limit 1) as 'id'
       from (select distinct signature
      from ctop_material_cut_frame
      where video_signature = #{videoSignature}) a
    </select>


    <select id="getProgramCreativeCover" resultType="com.alibaba.fastjson.JSONObject">
      SELECT
      signature as 'signature',
      url as 'url'
      FROM ctop_material_cut_frame
      WHERE video_signature = #{signature}
      ORDER BY RAND() LIMIT 5;
    </select>

    <select id="getCutFrameByVideoMd5" resultType="com.alibaba.fastjson.JSONObject">
      SELECT
	   url as 'url',
	   signature as 'signature'
        FROM
	    ctop_material_cut_frame
        WHERE
	video_signature = (
		SELECT
			signature
		FROM
			ctop_kuaishou_video_get
		WHERE
			photo_id = #{photoId}
		LIMIT 1
	    )
        AND signature !=
        IFNULL((
	SELECT
		signature
	FROM
		ctop_kuaishou_image_get
	WHERE
		image_token = #{imageToken}
	LIMIT 1
        ),'')
        LIMIT 1
    </select>

</mapper>
