<?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.learn.mapper.LearnWrongBookMapper">
    
    <resultMap type="LearnWrongBook" id="LearnWrongBookResult">
        <result property="wrongId"    column="wrong_id"    />
        <result property="studentId"    column="student_id"    />
        <result property="questionId"    column="question_id"    />
        <result property="source"    column="source"    />
        <result property="state"    column="state"    />
        <result property="knownledgeId"    column="knownledge_id"    />
        <result property="subjectId"    column="subject_id"    />
        <result property="paperId"    column="paper_id"    />
        <result property="answers"    column="answers"    />
        <result property="answer1"    column="answer1"    />
        <result property="answer2"    column="answer2"    />
        <result property="scoreTotal"    column="score_total"    />
        <result property="score"    column="score"    />
        <result property="scoreLevel"    column="score_level"    />
        <result property="scoreRate"    column="score_rate"    />
        <result property="wrongCount"    column="wrong_count"    />
        <result property="rightCount"    column="right_count"    />
        <result property="totalCount"    column="total_count"    />
        <result property="createdTime"    column="created_time"    />
        <result property="updatedTime"    column="updated_time"    />
        <result property="collect"    column="collect"    />
    </resultMap>

    <sql id="selectLearnWrongBookVo">
        select wrong_id, student_id, question_id, source, state, knownledge_id, subject_id, paper_id, answers, answer1, answer2, score_total, score, score_level, score_rate, wrong_count, right_count, total_count, created_time, updated_time, collect from learn_wrong_book
    </sql>

    <select id="selectLearnWrongBookList" parameterType="LearnWrongBook" resultMap="LearnWrongBookResult">
        <include refid="selectLearnWrongBookVo"/>
        <where>  
            <if test="studentId != null "> and student_id = #{studentId}</if>
            <if test="questionId != null "> and question_id = #{questionId}</if>
            <if test="source != null  and source != ''"> and source = #{source}</if>
            <if test="state != null "> and state = #{state}</if>
            <if test="knownledgeId != null "> and knownledge_id = #{knownledgeId}</if>
            <if test="subjectId != null "> and subject_id = #{subjectId}</if>
            <if test="paperId != null "> and paper_id = #{paperId}</if>
            <if test="answers != null  and answers != ''"> and answers = #{answers}</if>
            <if test="answer1 != null  and answer1 != ''"> and answer1 = #{answer1}</if>
            <if test="answer2 != null  and answer2 != ''"> and answer2 = #{answer2}</if>
            <if test="scoreTotal != null "> and score_total = #{scoreTotal}</if>
            <if test="score != null "> and score = #{score}</if>
            <if test="scoreLevel != null  and scoreLevel != ''"> and score_level = #{scoreLevel}</if>
            <if test="scoreRate != null "> and score_rate = #{scoreRate}</if>
            <if test="wrongCount != null "> and wrong_count = #{wrongCount}</if>
            <if test="rightCount != null "> and right_count = #{rightCount}</if>
            <if test="totalCount != null "> and total_count = #{totalCount}</if>
            <if test="createdTime != null "> and created_time = #{createdTime}</if>
            <if test="updatedTime != null "> and updated_time = #{updatedTime}</if>
            <if test="collect != null "> and collect = #{collect}</if>
        </where>
    </select>
    
    <select id="selectLearnWrongBookByWrongId" parameterType="Long" resultMap="LearnWrongBookResult">
        <include refid="selectLearnWrongBookVo"/>
        where wrong_id = #{wrongId}
    </select>

    <insert id="insertLearnWrongBook" parameterType="LearnWrongBook" useGeneratedKeys="true" keyProperty="wrongId">
        insert into learn_wrong_book
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="studentId != null">student_id,</if>
            <if test="questionId != null">question_id,</if>
            <if test="source != null">source,</if>
            <if test="state != null">state,</if>
            <if test="knownledgeId != null">knownledge_id,</if>
            <if test="subjectId != null">subject_id,</if>
            <if test="paperId != null">paper_id,</if>
            <if test="answers != null">answers,</if>
            <if test="answer1 != null">answer1,</if>
            <if test="answer2 != null">answer2,</if>
            <if test="scoreTotal != null">score_total,</if>
            <if test="score != null">score,</if>
            <if test="scoreLevel != null">score_level,</if>
            <if test="scoreRate != null">score_rate,</if>
            <if test="wrongCount != null">wrong_count,</if>
            <if test="rightCount != null">right_count,</if>
            <if test="totalCount != null">total_count,</if>
            <if test="createdTime != null">created_time,</if>
            <if test="updatedTime != null">updated_time,</if>
            <if test="collect != null">collect,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="studentId != null">#{studentId},</if>
            <if test="questionId != null">#{questionId},</if>
            <if test="source != null">#{source},</if>
            <if test="state != null">#{state},</if>
            <if test="knownledgeId != null">#{knownledgeId},</if>
            <if test="subjectId != null">#{subjectId},</if>
            <if test="paperId != null">#{paperId},</if>
            <if test="answers != null">#{answers},</if>
            <if test="answer1 != null">#{answer1},</if>
            <if test="answer2 != null">#{answer2},</if>
            <if test="scoreTotal != null">#{scoreTotal},</if>
            <if test="score != null">#{score},</if>
            <if test="scoreLevel != null">#{scoreLevel},</if>
            <if test="scoreRate != null">#{scoreRate},</if>
            <if test="wrongCount != null">#{wrongCount},</if>
            <if test="rightCount != null">#{rightCount},</if>
            <if test="totalCount != null">#{totalCount},</if>
            <if test="createdTime != null">#{createdTime},</if>
            <if test="updatedTime != null">#{updatedTime},</if>
            <if test="collect != null">#{collect},</if>
         </trim>
    </insert>

    <update id="updateLearnWrongBook" parameterType="LearnWrongBook">
        update learn_wrong_book
        <trim prefix="SET" suffixOverrides=",">
            <if test="studentId != null">student_id = #{studentId},</if>
            <if test="questionId != null">question_id = #{questionId},</if>
            <if test="source != null">source = #{source},</if>
            <if test="state != null">state = #{state},</if>
            <if test="knownledgeId != null">knownledge_id = #{knownledgeId},</if>
            <if test="subjectId != null">subject_id = #{subjectId},</if>
            <if test="paperId != null">paper_id = #{paperId},</if>
            <if test="answers != null">answers = #{answers},</if>
            <if test="answer1 != null">answer1 = #{answer1},</if>
            <if test="answer2 != null">answer2 = #{answer2},</if>
            <if test="scoreTotal != null">score_total = #{scoreTotal},</if>
            <if test="score != null">score = #{score},</if>
            <if test="scoreLevel != null">score_level = #{scoreLevel},</if>
            <if test="scoreRate != null">score_rate = #{scoreRate},</if>
            <if test="wrongCount != null">wrong_count = #{wrongCount},</if>
            <if test="rightCount != null">right_count = #{rightCount},</if>
            <if test="totalCount != null">total_count = #{totalCount},</if>
            <if test="createdTime != null">created_time = #{createdTime},</if>
            <if test="updatedTime != null">updated_time = #{updatedTime},</if>
            <if test="collect != null">collect = #{collect},</if>
        </trim>
        where wrong_id = #{wrongId}
    </update>

    <delete id="deleteLearnWrongBookByWrongId" parameterType="Long">
        delete from learn_wrong_book where wrong_id = #{wrongId}
    </delete>

    <delete id="deleteLearnWrongBookByWrongIds" parameterType="String">
        delete from learn_wrong_book where wrong_id in 
        <foreach item="wrongId" collection="array" open="(" separator="," close=")">
            #{wrongId}
        </foreach>
    </delete>
</mapper>