<?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.goomood.phm.mapper.FaultCaseMapper">
    
    <resultMap type="FaultCase" id="FaultCaseResult">
        <result property="id"    column="id"    />
        <result property="faultName"    column="fault_name"    />
        <result property="useSystem"    column="use_system"    />
        <result property="subsystem"    column="subsystem"    />
        <result property="partName"    column="part_name"    />
        <result property="specialty"    column="specialty"    />
        <result property="aircraftType"    column="aircraft_type"    />
        <result property="faultCause"    column="fault_cause"    />
        <result property="faultDetail"    column="fault_detail"    />
        <result property="handlingMethod"    column="handling_method"    />
        <result property="caseNo"    column="case_no"    />
        <result property="filePath"    column="file_path"    />
        <result property="imagePath"    column="image_path"    />
        <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="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectFaultCaseVo">
        select id, fault_name, use_system, subsystem, part_name, specialty, aircraft_type, fault_cause, fault_detail, handling_method, case_no, file_path, image_path, create_by, create_time, update_by, update_time, remarks from fault_case
    </sql>

    <select id="selectFaultCaseList" parameterType="FaultCase" resultMap="FaultCaseResult">
        <include refid="selectFaultCaseVo"/>
        <where>  
            <if test="faultName != null  and faultName != ''"> and fault_name like concat('%', #{faultName}, '%')</if>
            <if test="specialty != null  and specialty != ''"> and specialty = #{specialty}</if>
            <if test="aircraftType != null  and aircraftType != ''"> and aircraft_type = #{aircraftType}</if>
            <if test="caseNo != null  and caseNo != ''"> and case_no = #{caseNo}</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 fault_case
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="faultName != null">fault_name,</if>
            <if test="useSystem != null">use_system,</if>
            <if test="subsystem != null">subsystem,</if>
            <if test="partName != null">part_name,</if>
            <if test="specialty != null">specialty,</if>
            <if test="aircraftType != null">aircraft_type,</if>
            <if test="faultCause != null">fault_cause,</if>
            <if test="faultDetail != null">fault_detail,</if>
            <if test="handlingMethod != null">handling_method,</if>
            <if test="caseNo != null">case_no,</if>
            <if test="filePath != null">file_path,</if>
            <if test="imagePath != null">image_path,</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="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="faultName != null">#{faultName},</if>
            <if test="useSystem != null">#{useSystem},</if>
            <if test="subsystem != null">#{subsystem},</if>
            <if test="partName != null">#{partName},</if>
            <if test="specialty != null">#{specialty},</if>
            <if test="aircraftType != null">#{aircraftType},</if>
            <if test="faultCause != null">#{faultCause},</if>
            <if test="faultDetail != null">#{faultDetail},</if>
            <if test="handlingMethod != null">#{handlingMethod},</if>
            <if test="caseNo != null">#{caseNo},</if>
            <if test="filePath != null">#{filePath},</if>
            <if test="imagePath != null">#{imagePath},</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="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateFaultCase" parameterType="FaultCase">
        update fault_case
        <trim prefix="SET" suffixOverrides=",">
            <if test="faultName != null">fault_name = #{faultName},</if>
            <if test="useSystem != null">use_system = #{useSystem},</if>
            <if test="subsystem != null">subsystem = #{subsystem},</if>
            <if test="partName != null">part_name = #{partName},</if>
            <if test="specialty != null">specialty = #{specialty},</if>
            <if test="aircraftType != null">aircraft_type = #{aircraftType},</if>
            <if test="faultCause != null">fault_cause = #{faultCause},</if>
            <if test="faultDetail != null">fault_detail = #{faultDetail},</if>
            <if test="handlingMethod != null">handling_method = #{handlingMethod},</if>
            <if test="caseNo != null">case_no = #{caseNo},</if>
            <if test="filePath != null">file_path = #{filePath},</if>
            <if test="imagePath != null">image_path = #{imagePath},</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="remarks != null">remarks = #{remarks},</if>
        </trim>
        where id = #{id}
    </update>

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

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