<?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.grade.mapper.UserPeriodStatusMapper">

    <resultMap type="com.zhongzheng.modules.grade.domain.UserPeriodStatus" id="UserPeriodStatusResult">
        <result property="status" column="status"/>
        <result property="recordStartTime" column="record_start_time"/>
        <result property="recordEndTime" column="record_end_time"/>
        <result property="id" column="id"/>
        <result property="periodId" column="period_id"/>
        <result property="periodStatus" column="period_status"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>


    <resultMap type="com.zhongzheng.modules.grade.vo.UserPeriodStatusVo" id="UserPeriodStatusVo">
        <result property="status" column="status"/>
        <result property="recordStartTime" column="record_start_time"/>
        <result property="recordEndTime" column="record_end_time"/>
        <result property="id" column="id"/>
        <result property="periodId" column="period_id"/>
        <result property="periodStatus" column="period_status"/>
        <result property="auditTime" column="audit_time"/>
        <result property="type" column="type"/>
        <result property="typeName" column="type_name"/>
        <result property="realName" column="realname"/>
        <result property="performance" column="performance"/>
    </resultMap>

    <select id="selectPeriodStatus" parameterType="com.zhongzheng.modules.grade.bo.UserPeriodQueryBo" resultMap="UserPeriodStatusVo">
        SELECT
        ups.*,
        (select realname from `user` u where up.user_id = u.user_id) as  realname,
        <if test="examId != null ">
            (SELECT exam_name FROM exam e where e.exam_id= up.exam_id)
        </if>
        <if test="sectionId != null ">
            (SELECT name FROM course_section cs where up.section_id= cs.section_id)
        </if>
         as type_name
        FROM
        user_period_status ups
        LEFT JOIN user_period up ON up.id = ups.period_id
        WHERE 1=1
        <if test="goodsId != null and goodsId != ''">
            and up.goods_id = #{goodsId}
        </if>
        <if test="gradeId != null and gradeId != ''">
            and up.grade_id = #{gradeId}
        </if>

        <if test="userId != null and userId != ''">
            and up.user_id = #{userId}
        </if>
        <if test="sectionId != null ">
            and up.section_id = #{sectionId}
        </if>
        <if test="moduleId != null ">
            and up.module_id = #{moduleId}
        </if>

        <if test="chapterId != null">
            and up.chapter_id = #{chapterId}
        </if>
        <if test="courseId != null ">
            and up.course_id = #{courseId}
        </if>
        <if test="examId != null ">
            and up.exam_id = #{examId}
        </if>
        ORDER BY
            ups.create_time asc
    </select>
</mapper>
