<?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.kuaishou.modules.dimension.mapper.KuaiShouDimensionMaterialMapper">

    <insert id="addBatch">
        replace into ctop_kuaishou_dimension_material(
        strategy_id,
        photo_id

        )
        values
        <foreach collection="addList" item="ad" separator=",">
            (
            #{ad.strategyId},
            #{ad.photoId}

            )
        </foreach>

    </insert>


    <select id="getVideoList" resultType="com.alibaba.fastjson.JSONObject">
        SELECT
        t1.photo_id AS 'photoId',
        t1.cover_url AS 'coverUrl',
        t1.url AS 'photoUrl',
        t1.channel_type AS 'channelType',
        t1.stat_date AS 'statDate',
        t1.photo_name AS 'photoName',
        (
        CASE
        WHEN t2.id IS NULL THEN
        1
        ELSE
        0
        END
        ) AS 'useStatus'
        FROM
        (
        SELECT
        *
        FROM
        ctop_kuaishou_video_get
        WHERE
        account_id = #{accountId}
        <if test="startDate != null and startDate != '' ">
            AND stat_date &gt;= #{startDate}
        </if>
        <if test="endDate != null and endDate != '' ">
            AND stat_date &lt;= #{endDate}
        </if>
        ) t1
        LEFT JOIN (
        SELECT
        id,
        photo_id
        FROM
        ctop_kuaishou_dimension_material
        where strategy_id = #{strategyId}
        group by photo_id
        ) t2 ON t1.photo_id = t2.photo_id
        ORDER BY
        t1.stat_date DESC
    </select>
    <select id="getSignatureByPhotoId" resultType="java.lang.String">
        select  signature  from ctop_kuaishou_video_get
        where photo_id = #{photoId}
        and signature is  not null
        limit 1
    </select>
</mapper>