数据20250904优化

This commit is contained in:
2025-09-12 04:40:47 +08:00
parent ab6771d33d
commit bfdbc4f42c
14 changed files with 162 additions and 68 deletions

View File

@ -918,24 +918,25 @@
</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
SELECT ammeterDate,
dataUpdateTime,
totalChargedCap,
totalDisChargedCap,
totalChargedCap - LAG(totalChargedCap) OVER (ORDER BY ammeterDate) AS chargedCap,
totalDisChargedCap - LAG(totalDisChargedCap) OVER (ORDER BY ammeterDate) AS disChargedCap
FROM ( SELECT data_update_time AS dataUpdateTime,
current_forward_active_total AS totalChargedCap,
current_reverse_active_total AS totalDisChargedCap,
DATE_FORMAT(data_update_time, '%H:00') AS ammeterDate,
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
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>

View File

@ -428,8 +428,8 @@
</select>
<select id="getSiteSumStackInfo" parameterType="String" resultType="com.xzzn.ems.domain.EmsBatteryStack">
select SUM(t.stack_soc) as stackSoc,
sum(t.stack_soh) as stackSoh
select AVG(t.stack_soc) as stackSoc,
AVG(t.stack_soh) as stackSoh
from ems_battery_stack t
INNER JOIN (
select p.site_id,p.device_id,MAX(p.create_time) as max_time

View File

@ -143,16 +143,25 @@
</insert>
<select id="getAllSiteChargeData" resultType="map">
SELECT SUM(t.total_charge_data) AS totalChargedCap,
SUM(t.total_discharge_data) AS totalDischargedCap
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}
LEFT JOIN ems_site_setting ss ON t.site_id = ss.site_id
INNER JOIN (
SELECT site_id,MAX(date_time) AS latest_date FROM ems_daily_charge_data
WHERE date_time &lt;= #{nowData}
<if test="siteId != null">
and t.site_id = #{siteId}
and site_id = #{siteId}
</if>
AND t.total_charge_data IS NOT NULL
AND t.total_discharge_data IS NOT NULL
AND total_charge_data IS NOT NULL
AND total_discharge_data IS NOT NULL
GROUP BY site_id
) AS latest ON t.date_time = latest.latest_date
and t.site_id = latest.site_id
<if test="siteId != null">
where t.site_id = #{siteId}
</if>
</select>
<select id="getSingleSiteChargeData" resultType="com.xzzn.ems.domain.vo.SiteMonitorDataVo">
@ -168,11 +177,34 @@
<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
SUM(t.charge_data) as chargedCap,
SUM(t.discharge_data) as disChargedCap
FROM ems_daily_charge_data t
WHERE t.site_id = #{siteId}
AND t.date_time BETWEEN #{startDate} AND #{endDate}
group BY ammeterDate
order by ammeterDate
</select>
<select id="getTotalChargeDataByMonth" resultType="com.xzzn.ems.domain.vo.SiteMonitorDataVo">
SELECT
DATE_FORMAT(t.date_time, '%Y-%m') AS ammeterMonth,
SUM(t.charge_data) AS chargedCap,
SUM(t.discharge_data) AS disChargedCap
FROM ems_daily_charge_data t
WHERE t.site_id = #{siteId}
AND t.date_time BETWEEN #{startDate} AND #{endDate}
GROUP BY ammeterMonth
ORDER BY ammeterMonth
</select>
<select id="getAllSiteChargeDataByMonth" resultType="com.xzzn.ems.domain.vo.ElectricIndexList">
SELECT
DATE_FORMAT(t.date_time, '%Y-%m') AS dateMonth,
SUM(t.charge_data) AS chargeEnergy,
SUM(t.discharge_data) AS disChargeEnergy
FROM ems_daily_charge_data t
GROUP BY dateMonth
ORDER BY dateMonth
</select>
</mapper>

View File

@ -182,10 +182,15 @@
</select>
<select id="getDeviceInfosBySiteIdAndCategory" resultType="java.util.Map">
select DISTINCT device_id as id,
device_name as deviceName,
communication_status as communicationStatus
from ems_devices_setting where site_id = #{siteId} and device_category = #{deviceCategory}
select DISTINCT t1.device_id as id,
t1.device_name as deviceName,
t1.communication_status as communicationStatus,
t1.parent_id as parentDeviceId,
t2.device_name as parentDeviceName
from ems_devices_setting t1
LEFT JOIN ems_devices_setting t2
ON t1.parent_id = t2.device_id and t1.site_id = t2.site_id
where t1.site_id = #{siteId} and t1.device_category = #{deviceCategory}
</select>
<select id="getDeviceBySiteAndDeviceId" parameterType="String" resultMap="EmsDevicesSettingResult">
@ -195,8 +200,8 @@
limit 1
</select>
<select id="getLoadNameList" parameterType="String" resultType="java.util.Map">
select distinct device_id as id,device_name as deviceName from ems_devices_setting where site_id = #{siteId} and device_id like '%LOAD%'
<select id="getAmmeterNameList" parameterType="String" resultType="java.util.Map">
select distinct device_id as id,device_name as deviceName from ems_devices_setting where site_id = #{siteId} and device_category = 'AMMETER'
</select>
<select id="getClusterIdsByFuzzyQuery" resultType="java.util.Map">

View File

@ -454,8 +454,8 @@
<select id="getPcsDataByHour" resultType="com.xzzn.ems.domain.vo.SiteMonitorDataVo">
select latest.dateHour as ammeterDate,
sum(t.total_ac_charge_energy) as chargedCap,
sum(t.total_ac_discharge_energy) as disChargedCap
sum(t.daily_ac_charge_energy) as chargedCap,
sum(t.daily_ac_discharge_energy) as disChargedCap
from ( SELECT p.site_id, p.device_id,DATE_FORMAT(p.data_update_time, '%H')+1 AS dateHour,MAX(p.data_update_time) as max_update_time
FROM ems_pcs_data p
<include refid="commonFilter"/>