| | |
| | | |
| | | //入出库 ===>> 堆垛机入出库作业下发 |
| | | private void crnIoExecuteNormal(BasCrnp currentCrn, Set<Integer> crnMoveBlockedCrnNos) { |
| | | Map<Integer, BasCrnp> dispatchCrnMap = new HashMap<>(); |
| | | Map<Integer, CrnThread> dispatchThreadMap = new HashMap<>(); |
| | | Map<Integer, CrnProtocol> dispatchProtocolMap = new HashMap<>(); |
| | | for (BasCrnp basCrnp : java.util.Collections.singletonList(currentCrn)) { |
| | | if (basCrnp == null || basCrnp.getCrnNo() == null || crnMoveBlockedCrnNos.contains(basCrnp.getCrnNo())) { |
| | | continue; |
| | | } |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, basCrnp.getCrnNo()); |
| | | if (crnThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | CrnProtocol crnProtocol = crnThread.getStatus(); |
| | | if (crnProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | long runningCount = wrkMastService.count(new QueryWrapper<WrkMast>() |
| | | .eq("crn_no", basCrnp.getCrnNo()) |
| | | .in("wrk_sts", WrkStsType.INBOUND_RUN.sts, WrkStsType.OUTBOUND_RUN.sts, WrkStsType.LOC_MOVE_RUN.sts, WrkStsType.CRN_MOVE_RUN.sts)); |
| | | if (runningCount > 0) { |
| | | continue; |
| | | } |
| | | |
| | | // 只有当堆垛机空闲 并且 无任务时才继续执行 |
| | | if (crnProtocol.getMode() == CrnModeType.AUTO.id |
| | | && crnProtocol.getTaskNo() == 0 |
| | | && crnProtocol.getStatus() == CrnStatusType.IDLE.id |
| | | && crnProtocol.getLoaded() == 0 |
| | | && crnProtocol.getForkPos() == 0 |
| | | && crnProtocol.getAlarm() == 0 |
| | | ) { |
| | | Object clearLock = redisUtil.get(RedisKeyType.CLEAR_CRN_TASK_LIMIT.key + basCrnp.getCrnNo()); |
| | | if (clearLock != null) { |
| | | continue; |
| | | } |
| | | dispatchCrnMap.put(basCrnp.getCrnNo(), basCrnp); |
| | | dispatchThreadMap.put(basCrnp.getCrnNo(), crnThread); |
| | | dispatchProtocolMap.put(basCrnp.getCrnNo(), crnProtocol); |
| | | } |
| | | } |
| | | |
| | | if (dispatchCrnMap.isEmpty()) { |
| | | if (currentCrn == null || currentCrn.getCrnNo() == null || crnMoveBlockedCrnNos.contains(currentCrn.getCrnNo())) { |
| | | return; |
| | | } |
| | | |
| | | Integer crnNo = currentCrn.getCrnNo(); |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crnNo); |
| | | if (crnThread == null) { |
| | | return; |
| | | } |
| | | |
| | | CrnProtocol crnProtocol = crnThread.getStatus(); |
| | | if (crnProtocol == null) { |
| | | return; |
| | | } |
| | | |
| | | long runningCount = wrkMastService.count(new QueryWrapper<WrkMast>() |
| | | .eq("crn_no", crnNo) |
| | | .in("wrk_sts", WrkStsType.INBOUND_RUN.sts, WrkStsType.OUTBOUND_RUN.sts, WrkStsType.LOC_MOVE_RUN.sts, WrkStsType.CRN_MOVE_RUN.sts)); |
| | | if (runningCount > 0) { |
| | | return; |
| | | } |
| | | |
| | | // 只有当堆垛机空闲 并且 无任务时才继续执行 |
| | | if (crnProtocol.getMode() != CrnModeType.AUTO.id |
| | | || crnProtocol.getTaskNo() != 0 |
| | | || crnProtocol.getStatus() != CrnStatusType.IDLE.id |
| | | || crnProtocol.getLoaded() != 0 |
| | | || crnProtocol.getForkPos() != 0 |
| | | || crnProtocol.getAlarm() != 0) { |
| | | return; |
| | | } |
| | | |
| | | Object clearLock = redisUtil.get(RedisKeyType.CLEAR_CRN_TASK_LIMIT.key + crnNo); |
| | | if (clearLock != null) { |
| | | return; |
| | | } |
| | | |
| | | String lastIo = resolveCrnLastIo(crnProtocol); |
| | | |
| | | List<WrkMast> taskQueue = wrkMastService.list(new QueryWrapper<WrkMast>() |
| | | .in("crn_no", new ArrayList<>(dispatchCrnMap.keySet())) |
| | | .eq("crn_no", crnNo) |
| | | .in("wrk_sts", |
| | | WrkStsType.INBOUND_STATION_RUN_COMPLETE.sts, |
| | | WrkStsType.NEW_OUTBOUND.sts, |
| | | WrkStsType.NEW_LOC_MOVE.sts)); |
| | | taskQueue.sort(Comparator |
| | | .comparingInt(this::resolveBatchOutboundRank) |
| | | taskQueue.sort(Comparator.comparingInt((WrkMast wrkMast) -> resolveTaskTypeRank(wrkMast, lastIo)) |
| | | .thenComparingInt(this::resolveBatchOutboundRank) |
| | | .thenComparingInt(this::resolveBatchSeqOrder) |
| | | .thenComparingDouble(this::resolveTaskIoPri) |
| | | .thenComparingLong(this::resolveTaskQueueTime) |
| | | .thenComparingInt(this::resolveTaskQueueNo)); |
| | | |
| | | for (WrkMast wrkMast : taskQueue) { |
| | | if (wrkMast == null || wrkMast.getCrnNo() == null) { |
| | | continue; |
| | | } |
| | | |
| | | Integer crnNo = wrkMast.getCrnNo(); |
| | | BasCrnp basCrnp = dispatchCrnMap.get(crnNo); |
| | | CrnThread crnThread = dispatchThreadMap.get(crnNo); |
| | | CrnProtocol crnProtocol = dispatchProtocolMap.get(crnNo); |
| | | if (basCrnp == null || crnThread == null || crnProtocol == null) { |
| | | if (wrkMast == null || wrkMast.getCrnNo() == null || !Objects.equals(wrkMast.getCrnNo(), crnNo)) { |
| | | continue; |
| | | } |
| | | |
| | | if (wrkMast.getWrkSts() != null && wrkMast.getWrkSts() == WrkStsType.INBOUND_STATION_RUN_COMPLETE.sts) { |
| | | boolean result = this.crnExecuteInPlanner(basCrnp, crnThread, wrkMast); |
| | | boolean result = this.crnExecuteInPlanner(currentCrn, crnThread, wrkMast); |
| | | if (result) { |
| | | crnProtocol.setLastIo("O"); |
| | | return; |
| | |
| | | } |
| | | |
| | | if (wrkMast.getWrkSts() != null && wrkMast.getWrkSts() == WrkStsType.NEW_OUTBOUND.sts) { |
| | | boolean result = this.crnExecuteOutPlanner(basCrnp, crnThread, wrkMast); |
| | | boolean result = this.crnExecuteOutPlanner(currentCrn, crnThread, wrkMast); |
| | | if (result) { |
| | | crnProtocol.setLastIo("I"); |
| | | return; |
| | |
| | | } |
| | | |
| | | if (wrkMast.getWrkSts() != null && wrkMast.getWrkSts() == WrkStsType.NEW_LOC_MOVE.sts) { |
| | | boolean transfer = this.crnExecuteMovePlanner(basCrnp, crnThread, wrkMast); |
| | | boolean transfer = this.crnExecuteMovePlanner(currentCrn, crnThread, wrkMast); |
| | | if (transfer) { |
| | | return; |
| | | } |
| | |
| | | |
| | | private int resolveBatchOutboundRank(WrkMast wrkMast) { |
| | | return isBatchOutboundTask(wrkMast) ? 0 : 1; |
| | | } |
| | | |
| | | private String resolveCrnLastIo(CrnProtocol crnProtocol) { |
| | | if (crnProtocol == null) { |
| | | return "I"; |
| | | } |
| | | if (Cools.isEmpty(crnProtocol.getLastIo())) { |
| | | return "I"; |
| | | } |
| | | return crnProtocol.getLastIo(); |
| | | } |
| | | |
| | | private int resolveTaskTypeRank(WrkMast wrkMast, String lastIo) { |
| | | if (wrkMast == null || wrkMast.getWrkSts() == null) { |
| | | return Integer.MAX_VALUE; |
| | | } |
| | | |
| | | if (Objects.equals(wrkMast.getWrkSts(), WrkStsType.NEW_LOC_MOVE.sts)) { |
| | | return 0; |
| | | } |
| | | |
| | | if (Objects.equals("O", lastIo)) { |
| | | if (Objects.equals(wrkMast.getWrkSts(), WrkStsType.INBOUND_STATION_RUN_COMPLETE.sts)) { |
| | | return 1; |
| | | } |
| | | if (Objects.equals(wrkMast.getWrkSts(), WrkStsType.NEW_OUTBOUND.sts)) { |
| | | return 2; |
| | | } |
| | | return 3; |
| | | } |
| | | |
| | | if (Objects.equals(wrkMast.getWrkSts(), WrkStsType.NEW_OUTBOUND.sts)) { |
| | | return 1; |
| | | } |
| | | if (Objects.equals(wrkMast.getWrkSts(), WrkStsType.INBOUND_STATION_RUN_COMPLETE.sts)) { |
| | | return 2; |
| | | } |
| | | return 3; |
| | | } |
| | | |
| | | private int resolveBatchSeqOrder(WrkMast wrkMast) { |
| | |
| | | return false; |
| | | } |
| | | |
| | | if (!allowBatchOutboundExecute(wrkMast)) { |
| | | if (!allowBatchOutboundExecute(wrkMast, true)) { |
| | | return false; |
| | | } |
| | | |
| | |
| | | return false; |
| | | } |
| | | |
| | | private boolean allowBatchOutboundExecute(WrkMast wrkMast) { |
| | | public boolean canOutboundTaskExecuteInCurrentBatchWindow(WrkMast wrkMast) { |
| | | return allowBatchOutboundExecute(wrkMast, false); |
| | | } |
| | | |
| | | private boolean allowBatchOutboundExecute(WrkMast wrkMast, boolean logBlockedReason) { |
| | | if (wrkMast == null || Cools.isEmpty(wrkMast.getBatch())) { |
| | | return true; |
| | | } |
| | | |
| | | if (Cools.isEmpty(wrkMast.getBatchSeq())) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "批次:{} 缺少批次序号,暂不允许堆垛机出库", wrkMast.getBatch()); |
| | | if (logBlockedReason) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "批次:{} 缺少批次序号,暂不允许堆垛机出库", wrkMast.getBatch()); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | if (Cools.isEmpty(firstBatchWrkMast.getBatchSeq())) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "批次:{} 存在未配置批次序号的任务,暂不允许堆垛机出库", wrkMast.getBatch()); |
| | | if (logBlockedReason) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "批次:{} 存在未配置批次序号的任务,暂不允许堆垛机出库", wrkMast.getBatch()); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | |
| | | boolean firstBatchTaskExecuted = firstBatchWrkMast.getWrkSts() != null |
| | | && !firstBatchWrkMast.getWrkSts().equals(WrkStsType.NEW_OUTBOUND.sts); |
| | | if (!currentIsFirstBatchTask && !firstBatchTaskExecuted) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "批次:{} 首个序号任务:{} 尚未执行,当前任务暂不允许出库", wrkMast.getBatch(), firstBatchWrkMast.getWrkNo()); |
| | | if (logBlockedReason) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "批次:{} 首个序号任务:{} 尚未执行,当前任务暂不允许出库", wrkMast.getBatch(), firstBatchWrkMast.getWrkNo()); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | |
| | | |
| | | List<WrkMast> unfinishedBatchWrkMasts = listUnfinishedBatchWrkMasts(wrkMast.getBatch()); |
| | | if (hasMissingBatchSeq(unfinishedBatchWrkMasts)) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "批次:{} 存在未配置批次序号的未完成任务,暂不允许堆垛机出库", wrkMast.getBatch()); |
| | | if (logBlockedReason) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "批次:{} 存在未配置批次序号的未完成任务,暂不允许堆垛机出库", wrkMast.getBatch()); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | if (!isWithinBatchExecuteWindow(wrkMast, unfinishedBatchWrkMasts, batchRunningLimit)) { |
| | | Integer windowStartSeq = unfinishedBatchWrkMasts.get(0).getBatchSeq(); |
| | | Integer windowEndSeq = unfinishedBatchWrkMasts.get(Math.min(batchRunningLimit, unfinishedBatchWrkMasts.size()) - 1).getBatchSeq(); |
| | | News.taskInfo(wrkMast.getWrkNo(), |
| | | "批次:{} 当前严格执行窗口序号为[{}-{}],当前序号={},暂不允许堆垛机出库", |
| | | wrkMast.getBatch(), |
| | | windowStartSeq, |
| | | windowEndSeq, |
| | | wrkMast.getBatchSeq()); |
| | | if (logBlockedReason) { |
| | | List<Integer> windowBatchSeqList = unfinishedBatchWrkMasts.stream() |
| | | .limit(Math.min(batchRunningLimit, unfinishedBatchWrkMasts.size())) |
| | | .map(WrkMast::getBatchSeq) |
| | | .collect(java.util.stream.Collectors.toList()); |
| | | News.taskInfo(wrkMast.getWrkNo(), |
| | | "批次:{} 当前严格执行窗口序号列表为{},当前序号={},暂不允许堆垛机出库", |
| | | wrkMast.getBatch(), |
| | | windowBatchSeqList, |
| | | wrkMast.getBatchSeq()); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | |
| | | WrkStsType.COMPLETE_OUTBOUND.sts, |
| | | WrkStsType.SETTLE_OUTBOUND.sts)); |
| | | if (batchRunningCount >= batchRunningLimit) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "批次:{} 执行中任务数达到上限,当前={},上限={}", wrkMast.getBatch(), batchRunningCount, batchRunningLimit); |
| | | if (logBlockedReason) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "批次:{} 执行中任务数达到上限,当前={},上限={}", wrkMast.getBatch(), batchRunningCount, batchRunningLimit); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | |
| | | |
| | | //调度堆垛机移动 |
| | | public synchronized boolean dispatchCrnMove(Integer crnNo, String targetLocNo) { |
| | | return dispatchCrnMove(crnNo, targetLocNo, false); |
| | | } |
| | | |
| | | public synchronized boolean dispatchCrnMove(Integer crnNo, String targetLocNo, boolean allowQueueWhenBusy) { |
| | | if (crnNo == null || Cools.isEmpty(targetLocNo)) { |
| | | return false; |
| | | } |
| | |
| | | return false; |
| | | } |
| | | |
| | | long runningCount = wrkMastService.count(new QueryWrapper<WrkMast>() |
| | | .eq("crn_no", crnNo) |
| | | .in("wrk_sts", |
| | | WrkStsType.INBOUND_RUN.sts, |
| | | WrkStsType.OUTBOUND_RUN.sts, |
| | | WrkStsType.LOC_MOVE_RUN.sts, |
| | | WrkStsType.CRN_MOVE_RUN.sts)); |
| | | if (runningCount > 0) { |
| | | News.info("堆垛机:{} 存在执行中的任务,暂不生成移动任务", crnNo); |
| | | return false; |
| | | if (!allowQueueWhenBusy) { |
| | | long runningCount = wrkMastService.count(new QueryWrapper<WrkMast>() |
| | | .eq("crn_no", crnNo) |
| | | .in("wrk_sts", |
| | | WrkStsType.INBOUND_RUN.sts, |
| | | WrkStsType.OUTBOUND_RUN.sts, |
| | | WrkStsType.LOC_MOVE_RUN.sts, |
| | | WrkStsType.CRN_MOVE_RUN.sts)); |
| | | if (runningCount > 0) { |
| | | News.info("堆垛机:{} 存在执行中的任务,暂不生成移动任务", crnNo); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | WrkMast activeTask = wrkMastService.getOne(new QueryWrapper<WrkMast>() |