<?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.EmsEmsDataMapper">
    
    <resultMap type="EmsEmsData" id="EmsEmsDataResult">
        <result property="id"    column="id"    />
        <result property="dataUpdateTime"    column="data_update_time"    />
        <result property="emsStatus"    column="ems_status"    />
        <result property="bms1Soc"    column="bms1_soc"    />
        <result property="bms2Soc"    column="bms2_soc"    />
        <result property="bms3Soc"    column="bms3_soc"    />
        <result property="bms4Soc"    column="bms4_soc"    />
        <result property="pcs1Yggl"    column="pcs1_yggl"    />
        <result property="pcs2Yggl"    column="pcs2_yggl"    />
        <result property="pcs3Yggl"    column="pcs3_yggl"    />
        <result property="pcs4Yggl"    column="pcs4_yggl"    />
        <result property="emsYggl"    column="ems_yggl"    />
        <result property="siteId"    column="site_id"    />
        <result property="deviceId"    column="device_id"    />
        <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"    />
    </resultMap>

    <sql id="selectEmsEmsDataVo">
        select id, data_update_time, ems_status, bms1_soc, bms2_soc, bms3_soc, bms4_soc, pcs1_yggl, pcs2_yggl, pcs3_yggl, pcs4_yggl, ems_yggl, site_id, device_id, create_by, create_time, update_by, update_time, remark from ems_ems_data
    </sql>

    <select id="selectEmsEmsDataList" parameterType="EmsEmsData" resultMap="EmsEmsDataResult">
        <include refid="selectEmsEmsDataVo"/>
        <where>  
            <if test="dataUpdateTime != null "> and data_update_time = #{dataUpdateTime}</if>
            <if test="emsStatus != null  and emsStatus != ''"> and ems_status = #{emsStatus}</if>
            <if test="bms1Soc != null "> and bms1_soc = #{bms1Soc}</if>
            <if test="bms2Soc != null "> and bms2_soc = #{bms2Soc}</if>
            <if test="bms3Soc != null "> and bms3_soc = #{bms3Soc}</if>
            <if test="bms4Soc != null "> and bms4_soc = #{bms4Soc}</if>
            <if test="pcs1Yggl != null "> and pcs1_yggl = #{pcs1Yggl}</if>
            <if test="pcs2Yggl != null "> and pcs2_yggl = #{pcs2Yggl}</if>
            <if test="pcs3Yggl != null "> and pcs3_yggl = #{pcs3Yggl}</if>
            <if test="pcs4Yggl != null "> and pcs4_yggl = #{pcs4Yggl}</if>
            <if test="emsYggl != null "> and ems_yggl = #{emsYggl}</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="selectEmsEmsDataById" parameterType="Long" resultMap="EmsEmsDataResult">
        <include refid="selectEmsEmsDataVo"/>
        where id = #{id}
    </select>

    <insert id="insertEmsEmsData" parameterType="EmsEmsData" useGeneratedKeys="true" keyProperty="id">
        insert into ems_ems_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dataUpdateTime != null">data_update_time,</if>
            <if test="emsStatus != null">ems_status,</if>
            <if test="bms1Soc != null">bms1_soc,</if>
            <if test="bms2Soc != null">bms2_soc,</if>
            <if test="bms3Soc != null">bms3_soc,</if>
            <if test="bms4Soc != null">bms4_soc,</if>
            <if test="pcs1Yggl != null">pcs1_yggl,</if>
            <if test="pcs2Yggl != null">pcs2_yggl,</if>
            <if test="pcs3Yggl != null">pcs3_yggl,</if>
            <if test="pcs4Yggl != null">pcs4_yggl,</if>
            <if test="emsYggl != null">ems_yggl,</if>
            <if test="siteId != null">site_id,</if>
            <if test="deviceId != null and deviceId != ''">device_id,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="dataUpdateTime != null">#{dataUpdateTime},</if>
            <if test="emsStatus != null">#{emsStatus},</if>
            <if test="bms1Soc != null">#{bms1Soc},</if>
            <if test="bms2Soc != null">#{bms2Soc},</if>
            <if test="bms3Soc != null">#{bms3Soc},</if>
            <if test="bms4Soc != null">#{bms4Soc},</if>
            <if test="pcs1Yggl != null">#{pcs1Yggl},</if>
            <if test="pcs2Yggl != null">#{pcs2Yggl},</if>
            <if test="pcs3Yggl != null">#{pcs3Yggl},</if>
            <if test="pcs4Yggl != null">#{pcs4Yggl},</if>
            <if test="emsYggl != null">#{emsYggl},</if>
            <if test="siteId != null">#{siteId},</if>
            <if test="deviceId != null and deviceId != ''">#{deviceId},</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>
         </trim>
    </insert>

    <update id="updateEmsEmsData" parameterType="EmsEmsData">
        update ems_ems_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="dataUpdateTime != null">data_update_time = #{dataUpdateTime},</if>
            <if test="emsStatus != null">ems_status = #{emsStatus},</if>
            <if test="bms1Soc != null">bms1_soc = #{bms1Soc},</if>
            <if test="bms2Soc != null">bms2_soc = #{bms2Soc},</if>
            <if test="bms3Soc != null">bms3_soc = #{bms3Soc},</if>
            <if test="bms4Soc != null">bms4_soc = #{bms4Soc},</if>
            <if test="pcs1Yggl != null">pcs1_yggl = #{pcs1Yggl},</if>
            <if test="pcs2Yggl != null">pcs2_yggl = #{pcs2Yggl},</if>
            <if test="pcs3Yggl != null">pcs3_yggl = #{pcs3Yggl},</if>
            <if test="pcs4Yggl != null">pcs4_yggl = #{pcs4Yggl},</if>
            <if test="emsYggl != null">ems_yggl = #{emsYggl},</if>
            <if test="siteId != null">site_id = #{siteId},</if>
            <if test="deviceId != null and deviceId != ''">device_id = #{deviceId},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteEmsEmsDataById" parameterType="Long">
        delete from ems_ems_data where id = #{id}
    </delete>

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