<?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="org.xyzh.workcase.mapper.TbVideoMeetingMapper">

    <resultMap id="BaseResultMap" type="org.xyzh.api.workcase.dto.TbVideoMeetingDTO">
        <id column="meeting_id" property="meetingId" jdbcType="VARCHAR"/>
        <result column="optsn" property="optsn" jdbcType="VARCHAR"/>
        <result column="room_id" property="roomId" jdbcType="VARCHAR"/>
        <result column="workcase_id" property="workcaseId" jdbcType="VARCHAR"/>
        <result column="meeting_name" property="meetingName" jdbcType="VARCHAR"/>
        <result column="meeting_password" property="meetingPassword" jdbcType="VARCHAR"/>
        <result column="description" property="description" jdbcType="VARCHAR"/>
        <result column="jwt_token" property="jwtToken" jdbcType="VARCHAR"/>
        <result column="jitsi_room_name" property="jitsiRoomName" jdbcType="VARCHAR"/>
        <result column="jitsi_server_url" property="jitsiServerUrl" jdbcType="VARCHAR"/>
        <result column="status" property="status" jdbcType="VARCHAR"/>
        <result column="creator" property="creator" jdbcType="VARCHAR"/>
        <result column="creator_type" property="creatorType" jdbcType="VARCHAR"/>
        <result column="creator_name" property="creatorName" jdbcType="VARCHAR"/>
        <result column="participant_count" property="participantCount" jdbcType="INTEGER"/>
        <result column="max_participants" property="maxParticipants" jdbcType="INTEGER"/>
        <result column="start_time" property="startTime" jdbcType="TIMESTAMP"/>
        <result column="end_time" property="endTime" jdbcType="TIMESTAMP"/>
        <result column="advance" property="advance" jdbcType="INTEGER"/>
        <result column="actual_start_time" property="actualStartTime" jdbcType="TIMESTAMP"/>
        <result column="actual_end_time" property="actualEndTime" jdbcType="TIMESTAMP"/>
        <result column="duration_seconds" property="durationSeconds" jdbcType="INTEGER"/>
        <result column="iframe_url" property="iframeUrl" jdbcType="VARCHAR"/>
        <result column="config" property="config" jdbcType="OTHER" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
        <result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
        <result column="deleted" property="deleted" jdbcType="BOOLEAN"/>
    </resultMap>

    <resultMap id="VOResultMap" type="org.xyzh.api.workcase.vo.VideoMeetingVO">
        <id column="meeting_id" property="meetingId" jdbcType="VARCHAR"/>
        <result column="optsn" property="optsn" jdbcType="VARCHAR"/>
        <result column="room_id" property="roomId" jdbcType="VARCHAR"/>
        <result column="workcase_id" property="workcaseId" jdbcType="VARCHAR"/>
        <result column="meeting_name" property="meetingName" jdbcType="VARCHAR"/>
        <result column="meeting_password" property="meetingPassword" jdbcType="VARCHAR"/>
        <result column="description" property="description" jdbcType="VARCHAR"/>
        <result column="jwt_token" property="jwtToken" jdbcType="VARCHAR"/>
        <result column="jitsi_room_name" property="jitsiRoomName" jdbcType="VARCHAR"/>
        <result column="jitsi_server_url" property="jitsiServerUrl" jdbcType="VARCHAR"/>
        <result column="status" property="status" jdbcType="VARCHAR"/>
        <result column="creator_type" property="creatorType" jdbcType="VARCHAR"/>
        <result column="creator_name" property="creatorName" jdbcType="VARCHAR"/>
        <result column="participant_count" property="participantCount" jdbcType="INTEGER"/>
        <result column="max_participants" property="maxParticipants" jdbcType="INTEGER"/>
        <result column="start_time" property="startTime" jdbcType="TIMESTAMP"/>
        <result column="end_time" property="endTime" jdbcType="TIMESTAMP"/>
        <result column="advance" property="advance" jdbcType="INTEGER"/>
        <result column="actual_start_time" property="actualStartTime" jdbcType="TIMESTAMP"/>
        <result column="actual_end_time" property="actualEndTime" jdbcType="TIMESTAMP"/>
        <result column="duration_seconds" property="durationSeconds" jdbcType="INTEGER"/>
        <result column="iframe_url" property="iframeUrl" jdbcType="VARCHAR"/>
        <result column="config" property="config" jdbcType="OTHER" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
        <result column="creator" property="creator" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
        <result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
        <result column="deleted" property="deleted" jdbcType="BOOLEAN"/>
    </resultMap>

    <sql id="Base_Column_List">
        meeting_id, optsn, room_id, workcase_id, meeting_name, meeting_password, description, jwt_token,
        jitsi_room_name, jitsi_server_url, status, creator_type, creator_name,
        participant_count, max_participants, start_time, end_time, advance,
        actual_start_time, actual_end_time, duration_seconds, iframe_url,
        config, creator, create_time, update_time, delete_time, deleted
    </sql>

    <insert id="insertVideoMeeting" parameterType="org.xyzh.api.workcase.dto.TbVideoMeetingDTO">
        INSERT INTO workcase.tb_video_meeting (
            optsn, meeting_id, room_id, workcase_id, meeting_name, jitsi_room_name, creator_type, creator_name, creator
            <if test="meetingPassword != null">, meeting_password</if>
            <if test="description != null">, description</if>
            <if test="jwtToken != null">, jwt_token</if>
            <if test="jitsiServerUrl != null">, jitsi_server_url</if>
            <if test="status != null">, status</if>
            <if test="maxParticipants != null">, max_participants</if>
            <if test="startTime != null">, start_time</if>
            <if test="endTime != null">, end_time</if>
            <if test="advance != null">, advance</if>
            <if test="iframeUrl != null">, iframe_url</if>
            <if test="config != null">, config</if>
        ) VALUES (
            #{optsn}, #{meetingId}, #{roomId}, #{workcaseId}, #{meetingName}, #{jitsiRoomName}, #{creatorType}, #{creatorName}, #{creator}
            <if test="meetingPassword != null">, #{meetingPassword}</if>
            <if test="description != null">, #{description}</if>
            <if test="jwtToken != null">, #{jwtToken}</if>
            <if test="jitsiServerUrl != null">, #{jitsiServerUrl}</if>
            <if test="status != null">, #{status}</if>
            <if test="maxParticipants != null">, #{maxParticipants}</if>
            <if test="startTime != null">, #{startTime}</if>
            <if test="endTime != null">, #{endTime}</if>
            <if test="advance != null">, #{advance}</if>
            <if test="iframeUrl != null">, #{iframeUrl}</if>
            <if test="config != null">, #{config, typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler}</if>
        )
    </insert>

    <update id="updateVideoMeeting" parameterType="org.xyzh.api.workcase.dto.TbVideoMeetingDTO">
        UPDATE workcase.tb_video_meeting
        <set>
            <if test="meetingName != null and meetingName != ''">meeting_name = #{meetingName},</if>
            <if test="meetingPassword != null">meeting_password = #{meetingPassword},</if>
            <if test="description != null">description = #{description},</if>
            <if test="jwtToken != null">jwt_token = #{jwtToken},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="participantCount != null">participant_count = #{participantCount},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="advance != null">advance = #{advance},</if>
            <if test="actualStartTime != null">actual_start_time = #{actualStartTime},</if>
            <if test="actualEndTime != null">actual_end_time = #{actualEndTime},</if>
            <if test="durationSeconds != null">duration_seconds = #{durationSeconds},</if>
            <if test="iframeUrl != null">iframe_url = #{iframeUrl},</if>
            <if test="config != null">config = #{config, typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler},</if>
            update_time = now()
        </set>
        WHERE meeting_id = #{meetingId} AND deleted = false
    </update>

    <update id="deleteVideoMeeting" parameterType="org.xyzh.api.workcase.dto.TbVideoMeetingDTO">
        UPDATE workcase.tb_video_meeting
        SET deleted = true, delete_time = now()
        WHERE meeting_id = #{meetingId} AND deleted = false
    </update>

    <select id="selectVideoMeetingById" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"/>
        FROM workcase.tb_video_meeting
        WHERE meeting_id = #{meetingId} AND deleted = false
    </select>

    <select id="selectVideoMeetingList" resultMap="VOResultMap">
        SELECT <include refid="Base_Column_List"/>
        FROM workcase.tb_video_meeting
        <where>
            <if test="filter.meetingId != null and filter.meetingId != ''">AND meeting_id = #{filter.meetingId}</if>
            <if test="filter.roomId != null and filter.roomId != ''">AND room_id = #{filter.roomId}</if>
            <if test="filter.workcaseId != null and filter.workcaseId != ''">AND workcase_id = #{filter.workcaseId}</if>
            <if test="filter.meetingName != null and filter.meetingName != ''">AND meeting_name LIKE CONCAT('%', #{filter.meetingName}, '%')</if>
            <if test="filter.status != null and filter.status != ''">AND status = #{filter.status}</if>
            <if test="filter.creator != null and filter.creator != ''">AND creator = #{filter.creator}</if>
            <if test="filter.creatorType != null and filter.creatorType != ''">AND creator_type = #{filter.creatorType}</if>
            AND deleted = false
        </where>
        ORDER BY create_time DESC
    </select>

    <select id="selectVideoMeetingPage" resultMap="VOResultMap">
        SELECT <include refid="Base_Column_List"/>
        FROM workcase.tb_video_meeting
        <where>
            <if test="filter.meetingId != null and filter.meetingId != ''">AND meeting_id = #{filter.meetingId}</if>
            <if test="filter.roomId != null and filter.roomId != ''">AND room_id = #{filter.roomId}</if>
            <if test="filter.workcaseId != null and filter.workcaseId != ''">AND workcase_id = #{filter.workcaseId}</if>
            <if test="filter.meetingName != null and filter.meetingName != ''">AND meeting_name LIKE CONCAT('%', #{filter.meetingName}, '%')</if>
            <if test="filter.status != null and filter.status != ''">AND status = #{filter.status}</if>
            <if test="filter.creator != null and filter.creator != ''">AND creator = #{filter.creator}</if>
            <if test="filter.creatorType != null and filter.creatorType != ''">AND creator_type = #{filter.creatorType}</if>
            AND deleted = false
        </where>
        ORDER BY create_time DESC
        LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
    </select>

    <select id="countVideoMeetings" resultType="long">
        SELECT COUNT(*)
        FROM workcase.tb_video_meeting
        <where>
            <if test="filter.meetingId != null and filter.meetingId != ''">AND meeting_id = #{filter.meetingId}</if>
            <if test="filter.roomId != null and filter.roomId != ''">AND room_id = #{filter.roomId}</if>
            <if test="filter.workcaseId != null and filter.workcaseId != ''">AND workcase_id = #{filter.workcaseId}</if>
            <if test="filter.meetingName != null and filter.meetingName != ''">AND meeting_name LIKE CONCAT('%', #{filter.meetingName}, '%')</if>
            <if test="filter.status != null and filter.status != ''">AND status = #{filter.status}</if>
            <if test="filter.creator != null and filter.creator != ''">AND creator = #{filter.creator}</if>
            <if test="filter.creatorType != null and filter.creatorType != ''">AND creator_type = #{filter.creatorType}</if>
            AND deleted = false
        </where>
    </select>

</mapper>
