<?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.xhkjedu.sstudy.mapper.question.UserBasketMapper">
    <resultMap id="basketResult" type="com.xhkjedu.sstudy.vo.question.UserBasketVo">
        <result property="userid" column="userid"></result>
        <result property="subjectid" column="subjectid"></result>
        <result property="qtypeid" column="qtypeid"></result>
        <result property="qtypename" column="qtypename"></result>
        <collection property="questions" ofType="com.xhkjedu.sstudy.vo.question.QuestionVo">
            <result property="questionid" column="questionid"></result>
            <result property="score" column="score"></result>
            <result property="complexity" column="complexity"></result>
            <result property="ctype" column="ctype"></result>
            <result property="qstem" column="qstem"></result>
            <result property="qoption" column="qoption"></result>
            <result property="qanswer" column="qanswer"></result>
            <result property="qanalyze" column="qanalyze"></result>
            <result property="qtypeid" column="qtypeid"></result>
            <result property="qtypename" column="qtypename"></result>
            <result property="createtime" column="createtime"></result>
            <result property="count" column="count"></result>
            <result property="qlevel" column="qlevel"></result>
            <result property="snum" column="snum"></result>
            <collection property="points" ofType="com.xhkjedu.sstudy.vo.subjectbook.PointVo">
                <result property="pointid" column="pointid"></result>
                <result property="pointname" column="pointname"></result>
            </collection>
            <collection property="sonqlist" ofType="com.xhkjedu.sstudy.vo.question.QuestionVo"
                        javaType="java.util.List" select="listSonQuestions" column="questionid">

            </collection>
        </collection>
    </resultMap>
    <resultMap id="listSonQuestions" type="com.xhkjedu.sstudy.vo.question.QuestionVo" >
        <result property="questionid" column="questionid"></result>
        <result property="score" column="score"></result>
        <result property="complexity" column="complexity"></result>
        <result property="ctype" column="ctype"></result>
        <result property="qstem" column="qstem"></result>
        <result property="qoption" column="qoption"></result>
        <result property="qanswer" column="qanswer"></result>
        <result property="qanalyze" column="qanalyze"></result>
        <result property="qtypeid" column="qtypeid"></result>
        <result property="qtypename" column="qtypename"></result>
        <result property="createtime" column="createtime"></result>
        <result property="count" column="count"></result>
        <result property="qlevel" column="qlevel"></result>
        <result property="sorder" column="sorder"></result>
        <collection property="points" ofType="com.xhkjedu.sstudy.vo.subjectbook.PointVo">
            <result property="pointid" column="pointid"></result>
            <result property="pointname" column="pointname"></result>
        </collection>
    </resultMap>
    <select id="findAll" resultMap="basketResult">
        select ub.*,q.questionid,q.score,q.complexity,q.ctype,q.qstem,q.qoption,q.qanswer,q.qanalyze,q.createtime
        ,q.count,qp.pointid,p.pointname,q.qlevel,q.snum
        from t_user_basket ub left join t_subject_questiontype tsq on ub.qtypeid = tsq.qtypeid
        left join t_question q on ub.questionid = q.questionid
        left join t_question_point qp on q.questionid = qp.questionid
        left join t_point p on qp.pointid = p.pointid
        where ub.userid=#{userid} and ub.subjectid=#{subjectid}
        order by tsq.qtypeorder,q.questionid
    </select>
    <select id="listSonQuestions" resultMap="listSonQuestions">
        select q.questionid,q.score,q.complexity,q.ctype,q.qtypeid,q.qtypename,q.qstem,q.qoption,q.qanswer,q.qanalyze,q.createtime
         ,q.count,q.questionpid,q.qlevel,q.sorder,qp.pointid,p.pointname from t_question q
        left join t_question_point qp on q.questionid = qp.questionid
        left join t_point p on qp.pointid = p.pointid
        where q.questionpid=#{questionid} order by q.sorder
    </select>
    <!--清空试题篮-->
    <delete id="deleteBySubjectId">
        delete from t_user_basket where userid=#{userid} and subjectid=#{subjectid}
    </delete>
    <!--删除题型下指定试题-->
    <delete id="deleteByTypeId">
        delete from t_user_basket where userid=#{userid} and qtypeid=#{qtypeid}
    </delete>
    <!--获取用户试题篮id-->
    <select id="getUbidByUserIdQuestionId" resultType="java.lang.Integer">
        select ubid from t_user_basket where userid=#{userid} and questionid=#{questionid} limit 1
    </select>

    <!-- 用户删除试题栏中指定试题 -->
    <delete id="deleteByQuestioniduid">
        delete from t_user_basket where userid=#{userid} and questionid=#{questionid}
    </delete>
</mapper>
