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

    <resultMap type="TaskFault" id="TaskFaultResult">
        <result property="relId" column="rel_id"/>
        <result property="taskId" column="task_id"/>
        <result property="faultId" column="fault_id"/>
        <result property="flag" column="flag"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectTaskFaultVo">
        select rel_id, task_id, fault_id, flag, update_time
        from sim_task_fault
    </sql>

    <select id="selectTaskFaultList" parameterType="TaskFault" resultMap="TaskFaultResult">
        <include refid="selectTaskFaultVo"/>
        <where>
            <if test="taskId != null ">and task_id = #{taskId}</if>
            <if test="faultId != null  and faultId != ''">and fault_id = #{faultId}</if>
            <if test="flag != null  and flag != ''">and flag = #{flag}</if>
        </where>
    </select>

    <select id="selectTaskFaultByRelId" parameterType="Long" resultMap="TaskFaultResult">
        <include refid="selectTaskFaultVo"/>
        where rel_id = #{relId}
    </select>

    <insert id="insertTaskFault" parameterType="TaskFault" useGeneratedKeys="true" keyProperty="relId">
        <selectKey keyProperty="relId" order="AFTER" resultType="java.lang.Long">
            select LAST_INSERT_ID()
        </selectKey>
        insert into sim_task_fault
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskId != null">task_id,</if>
            <if test="faultId != null and faultId != ''">fault_id,</if>
            <if test="flag != null and flag != ''">flag,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskId != null">#{taskId},</if>
            <if test="faultId != null and faultId != ''">#{faultId},</if>
            <if test="flag != null and flag != ''">#{flag},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateTaskFault" parameterType="TaskFault">
        update sim_task_fault
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="faultId != null and faultId != ''">fault_id = #{faultId},</if>
            <if test="flag != null and flag != ''">flag = #{flag},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where rel_id = #{relId}
    </update>

    <delete id="deleteTaskFaultByRelId" parameterType="Long">
        delete
        from sim_task_fault
        where rel_id = #{relId}
    </delete>

    <delete id="deleteTaskFaultByRelIds" parameterType="String">
        delete from sim_task_fault where rel_id in
        <foreach item="relId" collection="array" open="(" separator="," close=")">
            #{relId}
        </foreach>
    </delete>
</mapper>