优化
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()));
|
||||
|
||||
Reference in New Issue
Block a user