| | |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.BigInteger; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | |
| | | List<String> failMsgs = new ArrayList<>(); |
| | | List<WorkTaskParams> lastSentChunk = null; |
| | | String skipGroupKey = null; |
| | | Set<String> blockedOutboundUserKeys = new HashSet<>(); |
| | | |
| | | for (List<WorkTaskParams> chunk : chunks) { |
| | | if (chunk == null || chunk.isEmpty()) { |
| | |
| | | WorkTaskParams head = chunk.get(0); |
| | | WrkMast headMast = wrkMastMap.get(head.getTaskNo()); |
| | | String key = buildBatchGroupKey(head, headMast); |
| | | String outboundUserKey = buildOutboundUserKey(head, headMast); |
| | | |
| | | if (skipGroupKey != null && skipGroupKey.equals(key)) { |
| | | continue; |
| | | } |
| | | if (outboundUserKey != null && blockedOutboundUserKeys.contains(outboundUserKey)) { |
| | | continue; |
| | | } |
| | | |
| | | String batchBlockMsg = validateOutboundBatchSeqReady(chunk, wrkMastMap); |
| | | if (!Cools.isEmpty(batchBlockMsg)) { |
| | | skipMsgs.add(batchBlockMsg); |
| | | skipGroupKey = key; |
| | | if (outboundUserKey != null) { |
| | | blockedOutboundUserKeys.add(outboundUserKey); |
| | | } |
| | | continue; |
| | | } |
| | | |
| | |
| | | return outboundPltSlotReleasedInWms(userNo, batchGroup, minPlt - 1); |
| | | } |
| | | |
| | | private String validateOutboundBatchSeqReady(List<WorkTaskParams> chunk, Map<String, WrkMast> wrkMastMap) { |
| | | if (chunk == null || chunk.isEmpty()) { |
| | | return null; |
| | | } |
| | | WorkTaskParams head = chunk.get(0); |
| | | if (!"out".equalsIgnoreCase(head.getType())) { |
| | | return null; |
| | | } |
| | | WrkMast headMast = wrkMastMap.get(head.getTaskNo()); |
| | | String userNo = sortUserNoForPub(head, headMast); |
| | | if (Cools.isEmpty(userNo)) { |
| | | return null; |
| | | } |
| | | String batchSeq = sortBatchGroupForPub(head, headMast); |
| | | String blockingBatchSeq = findFirstUnfinishedOutboundBatchSeq(userNo); |
| | | if (blockingBatchSeq == null || compareBatchSeqNatural(batchSeq, blockingBatchSeq) == 0) { |
| | | return null; |
| | | } |
| | | return "出库批次未完成,暂停后续下发, userNo=" + userNo |
| | | + ", blockingBatchSeq=" + normalizeBatchSeq(blockingBatchSeq) |
| | | + ", nextBatchSeq=" + normalizeBatchSeq(batchSeq); |
| | | } |
| | | |
| | | 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.last(" and (wrk_sts < 14 or wrk_sts in (" |
| | | + OUT_LOCK_REPORT_SUCCESS_WRK_STS + "," + OUT_LOCK_REPORT_FAIL_WRK_STS + "))"); |
| | | List<WrkMast> rows = wrkMastService.selectList(wrapper); |
| | | if (rows == null || rows.isEmpty()) { |
| | | return null; |
| | | } |
| | | String firstBatchSeq = null; |
| | | for (WrkMast row : rows) { |
| | | if (row == null) { |
| | | continue; |
| | | } |
| | | String batchSeq = sortBatchGroupForPub(null, row); |
| | | if (firstBatchSeq == null || compareBatchSeqNatural(batchSeq, firstBatchSeq) < 0) { |
| | | firstBatchSeq = batchSeq; |
| | | } |
| | | } |
| | | return firstBatchSeq; |
| | | } |
| | | |
| | | private boolean outboundPltSlotReleasedInWms(String userNo, String batchSeq, int pltType) { |
| | | EntityWrapper<WrkMast> mastWrapper = new EntityWrapper<>(); |
| | | mastWrapper.eq("user_no", userNo); |
| | |
| | | return Comparator |
| | | .comparing((WorkTaskParams p) -> Optional.ofNullable(p.getType()).orElse(""), String.CASE_INSENSITIVE_ORDER) |
| | | .thenComparing(p -> sortUserNoForPub(p, wrkMastMap.get(p.getTaskNo())), Comparator.nullsLast(String::compareTo)) |
| | | .thenComparing(p -> sortBatchGroupForPub(p, wrkMastMap.get(p.getTaskNo())), Comparator.nullsLast(String::compareTo)) |
| | | .thenComparing(p -> sortBatchGroupForPub(p, wrkMastMap.get(p.getTaskNo())), WcsApiServiceImpl::compareBatchSeqNatural) |
| | | .thenComparing(p -> sortPltForPub(p, wrkMastMap.get(p.getTaskNo())), Comparator.nullsLast(Integer::compareTo)); |
| | | } |
| | | |
| | |
| | | return wrkMast.getBatchSeq(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private static String buildOutboundUserKey(WorkTaskParams params, WrkMast wrkMast) { |
| | | if (params == null || !"out".equalsIgnoreCase(params.getType())) { |
| | | return null; |
| | | } |
| | | String userNo = sortUserNoForPub(params, wrkMast); |
| | | if (Cools.isEmpty(userNo)) { |
| | | return null; |
| | | } |
| | | return resolveSafeKey(userNo); |
| | | } |
| | | |
| | | private static int compareBatchSeqNatural(String left, String right) { |
| | | String safeLeft = normalizeBatchSeq(left); |
| | | String safeRight = normalizeBatchSeq(right); |
| | | 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 Integer.compare(safeLeft.length(), safeRight.length()); |
| | | } |
| | | |
| | | private static String normalizeBatchSeq(String value) { |
| | | return Cools.isEmpty(value) ? "" : value; |
| | | } |
| | | |
| | | private static String resolveSafeKey(String value) { |
| | | return Cools.isEmpty(value) ? "_EMPTY_" : value; |
| | | } |
| | | |
| | | private static String buildOutboundBatchCacheKey(String userNo, String batchSeq) { |
| | |
| | | //wcs任务取消接口 |
| | | } else if (params.getMsgType().equals("task_cancel")) { |
| | | workService.cancelWrkMast(String.valueOf(mast.getWrkNo()), 9955L); |
| | | } else if (params.getMsgType().equals("task_arrive")) { |
| | | //到达目的地 |
| | | //如果出库任务是跨区则需要生成新的入库任务入库 |
| | | if(!Cools.isEmpty(mast.getLocNo())){ |
| | | mast.setOnlineYn("N");//等待生成跨区入库任务 |
| | | } |
| | | mast.setWrkSts(14L); |
| | | if(Cools.isEmpty(mast.getStaNo())){ |
| | | mast.setOveMk("Y"); |
| | | } |
| | | mast.setModiTime(new Date()); |
| | | if (!wrkMastService.updateById(mast)) { |
| | | throw new CoolException("任务状态修改失败!!"); |
| | | } |
| | | } |
| | | } else if (params.getNotifyType().equals("weight")) { |
| | | |
| | | } |
| | | return R.ok(); |
| | | } |