1
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package com.ruoyi.jarvis.domain.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 快捷录单:型号后缀店铺选项(前缀拼接到型号末尾,如 W5000PLUS2.0白 + 海尔厨房)
|
||||
*/
|
||||
@Data
|
||||
public class QuickRecordModelShopOption {
|
||||
|
||||
/** 拼接到型号末尾的短前缀,如 海尔官旗 */
|
||||
private String prefix;
|
||||
|
||||
/** 括号内完整店铺名,如 海尔官方旗舰店 */
|
||||
private String fullName;
|
||||
|
||||
/** 展示文案,如 海尔官旗(海尔官方旗舰店) */
|
||||
private String label;
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.ruoyi.jarvis.util;
|
||||
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.jarvis.domain.dto.QuickRecordModelShopOption;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 解析快捷录单型号店铺配置:每行/逗号分隔,格式「短前缀(完整店名)」。
|
||||
*/
|
||||
public final class QuickRecordModelShopOptionUtil {
|
||||
|
||||
public static final String CONFIG_KEY = "quickRecord.modelShopOptions";
|
||||
|
||||
private static final Pattern LINE_PATTERN = Pattern.compile("^(.+?)[((](.+)[))]$");
|
||||
|
||||
private QuickRecordModelShopOptionUtil() {
|
||||
}
|
||||
|
||||
public static List<QuickRecordModelShopOption> parseOptions(String raw) {
|
||||
if (StringUtils.isEmpty(raw)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
String[] parts = raw.split("[\\r\\n,,]+");
|
||||
List<QuickRecordModelShopOption> list = new ArrayList<>();
|
||||
for (String part : parts) {
|
||||
if (StringUtils.isEmpty(part)) {
|
||||
continue;
|
||||
}
|
||||
QuickRecordModelShopOption opt = parseOneLine(part.trim());
|
||||
if (opt != null && StringUtils.isNotEmpty(opt.getPrefix())) {
|
||||
list.add(opt);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private static QuickRecordModelShopOption parseOneLine(String line) {
|
||||
if (StringUtils.isEmpty(line)) {
|
||||
return null;
|
||||
}
|
||||
Matcher m = LINE_PATTERN.matcher(line);
|
||||
QuickRecordModelShopOption opt = new QuickRecordModelShopOption();
|
||||
if (m.matches()) {
|
||||
opt.setPrefix(m.group(1).trim());
|
||||
opt.setFullName(m.group(2).trim());
|
||||
} else {
|
||||
opt.setPrefix(line.trim());
|
||||
opt.setFullName("");
|
||||
}
|
||||
opt.setLabel(buildLabel(opt.getPrefix(), opt.getFullName()));
|
||||
return opt;
|
||||
}
|
||||
|
||||
private static String buildLabel(String prefix, String fullName) {
|
||||
if (StringUtils.isEmpty(fullName)) {
|
||||
return prefix;
|
||||
}
|
||||
return prefix + "(" + fullName + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* 从完整型号末尾匹配已知店铺前缀(长前缀优先),用于回显拆分。
|
||||
*/
|
||||
public static String[] splitModelSuffix(String fullModel, List<QuickRecordModelShopOption> options) {
|
||||
String full = StringUtils.trim(fullModel);
|
||||
if (StringUtils.isEmpty(full) || options == null || options.isEmpty()) {
|
||||
return new String[] { full, "" };
|
||||
}
|
||||
List<QuickRecordModelShopOption> sorted = new ArrayList<>(options);
|
||||
sorted.sort((a, b) -> {
|
||||
int la = a.getPrefix() != null ? a.getPrefix().length() : 0;
|
||||
int lb = b.getPrefix() != null ? b.getPrefix().length() : 0;
|
||||
return Integer.compare(lb, la);
|
||||
});
|
||||
for (QuickRecordModelShopOption opt : sorted) {
|
||||
String prefix = opt.getPrefix();
|
||||
if (StringUtils.isEmpty(prefix)) {
|
||||
continue;
|
||||
}
|
||||
if (full.endsWith(prefix) && full.length() > prefix.length()) {
|
||||
return new String[] { full.substring(0, full.length() - prefix.length()), prefix };
|
||||
}
|
||||
}
|
||||
return new String[] { full, "" };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user