sql优化

This commit is contained in:
2025-06-30 13:11:05 +08:00
parent 49a3ce2c11
commit cebd845af1
13 changed files with 356 additions and 169 deletions

View File

@ -311,27 +311,45 @@
<select id="getBMSBatteryCluster" parameterType="String" resultType="com.xzzn.ems.domain.vo.BMSBatteryClusterVo">
select td.device_name as deviceName, tmp.work_status as workStatus,
tmp.pcs_communication_status as pcsCommunicationStatus, tmp.ems_communication_status as emsCommunicationStatus,
tmp.cluster_voltage as clusterVoltage,tmp.chargeable_capacity as chargeableCapacity, tmp.total_charged_capacity as totalChargedCapacity,
tmp.cluster_current as clusterCurrent,tmp.dischargeable_capacity as dischargeableCapacity, tmp.total_discharged_capacity as totalDischargedCapacity,
tmp.soh as soh,tmp.average_temperature as averageTemperature,tmp.insulation_resistance as insulationResistance,
tmp.current_soc as currentSoc,tmp.site_id as siteId,tmp.device_id as deviceId
from ems_battery_cluster tmp left join ems_devices_setting td on tmp.device_id = td.id and tmp.site_id = td.site_id
tmp.pcs_communication_status as pcsCommunicationStatus, tmp.ems_communication_status as emsCommunicationStatus,
tmp.cluster_voltage as clusterVoltage,tmp.chargeable_capacity as chargeableCapacity,
tmp.total_charged_capacity as totalChargedCapacity,
tmp.cluster_current as clusterCurrent,tmp.dischargeable_capacity as dischargeableCapacity,
tmp.total_discharged_capacity as totalDischargedCapacity,
tmp.soh as soh,tmp.average_temperature as averageTemperature,tmp.insulation_resistance as insulationResistance,
tmp.current_soc as currentSoc,tmp.site_id as siteId,tmp.device_id as deviceId,
tmp.avg_cell_voltage as avgVoltage,tmp.avg_cell_temp as avgTemp,tmp.avg_cell_temp as avgSoc,
tmp.max_cell_voltage as maxVoltage,tmp.max_cell_voltage_id as maxVoltageId,
tmp.min_cell_voltage as minVolatage,tmp.min_cell_voltage_id as minVoltageId,
tmp.max_cell_temp as maxTem,tmp.max_cell_temp_id as maxTempId,
tmp.min_cell_temp as minTemp,tmp.min_cell_temp_id as minTempId,
tmp.max_cell_soc as maxSoc,tmp.max_cell_soc_id as maxSocId,
tmp.min_cell_soc as minSoc,tmp.min_cell_soc_id as minSocId
from ems_battery_cluster tmp left join ems_devices_setting td on tmp.device_id = td.device_id and tmp.site_id = td.site_id
INNER JOIN (
SELECT p.site_id, p.device_id, MAX(p.update_time) AS max_update_time
FROM ems_battery_cluster p
WHERE p.site_id = #{siteId}
GROUP BY p.site_id,p.device_id
) latest on tmp.device_id = latest.device_id and tmp.update_time = latest.max_update_time
where tmp.site_id = #{siteId}
and tmp.update_time = (select MAX(t.update_time) FROM ems_battery_cluster t where t.site_id = tmp.site_id
and t.device_id = tmp.device_id)
order by tmp.device_id
</select>
<select id="getBmsBatteryData" resultType="com.xzzn.ems.domain.vo.BMSBatteryDataList">
select t.cluster_voltage as clusterVoltage,t.cluster_current as clusterCurrent,
t.current_soc as currentSoc,MAX(tb.voltage) as maxVoltage,MIN(tb.voltage) as minVoltage,
MAX(tb.temperature) as maxTemperature,MIN(tb.temperature) as minTemperature,
tb.site_id as siteId,tb.cluster_device_id as clusterId,tb.device_id as stackDeviceId
from ems_battery_cluster t left join ems_battery_data tb on t.device_id = tb.cluster_device_id
SELECT t.cluster_voltage as clusterVoltage,t.cluster_current as clusterCurrent,
t.current_soc as currentSoc,t.site_id as siteId,t.device_id as clusterId,
t.max_cell_voltage as maxVoltage,t.min_cell_voltage as minVoltage,
t.max_cell_temp as maxTemperature,t.min_cell_temp as minTemperature
FROM ems_battery_cluster t
INNER JOIN (
SELECT p.site_id, p.device_id, MAX(p.update_time) AS max_update_time
FROM ems_battery_cluster p
WHERE p.site_id = #{siteId} and p.stack_device_id = #{stackDeviceId}
GROUP BY p.site_id,p.device_id
) latest on t.device_id = latest.device_id and t.update_time = latest.max_update_time
where t.site_id = #{siteId} and t.stack_device_id = #{stackDeviceId}
and t.update_time = (select MAX(update_time) FROM ems_battery_cluster where site_id = t.site_id
and device_id = t.device_id and stack_device_id = t.stack_device_id)
group by t.cluster_voltage,t.cluster_current,t.current_soc,tb.site_id,tb.cluster_device_id,tb.device_id
group by t.cluster_voltage,t.cluster_current,t.current_soc,t.site_id,t.device_id,t.max_cell_voltage,t.min_cell_voltage,
t.max_cell_temp,t.min_cell_temp
</select>
</mapper>