Browse Source

2026-07-07

创建箱号不限制三位流水
master
fengyuan_yang 4 weeks ago
parent
commit
713a1cb4d4
  1. 19
      src/main/java/com/gaotao/modules/boxManage/service/impl/BoxForNotificationServiceImpl.java

19
src/main/java/com/gaotao/modules/boxManage/service/impl/BoxForNotificationServiceImpl.java

@ -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后继续10001001...
* 例如已有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);
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);
}

Loading…
Cancel
Save