From 770a198772c573a62e0f4c211a7d258d58306d71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=89=91=E9=9B=A8?= <2375294554@qq.com> Date: Wed, 7 May 2025 11:04:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E8=AE=BE=E5=A4=87=E6=9C=80?= =?UTF-8?q?=E5=A4=A7=E7=9A=84=E6=9C=80=E8=BF=91=E8=BF=9E=E6=8E=A5=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E3=80=82=E6=94=B9=E4=B8=BA=E5=9C=A8=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E9=87=8C=E6=8E=92=E5=BA=8F=E5=A5=BD=E5=90=8E=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E7=BB=99=E7=B3=BB=E7=BB=9F=EF=BC=8C=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E4=BF=AE=E6=94=B9=E4=B8=BA2=E5=88=86?= =?UTF-8?q?=E9=92=9F=20--DeviceDao.java=20=E4=BF=AE=E6=94=B9=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E8=BF=94=E5=9B=9E=E5=80=BC=20--DeviceDao.xml=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9sql=EF=BC=8C=E5=9C=A8=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E9=87=8C=E6=8E=92=E5=BA=8F=E8=BF=94=E5=9B=9E=20--Devi?= =?UTF-8?q?ceServiceImpl.java=20=E4=BF=AE=E6=94=B9=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E4=B8=BA2=E5=88=86=E9=92=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/xiaozhi/modules/device/dao/DeviceDao.java | 2 +- .../modules/device/service/impl/DeviceServiceImpl.java | 7 ++----- .../src/main/resources/mapper/device/DeviceDao.xml | 6 +++++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/main/manager-api/src/main/java/xiaozhi/modules/device/dao/DeviceDao.java b/main/manager-api/src/main/java/xiaozhi/modules/device/dao/DeviceDao.java index abff8ab3..6570b89b 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/device/dao/DeviceDao.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/device/dao/DeviceDao.java @@ -16,6 +16,6 @@ public interface DeviceDao extends BaseMapper { * @param agentId 智能体id * @return */ - List getAllLastConnectedAtByAgentId(String agentId); + Date getAllLastConnectedAtByAgentId(String agentId); } \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/device/service/impl/DeviceServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/device/service/impl/DeviceServiceImpl.java index 0475f2e9..59e329fa 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/device/service/impl/DeviceServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/device/service/impl/DeviceServiceImpl.java @@ -260,12 +260,9 @@ public class DeviceServiceImpl extends BaseServiceImpl if (cachedDate != null) { return cachedDate; } - List list = deviceDao.getAllLastConnectedAtByAgentId(agentId); - Date maxDate = Collections.max(list, Comparator.comparing(Date::getTime)); - // 将结果存入Redis, 存储设备最近最后连接时间,和设备数量 - redisUtils.set(RedisKeys.getAgentDeviceCountById(agentId), list.size(), 60); + Date maxDate = deviceDao.getAllLastConnectedAtByAgentId(agentId); if (maxDate != null) { - redisUtils.set(RedisKeys.getAgentDeviceLastConnectedAtById(agentId), maxDate, 60); + redisUtils.set(RedisKeys.getAgentDeviceLastConnectedAtById(agentId), maxDate, 60 * 2); } return maxDate; } diff --git a/main/manager-api/src/main/resources/mapper/device/DeviceDao.xml b/main/manager-api/src/main/resources/mapper/device/DeviceDao.xml index 09f16760..54de47c9 100644 --- a/main/manager-api/src/main/resources/mapper/device/DeviceDao.xml +++ b/main/manager-api/src/main/resources/mapper/device/DeviceDao.xml @@ -3,6 +3,10 @@ \ No newline at end of file