<?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.BmsChargeTemperatureMapper">
    
    <resultMap type="BmsChargeTemperature" id="BmsChargeTemperatureResult">
        <result property="id"    column="id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="timestamp"    column="timestamp"    />
        <result property="tempIndex"    column="temp_index"    />
        <result property="temperature"    column="temperature"    />
        <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="selectBmsChargeTemperatureVo">
        select id, device_id, `timestamp`, temp_index, temperature, create_by, update_by, create_time, update_time from bms_charge_temperature
    </sql>

    <select id="selectBmsChargeTemperatureList" parameterType="BmsChargeTemperature" resultMap="BmsChargeTemperatureResult">
        <include refid="selectBmsChargeTemperatureVo"/>
        <where>  
            <if test="deviceId != null  and deviceId != ''"> and device_id = #{deviceId}</if>
            <if test="timestamp != null "> and `timestamp` = #{timestamp}</if>
            <if test="tempIndex != null "> and temp_index = #{tempIndex}</if>
            <if test="temperature != null "> and temperature = #{temperature}</if>
        </where>
    </select>
    
    <select id="selectBmsChargeTemperatureById" parameterType="Long" resultMap="BmsChargeTemperatureResult">
        <include refid="selectBmsChargeTemperatureVo"/>
        where id = #{id}
    </select>

    <insert id="insertBmsChargeTemperature" parameterType="BmsChargeTemperature" useGeneratedKeys="true" keyProperty="id">
        insert into bms_charge_temperature
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceId != null and deviceId != ''">device_id,</if>
            <if test="timestamp != null">`timestamp`,</if>
            <if test="tempIndex != null">temp_index,</if>
            <if test="temperature != null">temperature,</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="tempIndex != null">#{tempIndex},</if>
            <if test="temperature != null">#{temperature},</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="updateBmsChargeTemperature" parameterType="BmsChargeTemperature">
        update bms_charge_temperature
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null and deviceId != ''">device_id = #{deviceId},</if>
            <if test="timestamp != null">`timestamp` = #{timestamp},</if>
            <if test="tempIndex != null">temp_index = #{tempIndex},</if>
            <if test="temperature != null">temperature = #{temperature},</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="deleteBmsChargeTemperatureById" parameterType="Long">
        delete from bms_charge_temperature where id = #{id}
    </delete>

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