| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.model.NavigateNode; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.News; |
| | |
| | | |
| | | @Override |
| | | public boolean connect() { |
| | | Thread checkThread = new Thread(() -> { |
| | | while (true) { |
| | | try { |
| | | for (Map.Entry<Integer, List<ZyStationStatusEntity>> entry : deviceStatusMap.entrySet()) { |
| | | List<ZyStationStatusEntity> stationList = entry.getValue(); |
| | | for (ZyStationStatusEntity statusEntity : stationList) { |
| | | if (statusEntity.isAutoing() |
| | | && statusEntity.isLoading() |
| | | && statusEntity.getTaskNo() > 0 |
| | | && !statusEntity.isRunBlock() |
| | | && !statusEntity.getStationId().equals(statusEntity.getTargetStaNo()) |
| | | ) { |
| | | BlockingQueue<StationCommand> commands = taskQueues.get(statusEntity.getTaskNo()); |
| | | if (commands == null) { |
| | | statusEntity.setRunBlock(true); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | Thread.sleep(100); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }); |
| | | checkThread.start(); |
| | | return true; |
| | | } |
| | | |
| | |
| | | return new CommandResponse(false, "任务号为空"); |
| | | } |
| | | |
| | | taskQueues.computeIfAbsent(taskNo, k -> new LinkedBlockingQueue<>()).offer(command); |
| | | taskLastUpdateTime.put(taskNo, System.currentTimeMillis()); |
| | | // 处理非移动命令 |
| | | if (command.getCommandType() != StationCommandType.MOVE) { |
| | | handleCommand(deviceNo, command); |
| | | }else { |
| | | taskQueues.computeIfAbsent(taskNo, k -> new LinkedBlockingQueue<>()).offer(command); |
| | | taskLastUpdateTime.put(taskNo, System.currentTimeMillis()); |
| | | |
| | | if (taskRunning.putIfAbsent(taskNo, true) == null) { |
| | | executor.submit(() -> runTaskLoop(deviceNo, taskNo)); |
| | | if (taskRunning.putIfAbsent(taskNo, true) == null) { |
| | | executor.submit(() -> runTaskLoop(deviceNo, taskNo)); |
| | | } |
| | | } |
| | | |
| | | return new CommandResponse(true, "命令已受理(异步执行)"); |
| | |
| | | StationCommand initialCommand = null; |
| | | Integer finalTargetStationId = null; |
| | | boolean generateBarcode = false; |
| | | long stepExecuteTime = System.currentTimeMillis(); |
| | | |
| | | while (true) { |
| | | BlockingQueue<StationCommand> commandQueue = taskQueues.get(taskNo); |
| | |
| | | // 尝试获取新命令,如果没有新命令则继续执行现有路径 |
| | | StationCommand command = commandQueue.poll(100, TimeUnit.MILLISECONDS); |
| | | if (command != null) { |
| | | stepExecuteTime = System.currentTimeMillis(); |
| | | taskLastUpdateTime.put(taskNo, System.currentTimeMillis()); |
| | | |
| | | if (initialCommand == null) { |
| | |
| | | pathQueue.offer(stationId); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 处理非移动命令 |
| | | if (command.getCommandType() != StationCommandType.MOVE) { |
| | | handleCommand(deviceNo, command); |
| | | } |
| | | } |
| | | |
| | |
| | | if (moveSuccess) { |
| | | currentPathIndex++; |
| | | pathQueue.poll(); |
| | | stepExecuteTime = System.currentTimeMillis(); |
| | | sleep(1000); // 模拟耗时 |
| | | } else { |
| | | if (!checkTaskNoInArea(taskNo)) { |
| | | boolean fakeAllowCheckBlock = true; |
| | | Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key); |
| | | if (systemConfigMapObj != null) { |
| | | HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj; |
| | | if (systemConfigMap.get("fakeAllowCheckBlock") != null && !systemConfigMap.get("fakeAllowCheckBlock").equals("Y")) { |
| | | fakeAllowCheckBlock = false; |
| | | } |
| | | } |
| | | |
| | | if (fakeAllowCheckBlock && System.currentTimeMillis() - stepExecuteTime > 1000 * 10) { |
| | | //认定堵塞 |
| | | boolean result = runBlockStation(taskNo, currentStationId, currentDeviceNo, taskNo, currentStationId); |
| | | if(result) { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | sleep(1000); // 失败重试等待 |
| | | } |
| | | } else { |