<?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.fs.course.mapper.FsCourseLinkMapper">

    <resultMap type="FsCourseLink" id="FsCourseLinkResult">
        <result property="linkId"    column="link_id"    />
        <result property="link"    column="link"    />
        <result property="realLink"    column="real_link"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="companyId"    column="company_id"    />
        <result property="companyUserId"    column="company_user_id"    />
        <result property="qwUserId"    column="qw_user_id"    />
        <result property="videoId"    column="video_id"    />
        <result property="corpId"    column="corp_id"    />
        <result property="courseId"    column="course_id"    />
        <result property="qwExternalId"    column="qw_external_id"    />
        <result property="linkType"    column="link_type"    />
        <result property="isRoom"    column="is_room"    />
    </resultMap>

    <sql id="selectFsCourseLinkVo">
        select link_id, is_room,link, real_link,link_type, create_time, update_time, company_id, company_user_id, qw_user_id, video_id, corp_id, course_id ,qw_external_id  from fs_course_link
    </sql>

    <select id="selectFsCourseLinkList" parameterType="FsCourseLink" resultMap="FsCourseLinkResult">
        <include refid="selectFsCourseLinkVo"/>
        <where>
            <if test="link != null  and link != ''"> and link = #{link}</if>
            <if test="realLink != null  and realLink != ''"> and real_link = #{realLink}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
            <if test="qwUserId != null  and qwUserId != ''"> and qw_user_id = #{qwUserId}</if>
            <if test="videoId != null "> and video_id = #{videoId}</if>
            <if test="corpId != null  and corpId != ''"> and corp_id = #{corpId}</if>
            <if test="courseId != null  and courseId != ''"> and course_id = #{courseId}</if>
            <if test="linkType != null "> and link_type = #{linkType}</if>
            <if test="qwExternalId != null  and qwExternalId != ''"> and qw_external_id = #{qwExternalId}</if>
        </where>
    </select>

    <select id="selectFsCourseLinkByLinkId" parameterType="Long" resultMap="FsCourseLinkResult">
        <include refid="selectFsCourseLinkVo"/>
        where link_id = #{linkId}
    </select>

    <insert id="insertFsCourseLink" parameterType="FsCourseLink" useGeneratedKeys="true" keyProperty="linkId">
        insert into fs_course_link
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="link != null">link,</if>
            <if test="realLink != null">real_link,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="companyId != null">company_id,</if>
            <if test="companyUserId != null">company_user_id,</if>
            <if test="qwUserId != null">qw_user_id,</if>
            <if test="videoId != null">video_id,</if>
            <if test="corpId != null">corp_id,</if>
            <if test="courseId != null">course_id,</if>
            <if test="qwExternalId != null">qw_external_id,</if>
            <if test="linkType != null">link_type,</if>
            <if test="isRoom != null">is_room,</if>
            <if test="chatId != null">chat_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="link != null">#{link},</if>
            <if test="realLink != null">#{realLink},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="companyUserId != null">#{companyUserId},</if>
            <if test="qwUserId != null">#{qwUserId},</if>
            <if test="videoId != null">#{videoId},</if>
            <if test="corpId != null">#{corpId},</if>
            <if test="courseId != null">#{courseId},</if>
            <if test="qwExternalId != null">#{qwExternalId},</if>
            <if test="linkType != null">#{linkType},</if>
            <if test="isRoom != null">#{isRoom},</if>
            <if test="chatId != null">#{chatId},</if>
         </trim>
    </insert>

    <insert id="insertFsCourseLinkBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="linkId">
        INSERT INTO fs_course_link
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="courseLinks != null and courseLinks.size() &gt; 0">
                <!-- 假设所有日志对象的字段一致 -->
                <!-- 动态生成列列表，基于第一个日志对象 -->
                <foreach collection="courseLinks" item="item" index="index" open="" close="" separator="">
                    <if test="index == 0">
                        <if test="item.link != null">link,</if>
                        <if test="item.realLink != null">real_link,</if>
                        <if test="item.createTime != null">create_time,</if>
                        <if test="item.updateTime != null">update_time,</if>
                        <if test="item.companyId != null">company_id,</if>
                        <if test="item.companyUserId != null">company_user_id,</if>
                        <if test="item.qwUserId != null">qw_user_id,</if>
                        <if test="item.videoId != null">video_id,</if>
                        <if test="item.corpId != null">corp_id,</if>
                        <if test="item.courseId != null">course_id,</if>
                        <if test="item.qwExternalId != null">qw_external_id,</if>
                        <if test="item.linkType != null">link_type,</if>
                        <if test="item.isRoom != null">is_room,</if>
                    </if>
                </foreach>
            </if>
        </trim>
        <trim prefix="VALUES">
            <foreach collection="courseLinks" item="item" separator=",">
                (<trim suffixOverrides=",">
                <if test="item.link != null">#{item.link},</if>
                <if test="item.realLink != null">#{item.realLink},</if>
                <if test="item.createTime != null">#{item.createTime},</if>
                <if test="item.updateTime != null">#{item.updateTime},</if>
                <if test="item.companyId != null">#{item.companyId},</if>
                <if test="item.companyUserId != null">#{item.companyUserId},</if>
                <if test="item.qwUserId != null">#{item.qwUserId},</if>
                <if test="item.videoId != null">#{item.videoId},</if>
                <if test="item.corpId != null">#{item.corpId},</if>
                <if test="item.courseId != null">#{item.courseId},</if>
                <if test="item.qwExternalId != null">#{item.qwExternalId},</if>
                <if test="item.linkType != null">#{item.linkType},</if>
                <if test="item.isRoom != null">#{item.isRoom},</if>
            </trim>)
            </foreach>
        </trim>
    </insert>


    <update id="updateFsCourseLink" parameterType="FsCourseLink">
        update fs_course_link
        <trim prefix="SET" suffixOverrides=",">
            <if test="link != null">link = #{link},</if>
            <if test="realLink != null">real_link = #{realLink},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
            <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
            <if test="videoId != null">video_id = #{videoId},</if>
            <if test="corpId != null">corp_id = #{corpId},</if>
            <if test="courseId != null">course_id = #{courseId},</if>
            <if test="qwExternalId != null">qw_external_id = #{qwExternalId},</if>
            <if test="linkType != null">link_type = #{linkType},</if>
            <if test="isRoom != null">is_room = #{isRoom},</if>
        </trim>
        where link_id = #{linkId}
    </update>

    <delete id="deleteFsCourseLinkByLinkId" parameterType="Long">
        delete from fs_course_link where link_id = #{linkId}
    </delete>

    <delete id="deleteFsCourseLinkByLinkIds" parameterType="String">
        delete from fs_course_link where link_id in
        <foreach item="linkId" collection="array" open="(" separator="," close=")">
            #{linkId}
        </foreach>
    </delete>
</mapper>
