<?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.UavBatteryMapper">

    <resultMap type="com.djhk.uav.uav.model.UavBattery" id="UavBatteryResult">
        <result property="id"    column="id"    />
        <result property="batteryNo"    column="battery_no"    />
        <result property="batteryStatus"    column="battery_status"    />
        <result property="batteryWeight"    column="battery_weight"    />
        <result property="batteryLife"    column="battery_life"    />
        <result property="delFlag"    column="del_flag"    />
        <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="remark"    column="remark"    />
        <result property="deleteTime"    column="delete_time"    />
        <result property="deleteBy"    column="delete_by"    />
    </resultMap>

    <sql id="selectUavBatteryVo">
        select id, battery_no, battery_status, battery_weight, battery_life, del_flag, create_by, create_time, update_by, update_time, remark, delete_time, delete_by from uav_battery
    </sql>

    <select id="selectUavBatteryList" parameterType="com.djhk.uav.uav.model.UavBattery" resultMap="UavBatteryResult">
        <include refid="selectUavBatteryVo"/>
        <where>
            <if test="batteryNo != null  and batteryNo != ''"> and battery_no = #{batteryNo}</if>
            <if test="batteryStatus != null "> and battery_status = #{batteryStatus}</if>
            <if test="batteryWeight != null "> and battery_weight = #{batteryWeight}</if>
            <if test="batteryLife != null "> and battery_life = #{batteryLife}</if>
            <if test="deleteTime != null "> and delete_time = #{deleteTime}</if>
            <if test="deleteBy != null  and deleteBy != ''"> and delete_by = #{deleteBy}</if>
        </where>
    </select>

    <select id="selectUavBatteryById" parameterType="Long" resultMap="UavBatteryResult">
        <include refid="selectUavBatteryVo"/>
        where id = #{id}
    </select>

    <insert id="insertUavBattery" parameterType="com.djhk.uav.uav.model.UavBattery" useGeneratedKeys="true" keyProperty="id">
        insert into uav_battery
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="batteryNo != null">battery_no,</if>
            <if test="batteryStatus != null">battery_status,</if>
            <if test="batteryWeight != null">battery_weight,</if>
            <if test="batteryLife != null">battery_life,</if>
            <if test="delFlag != null">del_flag,</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="remark != null">remark,</if>
            <if test="deleteTime != null">delete_time,</if>
            <if test="deleteBy != null">delete_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="batteryNo != null">#{batteryNo},</if>
            <if test="batteryStatus != null">#{batteryStatus},</if>
            <if test="batteryWeight != null">#{batteryWeight},</if>
            <if test="batteryLife != null">#{batteryLife},</if>
            <if test="delFlag != null">#{delFlag},</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="remark != null">#{remark},</if>
            <if test="deleteTime != null">#{deleteTime},</if>
            <if test="deleteBy != null">#{deleteBy},</if>
         </trim>
    </insert>

    <update id="updateUavBattery" parameterType="com.djhk.uav.uav.model.UavBattery">
        update uav_battery
        <trim prefix="SET" suffixOverrides=",">
            <if test="batteryNo != null">battery_no = #{batteryNo},</if>
            <if test="batteryStatus != null">battery_status = #{batteryStatus},</if>
            <if test="batteryWeight != null">battery_weight = #{batteryWeight},</if>
            <if test="batteryLife != null">battery_life = #{batteryLife},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</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="remark != null">remark = #{remark},</if>
            <if test="deleteTime != null">delete_time = #{deleteTime},</if>
            <if test="deleteBy != null">delete_by = #{deleteBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteUavBatteryById" parameterType="Long">
        delete from uav_battery where id = #{id}
    </delete>

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