<?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.FaultMapper">

    <resultMap type="Fault" id="FaultResult">
        <result property="faultId" column="fault_id"/>
        <result property="parentFaultId" column="parent_fault_id"/>
        <result property="simType" column="sim_type"/>
        <result property="faultType" column="fault_type"/>
        <result property="conflictFaultId" column="conflict_fault_id"/>
        <result property="name" column="name"/>
        <result property="simMsg" column="sim_msg"/>
        <result property="orderNum" column="order_num"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectFaultVo">
        select fault_id,
               parent_fault_id,
               sim_type,
               fault_type,
               conflict_fault_id,
               name,
               sim_msg,
               order_num,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from sim_fault
    </sql>

    <select id="selectFaultList" parameterType="Fault" resultMap="FaultResult">
        <include refid="selectFaultVo"/>
        <where>
            <if test="parentFaultId != null  and parentFaultId != ''">and parent_fault_id = #{parentFaultId}</if>
            <if test="simType != null  and simType != ''">and sim_type = #{simType}</if>
            <if test="faultType != null  and faultType != ''">and fault_type = #{faultType}</if>
            <if test="conflictFaultId != null  and conflictFaultId != ''">and conflict_fault_id = #{conflictFaultId}
            </if>
            <if test="name != null  and name != ''">and name like concat('%', #{name}, '%')</if>
            <if test="simMsg != null  and simMsg != ''">and sim_msg = #{simMsg}</if>
            <if test="orderNum != null ">and order_num = #{orderNum}</if>
        </where>
    </select>

    <select id="selectFaultByFaultId" parameterType="String" resultMap="FaultResult">
        <include refid="selectFaultVo"/>
        where fault_id = #{faultId}
    </select>

    <insert id="insertFault" parameterType="Fault">
        insert into sim_fault
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="faultId != null">fault_id,</if>
            <if test="parentFaultId != null and parentFaultId != ''">parent_fault_id,</if>
            <if test="simType != null and simType != ''">sim_type,</if>
            <if test="faultType != null">fault_type,</if>
            <if test="conflictFaultId != null">conflict_fault_id,</if>
            <if test="name != null">name,</if>
            <if test="simMsg != null">sim_msg,</if>
            <if test="orderNum != null">order_num,</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>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="faultId != null">#{faultId},</if>
            <if test="parentFaultId != null and parentFaultId != ''">#{parentFaultId},</if>
            <if test="simType != null and simType != ''">#{simType},</if>
            <if test="faultType != null">#{faultType},</if>
            <if test="conflictFaultId != null">#{conflictFaultId},</if>
            <if test="name != null">#{name},</if>
            <if test="simMsg != null">#{simMsg},</if>
            <if test="orderNum != null">#{orderNum},</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>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateFault" parameterType="Fault">
        update sim_fault
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentFaultId != null and parentFaultId != ''">parent_fault_id = #{parentFaultId},</if>
            <if test="simType != null and simType != ''">sim_type = #{simType},</if>
            <if test="faultType != null">fault_type = #{faultType},</if>
            <if test="conflictFaultId != null">conflict_fault_id = #{conflictFaultId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="simMsg != null">sim_msg = #{simMsg},</if>
            <if test="orderNum != null">order_num = #{orderNum},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where fault_id = #{faultId}
    </update>

    <delete id="deleteFaultByFaultId" parameterType="String">
        delete
        from sim_fault
        where fault_id = #{faultId}
    </delete>

    <delete id="deleteFaultByFaultIds" parameterType="String">
        delete from sim_fault where fault_id in
        <foreach item="faultId" collection="array" open="(" separator="," close=")">
            #{faultId}
        </foreach>
    </delete>
</mapper>