2025-06-19 19:00:33 +08:00
|
|
|
<?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.EmsBatteryDataMapper">
|
|
|
|
|
|
|
|
|
|
<resultMap type="EmsBatteryData" id="EmsBatteryDataResult">
|
|
|
|
|
<result property="id" column="id" />
|
|
|
|
|
<result property="batteryPack" column="battery_pack" />
|
|
|
|
|
<result property="batteryCluster" column="battery_cluster" />
|
|
|
|
|
<result property="batteryCellId" column="battery_cell_id" />
|
|
|
|
|
<result property="voltage" column="voltage" />
|
|
|
|
|
<result property="temperature" column="temperature" />
|
|
|
|
|
<result property="soc" column="soc" />
|
|
|
|
|
<result property="soh" column="soh" />
|
|
|
|
|
<result property="dataTimestamp" column="data_timestamp" />
|
|
|
|
|
<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" />
|
|
|
|
|
<result property="siteId" column="site_id" />
|
|
|
|
|
<result property="deviceId" column="device_id" />
|
2025-06-27 10:14:15 +08:00
|
|
|
<result property="clusterDeviceId" column="cluster_device_id" />
|
2025-07-29 15:58:26 +08:00
|
|
|
<result property="interResistance" column="inter_resistance" />
|
2025-06-19 19:00:33 +08:00
|
|
|
</resultMap>
|
|
|
|
|
|
|
|
|
|
<sql id="selectEmsBatteryDataVo">
|
2025-07-29 15:58:26 +08:00
|
|
|
select id, battery_pack, battery_cluster, battery_cell_id, voltage, temperature, soc, soh, data_timestamp, create_by, create_time, update_by, update_time, remark, site_id, device_id, cluster_device_id, inter_resistance from ems_battery_data
|
2025-06-19 19:00:33 +08:00
|
|
|
</sql>
|
|
|
|
|
|
|
|
|
|
<select id="selectEmsBatteryDataList" parameterType="EmsBatteryData" resultMap="EmsBatteryDataResult">
|
|
|
|
|
<include refid="selectEmsBatteryDataVo"/>
|
|
|
|
|
<where>
|
|
|
|
|
<if test="batteryPack != null and batteryPack != ''"> and battery_pack = #{batteryPack}</if>
|
|
|
|
|
<if test="batteryCluster != null and batteryCluster != ''"> and battery_cluster = #{batteryCluster}</if>
|
|
|
|
|
<if test="batteryCellId != null and batteryCellId != ''"> and battery_cell_id = #{batteryCellId}</if>
|
|
|
|
|
<if test="voltage != null "> and voltage = #{voltage}</if>
|
|
|
|
|
<if test="temperature != null "> and temperature = #{temperature}</if>
|
|
|
|
|
<if test="soc != null "> and soc = #{soc}</if>
|
|
|
|
|
<if test="soh != null "> and soh = #{soh}</if>
|
|
|
|
|
<if test="dataTimestamp != null "> and data_timestamp = #{dataTimestamp}</if>
|
2025-06-29 10:55:05 +08:00
|
|
|
<if test="siteId != null and siteId != ''"> and site_id = #{siteId}</if>
|
|
|
|
|
<if test="deviceId != null and deviceId != ''"> and device_id = #{deviceId}</if>
|
|
|
|
|
<if test="clusterDeviceId != null and clusterDeviceId != ''"> and cluster_device_id = #{clusterDeviceId}</if>
|
2025-07-29 15:58:26 +08:00
|
|
|
<if test="interResistance != null "> and inter_resistance = #{interResistance}</if>
|
2025-06-19 19:00:33 +08:00
|
|
|
</where>
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<select id="selectEmsBatteryDataById" parameterType="Long" resultMap="EmsBatteryDataResult">
|
|
|
|
|
<include refid="selectEmsBatteryDataVo"/>
|
|
|
|
|
where id = #{id}
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<insert id="insertEmsBatteryData" parameterType="EmsBatteryData" useGeneratedKeys="true" keyProperty="id">
|
|
|
|
|
insert into ems_battery_data
|
|
|
|
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
|
|
|
|
<if test="batteryPack != null">battery_pack,</if>
|
|
|
|
|
<if test="batteryCluster != null">battery_cluster,</if>
|
|
|
|
|
<if test="batteryCellId != null">battery_cell_id,</if>
|
|
|
|
|
<if test="voltage != null">voltage,</if>
|
|
|
|
|
<if test="temperature != null">temperature,</if>
|
|
|
|
|
<if test="soc != null">soc,</if>
|
|
|
|
|
<if test="soh != null">soh,</if>
|
|
|
|
|
<if test="dataTimestamp != null">data_timestamp,</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>
|
|
|
|
|
<if test="siteId != null">site_id,</if>
|
2025-06-29 10:55:05 +08:00
|
|
|
<if test="deviceId != null and deviceId != ''">device_id,</if>
|
|
|
|
|
<if test="clusterDeviceId != null and clusterDeviceId != ''">cluster_device_id,</if>
|
2025-07-29 15:58:26 +08:00
|
|
|
<if test="interResistance != null">inter_resistance,</if>
|
2025-06-19 19:00:33 +08:00
|
|
|
</trim>
|
|
|
|
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
|
|
|
<if test="batteryPack != null">#{batteryPack},</if>
|
|
|
|
|
<if test="batteryCluster != null">#{batteryCluster},</if>
|
|
|
|
|
<if test="batteryCellId != null">#{batteryCellId},</if>
|
|
|
|
|
<if test="voltage != null">#{voltage},</if>
|
|
|
|
|
<if test="temperature != null">#{temperature},</if>
|
|
|
|
|
<if test="soc != null">#{soc},</if>
|
|
|
|
|
<if test="soh != null">#{soh},</if>
|
|
|
|
|
<if test="dataTimestamp != null">#{dataTimestamp},</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>
|
|
|
|
|
<if test="siteId != null">#{siteId},</if>
|
2025-06-29 10:55:05 +08:00
|
|
|
<if test="deviceId != null and deviceId != ''">#{deviceId},</if>
|
|
|
|
|
<if test="clusterDeviceId != null and clusterDeviceId != ''">#{clusterDeviceId},</if>
|
2025-07-29 15:58:26 +08:00
|
|
|
<if test="interResistance != null">#{interResistance},</if>
|
2025-06-19 19:00:33 +08:00
|
|
|
</trim>
|
|
|
|
|
</insert>
|
|
|
|
|
|
|
|
|
|
<update id="updateEmsBatteryData" parameterType="EmsBatteryData">
|
|
|
|
|
update ems_battery_data
|
|
|
|
|
<trim prefix="SET" suffixOverrides=",">
|
|
|
|
|
<if test="batteryPack != null">battery_pack = #{batteryPack},</if>
|
|
|
|
|
<if test="batteryCluster != null">battery_cluster = #{batteryCluster},</if>
|
|
|
|
|
<if test="batteryCellId != null">battery_cell_id = #{batteryCellId},</if>
|
|
|
|
|
<if test="voltage != null">voltage = #{voltage},</if>
|
|
|
|
|
<if test="temperature != null">temperature = #{temperature},</if>
|
|
|
|
|
<if test="soc != null">soc = #{soc},</if>
|
|
|
|
|
<if test="soh != null">soh = #{soh},</if>
|
|
|
|
|
<if test="dataTimestamp != null">data_timestamp = #{dataTimestamp},</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>
|
|
|
|
|
<if test="siteId != null">site_id = #{siteId},</if>
|
2025-06-29 10:55:05 +08:00
|
|
|
<if test="deviceId != null and deviceId != ''">device_id = #{deviceId},</if>
|
|
|
|
|
<if test="clusterDeviceId != null and clusterDeviceId != ''">cluster_device_id = #{clusterDeviceId},</if>
|
2025-07-29 15:58:26 +08:00
|
|
|
<if test="interResistance != null">inter_resistance = #{interResistance},</if>
|
2025-06-19 19:00:33 +08:00
|
|
|
</trim>
|
|
|
|
|
where id = #{id}
|
|
|
|
|
</update>
|
|
|
|
|
|
|
|
|
|
<delete id="deleteEmsBatteryDataById" parameterType="Long">
|
|
|
|
|
delete from ems_battery_data where id = #{id}
|
|
|
|
|
</delete>
|
|
|
|
|
|
|
|
|
|
<delete id="deleteEmsBatteryDataByIds" parameterType="String">
|
|
|
|
|
delete from ems_battery_data where id in
|
|
|
|
|
<foreach item="id" collection="array" open="(" separator="," close=")">
|
|
|
|
|
#{id}
|
|
|
|
|
</foreach>
|
|
|
|
|
</delete>
|
|
|
|
|
|
2025-06-29 10:55:05 +08:00
|
|
|
<select id="getBatteryDataBySiteId" parameterType="String" resultMap="EmsBatteryDataResult">
|
2025-06-19 19:00:33 +08:00
|
|
|
<include refid="selectEmsBatteryDataVo"/>
|
2025-06-30 13:11:05 +08:00
|
|
|
WHERE site_id = #{siteId} AND data_timestamp >= CURDATE()
|
|
|
|
|
ORDER BY data_timestamp desc limit 1
|
2025-06-19 19:00:33 +08:00
|
|
|
</select>
|
2025-06-27 10:14:15 +08:00
|
|
|
|
|
|
|
|
<select id="getBatteryDataByClusterId" resultType="com.xzzn.ems.domain.vo.BatteryClusterDataDetailVo">
|
|
|
|
|
select t.site_id as siteId,t.cluster_device_id as clusterId,
|
|
|
|
|
AVG(t.voltage) as avgVoltage,MAX(t.voltage) as maxVoltage,MIN(t.voltage) as minVoltage,
|
|
|
|
|
AVG(t.temperature) as avgTemp,MAX(t.temperature) as maxTemp,MIN(t.temperature) as minTemp,
|
|
|
|
|
AVG(t.soc) as avgSoc,MAX(t.soc) as maxSoc,MIN(t.soc) as minSoc
|
|
|
|
|
from ems_battery_data t
|
|
|
|
|
where t.site_id = #{siteId}
|
|
|
|
|
and t.cluster_device_id = #{clusterDeviceId}
|
|
|
|
|
and t.update_time = (select MAX(update_time) FROM ems_battery_data where site_id = t.site_id
|
|
|
|
|
and device_id = t.device_id and cluster_device_id = t.cluster_device_id)
|
|
|
|
|
group by t.site_id,t.cluster_device_id
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<select id="getDataIdsMap" parameterType="com.xzzn.ems.domain.vo.BatteryClusterDataDetailVo" resultType="java.util.Map">
|
|
|
|
|
<if test="maxVoltage != null">
|
|
|
|
|
select 'maxVoltageId' as type, t.device_id from ems_battery_data t
|
|
|
|
|
where t.site_id = #{siteId} and t.cluster_device_id = #{clusterId} and t.voltage = #{maxVoltage}
|
|
|
|
|
union all
|
|
|
|
|
</if>
|
|
|
|
|
<if test="minVoltage != null">
|
|
|
|
|
select 'minVoltageId' as type, t.device_id from ems_battery_data t
|
|
|
|
|
where t.site_id = #{siteId} and t.cluster_device_id = #{clusterId} and t.voltage = #{minVoltage}
|
|
|
|
|
union all
|
|
|
|
|
</if>
|
|
|
|
|
<if test="maxTemp != null">
|
|
|
|
|
select 'maxTempId' as type, t.device_id from ems_battery_data t
|
|
|
|
|
where t.site_id = #{siteId} and t.cluster_device_id = #{clusterId} and t.temperature = #{maxTemp}
|
|
|
|
|
union all
|
|
|
|
|
</if>
|
|
|
|
|
<if test="minTemp != null">
|
|
|
|
|
select 'minTempId' as type, t.device_id from ems_battery_data t
|
|
|
|
|
where t.site_id = #{siteId} and t.cluster_device_id = #{clusterId} and t.temperature = #{minTemp}
|
|
|
|
|
union all
|
|
|
|
|
</if>
|
|
|
|
|
<if test="maxSoc != null">
|
|
|
|
|
select 'maxSocId' as type, t.device_id from ems_battery_data t
|
|
|
|
|
where t.site_id = #{siteId} and t.cluster_device_id = #{clusterId} and t.soc = #{maxSoc}
|
|
|
|
|
union all
|
|
|
|
|
</if>
|
|
|
|
|
<if test="minSoc != null">
|
|
|
|
|
select 'minSocId' as type, t.device_id from ems_battery_data t
|
|
|
|
|
where t.site_id = #{siteId} and t.cluster_device_id = #{clusterId} and t.soc = #{minSoc}
|
|
|
|
|
union all
|
|
|
|
|
</if>
|
|
|
|
|
SELECT NULL AS type, NULL AS device_id FROM DUAL WHERE 1=0
|
|
|
|
|
</select>
|
2025-06-29 14:03:24 +08:00
|
|
|
|
2025-06-30 22:22:47 +08:00
|
|
|
<select id="getAllBatteryDataByClusterId" resultType="com.xzzn.ems.domain.vo.BatteryDataStatsListVo">
|
2025-06-30 23:01:41 +08:00
|
|
|
SELECT t.data_timestamp as updateTime, t.voltage, t.temperature,
|
2025-07-01 13:28:50 +08:00
|
|
|
t.soc, t.soh, t.device_id as deviceId,t.cluster_device_id as clusterDeviceId
|
2025-06-30 22:22:47 +08:00
|
|
|
FROM ems_battery_data t
|
2025-07-01 13:28:50 +08:00
|
|
|
INNER JOIN ( SELECT device_id, cluster_device_id, MAX(data_timestamp) AS max_update_time
|
2025-06-30 22:22:47 +08:00
|
|
|
FROM ems_battery_data
|
|
|
|
|
WHERE site_id = #{siteId}
|
2025-07-01 13:28:50 +08:00
|
|
|
and data_timestamp >= CURDATE()
|
2025-06-30 22:22:47 +08:00
|
|
|
<if test="clusterDeviceId != null and clusterDeviceId != ''">
|
|
|
|
|
and cluster_device_id = #{clusterDeviceId}
|
|
|
|
|
</if>
|
2025-07-01 13:28:50 +08:00
|
|
|
GROUP BY device_id, cluster_device_id
|
2025-06-30 23:01:41 +08:00
|
|
|
) latest ON t.device_id = latest.device_id AND t.data_timestamp = latest.max_update_time
|
2025-07-01 13:28:50 +08:00
|
|
|
AND t.cluster_device_id = latest.cluster_device_id
|
2025-06-30 22:22:47 +08:00
|
|
|
WHERE t.site_id = #{siteId}
|
|
|
|
|
<if test="clusterDeviceId != null and clusterDeviceId != ''">
|
|
|
|
|
and t.cluster_device_id = #{clusterDeviceId}
|
|
|
|
|
</if>
|
2025-06-29 13:40:37 +08:00
|
|
|
</select>
|
|
|
|
|
|
2025-06-29 14:03:24 +08:00
|
|
|
<insert id="insertEmsBatteryDataList" parameterType="java.util.List">
|
|
|
|
|
INSERT INTO ems_battery_data (
|
|
|
|
|
battery_pack, battery_cluster, battery_cell_id,
|
|
|
|
|
voltage, temperature, soc, soh, data_timestamp,
|
|
|
|
|
create_by, create_time, update_by, update_time,
|
2025-07-29 15:58:26 +08:00
|
|
|
remark, site_id, device_id, cluster_device_id, inter_resistance
|
2025-06-29 14:03:24 +08:00
|
|
|
) VALUES
|
|
|
|
|
<foreach collection="list" item="item" separator=",">
|
|
|
|
|
(
|
|
|
|
|
#{item.batteryPack}, #{item.batteryCluster}, #{item.batteryCellId},
|
|
|
|
|
#{item.voltage}, #{item.temperature}, #{item.soc}, #{item.soh}, #{item.dataTimestamp},
|
|
|
|
|
#{item.createBy}, #{item.createTime}, #{item.updateBy}, #{item.updateTime},
|
2025-07-29 15:58:26 +08:00
|
|
|
#{item.remark}, #{item.siteId}, #{item.deviceId}, #{item.clusterDeviceId},#{item.interResistance}
|
2025-06-29 14:03:24 +08:00
|
|
|
)
|
|
|
|
|
</foreach>
|
|
|
|
|
</insert>
|
2025-07-17 13:31:25 +08:00
|
|
|
|
2025-06-19 19:00:33 +08:00
|
|
|
</mapper>
|