| | |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.asrs.task.core.ReturnT; |
| | | import com.zy.asrs.task.handler.WorkMastHandler; |
| | | import com.zy.asrs.task.support.OutboundBatchSeqReleaseGuard; |
| | | import com.zy.asrs.utils.Utils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private WorkMastHandler workMastHandler; |
| | | @Autowired |
| | | private OutboundBatchSeqReleaseGuard outboundBatchSeqReleaseGuard; |
| | | |
| | | @Scheduled(cron = "0/3 * * * * ? ") |
| | | private void execute(){ |
| | |
| | | continue; |
| | | } |
| | | |
| | | WorkTaskParams params = buildWorkTaskParams(wrkMast); |
| | | if (isOutboundPublishTask(wrkMast)) { |
| | | if (Cools.isEmpty(wrkMast.getBatchSeq())) { |
| | | log.warn("出库进仓编号(batchSeq)为空,跳过下发, wrkNo={}, userNo={}", |
| | | wrkMast.getWrkNo(), wrkMast.getUserNo()); |
| | | continue; |
| | | } |
| | | WorkTaskParams params = buildWorkTaskParams(wrkMast); |
| | | String userNo = normalizeGroupKey(wrkMast.getUserNo()); |
| | | String batchSeq = normalizeGroupKey(wrkMast.getBatchSeq()); |
| | | outboundTasksByUserNo |
| | |
| | | .computeIfAbsent(batchSeq, key -> new ArrayList<>()) |
| | | .add(params); |
| | | } else { |
| | | paramsList.add(params); |
| | | paramsList.add(buildWorkTaskParams(wrkMast)); |
| | | } |
| | | } |
| | | |
| | |
| | | batchSeqs.sort(this::compareBatchSeqNatural); |
| | | |
| | | for (String batchSeq : batchSeqs) { |
| | | String blockingBatchSeq = findFirstUnfinishedOutboundBatchSeq(userNo); |
| | | if (!Objects.equals(batchSeq, blockingBatchSeq)) { |
| | | log.info("出库批次未完成,暂停后续下发, userNo={}, blockingBatchSeq={}, nextBatchSeq={}", |
| | | userNo, blockingBatchSeq, batchSeq); |
| | | String blockMsg = outboundBatchSeqReleaseGuard.validateReady(userNo, batchSeq); |
| | | if (!Cools.isEmpty(blockMsg)) { |
| | | log.info(blockMsg); |
| | | break; |
| | | } |
| | | |
| | |
| | | .setTaskPri(wrkMast.getIoPri().intValue()) |
| | | .setBarcode(wrkMast.getBarcode()); |
| | | if (wrkMast.getPltType() != null && wrkMast.getPltType() > 0) { |
| | | params.setBatch(wrkMast.getUserNo()) |
| | | params.setBatch(wrkMast.getBatchSeq()) |
| | | .setBatchSeq(wrkMast.getPltType()); |
| | | } |
| | | // 2: 入库。入库接口使用 sourceStaNo + 目标库位。 |
| | |
| | | return wrkMast != null && Objects.equals(wrkMast.getIoType(), 101); |
| | | } |
| | | |
| | | private String findFirstUnfinishedOutboundBatchSeq(String userNo) { |
| | | EntityWrapper<WrkMast> wrapper = new EntityWrapper<>(); |
| | | if (Cools.isEmpty(userNo)) { |
| | | wrapper.isNull("user_no"); |
| | | } else { |
| | | wrapper.eq("user_no", userNo); |
| | | } |
| | | wrapper.eq("io_type", 101); |
| | | wrapper.lt("wrk_sts", 14); |
| | | List<WrkMast> rows = wrkMastService.selectList(wrapper); |
| | | if (rows == null || rows.isEmpty()) { |
| | | return null; |
| | | } |
| | | String firstBatchSeq = null; |
| | | for (WrkMast row : rows) { |
| | | String batchSeq = normalizeGroupKey(row.getBatchSeq()); |
| | | if (firstBatchSeq == null || compareBatchSeqNatural(batchSeq, firstBatchSeq) < 0) { |
| | | firstBatchSeq = batchSeq; |
| | | } |
| | | } |
| | | return firstBatchSeq; |
| | | } |
| | | |
| | | private int compareBatchSeqNatural(String left, String right) { |
| | | String safeLeft = Cools.isEmpty(left) ? "" : left; |
| | | String safeRight = Cools.isEmpty(right) ? "" : right; |
| | | boolean leftNumeric = isDigits(safeLeft); |
| | | boolean rightNumeric = isDigits(safeRight); |
| | | if (leftNumeric && rightNumeric) { |
| | | BigInteger leftValue = new BigInteger(safeLeft); |
| | | BigInteger rightValue = new BigInteger(safeRight); |
| | | int compare = leftValue.compareTo(rightValue); |
| | | int leftIndex = 0; |
| | | int rightIndex = 0; |
| | | while (leftIndex < safeLeft.length() && rightIndex < safeRight.length()) { |
| | | char leftChar = safeLeft.charAt(leftIndex); |
| | | char rightChar = safeRight.charAt(rightIndex); |
| | | if (Character.isDigit(leftChar) && Character.isDigit(rightChar)) { |
| | | int leftStart = leftIndex; |
| | | int rightStart = rightIndex; |
| | | while (leftIndex < safeLeft.length() && Character.isDigit(safeLeft.charAt(leftIndex))) { |
| | | leftIndex++; |
| | | } |
| | | while (rightIndex < safeRight.length() && Character.isDigit(safeRight.charAt(rightIndex))) { |
| | | rightIndex++; |
| | | } |
| | | String leftNumber = safeLeft.substring(leftStart, leftIndex); |
| | | String rightNumber = safeRight.substring(rightStart, rightIndex); |
| | | int compare = new BigInteger(leftNumber).compareTo(new BigInteger(rightNumber)); |
| | | if (compare != 0) { |
| | | return compare; |
| | | } |
| | | compare = Integer.compare(leftNumber.length(), rightNumber.length()); |
| | | if (compare != 0) { |
| | | return compare; |
| | | } |
| | | continue; |
| | | } |
| | | int compare = Character.compare(leftChar, rightChar); |
| | | if (compare != 0) { |
| | | return compare; |
| | | } |
| | | leftIndex++; |
| | | rightIndex++; |
| | | } |
| | | return safeLeft.compareTo(safeRight); |
| | | } |
| | | |
| | | private boolean isDigits(String value) { |
| | | if (Cools.isEmpty(value)) { |
| | | return false; |
| | | } |
| | | for (int i = 0; i < value.length(); i++) { |
| | | if (!Character.isDigit(value.charAt(i))) { |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | return Integer.compare(safeLeft.length(), safeRight.length()); |
| | | } |
| | | |
| | | private String normalizeGroupKey(String value) { |