#
vincentlu
2025-04-01 d59d4495574968e23e520da71f89790f0ad09df0
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java
@@ -35,7 +35,7 @@
import com.zy.acs.manager.system.service.ConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
@@ -47,7 +47,7 @@
 * Created by vincent on 2023/6/14
 */
@Slf4j
@Component("mainService")
@Service("mainService")
public class MainService {
    @Autowired
@@ -96,7 +96,6 @@
    private LaneService laneService;
    @Autowired
    private ActionSorter actionSorter;
    @SuppressWarnings("all")
    @Transactional
@@ -175,8 +174,28 @@
                    if (!locService.updateById(oriLoc)) {
                        throw new BusinessException("oriLoc:" + task.getOriLoc$() + " failed to update");
                    }
                    destSta = staService.getById(task.getDestSta());
                    if (!destSta.getStaSts().equals(StaStsType.IDLE.val())) {
                        throw new BusinessException("destSta:" + task.getDestSta$() + " is not in IDLE status");
                    }
                    destSta.setStaSts(StaStsType.PAKIN.val());
                    destSta.setUpdateTime(now);
                    if (!staService.updateById(destSta)) {
                        throw new BusinessException("destSta:" + task.getDestSta$() + " failed to update");
                    }
                    break;
                case STA_TO_LOC:
                    oriSta = staService.getById(task.getOriSta());
                    if (!oriSta.getStaSts().equals(StaStsType.STOCK.val())) {
                        throw new BusinessException("oriSta:" + task.getOriSta$() + " is not in STOCK status");
                    }
                    oriSta.setStaSts(StaStsType.PAKOUT.val());
                    oriSta.setUpdateTime(now);
                    if (!staService.updateById(oriSta)) {
                        throw new BusinessException("oriSta:" + task.getOriSta$() + " failed to update");
                    }
                    destLoc = locService.getById(task.getDestLoc());
                    if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) {
                        throw new BusinessException("destLoc:" + task.getDestLoc$() + " is not in IDLE status");
@@ -188,6 +207,25 @@
                    }
                    break;
                case STA_TO_STA:
                    oriSta = staService.getById(task.getOriSta());
                    if (!oriSta.getStaSts().equals(StaStsType.STOCK.val())) {
                        throw new BusinessException("oriSta:" + task.getOriSta$() + " is not in STOCK status");
                    }
                    oriSta.setStaSts(StaStsType.PAKOUT.val());
                    oriSta.setUpdateTime(now);
                    if (!staService.updateById(oriSta)) {
                        throw new BusinessException("oriSta:" + task.getOriSta$() + " failed to update");
                    }
                    destSta = staService.getById(task.getDestSta());
                    if (!destSta.getStaSts().equals(StaStsType.IDLE.val())) {
                        throw new BusinessException("destSta:" + task.getDestSta$() + " is not in IDLE status");
                    }
                    destSta.setStaSts(StaStsType.PAKIN.val());
                    destSta.setUpdateTime(now);
                    if (!staService.updateById(destSta)) {
                        throw new BusinessException("destSta:" + task.getDestSta$() + " failed to update");
                    }
                    break;
                default:
                    break;
@@ -223,7 +261,7 @@
            for (Task task : taskList) {
                Agv agv = allocateService.execute(task);
                if (null == agv) {
//                    log.warn("Task[{}] has an issue, because it failed to checkout agv which is idle...", task.getSeqNum());
//                    log.warn("Task[{}] has an issue, because it failed to check out agv which is idle...", task.getSeqNum());
                    continue;
                }
                task.setAgvId(agv.getId());
@@ -667,7 +705,7 @@
            List<Action> actionList = new ArrayList<>();
            // start node
            Code lastCode = codeService.getCacheById(agvDetail.getRecentCode());
            Double lastDirection = agvDetail.getAgvAngle();
            Double lastDirection = MapService.mapToNearest(agvDetail.getAgvAngle());
            if (!lastCode.getData().equals(pathList.get(0))) {
                throw new CoolException("AGV[" + agvNo + "]定位偏移...");
            }
@@ -696,12 +734,55 @@
                        Code nextCode = codeService.getCacheByData(next);
                        Double nextDirection = mapService.calculateDirection(lastCode, nextCode, angleOffsetVal);
                        // 第一步:如果下一个方向正好是作业方向的相反方向,则重置下一个方向为作业方向,标记 reverse = true
                        boolean reverse = false;
                        if (nextDirection.equals((workDirection + 180) % 360)) {
                            nextDirection = workDirection;
                            reverse = true;
                        }
                        if (!lastDirection.equals(nextDirection) || actionList.isEmpty()) {
                        // 第二步:判断当前节点是否可以旋转
                        if (!lastCode.getCornerBool()) {
                            // 如果是作业方向,但是小车在巷道内方向错误,则停止
                            if (reverse && !lastDirection.equals(nextDirection)) {
//                                throw new CoolException(agvNo + "号小车方向错误,请推至转弯点手动调整");
                            }
                            // 如果不是作业方向,判断是否相反方向,如果反方向则倒退行走
                            if (nextDirection.equals((lastDirection + 180) % 360)) {
                                nextDirection = lastDirection;
                                reverse = true;
                            }
                        } else {
                            if (!lastDirection.equals(nextDirection)) {
                                // 如果下个节点方向与当前agv方向相反,则倒退行走,但是如果当前agv方向正好与工作方向相反,则旋转至工作方向
                                if (nextDirection.equals((lastDirection + 180) % 360) && !workDirection.equals((lastDirection + 180) % 360)) {
                                    nextDirection = lastDirection;
                                    reverse = true;
                                } else {
                                    // turn
                                    actionList.add(new Action(
                                            null,    // 编号s
                                            task.getBusId(),    // 总线
                                            task.getId(),    // 任务
                                            null,    // 动作号
                                            null,    // 优先级
                                            ActionTypeType.TurnCorner.desc,    // 名称
                                            mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D,    // 属性值
                                            lastCode.getData(),    // 地面码
                                            String.valueOf(nextDirection),   // 动作参数
                                            ActionTypeType.TurnCorner.val(),    // 动作类型
                                            actionPrepareSts,    // 动作进度
                                            agvId,    // AGV
                                            now    // 工作时间
                                    ));
                                    lastDirection = nextDirection;
                                }
                            }
                        }
                        // 第一个动作一定是 turn
                        if (actionList.isEmpty()) {
                            // turn
                            actionList.add(new Action(
                                    null,    // 编号
@@ -720,7 +801,6 @@
                            ));
                            lastDirection = nextDirection;
                        }
                        // run
@@ -785,23 +865,24 @@
                        assert backpackType != null;
                        // 检验方向
                        if (!lastDirection.equals(workDirection)) {
                            throw new CoolException(agvNo + "号小车方向错误,请推至转弯点手动调整");
                            // turn
                            actionList.add(new Action(
                                    null,    // 编号
                                    task.getBusId(),    // 总线
                                    task.getId(),    // 任务
                                    null,    // 动作号
                                    null,    // 优先级
                                    ActionTypeType.TurnCorner.desc,    // 名称
                                    mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D,    // 属性值
                                    lastCode.getData(),    // 地面码
                                    String.valueOf(workDirection),   // 动作参数
                                    ActionTypeType.TurnCorner.val(),    // 动作类型
                                    actionPrepareSts,    // 动作进度
                                    agvId,    // AGV
                                    now    // 工作时间
                            ));
                            lastDirection = workDirection;
//                            actionList.add(new Action(
//                                    null,    // 编号
//                                    task.getBusId(),    // 总线
//                                    task.getId(),    // 任务
//                                    null,    // 动作号
//                                    null,    // 优先级
//                                    ActionTypeType.TurnCorner.desc,    // 名称
//                                    mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D,    // 属性值
//                                    lastCode.getData(),    // 地面码
//                                    String.valueOf(workDirection),   // 动作参数
//                                    ActionTypeType.TurnCorner.val(),    // 动作类型
//                                    actionPrepareSts,    // 动作进度
//                                    agvId,    // AGV
//                                    now    // 工作时间
//                            ));
//                            lastDirection = workDirection;
                        }
                        // 货架取货
                        Loc oriLoc = locService.getById(task.getOriLoc());
@@ -843,23 +924,24 @@
                        assert backpackType != null;
                        // 检验方向
                        if (!lastDirection.equals(workDirection)) {
                            // turn
                            actionList.add(new Action(
                                    null,    // 编号
                                    task.getBusId(),    // 总线
                                    task.getId(),    // 任务
                                    null,    // 动作号
                                    null,    // 优先级
                                    ActionTypeType.TurnCorner.desc,    // 名称
                                    mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D,    // 属性值
                                    lastCode.getData(),    // 地面码
                                    String.valueOf(workDirection),   // 动作参数
                                    ActionTypeType.TurnCorner.val(),    // 动作类型
                                    actionPrepareSts,    // 动作进度
                                    agvId,    // AGV
                                    now    // 工作时间
                            ));
                            lastDirection = workDirection;
                            throw new CoolException(agvNo + "号小车方向错误,请推至转弯点手动调整");
//                            // turn
//                            actionList.add(new Action(
//                                    null,    // 编号
//                                    task.getBusId(),    // 总线
//                                    task.getId(),    // 任务
//                                    null,    // 动作号
//                                    null,    // 优先级
//                                    ActionTypeType.TurnCorner.desc,    // 名称
//                                    mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D,    // 属性值
//                                    lastCode.getData(),    // 地面码
//                                    String.valueOf(workDirection),   // 动作参数
//                                    ActionTypeType.TurnCorner.val(),    // 动作类型
//                                    actionPrepareSts,    // 动作进度
//                                    agvId,    // AGV
//                                    now    // 工作时间
//                            ));
//                            lastDirection = workDirection;
                        }
                        // 暂存点取货货
                        actionList.add(new Action(
@@ -1050,9 +1132,9 @@
                action.setStartTime(now);
                action.setIoTime(now);
                action.setUpdateTime(now);
                if (!actionService.updateById(action)) {
                    throw new BusinessException(action.getPriority() + " - " + action.getName() + "动作更新失败");
                }
            }
            if (!actionService.updateBatchById(actionList)) {
                throw new BusinessException("failed to update action batch !!!");
            }
            // task