<?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.AircraftSubsystemMapper">
    
    <resultMap type="AircraftSubsystem" id="AircraftSubsystemResult">
        <result property="id"    column="id"    />
        <result property="aircraftSystemId"    column="aircraft_system_id"    />
        <result property="aircraftTypeName"    column="aircraft_type_name"    />
        <result property="remark"    column="remark"    />
        <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="selectAircraftSubsystemVo">
        select id, aircraft_system_id, aircraft_type_name, remark, create_by, create_time, update_by, update_time from biz_aircraft_subsystem
    </sql>


    <select id="getSubSystemOption" parameterType="Long" resultMap="AircraftSubsystemResult">
        <include refid="selectAircraftSubsystemVo"/>
        where aircraft_system_id = #{aircraftSystemId}
    </select>

    <select id="selectAircraftSubsystemList" parameterType="AircraftSubsystem" resultMap="AircraftSubsystemResult">
        <include refid="selectAircraftSubsystemVo"/>
        <where>  
            <if test="aircraftSystemId != null "> and aircraft_system_id = #{aircraftSystemId}</if>
            <if test="aircraftTypeName != null  and aircraftTypeName != ''"> and aircraft_type_name like concat('%', #{aircraftTypeName}, '%')</if>
        </where>
    </select>
    
    <select id="selectAircraftSubsystemById" parameterType="Long" resultMap="AircraftSubsystemResult">
        <include refid="selectAircraftSubsystemVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertAircraftSubsystem" parameterType="AircraftSubsystem" useGeneratedKeys="true" keyProperty="id">
        insert into biz_aircraft_subsystem
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="aircraftSystemId != null">aircraft_system_id,</if>
            <if test="aircraftTypeName != null">aircraft_type_name,</if>
            <if test="remark != null">remark,</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="aircraftSystemId != null">#{aircraftSystemId},</if>
            <if test="aircraftTypeName != null">#{aircraftTypeName},</if>
            <if test="remark != null">#{remark},</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="updateAircraftSubsystem" parameterType="AircraftSubsystem">
        update biz_aircraft_subsystem
        <trim prefix="SET" suffixOverrides=",">
            <if test="aircraftSystemId != null">aircraft_system_id = #{aircraftSystemId},</if>
            <if test="aircraftTypeName != null">aircraft_type_name = #{aircraftTypeName},</if>
            <if test="remark != null">remark = #{remark},</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="deleteAircraftSubsystemById" parameterType="Long">
        delete from biz_aircraft_subsystem where id = #{id}
    </delete>

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