Merge branch 'dev' into test

This commit is contained in:
chenbowen
2025-12-14 22:15:41 +08:00

View File

@@ -186,23 +186,39 @@ public class MasterDataCategorySyncServiceImpl implements MasterDataCategorySync
}
private String resolveParentCode(String code) {
if (code == null) {
String normalized = normalizeCode(code);
if (normalized == null) {
return null;
}
if (code.length() <= 2) {
String numericPart = extractNumericPart(normalized);
if (StrUtil.isBlank(numericPart) || numericPart.length() <= 2) {
return null;
}
if (code.length() <= 4) {
return code.substring(0, 2);
}
return code.substring(0, 4);
String prefix = normalized.substring(0, normalized.length() - numericPart.length());
String parentNumeric = numericPart.substring(0, numericPart.length() - 2);
return prefix + parentNumeric;
}
private long determineLevel(String code) {
if (code.length() <= 2) {
String normalized = normalizeCode(code);
if (normalized == null) {
return 1L;
}
if (code.length() <= 4) {
String numericPart = extractNumericPart(normalized);
if (StrUtil.isBlank(numericPart)) {
if (normalized.length() <= 2) {
return 1L;
}
if (normalized.length() <= 4) {
return 2L;
}
return 3L;
}
int len = numericPart.length();
if (len <= 2) {
return 1L;
}
if (len <= 4) {
return 2L;
}
return 3L;
@@ -211,4 +227,19 @@ public class MasterDataCategorySyncServiceImpl implements MasterDataCategorySync
private String normalizeCode(String code) {
return StrUtil.isBlank(code) ? null : StrUtil.trim(code);
}
/**
* 提取编码中连续的尾部数字部分,例如 ZT0103 -> 0103ZT010312 -> 010312
*/
private String extractNumericPart(String code) {
if (code == null) {
return null;
}
int idx = code.length();
while (idx > 0 && Character.isDigit(code.charAt(idx - 1))) {
idx--;
}
String numeric = code.substring(idx);
return StrUtil.isBlank(numeric) ? null : numeric;
}
}