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

    <resultMap type="com.ruoyi.school.paper.domain.DbErrorList" id="DbErrorListResult">
        <result property="id" column="id"/>
        <result property="userId" column="user_id"/>
        <result property="paperId" column="paper_id"/>
        <result property="questionBankId" column="question_bank_id"/>
        <result property="remark" column="remark"/>
        <result property="status" column="status"/>
        <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="findErrorTopicPage" resultType="com.ruoyi.school.paper.domain.vo.ErrorTopicListVo"
            parameterType="com.ruoyi.school.paper.domain.request.ErrorTopicRequest">
        SELECT
        del.id AS id,
        del.question_bank_id AS questionBankId,
        dqbtp.topic AS topic
        FROM
        db_error_list AS del
        LEFT JOIN db_question_bank_test_paper AS dqbtp ON dqbtp.id = del.question_bank_id
        LEFT JOIN db_test_paper_record AS dtpr ON dtpr.id = del.record_id
        LEFT JOIN db_test_paper_record_detail AS dtprd ON dtprd.record_id = dtpr.id and dtprd.question_bank_id =
        del.question_bank_id
        <where>
            <if test="request.categoryId != null">
                dqbtp.category_id = #{request.categoryId}
            </if>
            <if test="request.type != null">
                and dqbtp.type = #{request.type}
            </if>
            <if test="request.intensity != null">
                and dqbtp.intensity = #{request.intensity}
            </if>
            and del.user_id in
            <foreach collection="request.userIds" item="userId" open="(" separator="," close=")">
                #{userId}
            </foreach>
            GROUP BY dqbtp.topic

        </where>
    </select>
    <select id="getErrorTopicListDetailById" resultType="com.ruoyi.school.paper.domain.vo.ErrorTopicListDetailVo"
            parameterType="java.lang.Long">
        SELECT dqt.type_value       AS typeName,
               dqb.intensity        AS intensity,
               dqb.species          AS species,
               dqb.topic            AS topic,
               dqb.right_answers    AS rightAnswers,
               sd.dept_name         AS phaseName,
               del.question_bank_id AS questionBankId
        FROM db_error_list AS del
                 LEFT JOIN db_question_bank_test_paper dqb ON dqb.id = del.question_bank_id
                 LEFT JOIN sys_dept sd ON sd.dept_id = dqb.phase_id
                 LEFT JOIN db_question_type dqt ON dqt.id = dqb.category_id
        WHERE del.id = #{id}
    </select>
    <select id="findMyErrorTopicListVoPage" resultType="com.ruoyi.school.paper.domain.vo.MyErrorTopicListVo">
        SELECT
        del.id AS id,
        del.question_bank_id AS questionBankId,
        dqbtp.topic AS topic,
        dtprd.answer AS answer,
        dqbtp.right_answers AS correctAnswer,
        dqbtp.species AS species
        FROM
        db_error_list AS del
        LEFT JOIN db_question_bank_test_paper AS dqbtp ON dqbtp.id = del.question_bank_id
        LEFT JOIN db_test_paper_record AS dtpr ON dtpr.id = del.record_id
        LEFT JOIN db_test_paper_record_detail AS dtprd ON dtprd.record_id = dtpr.id and dtprd.question_bank_id =
        del.question_bank_id
        <where>
            del.user_id = #{request.userId}
            <if test="request.categoryId != null">
                and dqbtp.category_id = #{request.categoryId}
            </if>
        </where>
    </select>
</mapper>
