<?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.BmsVoltageChannelDataMapper">
    
    <resultMap type="BmsVoltageChannelData" id="BmsVoltageChannelDataResult">
        <result property="id"    column="id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="timestamp"    column="timestamp"    />
        <result property="channelType"    column="channel_type"    />
        <result property="channelIndex"    column="channel_index"    />
        <result property="voltage"    column="voltage"    />
        <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="selectBmsVoltageChannelDataVo">
        select id, device_id, `timestamp`, channel_type, channel_index, voltage, create_by, update_by, create_time, update_time from bms_voltage_channel_data
    </sql>

    <select id="selectBmsVoltageChannelDataList" parameterType="BmsVoltageChannelData" resultMap="BmsVoltageChannelDataResult">
        <include refid="selectBmsVoltageChannelDataVo"/>
        <where>  
            <if test="deviceId != null  and deviceId != ''"> and device_id = #{deviceId}</if>
            <if test="timestamp != null "> and `timestamp` = #{timestamp}</if>
            <if test="channelType != null  and channelType != ''"> and channel_type = #{channelType}</if>
            <if test="channelIndex != null "> and channel_index = #{channelIndex}</if>
            <if test="voltage != null "> and voltage = #{voltage}</if>
        </where>
    </select>
    
    <select id="selectBmsVoltageChannelDataById" parameterType="Long" resultMap="BmsVoltageChannelDataResult">
        <include refid="selectBmsVoltageChannelDataVo"/>
        where id = #{id}
    </select>

    <insert id="insertBmsVoltageChannelData" parameterType="BmsVoltageChannelData" useGeneratedKeys="true" keyProperty="id">
        insert into bms_voltage_channel_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceId != null and deviceId != ''">device_id,</if>
            <if test="timestamp != null">`timestamp`,</if>
            <if test="channelType != null and channelType != ''">channel_type,</if>
            <if test="channelIndex != null">channel_index,</if>
            <if test="voltage != null">voltage,</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="channelType != null and channelType != ''">#{channelType},</if>
            <if test="channelIndex != null">#{channelIndex},</if>
            <if test="voltage != null">#{voltage},</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="updateBmsVoltageChannelData" parameterType="BmsVoltageChannelData">
        update bms_voltage_channel_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null and deviceId != ''">device_id = #{deviceId},</if>
            <if test="timestamp != null">`timestamp` = #{timestamp},</if>
            <if test="channelType != null and channelType != ''">channel_type = #{channelType},</if>
            <if test="channelIndex != null">channel_index = #{channelIndex},</if>
            <if test="voltage != null">voltage = #{voltage},</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="deleteBmsVoltageChannelDataById" parameterType="Long">
        delete from bms_voltage_channel_data where id = #{id}
    </delete>

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