<?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.bcxin.identify.business.dao.PerVideoRoomMapper">

    <!-- 新增对象 -->
    <insert id="insertPerVideoRoom" parameterType="com.bcxin.identify.business.domain.ysp.PerVideoRoom">
        insert into per_video_room
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="perVideoRoomId != null">
                perVideoRoomId,
            </if>
            <if test="comVideoRoomId != null">
                comVideoRoomId,
            </if>
            <if test="cid != null">
                cid,
            </if>
            <if test="useid != null">
                useid,
            </if>
            <if test="attendExpoStatus != null">
                attendExpoStatus,
            </if>
            <if test="startTime != null">
                startTime,
            </if>
            <if test="endTime != null">
                endTime,
            </if>
            <if test="streamId != null">
                streamId,
            </if>
            <if test="fileId != null">
                fileId,
            </if>
            <if test="videoPath != null">
                videoPath,
            </if>
            <if test="isSponsor != null">
                isSponsor,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="perVideoRoomId != null">
                #{perVideoRoomId},
            </if>
            <if test="comVideoRoomId != null">
                #{comVideoRoomId},
            </if>
            <if test="cid != null">
                #{cid},
            </if>
            <if test="useid != null">
                #{useid},
            </if>
            <if test="attendExpoStatus != null">
                #{attendExpoStatus},
            </if>
            <if test="startTime != null">
                #{startTime},
            </if>
            <if test="endTime != null">
                #{endTime},
            </if>
            <if test="streamId != null">
                #{streamId},
            </if>
            <if test="fileId != null">
                #{fileId},
            </if>
            <if test="videoPath != null">
                #{videoPath},
            </if>
            <if test="isSponsor != null">
                #{isSponsor},
            </if>
        </trim>
    </insert>

    <insert id="insertBatchPerVideoRoom" >
        INSERT INTO per_video_room(
        perVideoRoomId,
        comVideoRoomId,
        cid,
        useid,
        attendExpoStatus,
        startTime,
        endTime,
        streamId,
        fileId,
        videoPath,
        isSponsor,
        personId,
        domainId)
        VALUES
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.perVideoRoomId},
            #{item.comVideoRoomId},
            #{item.cid},
            #{item.useid},
            #{item.attendExpoStatus},
            #{item.startTime},
            #{item.endTime},
            #{item.streamId},
            #{item.fileId},
            #{item.videoPath},
            #{item.isSponsor},
            #{item.personId},
            #{item.domainId})
        </foreach>
    </insert>

    <!-- 修改对象 -->
    <update id="updateVideo" parameterType="com.bcxin.identify.business.domain.ysp.PerVideoRoom">
        UPDATE per_video_room SET
        startTime=#{startTime},
        endTime=#{endTime},
        streamId=#{streamId},
        fileId=#{fileId},
        attendExpoStatus=#{attendExpoStatus},
        videoPath=#{videoPath}
        WHERE perVideoRoomId = #{perVideoRoomId}
    </update>

    <update id="updateStatus">
        UPDATE per_video_room
        SET attendExpoStatus=#{Status}
        WHERE perVideoRoomId = #{perVideoRoomId}
    </update>

    <!-- 返回详情信息 -->
    <select id="get" resultType="com.bcxin.identify.business.domain.ysp.PerVideoRoom">
        SELECT
        CONCAT(perVideoRoomId,'') AS perVideoRoomId
        ,CONCAT(comVideoRoomId,'') AS comVideoRoomId
        ,cid
        ,useid
        ,attendExpoStatus
        ,DATE_FORMAT(startTime,'%Y-%m-%d %H:%i:%s') AS startTime
        ,DATE_FORMAT(endTime,'%Y-%m-%d %H:%i:%s') AS endTime
        ,streamId
        ,fileId
        ,videoPath
        ,isSponsor
        FROM per_video_room
        WHERE perVideoRoomId = #{perVideoRoomId}
    </select>

    <select id="getByUseidAndCid" resultType="com.bcxin.identify.business.domain.ysp.PerVideoRoom">
        SELECT
        CONCAT(t1.perVideoRoomId,'') AS perVideoRoomId
        ,CONCAT(t1.comVideoRoomId,'') AS comVideoRoomId
        ,t1.cid
        ,t1.useid
        ,t1.attendExpoStatus
        ,DATE_FORMAT(t1.startTime,'%Y-%m-%d %H:%i:%s') AS startTime
        ,DATE_FORMAT(t1.endTime,'%Y-%m-%d %H:%i:%s') AS endTime
        ,t1.streamId
        ,t1.fileId
        ,t1.videoPath
        ,t1.isSponsor
        FROM per_video_room t1
        LEFT JOIN com_video_room t3 ON t1.comVideoRoomId = t3.comVideoRoomId
        WHERE t1.useid = #{useid}
        AND t3.roomNo = #{roomNo}
    </select>

    <select id="getPerVideoRoomFileId" resultType="com.bcxin.identify.business.domain.ysp.PerVideoRoom">
        SELECT
        CONCAT(t1.perVideoRoomId,'') AS perVideoRoomId
        ,CONCAT(t1.comVideoRoomId,'') AS comVideoRoomId
        ,t1.cid
        ,t1.useid
        ,t1.attendExpoStatus
        ,DATE_FORMAT(t1.startTime,'%Y-%m-%d %H:%i:%s') AS startTime
        ,DATE_FORMAT(t1.endTime,'%Y-%m-%d %H:%i:%s') AS endTime
        ,t1.streamId
        ,t1.fileId
        ,t1.videoPath
        ,t1.isSponsor
        FROM per_video_room t1
        LEFT JOIN com_video_room t3 ON t1.comVideoRoomId = t3.comVideoRoomId
        WHERE t1.fileId = #{file_id}
    </select>

    <select id="findPerVideoRoomByRoomId" resultType="java.util.Map">
        SELECT
        CONCAT(t1.perVideoRoomId,'') AS perVideoRoomId
        ,CONCAT(t1.comVideoRoomId,'') AS comVideoRoomId
        ,t1.cid
        ,t1.useid
        ,t1.attendExpoStatus
        ,DATE_FORMAT(t1.startTime,'%Y-%m-%d %H:%i:%s') AS startTime
        ,DATE_FORMAT(t1.endTime,'%Y-%m-%d %H:%i:%s') AS endTime
        ,t1.streamId
        ,t1.fileId
        ,t1.videoPath
        ,t1.isSponsor
        FROM per_video_room t1
        WHERE comVideoRoomId =#{comVideoRoomId}
    </select>

</mapper>