opt:1.取消任务逻辑修改。2.新增拖动点云重定位功能。

This commit is contained in:
2025-10-21 14:31:51 +08:00
parent 7a464b65fb
commit 71f2fd8da5
10 changed files with 201 additions and 24 deletions

View File

@@ -1,14 +1,17 @@
package org.nl.apt15e.apt.anomalyInfo.controller;
import com.alibaba.excel.EasyExcel;
import lombok.Value;
import org.nl.apt15e.apt.anomalyInfo.dao.ErrorHandling;
import org.nl.apt15e.apt.anomalyInfo.dao.ErrorInfo;
import org.nl.apt15e.apt.anomalyInfo.service.AnomalyInfoService;
import org.nl.apt15e.apt.anomalyInfo.service.ErrorHandlingService;
import org.nl.apt15e.apt.anomalyInfo.service.ErrorInfoService;
import org.nl.apt15e.apt.vehicle.ProcessZip;
import org.nl.apt15e.common.BadRequestException;
import org.nl.apt15e.common.excel.ErrorHandlingListener;
import org.nl.apt15e.common.excel.ErrorInfoListener;
import org.nl.apt15e.config.file.FileProperties;
import org.nl.apt15e.config.language.LangProcess;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -20,6 +23,7 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
/**
@@ -39,6 +43,12 @@ public class AnomalyInfoController {
@Resource
private ErrorHandlingService errorHandlingService;
@Resource
private FileProperties properties;
@Resource
private ProcessZip processZip;
@PostMapping("/queryErrorDataByCode")
public ResponseEntity<Object> queryErrorDataByCode(@RequestParam("code") String code) {
return new ResponseEntity<>(anomalyInfoService.queryErrorDataByCode(code), HttpStatus.OK);
@@ -80,4 +90,34 @@ public class AnomalyInfoController {
return new ResponseEntity<>(LangProcess.msg("successful"),HttpStatus.OK);
}
@PostMapping("/importErrorImage")
public ResponseEntity<Object> importErrorImage(@RequestParam("file") MultipartFile file) throws IOException {
if (file.isEmpty()) {
throw new BadRequestException("文件不能为空");
}
String originalFilename = file.getOriginalFilename();
if (originalFilename == null ||
(!originalFilename.toLowerCase().endsWith(".zip"))) {
throw new BadRequestException("目前只支持ZIP格式");
}
try {
// 创建上传目录
File uploadDir = new File(properties.getPath().getPath());
if (!uploadDir.exists()) {
uploadDir.mkdirs();
}
// 处理压缩文件
processZip.processCompressedFile(file);
return new ResponseEntity<>("上传成功!",HttpStatus.OK);
} catch (Exception e) {
throw new BadRequestException("处理文件失败:{}"+e.getMessage());
}
}
}

View File

@@ -91,7 +91,7 @@ public class TaskManageServiceImpl implements TaskManageService {
// 当前叉腿载货状态(Ascend或者Descend)
// String currentType = VehicleInfoServiceImpl.vehicleInfo.getVehiclePayloads() == 1? StationTypeEnum.ASCEND.getCode():StationTypeEnum.DESCEND.getCode();
String currentType = Objects.equals(VehicleInfoServiceImpl.vehicleInfo.getVehiclePayloads(), 1)? StationTypeEnum.ASCEND.getCode():StationTypeEnum.DESCEND.getCode();
String currentType = Objects.equals(VehicleInfoServiceImpl.vehicleInfo.getVehiclePayloads(), "1")? StationTypeEnum.ASCEND.getCode():StationTypeEnum.DESCEND.getCode();
for (int i = 0; i < staList.size(); i++) {
String proposedAction = staList.get(i).getAction_type();
@@ -170,18 +170,23 @@ public class TaskManageServiceImpl implements TaskManageService {
new QueryWrapper<Task>().lambda()
.lt(Task::getTask_status, TaskStatus.FINISHED.getCode())
);
if (ObjectUtil.isEmpty(task)) {
throw new BadRequestException(LangProcess.msg("task_Is_not_exist"));
}
// if (ObjectUtil.isEmpty(task)) {
// throw new BadRequestException(LangProcess.msg("task_Is_not_exist"));
// }
try {
HttpResponse response = HTTPUtil.post(URLConstant.RCS_IP_PORT, URLConstant.CANCEL_TASK_URL + task.getTask_id(), null);
JSONObject param = new JSONObject();
param.put("amrId", VehicleInfoServiceImpl.vehicleInfo.getId());
//取消调度任务
HttpResponse response = HTTPUtil.post(URLConstant.RCS_IP_PORT, URLConstant.VEHICLE_ID_CANCEL_TASK_URL, param);
JSONObject result = JSONObject.parseObject(response.body());
if (result.getBoolean("state").equals(false)) {
throw new BadRequestException(LangProcess.msg("error_request_rcs") + result.getString("errMsg"));
}
// 取消任务
task.setTask_status(TaskStatus.CANCELED.getCode());
iTaskService.updateById(task);
// 取消当前任务
if (ObjectUtil.isNotEmpty(task)) {
task.setTask_status(TaskStatus.CANCELED.getCode());
iTaskService.updateById(task);
}
} catch (Exception e) {
throw new BadRequestException(LangProcess.msg("error_request_rcs") + e.getMessage());
}

View File

@@ -104,7 +104,7 @@ public class TeachingController {
}
@PostMapping("/sendAutoBack")
private ResponseEntity<Object> sendAutoBack() {
return new ResponseEntity<>(teachingService.sendAutoBack(), HttpStatus.OK);
private ResponseEntity<Object> sendAutoBack(@RequestParam("isBack") Integer isBack) {
return new ResponseEntity<>(teachingService.sendAutoBack(isBack), HttpStatus.OK);
}
}

View File

@@ -101,5 +101,5 @@ public interface TeachingService {
/**
* 打点后 自动回到上一个点
*/
Map<String,Object> sendAutoBack();
Map<String,Object> sendAutoBack(Integer isBack);
}

View File

@@ -460,10 +460,13 @@ public class TeachingServiceImpl implements TeachingService {
}
@Override
public Map<String, Object> sendAutoBack() {
public Map<String, Object> sendAutoBack(Integer isBack) {
if (ObjectUtil.isEmpty(isBack)){
throw new BadRequestException(LangProcess.msg("param_is_null"));
}
JSONObject params = new JSONObject();
String attach = "{"+
"'sub_command':0,"+
"'sub_command':"+isBack+","+
"'param':''"+
"}";
params.put("cmd", 2212);

View File

@@ -22,6 +22,7 @@ import org.nl.apt15e.config.language.LangProcess;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.yaml.snakeyaml.Yaml;
import javax.annotation.Resource;
@@ -32,6 +33,9 @@ import java.awt.image.DataBufferByte;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -398,4 +402,106 @@ public class ProcessZip {
log.info("保存PNG失败: {}",e.getMessage());
}
}
/**
* 处理上传的异常文件
* @param file
* @throws IOException
*/
public void processCompressedFile(MultipartFile file) throws IOException {
List<String> skippedFiles = new ArrayList<>();
String filename = file.getOriginalFilename();
String extension = filename.substring(filename.lastIndexOf("."));
try (InputStream inputStream = file.getInputStream()) {
if (extension.toLowerCase().equals(".zip")) {
extractZipFile(inputStream, skippedFiles);
} else {
throw new BadRequestException("不支持的压缩格式: " + extension);
}
}
}
/**
* 解压上传异常图片压缩文件
* @param inputStream
* @param skippedFiles
* @throws IOException
*/
private void extractZipFile(InputStream inputStream, List<String> skippedFiles)
throws IOException {
int processedCount = 0;
int skippedCount = 0;
try (ZipInputStream zipInputStream = new ZipInputStream(inputStream)) {
ZipEntry entry;
while ((entry = zipInputStream.getNextEntry()) != null) {
if (!entry.isDirectory() && isImageFile(entry.getName())) {
String filename = new File(entry.getName()).getName();
if (isFileExists(filename)) {
skippedFiles.add(filename);
skippedCount++;
continue;
}
if (saveImageFile(zipInputStream, filename)) {
processedCount++;
}
}
zipInputStream.closeEntry();
}
}
log.info("处理文件数:{},跳过文件数:{},跳过文件名称集合:{}",processedCount,skippedCount,skippedFiles);
}
/**
* 判断是否是图片文件
* @param filename
* @return
*/
private boolean isImageFile(String filename) {
String lowerCaseFilename = filename.toLowerCase();
return lowerCaseFilename.endsWith(".jpg") ||
lowerCaseFilename.endsWith(".jpeg") ||
lowerCaseFilename.endsWith(".png") ||
lowerCaseFilename.endsWith(".gif") ||
lowerCaseFilename.endsWith(".bmp") ||
lowerCaseFilename.endsWith(".webp");
}
/**
* 查看文件名是否有重名
* @param filename
* @return
*/
private boolean isFileExists(String filename) {
File targetFile = new File(properties.getPath().getPath() + filename);
return targetFile.exists();
}
/**
* 保存图片文件到目录
* @param inputStream
* @param filename
* @return
*/
private boolean saveImageFile(InputStream inputStream, String filename) {
try {
File outputFile = new File(properties.getPath().getPath() + filename);
// 确保目录存在
File parentDir = outputFile.getParentFile();
if (!parentDir.exists()) {
parentDir.mkdirs();
}
Files.copy(inputStream, outputFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
return true;
} catch (IOException e) {
log.error("保存文件失败: " + filename, e);
return false;
}
}
}

View File

@@ -142,6 +142,6 @@ public class VehicleInfo implements Serializable {
/**
* 车辆载货状态 0未载货 1载货
*/
private Integer vehiclePayloads;
private String vehiclePayloads;
}

View File

@@ -78,7 +78,9 @@ public class VehicleInfoServiceImpl implements VehicleInfoService {
public static VehicleInfo vehicleInfo = new VehicleInfo();
public static Set<PointCloudDataDto> pointCloudData = new HashSet<>();
public static Set<PointCloudDataDto> currentPointCloudData = new HashSet<>();
public static Set<PointCloudDataDto> globalPointCloudData = new HashSet<>();
@Override
public VehicleInfo getVehicleInfo() {
@@ -295,7 +297,8 @@ public class VehicleInfoServiceImpl implements VehicleInfoService {
if (webSocketSet.size() > 0) {
webSocketSet.forEach(c -> {
Map<String, Object> vehicleInfoMap = new HashMap<>();
vehicleInfoMap.put("data", pointCloudData);
vehicleInfoMap.put("globalData", globalPointCloudData);
vehicleInfoMap.put("currentData", currentPointCloudData);
c.sendDataToClient(vehicleInfoMap);
});
}

View File

@@ -61,7 +61,7 @@ public class ProtobufWebSocketHandler extends BinaryWebSocketHandler {
// 自动回退状态标识 0 不处理 1 自动回退成功 2 自动回退失败
VehicleInfoServiceImpl.vehicleInfo.setAuto_back_finish(data_pool.getString("auto_back_finish"));
// 车辆载货状态 0未载货 1载货
VehicleInfoServiceImpl.vehicleInfo.setVehiclePayloads(robotBase.getPayloads());
VehicleInfoServiceImpl.vehicleInfo.setVehiclePayloads(data_pool.getString("carry_status"));
String ready = data_pool.getString("ready");
TeachingServiceImpl.teachingMappingStatus.put("mapping_return", mapping_return);
TeachingServiceImpl.teachingMappingStatus.put("mapping_percent", mapping_percent);
@@ -98,7 +98,8 @@ public class ProtobufWebSocketHandler extends BinaryWebSocketHandler {
Robottype.LaserData laser = datagram.getLaserScan();
// 9顶部激光
if (laser.getLocation() == 9){
Set<PointCloudDataDto> data = new HashSet<>();
Set<PointCloudDataDto> globalData = new HashSet<>();
Set<PointCloudDataDto> currentData = new HashSet<>();
for (Robottype.Point point: laser.getScanList()){
double cosYaw = cos(VehicleInfoServiceImpl.vehicleInfo.getTheta());
double sinYaw = sin(VehicleInfoServiceImpl.vehicleInfo.getTheta());
@@ -110,12 +111,26 @@ public class ProtobufWebSocketHandler extends BinaryWebSocketHandler {
DecimalFormat y_globalDF = new DecimalFormat("#.#");
String y_result = y_globalDF.format(y_global);
double y_globalNum = Double.parseDouble(y_result);
PointCloudDataDto pointCloudDataDto = new PointCloudDataDto();
pointCloudDataDto.setX(x_globalNum);
pointCloudDataDto.setY(y_globalNum);
data.add(pointCloudDataDto);
PointCloudDataDto globalPointCloudDataDto = new PointCloudDataDto();
globalPointCloudDataDto.setX(x_globalNum);
globalPointCloudDataDto.setY(y_globalNum);
globalData.add(globalPointCloudDataDto);
double x_current = point.getX();
DecimalFormat x_currentDF = new DecimalFormat("#.#");
String x_CurrentResult = x_currentDF.format(x_current);
double x_currentNum = Double.parseDouble(x_CurrentResult);
double y_current = point.getY();
DecimalFormat y_currentDF = new DecimalFormat("#.#");
String y_CurrentResult = y_currentDF.format(y_current);
double y_currentNum = Double.parseDouble(y_CurrentResult);
PointCloudDataDto currentPointCloudDataDto = new PointCloudDataDto();
currentPointCloudDataDto.setX(x_currentNum);
currentPointCloudDataDto.setY(y_currentNum);
currentData.add(currentPointCloudDataDto);
}
VehicleInfoServiceImpl.pointCloudData = data;
VehicleInfoServiceImpl.globalPointCloudData = globalData;
VehicleInfoServiceImpl.currentPointCloudData = currentData;
}
// System.out.println("Received laser_scan: " + list);
break;

View File

@@ -26,8 +26,13 @@ public class URLConstant {
public final static String SEND_TASK_URL = "/task/add";
/**
* 取消任务URL
* 根据任务ID取消任务URL + 任务ID
*/
public final static String CANCEL_TASK_URL = "/task/cancel/";
/**
* 根据车号ID取消任务URL
*/
public final static String VEHICLE_ID_CANCEL_TASK_URL = "/task/batchCancel";
}