<?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.evobms.project.bms.mapper.BmsRuntimeDataMapper">

    <resultMap type="BmsRuntimeData" id="BmsRuntimeDataResult">
        <result property="id"    column="id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="timestamp"    column="timestamp"    />
        <result property="vehicleSpeed"    column="vehicle_speed"    />
        <result property="mileage"    column="mileage"    />
        <result property="systemVoltage"    column="system_voltage"    />
        <result property="systemCurrent"    column="system_current"    />
        <result property="insulationResistance"    column="insulation_resistance"    />
        <result property="socMax"    column="soc_max"    />
        <result property="socMin"    column="soc_min"    />
        <result property="gpvVoltage"    column="gpv_voltage"    />
        <result property="runStatus"    column="run_status"    />
        <result property="powerStatus"    column="power_status"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectBmsRuntimeDataVo">
        select id, device_id, `timestamp`, vehicle_speed, mileage, system_voltage, system_current, insulation_resistance, soc_max, soc_min, gpv_voltage, run_status, power_status, create_by, update_by, create_time, update_time from bms_runtime_data
    </sql>

    <select id="selectBmsRuntimeDataList" parameterType="BmsRuntimeData" resultMap="BmsRuntimeDataResult">
        <include refid="selectBmsRuntimeDataVo"/>
        <where>
            <if test="deviceId != null  and deviceId != ''"> and device_id = #{deviceId}</if>
            <if test="timestamp != null "> and `timestamp` = #{timestamp}</if>
            <if test="vehicleSpeed != null "> and vehicle_speed = #{vehicleSpeed}</if>
            <if test="mileage != null "> and mileage = #{mileage}</if>
            <if test="systemVoltage != null "> and system_voltage = #{systemVoltage}</if>
            <if test="systemCurrent != null "> and system_current = #{systemCurrent}</if>
            <if test="insulationResistance != null "> and insulation_resistance = #{insulationResistance}</if>
            <if test="socMax != null "> and soc_max = #{socMax}</if>
            <if test="socMin != null "> and soc_min = #{socMin}</if>
            <if test="gpvVoltage != null "> and gpv_voltage = #{gpvVoltage}</if>
            <if test="runStatus != null "> and run_status = #{runStatus}</if>
            <if test="powerStatus != null "> and power_status = #{powerStatus}</if>
        </where>
    </select>

    <select id="selectBmsRuntimeDataById" parameterType="Long" resultMap="BmsRuntimeDataResult">
        <include refid="selectBmsRuntimeDataVo"/>
        where id = #{id}
    </select>

    <insert id="insertBmsRuntimeData" parameterType="BmsRuntimeData" useGeneratedKeys="true" keyProperty="id">
        insert into bms_runtime_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceId != null and deviceId != ''">device_id,</if>
            <if test="timestamp != null">`timestamp`,</if>
            <if test="vehicleSpeed != null">vehicle_speed,</if>
            <if test="mileage != null">mileage,</if>
            <if test="systemVoltage != null">system_voltage,</if>
            <if test="systemCurrent != null">system_current,</if>
            <if test="insulationResistance != null">insulation_resistance,</if>
            <if test="socMax != null">soc_max,</if>
            <if test="socMin != null">soc_min,</if>
            <if test="gpvVoltage != null">gpv_voltage,</if>
            <if test="runStatus != null">run_status,</if>
            <if test="powerStatus != null">power_status,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            <if test="updateBy != null and updateBy != ''">update_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceId != null and deviceId != ''">#{deviceId},</if>
            <if test="timestamp != null">#{timestamp},</if>
            <if test="vehicleSpeed != null">#{vehicleSpeed},</if>
            <if test="mileage != null">#{mileage},</if>
            <if test="systemVoltage != null">#{systemVoltage},</if>
            <if test="systemCurrent != null">#{systemCurrent},</if>
            <if test="insulationResistance != null">#{insulationResistance},</if>
            <if test="socMax != null">#{socMax},</if>
            <if test="socMin != null">#{socMin},</if>
            <if test="gpvVoltage != null">#{gpvVoltage},</if>
            <if test="runStatus != null">#{runStatus},</if>
            <if test="powerStatus != null">#{powerStatus},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="updateBy != null and updateBy != ''">#{updateBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateBmsRuntimeData" parameterType="BmsRuntimeData">
        update bms_runtime_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null and deviceId != ''">device_id = #{deviceId},</if>
            <if test="timestamp != null">`timestamp` = #{timestamp},</if>
            <if test="vehicleSpeed != null">vehicle_speed = #{vehicleSpeed},</if>
            <if test="mileage != null">mileage = #{mileage},</if>
            <if test="systemVoltage != null">system_voltage = #{systemVoltage},</if>
            <if test="systemCurrent != null">system_current = #{systemCurrent},</if>
            <if test="insulationResistance != null">insulation_resistance = #{insulationResistance},</if>
            <if test="socMax != null">soc_max = #{socMax},</if>
            <if test="socMin != null">soc_min = #{socMin},</if>
            <if test="gpvVoltage != null">gpv_voltage = #{gpvVoltage},</if>
            <if test="runStatus != null">run_status = #{runStatus},</if>
            <if test="powerStatus != null">power_status = #{powerStatus},</if>
            <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBmsRuntimeDataById" parameterType="Long">
        delete from bms_runtime_data where id = #{id}
    </delete>

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