arduino避障小车阶段性开发

This commit is contained in:
2025-05-30 19:33:46 +08:00
parent d0a550cab6
commit 2aa0c4ffde
3 changed files with 240 additions and 6 deletions

View File

@@ -2,6 +2,8 @@ package com.yupi.project.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yupi.project.common.ErrorCode;
import com.yupi.project.exception.BusinessException;
import com.yupi.project.model.entity.RobotTask;
import com.yupi.project.model.enums.CommandTypeEnum;
import com.yupi.project.model.enums.RobotTaskStatusEnum;
@@ -97,17 +99,21 @@ public class RobotTaskServiceImpl extends ServiceImpl<RobotTaskMapper, RobotTask
public boolean markTaskAsSent(Long taskId, Date sentTime) {
if (taskId == null || sentTime == null) {
log.error("Cannot mark task as sent: taskId or sentTime is null.");
return false;
// 抛出异常而不是返回false
throw new BusinessException(ErrorCode.PARAMS_ERROR, "Task ID or sentTime cannot be null when marking task as SENT.");
}
RobotTask task = this.getById(taskId);
if (task == null) {
log.warn("Cannot mark task as sent: Task with ID {} not found.", taskId);
return false;
// 抛出异常
throw new BusinessException(ErrorCode.NOT_FOUND_ERROR, "Task with ID " + taskId + " not found.");
}
if (task.getStatus() != RobotTaskStatusEnum.PENDING) {
log.warn("Cannot mark task {} as SENT. Current status is {}, expected PENDING.", taskId, task.getStatus());
return false;
// 抛出异常
throw new BusinessException(ErrorCode.OPERATION_ERROR,
"Task " + taskId + " is in status " + task.getStatus() + ", expected PENDING to mark as SENT.");
}
RobotTask updateTask = new RobotTask();
@@ -119,9 +125,11 @@ public class RobotTaskServiceImpl extends ServiceImpl<RobotTaskMapper, RobotTask
if (updated) {
log.info("Marked RobotTask with ID: {} as SENT at {}.", taskId, sentTime);
} else {
log.error("Failed to mark RobotTask with ID: {} as SENT.", taskId);
log.error("Failed to mark RobotTask with ID: {} as SENT. Update to database failed.", taskId);
// 抛出异常
throw new BusinessException(ErrorCode.OPERATION_ERROR, "Failed to update task " + taskId + " to SENT in database.");
}
return updated;
return true; // 如果没有抛出异常,则表示成功
}
@Override