| | |
| | | return value == null ? BigDecimal.ZERO : value; |
| | | } |
| | | |
| | | /** |
| | | * 批次号按前缀日期升序排序(格式如 20260703-ed01-001,日期早的在前) |
| | | */ |
| | | private void sortBatchNoList(List<String> batchNoList) { |
| | | if (batchNoList == null || batchNoList.size() < 2) { |
| | | return; |
| | | } |
| | | batchNoList.sort(Comparator |
| | | .comparingLong(this::batchDateKey) |
| | | .thenComparing(batchNo -> batchNo == null ? "" : batchNo)); |
| | | } |
| | | |
| | | /** |
| | | * 提取批次号开头的数字作为排序键(yyyyMMdd),无数字时放到最后 |
| | | */ |
| | | private long batchDateKey(String batchNo) { |
| | | if (batchNo == null) { |
| | | return Long.MAX_VALUE; |
| | | } |
| | | String trimmed = batchNo.trim(); |
| | | int end = 0; |
| | | while (end < trimmed.length() && Character.isDigit(trimmed.charAt(end))) { |
| | | end++; |
| | | } |
| | | if (end == 0) { |
| | | return Long.MAX_VALUE; |
| | | } |
| | | try { |
| | | return Long.parseLong(trimmed.substring(0, end)); |
| | | } catch (NumberFormatException e) { |
| | | return Long.MAX_VALUE; |
| | | } |
| | | } |
| | | |
| | | private void validateAndFillOrder(ProductionOrder productionOrder, ProductionOrder oldOrder) { |
| | | // 校验订单参数并补齐默认值 |
| | | if (productionOrder == null) { |
| | |
| | | List<String> batchNoList = stockBatchNoMap.get(productModelId) == null |
| | | ? Collections.emptyList() |
| | | : new ArrayList<>(stockBatchNoMap.get(productModelId)); |
| | | sortBatchNoList(batchNoList); |
| | | vo.setBatchNoList(batchNoList); |
| | | vo.setStockQuantity(stockQuantityMap.getOrDefault(productModelId, BigDecimal.ZERO)); |
| | | vo.setBom(true); |