CMVR-IOT/cmvr-iot-resource/src/main/java/com/cmvr/resource/service/ResourceRobotEndpointResolver.java
lixiaolong ca62f939a9 refactor(config): 调整资源配置并移除设备配置相关代码
- 将application.yml中的inspection配置项重命名为resource
- 更新开发环境配置文件端口号从13080改为14080
- 在数据库连接URL中引入CMVR_DB_NAME环境变量
- 配置Redis数据库索引使用CMVR_REDIS_DATABASE环境变量
- 在测试环境中添加资源中心隔离配置
- 移除设备配置信息相关的域模型、控制器、数据访问层及映射文件
- 移除设备注册相关的域模型、控制器、数据访问层及映射文件
2026-08-25 10:58:17 +08:00

50 lines
2.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.cmvr.resource.service;
import com.cmvr.common.exception.GlobalException;
import com.cmvr.common.robot.RobotEndpoint;
import com.cmvr.common.robot.RobotEndpointResolver;
import com.cmvr.resource.config.ResourceRobotStateProperties;
import com.cmvr.resource.domain.ResourceRobot;
import com.cmvr.resource.mapper.ResourceRobotMapper;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Date;
@Service
@RequiredArgsConstructor
public class ResourceRobotEndpointResolver implements RobotEndpointResolver {
private final ResourceRobotMapper robotMapper;
private final ResourceRobotStateProperties stateProperties;
@Override
public RobotEndpoint resolve(String robotId) {
String normalized = StringUtils.trimToNull(robotId);
if (normalized == null) {
throw new GlobalException("机器人ID不能为空");
}
if (stateProperties.isVirtualRobot(normalized)) {
throw new GlobalException("虚拟机器人不能调用边缘设备服务:" + normalized);
}
ResourceRobot robot = robotMapper.selectByRobotIdentity(normalized);
if (robot == null) {
throw new GlobalException("机器人不存在:" + normalized);
}
if ("1".equals(robot.getArchivedStatus())) {
throw new GlobalException("机器人已归档:" + normalized);
}
if (!"1".equals(robot.getConnectStatus())) {
throw new GlobalException("机器人当前离线:" + normalized);
}
Date cutoff = stateProperties.heartbeatCutoff(new Date());
if (robot.getLastHeartbeatTime() == null || robot.getLastHeartbeatTime().before(cutoff)) {
throw new GlobalException("机器人QUIC心跳已超时:" + normalized);
}
if (StringUtils.isBlank(robot.getIpAddress()) || robot.getPort() == null) {
throw new GlobalException("机器人尚未上报gRPC地址:" + normalized);
}
return new RobotEndpoint(robot.getIpAddress(), robot.getPort().intValue());
}
}