优化
This commit is contained in:
+22
-4
@@ -11,6 +11,9 @@ import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@Component
|
||||
public class LastlegOrderNoGenerator {
|
||||
@@ -32,12 +35,31 @@ public class LastlegOrderNoGenerator {
|
||||
}
|
||||
|
||||
public String next(String businessType, String warehouse, long uniqueId) {
|
||||
String code = businessType == null ? "" : businessType.trim().toUpperCase(Locale.ROOT);
|
||||
String returnPrefix = switch (code) {
|
||||
case "RETURN" -> "RT";
|
||||
case "RETURN_RECEIPT" -> "RR";
|
||||
case "RETURN_BATCH" -> "RB";
|
||||
case "RETURN_CARTON" -> "RC";
|
||||
case "RETURN_RELABEL" -> "RETU";
|
||||
default -> null;
|
||||
};
|
||||
// Return numbers are independent business identifiers, not truncated database IDs.
|
||||
// Keep every UUID bit; the longest result (RETU + 25 base-36 digits) fits VARCHAR(32).
|
||||
if (returnPrefix != null) return returnPrefix + "-" + encodeReturnUuid(UUID.randomUUID());
|
||||
String type = normalizeType(businessType);
|
||||
return type + "-" + warehouseCode(warehouse) + "-"
|
||||
+ LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE) + "-"
|
||||
+ String.format(Locale.ROOT, "%06d", Math.floorMod(uniqueId, 1_000_000));
|
||||
}
|
||||
|
||||
static String encodeReturnUuid(UUID uuid) {
|
||||
byte[] bytes = ByteBuffer.allocate(16).putLong(uuid.getMostSignificantBits())
|
||||
.putLong(uuid.getLeastSignificantBits()).array();
|
||||
String encoded = new BigInteger(1, bytes).toString(36).toUpperCase(Locale.ROOT);
|
||||
return "0".repeat(25 - encoded.length()) + encoded;
|
||||
}
|
||||
|
||||
private String normalizeType(String value) {
|
||||
String code = value == null ? "LMO" : value.trim().toUpperCase(Locale.ROOT);
|
||||
return switch (code) {
|
||||
@@ -54,10 +76,6 @@ public class LastlegOrderNoGenerator {
|
||||
case "DISCARD" -> "CD";
|
||||
case "PROCUREMENT" -> "PR";
|
||||
case "INBOUND_PLAN" -> "IP";
|
||||
case "RETURN" -> "RT";
|
||||
case "RETURN_RECEIPT" -> "RR";
|
||||
case "RETURN_BATCH" -> "RB";
|
||||
case "RETURN_CARTON" -> "RC";
|
||||
default -> {
|
||||
String normalized = code.replaceAll("[^A-Z0-9]", "");
|
||||
yield normalized.isEmpty() ? "LMO" : normalized.substring(0, Math.min(4, normalized.length()));
|
||||
|
||||
@@ -1421,7 +1421,7 @@ paths:
|
||||
responses: { '200': { description: 当前客户退货订单分页 } }
|
||||
post:
|
||||
summary: 客户创建退货预报订单
|
||||
description: 客户只预报不重复的 SKU 和预计数量,不要求提前知道快递单号;仓库 PDA 实收数量才是实际入库事实。
|
||||
description: 客户只预报不重复的 SKU 和预计数量,不要求提前知道快递单号;仓库 PDA 实收数量才是实际入库事实。系统退货编号由业务前缀和25位大写Base36完整随机UUID编码组成,退货单RT、签收单RR、批次RB、箱唛RC及退货主单RETU均独立生成,不编码内部ID、仓库或日期。幂等重放返回已保存的编号,不重新生成。
|
||||
security: [{ bearerAuth: [] }]
|
||||
requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/ReturnOrderCreate' } } } }
|
||||
responses: { '200': { description: 创建后的退货订单详情 }, '409': { description: 幂等键冲突 } }
|
||||
|
||||
Reference in New Issue
Block a user