<?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.LearnWrongDetailMapper">
    
    <resultMap type="LearnWrongDetail" id="LearnWrongDetailResult">
        <result property="wrongDetailId"    column="wrong_detail_id"    />
        <result property="wrongId"    column="wrong_id"    />
        <result property="createdTime"    column="created_time"    />
        <result property="source"    column="source"    />
        <result property="studentId"    column="student_id"    />
        <result property="subjectId"    column="subject_id"    />
        <result property="knownledgeId"    column="knownledge_id"    />
        <result property="examineeId"    column="examinee_id"    />
        <result property="paperId"    column="paper_id"    />
        <result property="scoreTotal"    column="score_total"    />
        <result property="score"    column="score"    />
        <result property="scoreLevel"    column="score_level"    />
        <result property="scoreRate"    column="score_rate"    />
    </resultMap>

    <sql id="selectLearnWrongDetailVo">
        select wrong_detail_id, wrong_id, created_time, source, student_id, subject_id, knownledge_id, examinee_id, paper_id, score_total, score, score_level, score_rate from learn_wrong_detail
    </sql>

    <select id="selectLearnWrongDetailList" parameterType="LearnWrongDetail" resultMap="LearnWrongDetailResult">
        <include refid="selectLearnWrongDetailVo"/>
        <where>  
            <if test="wrongId != null "> and wrong_id = #{wrongId}</if>
            <if test="createdTime != null "> and created_time = #{createdTime}</if>
            <if test="source != null  and source != ''"> and source = #{source}</if>
            <if test="studentId != null "> and student_id = #{studentId}</if>
            <if test="subjectId != null "> and subject_id = #{subjectId}</if>
            <if test="knownledgeId != null "> and knownledge_id = #{knownledgeId}</if>
            <if test="examineeId != null "> and examinee_id = #{examineeId}</if>
            <if test="paperId != null "> and paper_id = #{paperId}</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>
        </where>
    </select>
    
    <select id="selectLearnWrongDetailByWrongDetailId" parameterType="Long" resultMap="LearnWrongDetailResult">
        <include refid="selectLearnWrongDetailVo"/>
        where wrong_detail_id = #{wrongDetailId}
    </select>

    <insert id="insertLearnWrongDetail" parameterType="LearnWrongDetail" useGeneratedKeys="true" keyProperty="wrongDetailId">
        insert into learn_wrong_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="wrongId != null">wrong_id,</if>
            <if test="createdTime != null">created_time,</if>
            <if test="source != null">source,</if>
            <if test="studentId != null">student_id,</if>
            <if test="subjectId != null">subject_id,</if>
            <if test="knownledgeId != null">knownledge_id,</if>
            <if test="examineeId != null">examinee_id,</if>
            <if test="paperId != null">paper_id,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="wrongId != null">#{wrongId},</if>
            <if test="createdTime != null">#{createdTime},</if>
            <if test="source != null">#{source},</if>
            <if test="studentId != null">#{studentId},</if>
            <if test="subjectId != null">#{subjectId},</if>
            <if test="knownledgeId != null">#{knownledgeId},</if>
            <if test="examineeId != null">#{examineeId},</if>
            <if test="paperId != null">#{paperId},</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>
         </trim>
    </insert>

    <update id="updateLearnWrongDetail" parameterType="LearnWrongDetail">
        update learn_wrong_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="wrongId != null">wrong_id = #{wrongId},</if>
            <if test="createdTime != null">created_time = #{createdTime},</if>
            <if test="source != null">source = #{source},</if>
            <if test="studentId != null">student_id = #{studentId},</if>
            <if test="subjectId != null">subject_id = #{subjectId},</if>
            <if test="knownledgeId != null">knownledge_id = #{knownledgeId},</if>
            <if test="examineeId != null">examinee_id = #{examineeId},</if>
            <if test="paperId != null">paper_id = #{paperId},</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>
        </trim>
        where wrong_detail_id = #{wrongDetailId}
    </update>

    <delete id="deleteLearnWrongDetailByWrongDetailId" parameterType="Long">
        delete from learn_wrong_detail where wrong_detail_id = #{wrongDetailId}
    </delete>

    <delete id="deleteLearnWrongDetailByWrongDetailIds" parameterType="String">
        delete from learn_wrong_detail where wrong_detail_id in 
        <foreach item="wrongDetailId" collection="array" open="(" separator="," close=")">
            #{wrongDetailId}
        </foreach>
    </delete>
</mapper>