<?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.airspace.mapper.AirspaceWaypointMapper">

    <resultMap type="com.djhk.uav.airspace.domain.AirspaceWaypoint" id="AirspaceWaypointResult">
        <result column="id"         property="id"/>
        <result column="airspace_apply_id" property="airspaceApplyId"/>
        <result column="lng"  property="lng"/>
        <result column="lat"  property="lat"/>
        <result column="seq"  property="seq"/>
    </resultMap>

    <sql id="selectAirspaceWaypointVo">
        select id,
        airspace_apply_id,
        lng,
        lat,
        seq
        from
        airspace_waypoint
    </sql>

    <select id="selectAirspaceWaypointList" parameterType="Long" resultMap="AirspaceWaypointResult">
        <include refid="selectAirspaceWaypointVo"/>
        where airspace_apply_id = #{airspaceApplyId}
    </select>

    <select id="selectAirspaceWaypointById" parameterType="Long" resultMap="AirspaceWaypointResult">
        <include refid="selectAirspaceWaypointVo"/>
        where airspace_apply_id = #{id}
    </select>

    <insert id="insertAirspaceWaypoint" parameterType="com.djhk.uav.airspace.domain.AirspaceWaypoint">
        insert into airspace_waypoint
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="airspaceApplyId != null">airspace_apply_id, </if>
            <if test="lat != null">lat,</if>
            <if test="lng != null">lng,</if>
            <if test="seq != null">seq,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="airspaceApplyId != null">#{airspaceApplyId},</if>
            <if test="lat != null">#{lat},</if>
            <if test="lng != null">#{lng},</if>
            <if test="seq != null">#{seq},</if>
        </trim>
    </insert>


    <delete id="deleteAirspaceWaypointById" parameterType="Long">
        DELETE FROM airspace_waypoint
        WHERE airspace_apply_id = #{id}
    </delete>

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