<?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.xzzn.ems.mapper.EmsBatteryGroupMapper">

    <resultMap type="EmsBatteryGroup" id="EmsBatteryGroupResult">
        <result property="id"    column="id"    />
        <result property="status"    column="status"    />
        <result property="voltage"    column="voltage"    />
        <result property="current"    column="current"    />
        <result property="soc"    column="soc"    />
        <result property="soh"    column="soh"    />
        <result property="estimatedBackupDuration"    column="estimated_backup_duration"    />
        <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="siteId"    column="site_id"    />
        <result property="deviceId"    column="device_id"    />
    </resultMap>

    <sql id="selectEmsBatteryGroupVo">
        select id, status, voltage, current, soc, soh, estimated_backup_duration, create_by, create_time, update_by, update_time, remark, site_id, device_id from ems_battery_group
    </sql>

    <select id="selectEmsBatteryGroupList" parameterType="EmsBatteryGroup" resultMap="EmsBatteryGroupResult">
        <include refid="selectEmsBatteryGroupVo"/>
        <where>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="voltage != null "> and voltage = #{voltage}</if>
            <if test="current != null "> and current = #{current}</if>
            <if test="soc != null "> and soc = #{soc}</if>
            <if test="soh != null "> and soh = #{soh}</if>
            <if test="estimatedBackupDuration != null "> and estimated_backup_duration = #{estimatedBackupDuration}</if>
            <if test="siteId != null  and siteId != ''"> and site_id = #{siteId}</if>
            <if test="deviceId != null  and deviceId != ''"> and device_id = #{deviceId}</if>
        </where>
    </select>

    <select id="selectEmsBatteryGroupById" parameterType="Long" resultMap="EmsBatteryGroupResult">
        <include refid="selectEmsBatteryGroupVo"/>
        where id = #{id}
    </select>

    <insert id="insertEmsBatteryGroup" parameterType="EmsBatteryGroup" useGeneratedKeys="true" keyProperty="id">
        insert into ems_battery_group
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="status != null">status,</if>
            <if test="voltage != null">voltage,</if>
            <if test="current != null">current,</if>
            <if test="soc != null">soc,</if>
            <if test="soh != null">soh,</if>
            <if test="estimatedBackupDuration != null">estimated_backup_duration,</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="siteId != null">site_id,</if>
            <if test="deviceId != null and deviceId != ''">device_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="status != null">#{status},</if>
            <if test="voltage != null">#{voltage},</if>
            <if test="current != null">#{current},</if>
            <if test="soc != null">#{soc},</if>
            <if test="soh != null">#{soh},</if>
            <if test="estimatedBackupDuration != null">#{estimatedBackupDuration},</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="siteId != null">#{siteId},</if>
            <if test="deviceId != null and deviceId != ''">#{deviceId},</if>
        </trim>
    </insert>

    <update id="updateEmsBatteryGroup" parameterType="EmsBatteryGroup">
        update ems_battery_group
        <trim prefix="SET" suffixOverrides=",">
            <if test="status != null">status = #{status},</if>
            <if test="voltage != null">voltage = #{voltage},</if>
            <if test="current != null">current = #{current},</if>
            <if test="soc != null">soc = #{soc},</if>
            <if test="soh != null">soh = #{soh},</if>
            <if test="estimatedBackupDuration != null">estimated_backup_duration = #{estimatedBackupDuration},</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="siteId != null">site_id = #{siteId},</if>
            <if test="deviceId != null and deviceId != ''">device_id = #{deviceId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteEmsBatteryGroupById" parameterType="Long">
        delete from ems_battery_group where id = #{id}
    </delete>

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

    <insert id="batchInsertGroupData" parameterType="java.util.List">
        INSERT INTO ems_battery_group (
        status,
        voltage,
        current,
        soc,
        soh,
        estimated_backup_duration,
        create_by,
        create_time,
        update_by,
        update_time,
        remark,
        site_id,
        device_id
        ) VALUES
        <!-- 遍历集合生成多条记录，注意separator和括号闭合 -->
        <foreach collection="list" item="item" separator=",">
            (
            #{item.status},
            #{item.voltage},
            #{item.current},
            #{item.soc},
            #{item.soh},
            #{item.estimatedBackupDuration},
            #{item.createBy},
            #{item.createTime},
            #{item.updateBy},
            #{item.updateTime},
            #{item.remark},
            #{item.siteId},
            #{item.deviceId}
            )
        </foreach>
    </insert>

</mapper>