mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-27 17:43:55 +08:00
优化获取这个智能体设备理的最近的最后连接时间方法,缓存时间和设备数量
--DeviceServiceImpl.java 优化方法
This commit is contained in:
+12
-1
@@ -255,8 +255,19 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Date getLatestLastConnectionTime(String agentId) {
|
public Date getLatestLastConnectionTime(String agentId) {
|
||||||
|
// 查询是否有缓存时间,有则返回
|
||||||
|
Date cachedDate = (Date) redisUtils.get(RedisKeys.getAgentDeviceLastConnectedAtById(agentId));
|
||||||
|
if (cachedDate != null) {
|
||||||
|
return cachedDate;
|
||||||
|
}
|
||||||
List<Date> list = deviceDao.getAllLastConnectedAtByAgentId(agentId);
|
List<Date> list = deviceDao.getAllLastConnectedAtByAgentId(agentId);
|
||||||
return Collections.max(list, Comparator.comparing(Date::getTime));
|
Date maxDate = Collections.max(list, Comparator.comparing(Date::getTime));
|
||||||
|
// 将结果存入Redis, 存储设备最近最后连接时间,和设备数量
|
||||||
|
redisUtils.set(RedisKeys.getAgentDeviceCountById(agentId), list.size(), 60);
|
||||||
|
if (maxDate != null) {
|
||||||
|
redisUtils.set(RedisKeys.getAgentDeviceLastConnectedAtById(agentId), maxDate, 60);
|
||||||
|
}
|
||||||
|
return maxDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getDeviceCacheKey(String deviceId) {
|
private String getDeviceCacheKey(String deviceId) {
|
||||||
|
|||||||
Reference in New Issue
Block a user