| | |
| | | boolean initialized = false; |
| | | // 上一步执行时间(用于堵塞检测) |
| | | long stepExecuteTime = System.currentTimeMillis(); |
| | | // 避免在到达目标后重复执行到位逻辑 |
| | | boolean arrivalHandled = false; |
| | | |
| | | while (true) { |
| | | if (Thread.currentThread().isInterrupted()) { |
| | |
| | | Integer commandTargetStationId = command.getTargetStaNo(); |
| | | if (commandTargetStationId != null) { |
| | | if (!commandTargetStationId.equals(finalTargetStationId)) { |
| | | arrivalHandled = false; |
| | | News.info("[WCS Debug] 任务{}切换目标: {} -> {}", taskNo, finalTargetStationId, |
| | | commandTargetStationId); |
| | | } |
| | |
| | | currentStationId = nextStationId; |
| | | pendingPathQueue.poll(); |
| | | stepExecuteTime = System.currentTimeMillis(); |
| | | arrivalHandled = false; |
| | | News.info("[WCS Debug] 任务{}移动到站点: {}, 剩余队列: {}", taskNo, currentStationId, |
| | | pendingPathQueue.size()); |
| | | sleep(1000); // 模拟移动耗时 |
| | |
| | | // 路径队列为空,等待新的分段命令 |
| | | if (currentStationId != null && finalTargetStationId != null |
| | | && currentStationId.equals(finalTargetStationId)) { |
| | | // 已到达目标,先执行一次到位逻辑,然后继续等待下一条移动命令 |
| | | if (!arrivalHandled) { |
| | | // 已到达目标:立即清空当前队列并结束本轮执行,后续新命令重新创建执行线程 |
| | | if (generateBarcode) { |
| | | Integer targetDeviceNo = getDeviceNoByStationId(finalTargetStationId); |
| | | if (targetDeviceNo != null) { |
| | |
| | | News.info("[WCS Debug] 任务{}到达目标{}并生成条码", taskNo, finalTargetStationId); |
| | | } |
| | | } |
| | | arrivalHandled = true; |
| | | } |
| | | commandQueue.clear(); |
| | | pendingPathQueue.clear(); |
| | | News.info("[WCS Debug] 任务{}到达目标后清空队列并结束,等待后续新命令重启", taskNo); |
| | | break; |
| | | } |
| | | |
| | | // 继续等待新的分段命令 |