<?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="refType330FaultId" column="ref_type3_30_fault_id"/>
        <result property="refType4FaultId" column="ref_type4_fault_id"/>
        <result property="faultType" column="fault_type"/>
        <result property="simType" column="sim_type"/>
        <result property="faultState" column="fault_state"/>
        <result property="conflictFaultIds" column="conflict_fault_ids"/>
        <result property="replacePart" column="replace_part"/>
        <result property="replaceName" column="replace_name"/>
        <result property="name" column="name"/>
        <result property="bindHardwareMsg" column="bind_hardware_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,
               ref_type3_30_fault_id,
               ref_type4_fault_id,
               fault_type,
               sim_type,
               fault_state,
               conflict_fault_ids,
               replace_part,
               replace_name,
               name,
               bind_hardware_msg,
               order_num,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from mx_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="refType330FaultId != null  and refType330FaultId != ''">and ref_type3_30_fault_id =
                #{refType330FaultId}
            </if>
            <if test="refType4FaultId != null  and refType4FaultId != ''">and ref_type4_fault_id = #{refType4FaultId}
            </if>
            <if test="faultType != null  and faultType != ''">and fault_type = #{faultType}</if>
            <if test="simType != null  and simType != ''">and sim_type = #{simType}</if>
            <if test="faultState != null  and faultState != ''">and fault_state = #{faultState}</if>
            <if test="conflictFaultIds != null  and conflictFaultIds != ''">and conflict_fault_ids =
                #{conflictFaultIds}
            </if>
            <if test="replacePart != null  and replacePart != ''">and replace_part = #{replacePart}</if>
            <if test="replaceName != null  and replaceName != ''">and replace_name like concat('%', #{replaceName},
                '%')
            </if>
            <if test="name != null  and name != ''">and name like concat('%', #{name}, '%')</if>
            <if test="bindHardwareMsg != null  and bindHardwareMsg != ''">and bind_hardware_msg = #{bindHardwareMsg}
            </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">
        <selectKey keyProperty="faultId" order="AFTER" resultType="java.lang.String">
            select LAST_INSERT_ID()
        </selectKey>
        insert into mx_fault
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="faultId != null">fault_id,</if>
            <if test="parentFaultId != null and parentFaultId != ''">parent_fault_id,</if>
            <if test="refType330FaultId != null and refType330FaultId != ''">ref_type3_30_fault_id,</if>
            <if test="refType4FaultId != null and refType4FaultId != ''">ref_type4_fault_id,</if>
            <if test="faultType != null">fault_type,</if>
            <if test="simType != null and simType != ''">sim_type,</if>
            <if test="faultState != null">fault_state,</if>
            <if test="conflictFaultIds != null and conflictFaultIds != ''">conflict_fault_ids,</if>
            <if test="replacePart != null">replace_part,</if>
            <if test="replaceName != null">replace_name,</if>
            <if test="name != null">name,</if>
            <if test="bindHardwareMsg != null and bindHardwareMsg != ''">bind_hardware_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="refType330FaultId != null and refType330FaultId != ''">#{refType330FaultId},</if>
            <if test="refType4FaultId != null and refType4FaultId != ''">#{refType4FaultId},</if>
            <if test="faultType != null">#{faultType},</if>
            <if test="simType != null and simType != ''">#{simType},</if>
            <if test="faultState != null">#{faultState},</if>
            <if test="conflictFaultIds != null and conflictFaultIds != ''">#{conflictFaultIds},</if>
            <if test="replacePart != null">#{replacePart},</if>
            <if test="replaceName != null">#{replaceName},</if>
            <if test="name != null">#{name},</if>
            <if test="bindHardwareMsg != null and bindHardwareMsg != ''">#{bindHardwareMsg},</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 mx_fault
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentFaultId != null and parentFaultId != ''">parent_fault_id = #{parentFaultId},</if>
            <if test="refType330FaultId != null and refType330FaultId != ''">ref_type3_30_fault_id =
                #{refType330FaultId},
            </if>
            <if test="refType4FaultId != null and refType4FaultId != ''">ref_type4_fault_id = #{refType4FaultId},</if>
            <if test="faultType != null">fault_type = #{faultType},</if>
            <if test="simType != null and simType != ''">sim_type = #{simType},</if>
            <if test="faultState != null">fault_state = #{faultState},</if>
            <if test="conflictFaultIds != null and conflictFaultIds != ''">conflict_fault_ids = #{conflictFaultIds},
            </if>
            <if test="replacePart != null">replace_part = #{replacePart},</if>
            <if test="replaceName != null">replace_name = #{replaceName},</if>
            <if test="name != null">name = #{name},</if>
            <if test="bindHardwareMsg != null and bindHardwareMsg != ''">bind_hardware_msg = #{bindHardwareMsg},</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 mx_fault
        where fault_id = #{faultId}
    </delete>

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