<?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.user.mapper.UserBankQuestionRecordMapper">

    <resultMap type="com.zhongzheng.modules.user.domain.UserBankQuestionRecord" id="UserBankQuestionRecordResult">
        <result property="replyId" column="reply_id"/>
        <result property="recordId" column="record_id"/>
        <result property="questionId" column="question_id"/>
        <result property="isRight" column="is_right"/>
        <result property="bankId" column="bank_id"/>
        <result property="selectIds" column="select_ids"/>
        <result property="replyStr" column="reply_str"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="userId" column="user_id"/>
    </resultMap>

    <select id="queryWrongList" parameterType="com.zhongzheng.modules.user.domain.UserBankQuestionRecord"  resultType="com.zhongzheng.modules.bank.domain.Question">
        SELECT
        q.*
        FROM
        user_bank_question_record ubqr
        LEFT JOIN question q ON ubqr.question_id = q.question_id
        WHERE
        1 = 1
        <if test="userId != null and userId != ''">
            AND user_id = #{userId}
        </if>
        AND ubqr.bank_id = #{bankId}
        GROUP BY
        ubqr.question_id
        HAVING
        max(ubqr.is_right) = 0

    </select>

    <select id="queryDoneList" parameterType="com.zhongzheng.modules.user.domain.UserBankQuestionRecord"  resultType="com.zhongzheng.modules.bank.domain.Question">
        SELECT
        q.*
        FROM
        user_bank_question_record ubqr
        LEFT JOIN question q ON ubqr.question_id = q.question_id
        WHERE
        1 = 1
        <if test="userId != null and userId != ''">
            AND user_id = #{userId}
        </if>
        AND ubqr.bank_id = #{bankId}
        GROUP BY
        ubqr.question_id

    </select>

</mapper>
