|
|
|
@ -51,7 +51,7 @@ public class BoxForNotificationServiceImpl implements BoxForNotificationService |
|
|
|
|
|
|
|
@Override |
|
|
|
public String newSoReceiveBoxesData(SoReceiveBoxesData inData){ |
|
|
|
// 生成箱号:销售订单号 + 三位流水号,支持断号取号 |
|
|
|
// 生成箱号:销售订单号 + 流水号(最少三位),支持断号取号 |
|
|
|
String saleOrderNo = inData.getSaleOrderNo(); |
|
|
|
if (saleOrderNo == null || saleOrderNo.isEmpty()) { |
|
|
|
throw new RuntimeException("销售订单号不能为空!"); |
|
|
|
@ -70,7 +70,7 @@ public class BoxForNotificationServiceImpl implements BoxForNotificationService |
|
|
|
|
|
|
|
/** |
|
|
|
* 生成箱号,支持断号取号 |
|
|
|
* 格式:订单号 + 三位流水号(001-999) |
|
|
|
* 格式:订单号 + 流水号(最少三位,001开始,超过999后继续1000、1001...) |
|
|
|
* 例如:已有AAA001和AAA003,下次生成AAA002 |
|
|
|
*/ |
|
|
|
private String generateBoxNoWithGapFilling(String orderNo, List<String> existingBoxNos) { |
|
|
|
@ -79,11 +79,16 @@ public class BoxForNotificationServiceImpl implements BoxForNotificationService |
|
|
|
String prefix = orderNo; |
|
|
|
|
|
|
|
for (String boxNo : existingBoxNos) { |
|
|
|
if (boxNo != null && boxNo.startsWith(prefix) && boxNo.length() == prefix.length() + 3) { |
|
|
|
if (boxNo != null && boxNo.startsWith(prefix) && boxNo.length() > prefix.length()) { |
|
|
|
try { |
|
|
|
String seqStr = boxNo.substring(prefix.length()); |
|
|
|
if (!seqStr.chars().allMatch(Character::isDigit)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
int seqNo = Integer.parseInt(seqStr); |
|
|
|
usedSeqNos.add(seqNo); |
|
|
|
if (seqNo > 0) { |
|
|
|
usedSeqNos.add(seqNo); |
|
|
|
} |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
// 忽略非数字后缀的箱号 |
|
|
|
} |
|
|
|
@ -92,15 +97,11 @@ public class BoxForNotificationServiceImpl implements BoxForNotificationService |
|
|
|
|
|
|
|
// 找到第一个未使用的流水号(断号取号) |
|
|
|
int newSeqNo = 1; |
|
|
|
while (usedSeqNos.contains(newSeqNo) && newSeqNo <= 999) { |
|
|
|
while (usedSeqNos.contains(newSeqNo)) { |
|
|
|
newSeqNo++; |
|
|
|
} |
|
|
|
|
|
|
|
if (newSeqNo > 999) { |
|
|
|
throw new RuntimeException("箱号流水号已达到上限999,无法继续生成!"); |
|
|
|
} |
|
|
|
|
|
|
|
// 生成三位流水号 |
|
|
|
// 生成流水号(不足三位补零,超过三位按实际位数输出) |
|
|
|
return prefix + String.format("%03d", newSeqNo); |
|
|
|
} |
|
|
|
|
|
|
|
|