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

    <resultMap type="FsCourseAnswerLogs" id="FsCourseAnswerLogsResult">
        <result property="logId"    column="log_id"    />
        <result property="userId"    column="user_id"    />
        <result property="videoId"    column="video_id"    />
        <result property="isRight"    column="is_right"    />
        <result property="createTime"    column="create_time"    />
        <result property="companyId"    column="company_id"    />
        <result property="companyUserId"    column="company_user_id"    />
        <result property="qwUserId"    column="qw_user_id"    />
        <result property="courseId"    column="course_id"    />
        <result property="answer"    column="answer"    />
        <result property="questionId"    column="question_id"    />
        <result property="questionJson"    column="question_json"    />
        <result property="watchLogId"    column="watch_log_id"    />
    </resultMap>

    <sql id="selectFsCourseAnswerLogsVo">
        select * from fs_course_answer_logs
    </sql>

    <select id="selectFsCourseAnswerLogsList" parameterType="FsCourseAnswerLogs" resultMap="FsCourseAnswerLogsResult">
        <include refid="selectFsCourseAnswerLogsVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="videoId != null "> and video_id = #{videoId}</if>
            <if test="isRight != null "> and is_right = #{isRight}</if>
            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="qwUserId != null "> and qw_user_id = #{qwUserId}</if>
        </where>
    </select>

    <select id="selectFsCourseAnswerLogsByLogId" parameterType="Long" resultMap="FsCourseAnswerLogsResult">
        <include refid="selectFsCourseAnswerLogsVo"/>
        where log_id = #{logId}
    </select>
    <select id="selectFsCourseAnswerLogsListVONew" resultType="com.fs.course.vo.FsCourseAnswerLogsListVO">
        select cal.*,uc.course_name as course_name,uc.project as project from fs_course_answer_logs cal
        left join fs_user_course uc on cal.course_id=uc.course_id
        <where>
            <if test="courseId != null">
                cal.course_id = #{courseId}
            </if>
            <if test="companyUserId != null">
                AND cal.company_user_id = #{companyUserId}
            </if>
            <if test="companyId != null">
                AND cal.company_id = #{companyId}
            </if>
            <if test="isRight != null">
                AND is_right = #{isRight}
            </if>
            <if test="project != null">
                AND uc.project = #{project}
            </if>
            <if test="sTime != null and eTime != null">
                AND cal.create_time BETWEEN #{sTime} AND #{eTime}
            </if>
        </where>
    </select>

    <insert id="insertFsCourseAnswerLogs" parameterType="FsCourseAnswerLogs" useGeneratedKeys="true" keyProperty="logId">
        insert into fs_course_answer_logs
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="videoId != null">video_id,</if>
            <if test="isRight != null">is_right,</if>
            <if test="createTime != null">create_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="courseId != null">course_id,</if>
            <if test="questionJson != null">question_json,</if>
            <if test="watchLogId != null">watch_log_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="videoId != null">#{videoId},</if>
            <if test="isRight != null">#{isRight},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="companyUserId != null">#{companyUserId},</if>
            <if test="qwUserId != null">#{qwUserId},</if>
            <if test="courseId != null">#{courseId},</if>
            <if test="questionJson != null">#{questionJson},</if>
            <if test="watchLogId != null">#{watchLogId},</if>
         </trim>
    </insert>

    <update id="updateFsCourseAnswerLogs" parameterType="FsCourseAnswerLogs">
        update fs_course_answer_logs
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="videoId != null">video_id = #{videoId},</if>
            <if test="isRight != null">is_right = #{isRight},</if>
            <if test="createTime != null">create_time = #{createTime},</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="courseId != null">course_id = #{courseId},</if>
            <if test="watchLogId != null">watch_log_id = #{watchLogId},</if>
        </trim>
        where log_id = #{logId}
    </update>

    <delete id="deleteFsCourseAnswerLogsByLogId" parameterType="Long">
        delete from fs_course_answer_logs where log_id = #{logId}
    </delete>

    <delete id="deleteFsCourseAnswerLogsByLogIds" parameterType="String">
        delete from fs_course_answer_logs where log_id in
        <foreach item="logId" collection="array" open="(" separator="," close=")">
            #{logId}
        </foreach>
    </delete>
</mapper>
