#
Junjie
7 天以前 2c1e3b7b10c0d4afbf09a9151e132f1ee85b9c6f
#
5个文件已修改
1个文件已添加
53 ■■■■■ 已修改文件
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/action/ShuttleAction.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/task/ShuttleExecuteScheduler.java 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/impl/NyShuttleThread.java 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/impl/TrafficControlImplThread.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/utils/TimeoutExecutor.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -498,7 +498,10 @@
                return false;
            }
            //判断小车是否到达货物库位
            if (!shuttleProtocol.getCurrentLocNo().equals(wrkMast.getSourceLocNo())) {
                //小车未到达取货位置
                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getShuttleNo());//调度小车到货物所在库位进行取货
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,小车未到达取货位置", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
                return false;
            }
@@ -1092,6 +1095,16 @@
                    continue;
                }
                WrkMast wrkMast1 = wrkMastService.selectShuttleWorking(shuttleProtocol.getShuttleNo());
                if (wrkMast1 != null) {
                    continue;
                }
                WrkMast wrkMast2 = wrkMastService.selectShuttleHasMoveWorking(shuttleProtocol.getShuttleNo());
                if (wrkMast2 != null) {
                    continue;
                }
                WrkMast wrkMast = wrkMastService.selectChargeWorking(shuttleProtocol.getShuttleNo());
                if (wrkMast != null) {//已有充电任务
                    continue;
src/main/java/com/zy/core/action/ShuttleAction.java
@@ -203,8 +203,10 @@
            }
        }
        News.info("execute send command {},{}", shuttleNo, taskNo);
        // 下发命令
        CommandResponse response = write(command, shuttleNo);
        News.info("execute send command complete {},{}", shuttleNo, taskNo);
        //保存命令日志
        BasShuttleOpt basShuttleOpt = new BasShuttleOpt();
@@ -1158,7 +1160,7 @@
//        }
//    }
    private synchronized CommandResponse write(ShuttleCommand command, Integer shuttleNo) {
    private CommandResponse write(ShuttleCommand command, Integer shuttleNo) {
        CommandResponse response = new CommandResponse(false);
        if (null == command) {
            News.error("四向穿梭车写入命令为空");
src/main/java/com/zy/core/task/ShuttleExecuteScheduler.java
@@ -8,10 +8,12 @@
import com.zy.core.action.ShuttleAction;
import com.zy.core.enums.RedisKeyType;
import com.zy.core.enums.SlaveType;
import com.zy.core.utils.TimeoutExecutor;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class ShuttleExecuteScheduler implements Runnable {
@@ -69,7 +71,12 @@
                                //存在任务需要执行
                                long startTime = System.currentTimeMillis();
                                News.info("execute {},{}", deviceConfig.getDeviceNo(), taskNo);
                                boolean result = shuttleAction.executeWork(deviceConfig.getDeviceNo(), taskNo);
                                // 在循环中使用
                                boolean result = TimeoutExecutor.executeWithTimeout(
                                        () -> shuttleAction.executeWork(deviceConfig.getDeviceNo(), taskNo),
                                        30,  // 30秒超时
                                        TimeUnit.SECONDS
                                );
                                Thread.sleep(100);
                                News.info("execute end {},{},{}", deviceConfig.getDeviceNo(), taskNo, System.currentTimeMillis() - startTime);
                            }
src/main/java/com/zy/core/thread/impl/NyShuttleThread.java
@@ -927,8 +927,11 @@
            return false;
        }
        List<NavigationMapType> restartCalcMapTypes = new ArrayList<>(mapTypes);
        restartCalcMapTypes.add(NavigationMapType.SHUTTLE);
        String currentLocNo = shuttleProtocol.getCurrentLocNo();
        List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(currentLocNo, locNo, mapTypes, assignCommand, this);
        List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(currentLocNo, locNo, restartCalcMapTypes, assignCommand, this);
        if (commands == null) {
            return false;
        }
src/main/java/com/zy/core/thread/impl/TrafficControlImplThread.java
@@ -393,6 +393,7 @@
        }
        trafficControlDataList.remove(idx);//取消管制
        redisUtil.del(RedisKeyType.TRAFFIC_CONTROL_SUCCESS_APPLY.key + shuttleNo + "_" + taskNo);
        return true;
    }
src/main/java/com/zy/core/utils/TimeoutExecutor.java
New file
@@ -0,0 +1,21 @@
package com.zy.core.utils;
import java.util.concurrent.*;
public class TimeoutExecutor {
    public static <T> T executeWithTimeout(Callable<T> task, long timeout, TimeUnit unit) throws Exception {
        ExecutorService executor = Executors.newSingleThreadExecutor();
        Future<T> future = executor.submit(task);
        try {
            return future.get(timeout, unit);
        } catch (TimeoutException e) {
            future.cancel(true); // 中断任务
            throw new TimeoutException("Task timed out");
        } finally {
            executor.shutdownNow();
        }
    }
}