<?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.inspect.metadata.mqtt.mapper.HrDroneBatteryMapper">
    <resultMap id="HrDroneBatteryResult" type="com.inspect.metadata.mqtt.domain.HrDroneBattery">
        <id property="droneBatteryId" column="drone_battery_id"/>
        <result property="nestCode" column="nest_code"/>
        <result property="isBatteryConnected" column="is_battery_connected" />
        <result property="isCellDamaged" column="is_cell_damaged" />
        <result property="isLowCellVoltageDetected" column="is_low_cell_voltage_detected" />
        <result property="batteryCurrentConsumption" column="battery_current_consumption" />
        <result property="batteryNumberOfDisCharges" column="battery_number_of_discharges" />
        <result property="voltage" column="voltage" />
        <result property="power" column="power" />
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectHrDroneBatteryVo">
        select drone_battery_id,
               nest_code,
               is_battery_connected,
               is_cell_damaged,
               is_low_cell_voltage_detected,
               battery_current_consumption,
               battery_number_of_discharges,
               voltage,
               power,
               create_time,
               update_time
        from basedata_hr_drone_battery
    </sql>
    <insert id="insertDroneBattery">
        insert into basedata_hr_drone_battery (
        <if test="nestCode != null">nest_code,
        </if>
        <if test="isBatteryConnected != null">is_battery_connected,
        </if>
        <if test="isCellDamaged != null">
            is_cell_damaged,
        </if>
        <if test="isLowCellVoltageDetected != null">
            is_low_cell_voltage_detected,
        </if>
        <if test="batteryCurrentConsumption != null">
            battery_current_consumption,
        </if>
        <if test="batteryNumberOfDisCharges != null">
            battery_number_of_discharges,
        </if>
        <if test="voltage != null">
            voltage,
        </if>
        <if test="power != null">
            power,
        </if>
        create_time
        ) values(
        <if test="nestCode != null">
            #{nestCode},
        </if>
        <if test="isBatteryConnected != null">
            #{isBatteryConnected},
        </if>
        <if test="isCellDamaged != null">
            #{isCellDamaged},
        </if>
        <if test="isLowCellVoltageDetected != null">
            #{isLowCellVoltageDetected},
        </if>
        <if test="batteryCurrentConsumption != null">
            #{batteryCurrentConsumption},
        </if>
        <if test="batteryNumberOfDisCharges != null">
            #{batteryNumberOfDisCharges},
        </if>
        <if test="voltage != null">
            #{voltage},
        </if>
        <if test="power != null">
            #{power},
        </if>
        sysdate()
        )
    </insert>

    <select id="selectDroneBatteryList" parameterType="com.inspect.metadata.mqtt.domain.HrDroneBattery"
            resultMap="HrDroneBatteryResult">
        <include refid="selectHrDroneBatteryVo"/>
        <where>
            <if test="nestCode != null ">and nest_code = #{nestCode}</if>
        </where>
        order by create_time
    </select>

    <select id="selectDroneBatteryOne" resultType="com.inspect.metadata.mqtt.domain.HrDroneBattery" resultMap="HrDroneBatteryResult">
        <include refid="selectHrDroneBatteryVo"/>
        <where>
            <if test="nestCode != null ">and nest_code = #{nestCode}</if>
        </where>
        order by create_time desc limit 1
    </select>
</mapper>