<?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.EmsSiteMonitorDataMapper">

    <select id="selectHistoryJsonByMinute" resultType="java.lang.String">
        select data_json
        from ${tableName}
        where site_id = #{siteId}
          and statis_minute = #{statisMinute}
        limit 1
    </select>

    <insert id="upsertHistoryJsonByMinute">
        insert into ${tableName} (
            site_id, statis_minute, data_json,
            hot_soc, hot_total_active_power, hot_total_reactive_power, hot_day_charged_cap, hot_day_dis_charged_cap,
            create_by, create_time, update_by, update_time
        ) values (
            #{siteId}, #{statisMinute}, #{dataJson},
            #{hotSoc}, #{hotTotalActivePower}, #{hotTotalReactivePower}, #{hotDayChargedCap}, #{hotDayDisChargedCap},
            #{operName}, now(), #{operName}, now()
        )
        on duplicate key update
            data_json = values(data_json),
            hot_soc = values(hot_soc),
            hot_total_active_power = values(hot_total_active_power),
            hot_total_reactive_power = values(hot_total_reactive_power),
            hot_day_charged_cap = values(hot_day_charged_cap),
            hot_day_dis_charged_cap = values(hot_day_dis_charged_cap),
            update_by = values(update_by),
            update_time = now()
    </insert>

</mapper>
