<?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.djhk.uav.uav.mapper.UavPilotMapper">

    <resultMap type="com.djhk.uav.uav.model.UavPilot" id="UavPilotResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="idCardNum"    column="id_card_num"    />
        <result property="phone"    column="phone"    />
        <result property="sn"    column="sn"    />
        <result property="relatedDetails"    column="related_details"    />
        <result property="inboundTime"    column="inbound_time"    />
        <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="selectUavPilotVo">
        select id, name,  id_card_num, phone, sn, related_details, inbound_time,
        create_time, update_by, update_time,create_by
        from pilot_information
    </sql>

    <select id="selectUavPilotById" parameterType="Long" resultMap="UavPilotResult">
        <include refid="selectUavPilotVo"/>
        where id = #{id}
    </select>



    <select id="selectUavPilotList" parameterType="com.djhk.uav.uav.model.UavPilot" resultMap="UavPilotResult">
        <include refid="selectUavPilotVo"/>
        <where>
            <if test="name != null "> and name = #{name}</if>
            <if test="idCardNum != null "> and id_card_num = #{idCardNum}</if>
            <if test="phone != null "> and phone = #{phone}</if>
            <if test="createBy != null  and createBy != ''"> and create_by = #{createBy}</if>
            <if test="sn != null  and sn != ''"> and sn like concat('%', #{sn}, '%')</if>
            <if test="relatedDetails != null  and relatedDetails != ''"> and related_details like concat('%', #{relatedDetails}, '%')</if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                and date_format(inbound_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                and date_format(inbound_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
<!--            <if test="inboundTime != null  and inboundTime != ''"> and inbound_time = #{inboundTime}</if>-->
        </where>
<!--        order by create_Time desc-->
    </select>


    <!--    useGeneratedKeys="true" keyProperty="id"-->
    <insert id="insertUavPilot" parameterType="com.djhk.uav.uav.model.UavPilot" >
        insert into pilot_information
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="idCardNum != null">id_card_num,</if>
            <if test="phone != null">phone,</if>
            <if test="sn != null">sn,</if>
            <if test="relatedDetails != null">related_details,</if>
            <if test="inboundTime != null">inbound_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="idCardNum != null">#{idCardNum},</if>
            <if test="phone != null">#{phone},</if>
            <if test="sn != null">#{sn},</if>
            <if test="relatedDetails != null">#{relatedDetails},</if>
            <if test="inboundTime != null">#{inboundTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateUavPilot" parameterType="com.djhk.uav.uav.model.UavPilot">
        update pilot_information
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="idCardNum != null">id_card_num = #{idCardNum},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="sn != null">sn = #{sn},</if>
            <if test="relatedDetails != null">related_details = #{relatedDetails},</if>
            <if test="inboundTime != null">inbound_time = #{inboundTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteUavPilotById" parameterType="Long">
        delete from pilot_information where id = #{id}
    </delete>

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