<?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.ruoyi.school.paper.mapper.DbTestPaperRecordMapper">

    <resultMap type="com.ruoyi.school.paper.domain.DbTestPaperRecord" id="DbTestPaperRecordResult">
        <result property="id" column="id"/>
        <result property="userId" column="user_id"/>
        <result property="testPaperId" column="test_paper_id"/>
        <result property="status" column="status"/>
        <result property="totalPoints" column="total_points"/>
        <result property="remark" column="remark"/>
        <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>

    <select id="getTestPaperlist" resultType="com.ruoyi.school.paper.domain.vo.DbTestPaperRecordVo">
        select dtpr.*,dtp.test_name
        from db_test_paper_record dtpr
        left join db_test_paper dtp on dtpr.test_paper_id = dtp.id
        where dtpr.user_id = #{bo.userId,jdbcType=BIGINT} and dtpr.status > 0
    </select>

    <select id="getPhaseList" resultType="com.ruoyi.school.paper.domain.vo.DbTestPaperVo">
        select dtp.id,
               dtp.test_name,
               dtp.total_points,
               dtp.class_id,
               concat(phase.dept_name, '', class.dept_name) as phase_class
        from db_test_paper_record dtpr
                 left join db_test_paper dtp on dtp.id = dtpr.test_paper_id
                 LEFT JOIN sys_dept phase on dtp.phase_id = phase.dept_id
                 left join sys_dept class on dtp.class_id = class.dept_id
        where dtpr.status in (1, 2, 3)
        <if test="bo.classId != null">
            and dtp.class_id = #{bo.classId,jdbcType=BIGINT}
        </if>
        <if test="bo.testName != null and bo.testName != ''">
            and dtp.test_name like concat('%', #{bo.testName,jdbcType=VARCHAR}, '%')
        </if>
    </select>

    <select id="getClassList" resultType="com.ruoyi.school.paper.domain.vo.DbTestPaperVo">
        select dtpr.id as recordId,
               SU.user_id,
               su.nick_name,
               dtpr.total_points,
               dtpr.status,
               concat(phase.dept_name, '', class.dept_name) as phase_class
        from db_test_paper_record dtpr
                 left join db_test_paper dtp on dtp.id = dtpr.test_paper_id
                 left join sys_user su on su.user_id = dtpr.user_id
                 LEFT JOIN sys_dept phase on dtp.phase_id = phase.dept_id
                 left join sys_dept class on dtp.class_id = class.dept_id
        where dtpr.status in (1, 2, 3)
        <if test="bo.classId != null">
            and dtp.class_id = #{bo.classId,jdbcType=BIGINT}
        </if>
        <if test="bo.nickName != null and bo.testName != ''">
            and su.nick_name like concat('%', #{bo.nickName,jdbcType=VARCHAR}, '%')
        </if>
    </select>
</mapper>
