From 2c1e3b7b10c0d4afbf09a9151e132f1ee85b9c6f Mon Sep 17 00:00:00 2001 From: Junjie <540245094@qq.com> Date: 星期六, 02 八月 2025 11:15:25 +0800 Subject: [PATCH] # --- src/main/java/com/zy/core/task/ShuttleExecuteScheduler.java | 9 ++++++++- src/main/java/com/zy/core/thread/impl/NyShuttleThread.java | 5 ++++- src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 13 +++++++++++++ src/main/java/com/zy/core/action/ShuttleAction.java | 4 +++- src/main/java/com/zy/core/utils/TimeoutExecutor.java | 21 +++++++++++++++++++++ src/main/java/com/zy/core/thread/impl/TrafficControlImplThread.java | 1 + 6 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java index 1d08bc7..63ca0b6 100644 --- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java +++ b/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; diff --git a/src/main/java/com/zy/core/action/ShuttleAction.java b/src/main/java/com/zy/core/action/ShuttleAction.java index 2486dd8..55bba24 100644 --- a/src/main/java/com/zy/core/action/ShuttleAction.java +++ b/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("鍥涘悜绌挎杞﹀啓鍏ュ懡浠や负绌�"); diff --git a/src/main/java/com/zy/core/task/ShuttleExecuteScheduler.java b/src/main/java/com/zy/core/task/ShuttleExecuteScheduler.java index a3d5036..4839cb1 100644 --- a/src/main/java/com/zy/core/task/ShuttleExecuteScheduler.java +++ b/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); } diff --git a/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java b/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java index 724ba7a..e311708 100644 --- a/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java +++ b/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; } diff --git a/src/main/java/com/zy/core/thread/impl/TrafficControlImplThread.java b/src/main/java/com/zy/core/thread/impl/TrafficControlImplThread.java index e63ef9d..89819a2 100644 --- a/src/main/java/com/zy/core/thread/impl/TrafficControlImplThread.java +++ b/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; } diff --git a/src/main/java/com/zy/core/utils/TimeoutExecutor.java b/src/main/java/com/zy/core/utils/TimeoutExecutor.java new file mode 100644 index 0000000..d7cc8f9 --- /dev/null +++ b/src/main/java/com/zy/core/utils/TimeoutExecutor.java @@ -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(); + } + } + +} \ No newline at end of file -- Gitblit v1.9.1