<?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.sim.mapper.DebugFaultMapper">

    <resultMap type="DebugFault" id="DebugFaultResult">
        <result property="refId" column="ref_id"/>
        <result property="simId" column="sim_id"/>
        <result property="faultId" column="fault_id"/>
        <result property="flag" column="flag"/>
        <result property="refState" column="ref_state"/>
        <result property="answerRight" column="answer_right"/>
        <result property="simFaultQuestionValue" column="sim_fault_question_value"/>
        <result property="simFaultAnswerValue" column="sim_fault_answer_value"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectDebugFaultVo">
        select ref_id,
               sim_id,
               fault_id,
               flag,
               ref_state,
               answer_right,
               sim_fault_question_value,
               sim_fault_answer_value,
               create_by,
               create_time,
               update_by,
               update_time
        from sim_debug_fault
    </sql>

    <select id="selectDebugFaultList" parameterType="DebugFault" resultMap="DebugFaultResult">
        <include refid="selectDebugFaultVo"/>
        <where>
            <if test="simId != null ">and sim_id = #{simId}</if>
            <if test="faultId != null  and faultId != ''">and fault_id = #{faultId}</if>
            <if test="flag != null  and flag != ''">and flag = #{flag}</if>
            <if test="refState != null  and refState != ''">and ref_state = #{refState}</if>
            <if test="answerRight != null  and answerRight != ''">and answer_right = #{answerRight}</if>
            <if test="simFaultQuestionValue != null  and simFaultQuestionValue != ''">and sim_fault_question_value =
                #{simFaultQuestionValue}
            </if>
            <if test="simFaultAnswerValue != null  and simFaultAnswerValue != ''">and sim_fault_answer_value =
                #{simFaultAnswerValue}
            </if>
        </where>
    </select>

    <select id="selectDebugFaultByRefId" parameterType="Long" resultMap="DebugFaultResult">
        <include refid="selectDebugFaultVo"/>
        where ref_id = #{refId}
    </select>

    <insert id="insertDebugFault" parameterType="DebugFault">
        <selectKey keyProperty="refId" order="AFTER" resultType="java.lang.Long">
            select LAST_INSERT_ID()
        </selectKey>
        insert into sim_debug_fault
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="refId != null">ref_id,</if>
            <if test="simId != null">sim_id,</if>
            <if test="faultId != null and faultId != ''">fault_id,</if>
            <if test="flag != null">flag,</if>
            <if test="refState != null">ref_state,</if>
            <if test="answerRight != null">answer_right,</if>
            <if test="simFaultQuestionValue != null">sim_fault_question_value,</if>
            <if test="simFaultAnswerValue != null">sim_fault_answer_value,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="refId != null">#{refId},</if>
            <if test="simId != null">#{simId},</if>
            <if test="faultId != null and faultId != ''">#{faultId},</if>
            <if test="flag != null">#{flag},</if>
            <if test="refState != null">#{refState},</if>
            <if test="answerRight != null">#{answerRight},</if>
            <if test="simFaultQuestionValue != null">#{simFaultQuestionValue},</if>
            <if test="simFaultAnswerValue != null">#{simFaultAnswerValue},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateDebugFault" parameterType="DebugFault">
        update sim_debug_fault
        <trim prefix="SET" suffixOverrides=",">
            <if test="simId != null">sim_id = #{simId},</if>
            <if test="faultId != null and faultId != ''">fault_id = #{faultId},</if>
            <if test="flag != null">flag = #{flag},</if>
            <if test="refState != null">ref_state = #{refState},</if>
            <if test="answerRight != null">answer_right = #{answerRight},</if>
            <if test="simFaultQuestionValue != null">sim_fault_question_value = #{simFaultQuestionValue},</if>
            <if test="simFaultAnswerValue != null">sim_fault_answer_value = #{simFaultAnswerValue},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where ref_id = #{refId}
    </update>

    <delete id="deleteDebugFaultByRefId" parameterType="Long">
        delete
        from sim_debug_fault
        where ref_id = #{refId}
    </delete>

    <delete id="deleteDebugFaultByRefIds" parameterType="String">
        delete from sim_debug_fault where ref_id in
        <foreach item="refId" collection="array" open="(" separator="," close=")">
            #{refId}
        </foreach>
    </delete>
</mapper>