mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-30 05:13:59 +08:00
获取设备最大的最近连接时间。改为在数据库里排序好后返回给系统,缓存时间修改为2分钟
--DeviceDao.java 修改方法返回值 --DeviceDao.xml 修改sql,在数据库里排序返回 --DeviceServiceImpl.java 修改缓存时间为2分钟
This commit is contained in:
@@ -16,6 +16,6 @@ public interface DeviceDao extends BaseMapper<DeviceEntity> {
|
|||||||
* @param agentId 智能体id
|
* @param agentId 智能体id
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<Date> getAllLastConnectedAtByAgentId(String agentId);
|
Date getAllLastConnectedAtByAgentId(String agentId);
|
||||||
|
|
||||||
}
|
}
|
||||||
+2
-5
@@ -260,12 +260,9 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
|
|||||||
if (cachedDate != null) {
|
if (cachedDate != null) {
|
||||||
return cachedDate;
|
return cachedDate;
|
||||||
}
|
}
|
||||||
List<Date> list = deviceDao.getAllLastConnectedAtByAgentId(agentId);
|
Date maxDate = deviceDao.getAllLastConnectedAtByAgentId(agentId);
|
||||||
Date maxDate = Collections.max(list, Comparator.comparing(Date::getTime));
|
|
||||||
// 将结果存入Redis, 存储设备最近最后连接时间,和设备数量
|
|
||||||
redisUtils.set(RedisKeys.getAgentDeviceCountById(agentId), list.size(), 60);
|
|
||||||
if (maxDate != null) {
|
if (maxDate != null) {
|
||||||
redisUtils.set(RedisKeys.getAgentDeviceLastConnectedAtById(agentId), maxDate, 60);
|
redisUtils.set(RedisKeys.getAgentDeviceLastConnectedAtById(agentId), maxDate, 60 * 2);
|
||||||
}
|
}
|
||||||
return maxDate;
|
return maxDate;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
<mapper namespace="xiaozhi.modules.device.dao.DeviceDao">
|
<mapper namespace="xiaozhi.modules.device.dao.DeviceDao">
|
||||||
<!-- 获取此智能体全部设备的最后连接时间 -->
|
<!-- 获取此智能体全部设备的最后连接时间 -->
|
||||||
<select id="getAllLastConnectedAtByAgentId" resultType="java.util.Date">
|
<select id="getAllLastConnectedAtByAgentId" resultType="java.util.Date">
|
||||||
SELECT last_connected_at FROM ai_device WHERE agent_id = #{agentId}
|
SELECT last_connected_at FROM ai_device
|
||||||
|
WHERE
|
||||||
|
agent_id = #{agentId}
|
||||||
|
order by
|
||||||
|
last_connected_at desc limit 0,1
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user