<?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.FsUserCourseCompanyUserTimeMapper">

    <resultMap type="FsUserCourseCompanyUserTime" id="FsUserCourseCompanyUserTimeResult">
        <result property="id"    column="id"    />
        <result property="periodId"    column="period_id"    />
        <result property="courseId"    column="course_id"    />
        <result property="videoId"    column="video_id"    />
        <result property="companyUserId"    column="company_user_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="startDateTime"    column="start_date_time"    />
        <result property="endDateTime"    column="end_date_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectFsUserCourseCompanyUserTimeVo">
        select id, period_id, course_id, video_id, company_user_id, company_id, start_date_time, end_date_time, create_time, create_by, update_time, update_by from fs_user_course_company_user_time
    </sql>

    <select id="selectFsUserCourseCompanyUserTimeList" parameterType="FsUserCourseCompanyUserTime" resultMap="FsUserCourseCompanyUserTimeResult">
        <include refid="selectFsUserCourseCompanyUserTimeVo"/>
        <where>
            <if test="periodId != null "> and period_id = #{periodId}</if>
            <if test="courseId != null "> and course_id = #{courseId}</if>
            <if test="videoId != null "> and video_id = #{videoId}</if>
            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="startDateTime != null "> and start_date_time = #{startDateTime}</if>
            <if test="endDateTime != null "> and end_date_time = #{endDateTime}</if>
        </where>
    </select>

    <select id="selectFsUserCourseCompanyUserTimeById" parameterType="Long" resultMap="FsUserCourseCompanyUserTimeResult">
        <include refid="selectFsUserCourseCompanyUserTimeVo"/>
        where id = #{id}
    </select>

    <insert id="insertFsUserCourseCompanyUserTime" parameterType="FsUserCourseCompanyUserTime" useGeneratedKeys="true" keyProperty="id">
        insert into fs_user_course_company_user_time
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="periodId != null">period_id,</if>
            <if test="courseId != null">course_id,</if>
            <if test="videoId != null">video_id,</if>
            <if test="companyUserId != null">company_user_id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="startDateTime != null">start_date_time,</if>
            <if test="endDateTime != null">end_date_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="periodId != null">#{periodId},</if>
            <if test="courseId != null">#{courseId},</if>
            <if test="videoId != null">#{videoId},</if>
            <if test="companyUserId != null">#{companyUserId},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="startDateTime != null">#{startDateTime},</if>
            <if test="endDateTime != null">#{endDateTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
    </insert>

    <update id="updateFsUserCourseCompanyUserTime" parameterType="FsUserCourseCompanyUserTime">
        update fs_user_course_company_user_time
        <trim prefix="SET" suffixOverrides=",">
            <if test="periodId != null">period_id = #{periodId},</if>
            <if test="courseId != null">course_id = #{courseId},</if>
            <if test="videoId != null">video_id = #{videoId},</if>
            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="startDateTime != null">start_date_time = #{startDateTime},</if>
            <if test="endDateTime != null">end_date_time = #{endDateTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFsUserCourseCompanyUserTimeById" parameterType="Long">
        delete from fs_user_course_company_user_time where id = #{id}
    </delete>

    <delete id="deleteFsUserCourseCompanyUserTimeByIds" parameterType="String">
        delete from fs_user_course_company_user_time where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <!-- 批量查询记录 -->
    <select id="batchSelectByParams" resultMap="FsUserCourseCompanyUserTimeResult">
        select id, period_id, course_id, video_id, company_user_id, company_id,
               start_date_time, end_date_time, create_time, create_by, update_time, update_by
        from fs_user_course_company_user_time
        where (
            <foreach collection="list" item="item" separator=" OR ">
                (period_id = #{item.periodId}
                AND course_id = #{item.courseId}
                AND video_id = #{item.videoId}
                AND company_user_id = #{item.companyUserId})
            </foreach>
        )
    </select>

    <!-- 批量插入记录 -->
    <insert id="batchInsert" useGeneratedKeys="true" keyProperty="id">
        insert into fs_user_course_company_user_time
        (period_id, course_id, video_id, company_user_id, company_id,
         start_date_time, end_date_time, create_time)
        values
        <foreach collection="list" item="item" separator=",">
            (#{item.periodId}, #{item.courseId}, #{item.videoId}, #{item.companyUserId},
             #{item.companyId}, #{item.startDateTime}, #{item.endDateTime},
             #{item.createTime})
        </foreach>
    </insert>

    <!-- 批量更新记录 -->
    <update id="batchUpdate">
        <foreach collection="list" item="item" separator=";">
            update fs_user_course_company_user_time
            set start_date_time = #{item.startDateTime},
                end_date_time = #{item.endDateTime},
                update_time = #{item.updateTime}
            where id = #{item.id}
        </foreach>
    </update>
</mapper>
