<?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.zhongzheng.modules.user.mapper.UserCourseAnswerMapper">

    <resultMap type="com.zhongzheng.modules.user.domain.UserCourseAnswer" id="UserCourseAnswerResult">
        <result property="answerId" column="answer_id"/>
        <result property="userId" column="user_id"/>
        <result property="assignUserId" column="assign_user_id"/>
        <result property="answerText" column="answer_text"/>
        <result property="courseId" column="course_id"/>
        <result property="sectionId" column="section_id"/>
        <result property="moduleId" column="module_id"/>
        <result property="chapterId" column="chapter_id"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.user.vo.UserCourseAnswerVo" id="UserCourseAnswerVo">
        <result property="answerId" column="answer_id"/>
        <result property="userId" column="user_id"/>
        <result property="assignUserId" column="assign_user_id"/>
        <result property="answerText" column="answer_text"/>
        <result property="courseId" column="course_id"/>
        <result property="sectionId" column="section_id"/>
        <result property="moduleId" column="module_id"/>
        <result property="chapterId" column="chapter_id"/>
        <result property="realname" column="realname"/>
        <result property="avatar" column="avatar"/>
        <result property="assignRealname" column="assign_realname"/>
        <result property="assignAvatar" column="assign_avatar"/>
    </resultMap>

    <select id="selectAnswer" parameterType="com.zhongzheng.modules.user.bo.UserCourseAnswerQueryBo"  resultMap="UserCourseAnswerVo">
        SELECT
            * ,
            (SELECT u.realname FROM `user` u where uca.user_id = u.user_id) realname,
            (SELECT u.realname FROM `user` u where uca.assign_user_id = u.user_id) assign_realname,
            (SELECT u.avatar FROM `user` u where uca.assign_user_id = u.user_id) assign_avatar,
            (SELECT u.avatar FROM `user` u where uca.user_id = u.user_id) avatar
        FROM
            user_course_answer uca
        WHERE 1=1
          AND uca.status=1
        <if test="courseId != null and courseId != ''">
          AND uca.course_id = #{courseId}
        </if>
        <if test="moduleId != null and moduleId != ''">
          AND uca.module_id = #{moduleId}
        </if>
        <if test="chapterId != null and chapterId != ''">
          AND uca.chapter_id = #{chapterId}
        </if>
        <if test="sectionId != null and sectionId != ''">
          AND uca.section_id = #{sectionId}
        </if>
    </select>
</mapper>
