<?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.tfis.system.mapper.FaultCaseMapper">
    
    <resultMap type="FaultCase" id="FaultCaseResult">
        <result property="id"    column="id"    />
        <result property="aircraftTypeId"    column="aircraft_type_id"    />
        <result property="aircraftSystemId"    column="aircraft_system_id"    />
        <result property="aircraftSubsystemId"    column="aircraft_subsystem_id"    />
        <result property="faultPhenomenon"    column="fault_phenomenon"    />
        <result property="faultCause"    column="fault_cause"    />
        <result property="faultTreePath"    column="fault_tree_path"    />
        <result property="faultPicturePath"    column="fault_picture_path"    />
        <result property="troubleshootingMethodPath"    column="troubleshooting_method_path"    />
        <result property="viewCount"    column="view_count"    />
        <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="selectFaultCaseVo">
        select id, aircraft_type_id, aircraft_system_id, aircraft_subsystem_id, fault_phenomenon, fault_cause, fault_tree_path, fault_picture_path, troubleshooting_method_path, view_count, create_by, create_time, update_by, update_time from biz_fault_case
    </sql>

    <select id="selectFaultCaseList" parameterType="FaultCase" resultMap="FaultCaseResult">
        <include refid="selectFaultCaseVo"/>
        <where>  
            <if test="aircraftTypeId != null "> and aircraft_type_id = #{aircraftTypeId}</if>
            <if test="aircraftSystemId != null "> and aircraft_system_id = #{aircraftSystemId}</if>
            <if test="aircraftSubsystemId != null "> and aircraft_subsystem_id = #{aircraftSubsystemId}</if>
            <if test="faultPhenomenon != null  and faultPhenomenon != ''"> and fault_phenomenon = #{faultPhenomenon}</if>
            <if test="faultCause != null  and faultCause != ''"> and fault_cause = #{faultCause}</if>
            <if test="faultTreePath != null  and faultTreePath != ''"> and fault_tree_path = #{faultTreePath}</if>
            <if test="faultPicturePath != null  and faultPicturePath != ''"> and fault_picture_path = #{faultPicturePath}</if>
            <if test="troubleshootingMethodPath != null  and troubleshootingMethodPath != ''"> and troubleshooting_method_path = #{troubleshootingMethodPath}</if>
            <if test="viewCount != null "> and view_count = #{viewCount}</if>
        </where>
    </select>
    
    <select id="selectFaultCaseById" parameterType="Long" resultMap="FaultCaseResult">
        <include refid="selectFaultCaseVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertFaultCase" parameterType="FaultCase" useGeneratedKeys="true" keyProperty="id">
        insert into biz_fault_case
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="aircraftTypeId != null">aircraft_type_id,</if>
            <if test="aircraftSystemId != null">aircraft_system_id,</if>
            <if test="aircraftSubsystemId != null">aircraft_subsystem_id,</if>
            <if test="faultPhenomenon != null">fault_phenomenon,</if>
            <if test="faultCause != null">fault_cause,</if>
            <if test="faultTreePath != null">fault_tree_path,</if>
            <if test="faultPicturePath != null">fault_picture_path,</if>
            <if test="troubleshootingMethodPath != null">troubleshooting_method_path,</if>
            <if test="viewCount != null">view_count,</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="aircraftTypeId != null">#{aircraftTypeId},</if>
            <if test="aircraftSystemId != null">#{aircraftSystemId},</if>
            <if test="aircraftSubsystemId != null">#{aircraftSubsystemId},</if>
            <if test="faultPhenomenon != null">#{faultPhenomenon},</if>
            <if test="faultCause != null">#{faultCause},</if>
            <if test="faultTreePath != null">#{faultTreePath},</if>
            <if test="faultPicturePath != null">#{faultPicturePath},</if>
            <if test="troubleshootingMethodPath != null">#{troubleshootingMethodPath},</if>
            <if test="viewCount != null">#{viewCount},</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="updateFaultCase" parameterType="FaultCase">
        update biz_fault_case
        <trim prefix="SET" suffixOverrides=",">
            <if test="aircraftTypeId != null">aircraft_type_id = #{aircraftTypeId},</if>
            <if test="aircraftSystemId != null">aircraft_system_id = #{aircraftSystemId},</if>
            <if test="aircraftSubsystemId != null">aircraft_subsystem_id = #{aircraftSubsystemId},</if>
            <if test="faultPhenomenon != null">fault_phenomenon = #{faultPhenomenon},</if>
            <if test="faultCause != null">fault_cause = #{faultCause},</if>
            <if test="faultTreePath != null">fault_tree_path = #{faultTreePath},</if>
            <if test="faultPicturePath != null">fault_picture_path = #{faultPicturePath},</if>
            <if test="troubleshootingMethodPath != null">troubleshooting_method_path = #{troubleshootingMethodPath},</if>
            <if test="viewCount != null">view_count = #{viewCount},</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 id = #{id}
    </update>

    <delete id="deleteFaultCaseById" parameterType="Long">
        delete from biz_fault_case where id = #{id}
    </delete>

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