This commit is contained in:
Tink
2025-06-26 16:22:21 +08:00
parent 033c8f9bee
commit f69b1b34f1
2 changed files with 18 additions and 11 deletions
@@ -19,6 +19,8 @@ import xiaozhi.modules.agent.service.AgentChatAudioService;
import xiaozhi.modules.agent.service.AgentChatHistoryService; import xiaozhi.modules.agent.service.AgentChatHistoryService;
import xiaozhi.modules.agent.service.AgentService; import xiaozhi.modules.agent.service.AgentService;
import xiaozhi.modules.agent.service.biz.AgentChatHistoryBizService; import xiaozhi.modules.agent.service.biz.AgentChatHistoryBizService;
import xiaozhi.modules.device.entity.DeviceEntity;
import xiaozhi.modules.device.service.DeviceService;
/** /**
* {@link AgentChatHistoryBizService} impl * {@link AgentChatHistoryBizService} impl
@@ -35,6 +37,7 @@ public class AgentChatHistoryBizServiceImpl implements AgentChatHistoryBizServic
private final AgentChatHistoryService agentChatHistoryService; private final AgentChatHistoryService agentChatHistoryService;
private final AgentChatAudioService agentChatAudioService; private final AgentChatAudioService agentChatAudioService;
private final RedisUtils redisUtils; private final RedisUtils redisUtils;
private final DeviceService deviceService;
/** /**
* 处理聊天记录上报,包括文件上传和相关信息记录 * 处理聊天记录上报,包括文件上传和相关信息记录
@@ -68,6 +71,15 @@ public class AgentChatHistoryBizServiceImpl implements AgentChatHistoryBizServic
// 更新设备最后对话时间 // 更新设备最后对话时间
redisUtils.set(RedisKeys.getAgentDeviceLastConnectedAtById(agentId), new Date()); redisUtils.set(RedisKeys.getAgentDeviceLastConnectedAtById(agentId), new Date());
// 更新设备最后连接时间
DeviceEntity device = deviceService.getDeviceByMacAddress(macAddress);
if (device != null) {
deviceService.updateDeviceConnectionInfo(agentId, device.getId(), null);
} else {
log.warn("聊天记录上报时,未找到mac地址为 {} 的设备", macAddress);
}
return Boolean.TRUE; return Boolean.TRUE;
} }
@@ -59,24 +59,19 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
@Async @Async
public void updateDeviceConnectionInfo(String agentId, String deviceId, String appVersion) { public void updateDeviceConnectionInfo(String agentId, String deviceId, String appVersion) {
log.info("Attempting to update connection info for deviceId: {}", deviceId);
try { try {
UpdateWrapper<DeviceEntity> updateWrapper = new UpdateWrapper<>(); DeviceEntity device = new DeviceEntity();
updateWrapper.eq("id", deviceId) device.setId(deviceId);
.set("last_connected_at", new Date()) device.setLastConnectedAt(new Date());
.set("update_date", new Date());
if (StringUtils.isNotBlank(appVersion)) { if (StringUtils.isNotBlank(appVersion)) {
updateWrapper.set("app_version", appVersion); device.setAppVersion(appVersion);
} }
int updatedRows = deviceDao.update(null, updateWrapper); deviceDao.updateById(device);
log.info("Update result for deviceId {}: {} rows affected.", deviceId, updatedRows);
if (StringUtils.isNotBlank(agentId)) { if (StringUtils.isNotBlank(agentId)) {
redisUtils.set(RedisKeys.getAgentDeviceLastConnectedAtById(agentId), new Date()); redisUtils.set(RedisKeys.getAgentDeviceLastConnectedAtById(agentId), new Date());
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Failed to update connection info for deviceId: {}", deviceId, e); log.error("异步更新设备连接信息失败", e);
} }
} }