20250808优化-充放电逻辑修改
This commit is contained in:
@ -891,4 +891,75 @@
|
||||
and DATE(data_update_time) = #{yestData}
|
||||
order by data_update_time desc limit 1
|
||||
</select>
|
||||
|
||||
<select id="getMonthlyTimeRanges" resultType="com.xzzn.ems.domain.vo.MonthlyTimeRange">
|
||||
SELECT site_id as siteId,
|
||||
DATE_FORMAT(data_update_time, '%Y-%m') AS month,
|
||||
MIN(data_update_time) AS firstDataTime,
|
||||
MAX(data_update_time) AS lastDataTime
|
||||
FROM ems_ammeter_data
|
||||
WHERE (site_id = '021_DDS_01' AND device_id = 'METE')
|
||||
OR (site_id = '021_FXX_01' AND device_id = 'LOAD')
|
||||
GROUP BY site_id, DATE_FORMAT(data_update_time, '%Y-%m')
|
||||
ORDER BY site_id, month
|
||||
</select>
|
||||
|
||||
<select id="batchGetTimePointValues" resultType="com.xzzn.ems.domain.vo.TimePointValue">
|
||||
SELECT site_id as siteId, data_update_time as dataUpdateTime,
|
||||
current_forward_active_total AS totalChargeData,
|
||||
current_reverse_active_total AS totalDischargeData
|
||||
FROM ems_ammeter_data
|
||||
WHERE (site_id, data_update_time) IN
|
||||
<foreach collection="list" item="item" separator="," open="(" close=")">
|
||||
(#{item.siteId}, #{item.dataTime})
|
||||
</foreach>
|
||||
AND ((site_id = '021_DDS_01' AND device_id = 'METE')
|
||||
OR (site_id = '021_FXX_01' AND device_id = 'LOAD'))
|
||||
</select>
|
||||
|
||||
<select id="getChargeDataByHour" resultType="com.xzzn.ems.domain.vo.SiteMonitorDataVo">
|
||||
SELECT hour AS ammeterDate,
|
||||
data_update_time AS dataUpdateTime,
|
||||
current_forward_active_total AS chargedCap,
|
||||
current_reverse_active_total AS disChargedCap
|
||||
FROM (
|
||||
SELECT data_update_time,
|
||||
current_forward_active_total,
|
||||
current_reverse_active_total,
|
||||
DATE_FORMAT(data_update_time, '%H:00') AS hour,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY DATE_FORMAT(data_update_time, '%H:00')
|
||||
ORDER BY data_update_time DESC
|
||||
) AS rn
|
||||
FROM ems_ammeter_data
|
||||
WHERE site_id = #{siteId}
|
||||
AND device_id = #{deviceId}
|
||||
AND DATE(data_update_time) = #{startDate}
|
||||
) AS hourly_data
|
||||
WHERE rn = 1
|
||||
ORDER BY ammeterDate
|
||||
</select>
|
||||
|
||||
<select id="getChargeDataByMonth" resultType="com.xzzn.ems.domain.vo.SiteMonitorDataVo">
|
||||
SELECT month as ammeterDate,
|
||||
data_update_time AS dataUpdateTime,
|
||||
current_forward_active_total AS chargedCap,
|
||||
current_reverse_active_total AS disChargedCap
|
||||
FROM (
|
||||
SELECT DATE_FORMAT(data_update_time, '%Y-%m') AS month,
|
||||
data_update_time,
|
||||
current_forward_active_total,
|
||||
current_reverse_active_total,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY DATE_FORMAT(data_update_time, '%Y-%m')
|
||||
ORDER BY data_update_time DESC
|
||||
) AS rn
|
||||
FROM ems_ammeter_data
|
||||
WHERE site_id = #{siteId}
|
||||
AND device_id = #{deviceId}
|
||||
AND data_update_time BETWEEN #{startDate} AND #{endDate}
|
||||
) AS monthly_data
|
||||
WHERE rn = 1
|
||||
ORDER BY ammeterDate
|
||||
</select>
|
||||
</mapper>
|
||||
@ -0,0 +1,177 @@
|
||||
<?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.EmsDailyChargeDataMapper">
|
||||
|
||||
<resultMap type="EmsDailyChargeData" id="EmsDailyChargeDataResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="siteId" column="site_id" />
|
||||
<result property="deviceId" column="device_id" />
|
||||
<result property="dateTime" column="date_time" />
|
||||
<result property="totalChargeData" column="total_charge_Data" />
|
||||
<result property="totalDischargeData" column="total_discharge_Data" />
|
||||
<result property="chargeData" column="charge_data" />
|
||||
<result property="dischargeData" column="discharge_data" />
|
||||
<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="selectEmsDailyChargeDataVo">
|
||||
select id, site_id, device_id, date_time, total_charge_Data, total_discharge_Data, charge_data, discharge_data, create_by, create_time, update_by, update_time, remark from ems_daily_charge_data
|
||||
</sql>
|
||||
|
||||
<select id="selectEmsDailyChargeDataList" parameterType="EmsDailyChargeData" resultMap="EmsDailyChargeDataResult">
|
||||
<include refid="selectEmsDailyChargeDataVo"/>
|
||||
<where>
|
||||
<if test="siteId != null and siteId != ''"> and site_id = #{siteId}</if>
|
||||
<if test="deviceId != null and deviceId != ''"> and device_id = #{deviceId}</if>
|
||||
<if test="dateTime != null "> and date_time = #{dateTime}</if>
|
||||
<if test="totalChargeData != null "> and total_charge_Data = #{totalChargeData}</if>
|
||||
<if test="totalDischargeData != null "> and total_discharge_Data = #{totalDischargeData}</if>
|
||||
<if test="chargeData != null "> and charge_data = #{chargeData}</if>
|
||||
<if test="dischargeData != null "> and discharge_data = #{dischargeData}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectEmsDailyChargeDataById" parameterType="Long" resultMap="EmsDailyChargeDataResult">
|
||||
<include refid="selectEmsDailyChargeDataVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertEmsDailyChargeData" parameterType="EmsDailyChargeData" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into ems_daily_charge_data
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="siteId != null">site_id,</if>
|
||||
<if test="deviceId != null and deviceId != ''">device_id,</if>
|
||||
<if test="dateTime != null">date_time,</if>
|
||||
<if test="totalChargeData != null">total_charge_Data,</if>
|
||||
<if test="totalDischargeData != null">total_discharge_Data,</if>
|
||||
<if test="chargeData != null">charge_data,</if>
|
||||
<if test="dischargeData != null">discharge_data,</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="siteId != null">#{siteId},</if>
|
||||
<if test="deviceId != null and deviceId != ''">#{deviceId},</if>
|
||||
<if test="dateTime != null">#{dateTime},</if>
|
||||
<if test="totalChargeData != null">#{totalChargeData},</if>
|
||||
<if test="totalDischargeData != null">#{totalDischargeData},</if>
|
||||
<if test="chargeData != null">#{chargeData},</if>
|
||||
<if test="dischargeData != null">#{dischargeData},</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="updateEmsDailyChargeData" parameterType="EmsDailyChargeData">
|
||||
update ems_daily_charge_data
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="siteId != null">site_id = #{siteId},</if>
|
||||
<if test="deviceId != null and deviceId != ''">device_id = #{deviceId},</if>
|
||||
<if test="dateTime != null">date_time = #{dateTime},</if>
|
||||
<if test="totalChargeData != null">total_charge_Data = #{totalChargeData},</if>
|
||||
<if test="totalDischargeData != null">total_discharge_Data = #{totalDischargeData},</if>
|
||||
<if test="chargeData != null">charge_data = #{chargeData},</if>
|
||||
<if test="dischargeData != null">discharge_data = #{dischargeData},</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="deleteEmsDailyChargeDataById" parameterType="Long">
|
||||
delete from ems_daily_charge_data where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteEmsDailyChargeDataByIds" parameterType="String">
|
||||
delete from ems_daily_charge_data where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<insert id="insertOrUpdateData" parameterType="EmsDailyChargeData">
|
||||
INSERT into ems_daily_charge_data (
|
||||
id,
|
||||
site_id,
|
||||
device_id,
|
||||
date_time,
|
||||
total_charge_Data,
|
||||
total_discharge_Data,
|
||||
charge_data,
|
||||
discharge_data,
|
||||
create_by,
|
||||
create_time,
|
||||
update_by,
|
||||
update_time,
|
||||
remark
|
||||
) values (
|
||||
#{id},
|
||||
#{siteId},
|
||||
#{deviceId},
|
||||
#{dateTime},
|
||||
#{totalChargeData},
|
||||
#{totalDischargeData},
|
||||
#{chargeData},
|
||||
#{dischargeData},
|
||||
#{createBy},
|
||||
#{createTime},
|
||||
#{updateBy},
|
||||
#{updateTime},
|
||||
#{remark}
|
||||
)
|
||||
on duplicate key update
|
||||
total_charge_Data = #{totalChargeData},
|
||||
total_discharge_Data = #{totalDischargeData},
|
||||
charge_data = #{chargeData},
|
||||
discharge_data = #{dischargeData},
|
||||
update_time = NOW()
|
||||
</insert>
|
||||
|
||||
<select id="getAllSiteChargeData" resultType="map">
|
||||
SELECT SUM(t.total_charge_data) AS totalChargedCap,
|
||||
SUM(t.total_discharge_data) AS totalDischargedCap
|
||||
FROM ems_daily_charge_data t
|
||||
LEFT JOIN ems_site_setting ss ON t.site_id = ss.site_id
|
||||
WHERE t.date_time = #{nowData}
|
||||
<if test="siteId != null">
|
||||
and t.site_id = #{siteId}
|
||||
</if>
|
||||
AND t.total_charge_data IS NOT NULL
|
||||
AND t.total_discharge_data IS NOT NULL
|
||||
</select>
|
||||
|
||||
<select id="getSingleSiteChargeData" resultType="com.xzzn.ems.domain.vo.SiteMonitorDataVo">
|
||||
SELECT t.charge_data AS chargedCap,
|
||||
t.discharge_data AS disChargedCap,
|
||||
t.date_time AS ammeterDate
|
||||
FROM ems_daily_charge_data t
|
||||
WHERE t.site_id = #{siteId}
|
||||
AND t.date_time BETWEEN #{startDate} AND #{endDate}
|
||||
order by ammeterDate
|
||||
</select>
|
||||
|
||||
<select id="getTotalChargeDataByDay" resultType="com.xzzn.ems.domain.vo.SiteMonitorDataVo">
|
||||
SELECT t.date_time AS ammeterDate,
|
||||
t.total_charge_Data as chargedCap,
|
||||
t.total_discharge_Data as disChargedCap
|
||||
FROM ems_daily_charge_data t
|
||||
WHERE t.site_id = #{siteId}
|
||||
AND t.date_time BETWEEN #{startDate} AND #{endDate}
|
||||
order by ammeterDate
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user