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

    <resultMap type="com.ruoyi.school.paper.domain.DbCollectList" id="DbCollectListResult">
        <result property="id" column="id"/>
        <result property="userId" column="user_id"/>
        <result property="questionBankId" column="question_bank_id"/>
        <result property="remark" column="remark"/>
        <result property="delFlag" column="del_flag"/>
        <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="findMyECollectListVoPage" resultType="com.ruoyi.school.paper.domain.vo.MyCollectListVo">
        SELECT
        dcl.question_bank_id questionBankId,
        dqb.topic AS topic,
        dqb.right_answers AS answer,
        dqb.right_answers_pic AS answerPic,
        dqb.species AS species,
        dcl.user_id AS userId
        FROM
        db_collect_list AS dcl
        LEFT JOIN db_question_bank_test_paper AS dqb ON dqb.id = dcl.question_bank_id
        LEFT JOIN db_question_bank_answer_test_paper AS dqbat ON dqbat.question_bank_id = dqb.question_bank_id

        <where>
            dcl.user_id = #{request.userId}
            and dcl.del_flag = 0
            <if test="request.categoryId != null">
                and dqb.category_id = #{request.categoryId}
            </if>
            <if test="request.species != null">
                and dqb.species = #{request.species}
            </if>
        </where>
    </select>

    <select id="getListByRecord" resultType="long">
        select count(1)
        from db_collect_list dcl
        left join db_test_paper_record dtpr on dcl.user_id = dtpr.user_id
        where dtpr.id = #{recordId,jdbcType=BIGINT}
        and dcl.question_bank_id = #{questionBankId,jdbcType=BIGINT}
        and dcl.del_flag = 0
    </select>
</mapper>
