<?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.crm.web.dao.mapper.WebVideoMapper">


    <select id="countList"
            parameterType="com.crm.rely.backend.model.entity.web.video.WebVideoSearchListEntity"
            resultType="Integer">
        select count( web_video.id)
        from web_video
        <where>
            <if test="startDate != null">
                AND web_video.add_time>#{startDate}
            </if>
            <if test="endDate != null">
                AND #{endDate}>web_video.add_time
            </if>
        </where>
    </select>

    <select id="pageList"
            parameterType="com.crm.rely.backend.model.entity.web.video.WebVideoSearchListEntity"
            resultType="com.crm.rely.backend.model.pojo.view.WebVideoView">
        select web_video.*,
        <if test="customId!=null">
            custom_video_record.id
        </if>
        <if test="customId==null">
            null
        </if>
        record_id
        from web_video
        <if test="customId!=null">
            left join custom_video_record on custom_video_record.video_id=web_video.id and
            custom_video_record.custom_id=#{customId}
        </if>
        <where>
            <if test="startDate != null">
                AND web_video.add_time>#{startDate}
            </if>
            <if test="endDate != null">
                AND #{endDate}>web_video.add_time
            </if>
        </where>
        order by
        <if test="customId!=null">
            CASE
            WHEN custom_video_record.id > 0 THEN
            1
            WHEN custom_video_record.id IS NULL THEN
            0
            END ASC,
        </if>
                 web_video.sub_index desc
        <if test="page!=null">
            limit #{page.offset},#{page.row}
        </if>
    </select>
    <select id="getCustomAllVideo"
            resultType="com.crm.rely.backend.model.pojo.view.WebVideoView">
        select web_video.*, custom_video_record.id record_id
        from web_video
                 left join custom_video_record on custom_video_record.video_id = web_video.id
        where custom_video_record.custom_id = #{customId}
    </select>
</mapper>