| | |
| | | @Component |
| | | public class StationOperateProcessUtils { |
| | | private static final int LOOP_LOAD_RESERVE_EXPIRE_SECONDS = 120; |
| | | private static final int OUT_ORDER_DISPATCH_LIMIT_SECONDS = 10; |
| | | |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | |
| | | continue; |
| | | } |
| | | |
| | | if (isWatchingCircleArrival(wrkMast.getWrkNo(), stationProtocol.getStationId())) { |
| | | continue; |
| | | } |
| | | |
| | | if (Cools.isEmpty(wrkMast.getBatch())) { |
| | | continue; |
| | | } |
| | |
| | | News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败"); |
| | | continue; |
| | | } |
| | | if (!tryAcquireOutOrderDispatchLock(wrkMast.getWrkNo(), stationProtocol.getStationId())) { |
| | | continue; |
| | | } |
| | | clearWatchCircleCommand(wrkMast.getWrkNo()); |
| | | MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command)); |
| | | News.info("{}任务直接去目标点", wrkMast.getWrkNo()); |
| | | } else if (commandType.equals("toCircle")) { |
| | |
| | | News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败"); |
| | | continue; |
| | | } |
| | | if (!tryAcquireOutOrderDispatchLock(wrkMast.getWrkNo(), stationProtocol.getStationId())) { |
| | | continue; |
| | | } |
| | | MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command)); |
| | | redisUtil.set(RedisKeyType.WATCH_CIRCLE_STATION_.key + wrkMast.getWrkNo(), JSON.toJSONString(command, SerializerFeature.DisableCircularReferenceDetect), 60 * 60 * 24); |
| | | saveWatchCircleCommand(wrkMast.getWrkNo(), command); |
| | | News.info("{}任务进行绕圈", wrkMast.getWrkNo()); |
| | | } |
| | | } |
| | |
| | | continue; |
| | | } |
| | | |
| | | Object circleObj = redisUtil.get(RedisKeyType.WATCH_CIRCLE_STATION_.key + stationProtocol.getTaskNo()); |
| | | if (circleObj == null) { |
| | | StationCommand circleCommand = getWatchCircleCommand(stationProtocol.getTaskNo()); |
| | | if (circleCommand == null) { |
| | | continue; |
| | | } |
| | | |
| | | StationCommand circleCommand = JSON.parseObject(circleObj.toString(), StationCommand.class); |
| | | if (!stationProtocol.getStationId().equals(circleCommand.getTargetStaNo())) { |
| | | continue; |
| | | } |
| | |
| | | if (command == null) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败"); |
| | | continue; |
| | | } |
| | | if (!tryAcquireOutOrderDispatchLock(wrkMast.getWrkNo(), stationProtocol.getStationId())) { |
| | | continue; |
| | | } |
| | | if (Objects.equals(moveStaNo, wrkMast.getStaNo())) { |
| | | clearWatchCircleCommand(wrkMast.getWrkNo()); |
| | | } else { |
| | | saveWatchCircleCommand(wrkMast.getWrkNo(), command); |
| | | } |
| | | MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command)); |
| | | } |
| | |
| | | return null; |
| | | } |
| | | |
| | | private boolean tryAcquireOutOrderDispatchLock(Integer wrkNo, Integer stationId) { |
| | | if (wrkNo == null || wrkNo <= 0 || stationId == null) { |
| | | return true; |
| | | } |
| | | String key = RedisKeyType.STATION_OUT_ORDER_DISPATCH_LIMIT_.key + wrkNo + "_" + stationId; |
| | | Object lock = redisUtil.get(key); |
| | | if (lock != null) { |
| | | return false; |
| | | } |
| | | redisUtil.set(key, "lock", OUT_ORDER_DISPATCH_LIMIT_SECONDS); |
| | | return true; |
| | | } |
| | | |
| | | private boolean isWatchingCircleArrival(Integer wrkNo, Integer stationId) { |
| | | StationCommand command = getWatchCircleCommand(wrkNo); |
| | | return command != null && stationId != null && stationId.equals(command.getTargetStaNo()); |
| | | } |
| | | |
| | | private StationCommand getWatchCircleCommand(Integer wrkNo) { |
| | | if (wrkNo == null || wrkNo <= 0) { |
| | | return null; |
| | | } |
| | | Object circleObj = redisUtil.get(RedisKeyType.WATCH_CIRCLE_STATION_.key + wrkNo); |
| | | if (circleObj == null) { |
| | | return null; |
| | | } |
| | | try { |
| | | return JSON.parseObject(circleObj.toString(), StationCommand.class); |
| | | } catch (Exception ignore) { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | private void saveWatchCircleCommand(Integer wrkNo, StationCommand command) { |
| | | if (wrkNo == null || wrkNo <= 0 || command == null) { |
| | | return; |
| | | } |
| | | redisUtil.set(RedisKeyType.WATCH_CIRCLE_STATION_.key + wrkNo, |
| | | JSON.toJSONString(command, SerializerFeature.DisableCircularReferenceDetect), 60 * 60 * 24); |
| | | } |
| | | |
| | | private void clearWatchCircleCommand(Integer wrkNo) { |
| | | if (wrkNo == null || wrkNo <= 0) { |
| | | return; |
| | | } |
| | | redisUtil.del(RedisKeyType.WATCH_CIRCLE_STATION_.key + wrkNo); |
| | | } |
| | | |
| | | public Integer getOutStationBatchSeq(List<NavigateNode> pathList, Integer searchStationId, String searchBatch) { |
| | | List<Integer> checkList = new ArrayList<>(); |
| | | for (int i = pathList.size() - 1; i >= 0; i--) { |