refactor(robot): 重构机器人地图上传功能
- 移除原有的 uploadMapToRobot 方法,简化服务接口 - 添加新的 uploadMapFromSource 方法,支持从源机器人下载并上传到目标机器人 - 更新控制器中的路径变量注解,移除冗余参数定义 - 实现跨机器人地图传输功能,包括从源机器人下载和向目标机器人上传 - 添加完整的异常处理和验证逻辑,确保机器人和地图存在性检查 - 统一错误消息处理,提高代码可维护性
This commit is contained in:
parent
87d691f927
commit
6d39c4296e
@ -112,7 +112,7 @@ public class InspectionRobotController extends BaseController
|
||||
@ApiOperation("获取机器人地图列表")
|
||||
@PreAuthorize("@ss.hasPermi('inspection:robot:query')")
|
||||
@GetMapping("/{robotId}/maps")
|
||||
public AjaxResult getRobotMapList(@PathVariable("robotId") String robotId)
|
||||
public AjaxResult getRobotMapList(@PathVariable String robotId)
|
||||
{
|
||||
AgvCommand.AgvMapStatus robotMapList = inspectionRobotService.getRobotMapList(robotId);
|
||||
return success(robotMapList.getMapsList());
|
||||
@ -125,26 +125,12 @@ public class InspectionRobotController extends BaseController
|
||||
@PreAuthorize("@ss.hasPermi('inspection:robot:edit')")
|
||||
@Log(title = "绑定机器人地图", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/{robotId}/bind-map/{mapId}")
|
||||
public AjaxResult bindRobotMap(@PathVariable("robotId") String robotId,
|
||||
@PathVariable("mapId") String mapId)
|
||||
public AjaxResult bindRobotMap(@PathVariable String robotId,
|
||||
@PathVariable String mapId)
|
||||
{
|
||||
return toAjax(inspectionRobotService.bindRobotMap(robotId, mapId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传地图到机器人
|
||||
*/
|
||||
@ApiOperation("上传地图到机器人")
|
||||
@PreAuthorize("@ss.hasPermi('inspection:robot:edit')")
|
||||
@Log(title = "上传地图到机器人", businessType = BusinessType.OTHER)
|
||||
@PostMapping("/{robotId}/upload-map/{mapId}")
|
||||
public AjaxResult uploadMapToRobot(@PathVariable("robotId") String robotId,
|
||||
@PathVariable("mapId") String mapId)
|
||||
{
|
||||
String result = inspectionRobotService.uploadMapToRobot(robotId, mapId);
|
||||
return success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从机器人下载地图
|
||||
*/
|
||||
@ -153,7 +139,7 @@ public class InspectionRobotController extends BaseController
|
||||
@Log(title = "从机器人下载地图", businessType = BusinessType.INSERT)
|
||||
@GetMapping("/{robotId}/download-map")
|
||||
public AjaxResult downloadMapFromRobot(
|
||||
@PathVariable(value = "robotId") @ApiParam("机器人ID") String robotId,
|
||||
@PathVariable @ApiParam("机器人ID") String robotId,
|
||||
@RequestParam(value = "mapName") @ApiParam("地图名称") String mapName
|
||||
)
|
||||
{
|
||||
@ -161,6 +147,19 @@ public class InspectionRobotController extends BaseController
|
||||
return success(mapId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传地图(从源机器人下载到目标机器人)
|
||||
*/
|
||||
@ApiOperation("上传地图到机器人")
|
||||
@PreAuthorize("@ss.hasPermi('inspection:robot:edit')")
|
||||
@Log(title = "上传地图到机器人", businessType = BusinessType.OTHER)
|
||||
@PostMapping("/{robotId}/upload-map-from-source")
|
||||
public AjaxResult uploadMapFromSource(@PathVariable String robotId)
|
||||
{
|
||||
String result = inspectionRobotService.uploadMapFromSource(robotId);
|
||||
return success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步机器人状态
|
||||
*/
|
||||
@ -168,7 +167,7 @@ public class InspectionRobotController extends BaseController
|
||||
@PreAuthorize("@ss.hasPermi('inspection:robot:edit')")
|
||||
@Log(title = "同步机器人状态", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/{robotId}/sync-status")
|
||||
public AjaxResult syncRobotStatus(@PathVariable("robotId") String robotId)
|
||||
public AjaxResult syncRobotStatus(@PathVariable String robotId)
|
||||
{
|
||||
return success(inspectionRobotService.syncRobotStatus(robotId));
|
||||
}
|
||||
|
||||
@ -73,15 +73,6 @@ public interface IInspectionRobotService extends IService<InspectionRobot>
|
||||
*/
|
||||
int bindRobotMap(String robotId, String mapId);
|
||||
|
||||
/**
|
||||
* 上传地图到机器人
|
||||
*
|
||||
* @param robotId 机器人ID
|
||||
* @param mapId 地图ID
|
||||
* @return 结果
|
||||
*/
|
||||
String uploadMapToRobot(String robotId, String mapId);
|
||||
|
||||
/**
|
||||
* 从机器人下载地图
|
||||
*
|
||||
@ -91,6 +82,14 @@ public interface IInspectionRobotService extends IService<InspectionRobot>
|
||||
*/
|
||||
String downloadMapFromRobot(String robotId, String mapName);
|
||||
|
||||
/**
|
||||
* 上传地图(从源机器人下载到目标机器人)
|
||||
*
|
||||
* @param robotId 目标机器人ID
|
||||
* @return 结果
|
||||
*/
|
||||
String uploadMapFromSource(String robotId);
|
||||
|
||||
/**
|
||||
* 同步机器人状态(电量、位置等)
|
||||
*
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
|
||||
package com.cmvr.inspection.service.impl;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -180,49 +181,6 @@ public class InspectionRobotServiceImpl extends ServiceImpl<InspectionRobotMappe
|
||||
return inspectionRobotMapper.updateInspectionRobot(robot);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传地图到机器人
|
||||
*
|
||||
* @param robotId 机器人ID
|
||||
* @param mapId 地图ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public String uploadMapToRobot(String robotId, String mapId)
|
||||
{
|
||||
InspectionRobot robot = inspectionRobotMapper.selectInspectionRobotById(robotId);
|
||||
if (robot == null) {
|
||||
throw new GlobalException("机器人不存在");
|
||||
}
|
||||
|
||||
InspectionMap map = inspectionMapMapper.selectInspectionMapById(mapId);
|
||||
if (map == null) {
|
||||
throw new GlobalException("地图不存在");
|
||||
}
|
||||
|
||||
if (StrUtil.isBlank(map.getMapFilePath())) {
|
||||
throw new GlobalException("地图文件路径不存在");
|
||||
}
|
||||
|
||||
// 从文件路径读取地图内容
|
||||
String mapContent = readMapFile(map.getMapFilePath());
|
||||
if (StrUtil.isBlank(mapContent)) {
|
||||
throw new GlobalException("地图文件内容为空");
|
||||
}
|
||||
|
||||
EdgeCommonVO edgeCommonVO = new EdgeCommonVO();
|
||||
edgeCommonVO.setTerminalId(robot.getTerminalId());
|
||||
edgeCommonVO.setDeviceId(robot.getRobotCode());
|
||||
|
||||
AgvCommand.AgvUploadMapResult result = edgeAgvService.robotConfigUploadMap(edgeCommonVO, mapContent);
|
||||
|
||||
if (result.getRetCode() != 0) {
|
||||
throw new GlobalException("上传地图失败: " + result.getErrMsg());
|
||||
}
|
||||
|
||||
return "上传成功";
|
||||
}
|
||||
|
||||
/**
|
||||
* 从机器人下载地图
|
||||
*
|
||||
@ -264,6 +222,75 @@ public class InspectionRobotServiceImpl extends ServiceImpl<InspectionRobotMappe
|
||||
return result.getMapContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传地图(从源机器人下载到目标机器人)
|
||||
*
|
||||
* @param robotId 目标机器人ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public String uploadMapFromSource(String robotId)
|
||||
{
|
||||
// 1. 获取目标机器人信息
|
||||
InspectionRobot targetRobot = inspectionRobotMapper.selectInspectionRobotById(robotId);
|
||||
if (targetRobot == null) {
|
||||
throw new GlobalException("目标机器人不存在");
|
||||
}
|
||||
|
||||
// 2. 获取地图信息
|
||||
InspectionMap map = inspectionMapMapper.selectInspectionMapById(targetRobot.getCurrentMapId());
|
||||
if (map == null) {
|
||||
throw new GlobalException("地图不存在");
|
||||
}
|
||||
|
||||
// 3. 检查地图是否有来源机器人ID和地图名称
|
||||
if (StrUtil.isBlank(map.getMapSourceRobotId())) {
|
||||
throw new GlobalException("地图未配置来源机器人ID");
|
||||
}
|
||||
if (StrUtil.isBlank(map.getMapSourceName())) {
|
||||
throw new GlobalException("地图未配置来源地图名称");
|
||||
}
|
||||
|
||||
// 4. 获取来源机器人信息
|
||||
InspectionRobot sourceRobot = inspectionRobotMapper.selectInspectionRobotById(map.getMapSourceRobotId());
|
||||
if (sourceRobot == null) {
|
||||
throw new GlobalException("来源机器人不存在");
|
||||
}
|
||||
|
||||
// 5. 从来源机器人下载地图JSON
|
||||
EdgeCommonVO sourceEdgeVO = new EdgeCommonVO();
|
||||
sourceEdgeVO.setTerminalId(sourceRobot.getTerminalId());
|
||||
sourceEdgeVO.setDeviceId(sourceRobot.getRobotCode());
|
||||
|
||||
AgvCommand.AgvDownloadMapResult downloadResult = edgeAgvService.robotConfigDownloadMap(
|
||||
sourceEdgeVO, map.getMapSourceName()
|
||||
);
|
||||
|
||||
if (downloadResult.getRetCode() != 0) {
|
||||
throw new GlobalException("从来源机器人下载地图失败: " + downloadResult.getErrMsg());
|
||||
}
|
||||
|
||||
String mapContent = downloadResult.getMapContent();
|
||||
if (StrUtil.isBlank(mapContent)) {
|
||||
throw new GlobalException("下载的地图内容为空");
|
||||
}
|
||||
|
||||
// 6. 上传地图到目标机器人
|
||||
EdgeCommonVO targetEdgeVO = new EdgeCommonVO();
|
||||
targetEdgeVO.setTerminalId(targetRobot.getTerminalId());
|
||||
targetEdgeVO.setDeviceId(targetRobot.getRobotCode());
|
||||
|
||||
AgvCommand.AgvUploadMapResult uploadResult = edgeAgvService.robotConfigUploadMap(
|
||||
targetEdgeVO, mapContent
|
||||
);
|
||||
|
||||
if (uploadResult.getRetCode() != 0) {
|
||||
throw new GlobalException("上传地图到目标机器人失败: " + uploadResult.getErrMsg());
|
||||
}
|
||||
|
||||
return "上传成功";
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步机器人状态(电量、位置等)
|
||||
*
|
||||
@ -305,16 +332,4 @@ public class InspectionRobotServiceImpl extends ServiceImpl<InspectionRobotMappe
|
||||
return robot;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取地图文件内容
|
||||
*
|
||||
* @param filePath 文件路径
|
||||
* @return 文件内容
|
||||
*/
|
||||
private String readMapFile(String filePath)
|
||||
{
|
||||
// TODO: 实现文件读取逻辑
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user