| | |
| | | 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; |
| | | } |
| | |
| | | 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; |
| | |
| | | } |
| | | } |
| | | |
| | | News.info("execute send command {},{}", shuttleNo, taskNo); |
| | | // 下发命令 |
| | | CommandResponse response = write(command, shuttleNo); |
| | | News.info("execute send command complete {},{}", shuttleNo, taskNo); |
| | | |
| | | //保存命令日志 |
| | | BasShuttleOpt basShuttleOpt = new BasShuttleOpt(); |
| | |
| | | // } |
| | | // } |
| | | |
| | | 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("四向穿梭车写入命令为空"); |
| | |
| | | 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 { |
| | | |
| | |
| | | //存在任务需要执行 |
| | | 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); |
| | | } |
| | |
| | | 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; |
| | | } |
| | |
| | | } |
| | | |
| | | trafficControlDataList.remove(idx);//取消管制 |
| | | redisUtil.del(RedisKeyType.TRAFFIC_CONTROL_SUCCESS_APPLY.key + shuttleNo + "_" + taskNo); |
| | | return true; |
| | | } |
| | | |
New file |
| | |
| | | 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(); |
| | | } |
| | | } |
| | | |
| | | } |