1
This commit is contained in:
@@ -76,8 +76,12 @@ public class InstructionServiceImpl implements IInstructionService {
|
|||||||
result = Collections.singletonList(handleTF(input));
|
result = Collections.singletonList(handleTF(input));
|
||||||
} else if (input.startsWith("H")) {
|
} else if (input.startsWith("H")) {
|
||||||
result = Collections.singletonList(handleH(input));
|
result = Collections.singletonList(handleH(input));
|
||||||
|
} else if (input.startsWith("W")) {
|
||||||
|
result = Collections.singletonList(handleW(input));
|
||||||
} else if (input.startsWith("生")) {
|
} else if (input.startsWith("生")) {
|
||||||
result = Collections.singletonList(handleSheng(input));
|
result = Collections.singletonList(handleSheng(input));
|
||||||
|
} else if (isPDDWCommand(input)) {
|
||||||
|
result = Collections.singletonList(handlePDDW(input));
|
||||||
} else if (input.equals("拼多多") || input.startsWith("拼多多\n") || input.startsWith("拼多多\r\n") || isPDDFormat(input)) {
|
} else if (input.equals("拼多多") || input.startsWith("拼多多\n") || input.startsWith("拼多多\r\n") || isPDDFormat(input)) {
|
||||||
result = Collections.singletonList(handlePDD(input));
|
result = Collections.singletonList(handlePDD(input));
|
||||||
} else if (input.startsWith("录单") || input.startsWith("慢单") || input.startsWith("慢搜") || input.startsWith("慢查") || input.startsWith("单")) {
|
} else if (input.startsWith("录单") || input.startsWith("慢单") || input.startsWith("慢搜") || input.startsWith("慢查") || input.startsWith("单")) {
|
||||||
@@ -749,8 +753,22 @@ private String handleTF(String input) {
|
|||||||
|
|
||||||
|
|
||||||
private String handleH(String input) {
|
private String handleH(String input) {
|
||||||
String[] lines = input.replaceFirst("^H", "").split("\n");
|
return handleHLike(input, "H", "H");
|
||||||
if (lines.length < 3) return "H 指令需三行:姓名[后缀]\n电话\n地址 … [后缀] 型号";
|
}
|
||||||
|
|
||||||
|
private String handleW(String input) {
|
||||||
|
return handleHLike(input, "W", "W");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String handleHLike(String input, String commandKeyword, String distributionMark) {
|
||||||
|
String cleaned = input.replaceFirst("^" + Pattern.quote(commandKeyword), "");
|
||||||
|
if (cleaned.startsWith("\n")) {
|
||||||
|
cleaned = cleaned.substring(1);
|
||||||
|
}
|
||||||
|
String[] lines = cleaned.split("\n");
|
||||||
|
if (lines.length < 3) {
|
||||||
|
return commandKeyword + " 指令需三行:姓名[后缀]\n电话\n地址 … [后缀] 型号";
|
||||||
|
}
|
||||||
|
|
||||||
String nameLine = lines[0].trim();
|
String nameLine = lines[0].trim();
|
||||||
String phone = lines[1].trim();
|
String phone = lines[1].trim();
|
||||||
@@ -764,7 +782,7 @@ private String handleTF(String input) {
|
|||||||
String fullAddress = cleanedAddress + " 安装派送联系" + phone + (suffix.isEmpty() ? "" : "转" + suffix);
|
String fullAddress = cleanedAddress + " 安装派送联系" + phone + (suffix.isEmpty() ? "" : "转" + suffix);
|
||||||
|
|
||||||
StringBuilder sheng = new StringBuilder();
|
StringBuilder sheng = new StringBuilder();
|
||||||
sheng.append("生\n").append("H\n").append(modelNumber).append("\n").append("\n") // 转链链接留空
|
sheng.append("生\n").append(distributionMark).append("\n").append(modelNumber).append("\n").append("\n") // 转链链接留空
|
||||||
.append("1\n").append(name).append(fullAddress);
|
.append("1\n").append(name).append(fullAddress);
|
||||||
return generateOrderText(sheng.toString());
|
return generateOrderText(sheng.toString());
|
||||||
}
|
}
|
||||||
@@ -805,34 +823,58 @@ private String handleTF(String input) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isPDDWCommand(String input) {
|
||||||
|
if (input == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String trimmed = input.trim();
|
||||||
|
if (trimmed.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return trimmed.equals("拼多多 W") || trimmed.equals("拼多多W")
|
||||||
|
|| trimmed.startsWith("拼多多 W") || trimmed.startsWith("拼多多W");
|
||||||
|
}
|
||||||
|
|
||||||
private String handlePDD(String input) {
|
private String handlePDD(String input) {
|
||||||
|
return handlePDDWithMark(input, "拼多多", "PDD");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String handlePDDW(String input) {
|
||||||
|
return handlePDDWithMark(input, "拼多多 W", "PDD-W");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String handlePDDWithMark(String input, String commandKeyword, String distributionMark) {
|
||||||
// 拼多多新格式:
|
// 拼多多新格式:
|
||||||
// 拼多多251102-457567158704072
|
// <指令>251102-457567158704072
|
||||||
// 赵政委[6947]
|
// 赵政委[6947]
|
||||||
// 17283248756
|
// 17283248756
|
||||||
// 安徽省 宿州市 埇桥区 映月湾东区3栋103[6947]
|
// 安徽省 宿州市 埇桥区 映月湾东区3栋103[6947]
|
||||||
// eb150
|
// eb150
|
||||||
|
//
|
||||||
// 旧格式兼容:
|
// 旧格式兼容:
|
||||||
// 🕒 林[1518]
|
// 🕒 林[1518]
|
||||||
// 17284023487
|
// 17284023487
|
||||||
// 广西壮族自治区 柳州市 柳北区 绿城·杨柳郡柳园7栋[1518]
|
// 广西壮族自治区 柳州市 柳北区 绿城·杨柳郡柳园7栋[1518]
|
||||||
// eb150
|
// eb150
|
||||||
|
|
||||||
// 如果输入只是"拼多多",返回提示信息
|
if (input == null || input.trim().isEmpty()) {
|
||||||
if (input.equals("拼多多") || input.trim().equals("拼多多")) {
|
return buildPddHelpMessage(commandKeyword);
|
||||||
return "请粘贴拼多多格式数据:\n新格式(推荐):\n拼多多251102-457567158704072\n赵政委[6947]\n17283248756\n安徽省 宿州市 埇桥区 映月湾东区3栋103[6947]\neb150\n\n旧格式(兼容):\n🕒 林[1518]\n17284023487\n广西壮族自治区 柳州市 柳北区 绿城·杨柳郡柳园7栋[1518]\neb150";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] lines = input.split("\r?\n");
|
String trimmedOriginal = input.trim();
|
||||||
|
if (trimmedOriginal.equals(commandKeyword)) {
|
||||||
|
return buildPddHelpMessage(commandKeyword);
|
||||||
|
}
|
||||||
|
|
||||||
|
String normalizedInput = normalizePddInput(input, commandKeyword);
|
||||||
|
String[] lines = normalizedInput.split("\r?\n");
|
||||||
String thirdPartyOrderNo = null;
|
String thirdPartyOrderNo = null;
|
||||||
int nameLineIndex = 0;
|
int nameLineIndex = 0;
|
||||||
boolean isNewFormat = false;
|
boolean isNewFormat = false;
|
||||||
|
|
||||||
// 检查是否是新格式(第一行包含"拼多多")
|
|
||||||
if (lines.length > 0) {
|
if (lines.length > 0) {
|
||||||
String firstLine = lines[0].trim();
|
String firstLine = lines[0].trim();
|
||||||
|
|
||||||
// 格式1:拼多多数字-数字(一行格式,如:拼多多251102-457567158704072)
|
// 格式1:拼多多数字-数字(一行格式,如:拼多多251102-457567158704072)
|
||||||
Pattern orderNoPattern = Pattern.compile("拼多多(\\d+-\\d+)");
|
Pattern orderNoPattern = Pattern.compile("拼多多(\\d+-\\d+)");
|
||||||
Matcher matcher = orderNoPattern.matcher(firstLine);
|
Matcher matcher = orderNoPattern.matcher(firstLine);
|
||||||
@@ -840,7 +882,7 @@ private String handleTF(String input) {
|
|||||||
thirdPartyOrderNo = matcher.group(1); // 提取订单号部分(不含"拼多多")
|
thirdPartyOrderNo = matcher.group(1); // 提取订单号部分(不含"拼多多")
|
||||||
isNewFormat = true;
|
isNewFormat = true;
|
||||||
nameLineIndex = 1; // 新格式下,姓名在第二行
|
nameLineIndex = 1; // 新格式下,姓名在第二行
|
||||||
}
|
}
|
||||||
// 格式2:第一行是"拼多多",第二行是订单号(多行格式)
|
// 格式2:第一行是"拼多多",第二行是订单号(多行格式)
|
||||||
else if (firstLine.equals("拼多多") && lines.length > 1) {
|
else if (firstLine.equals("拼多多") && lines.length > 1) {
|
||||||
String secondLine = lines.length > 1 ? lines[1].trim() : "";
|
String secondLine = lines.length > 1 ? lines[1].trim() : "";
|
||||||
@@ -853,30 +895,31 @@ private String handleTF(String input) {
|
|||||||
nameLineIndex = 2; // 多行格式下,姓名在第三行
|
nameLineIndex = 2; // 多行格式下,姓名在第三行
|
||||||
} else {
|
} else {
|
||||||
// 旧格式:移除"拼多多"前缀(如果有)
|
// 旧格式:移除"拼多多"前缀(如果有)
|
||||||
String data = input.replaceFirst("^拼多多\\s*[\r\n]+", "").trim();
|
String data = normalizedInput.replaceFirst("^拼多多\\s*[\r\n]+", "").trim();
|
||||||
lines = data.split("\r?\n");
|
lines = data.split("\r?\n");
|
||||||
nameLineIndex = 0;
|
nameLineIndex = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 旧格式:移除"拼多多"前缀(如果有)
|
// 旧格式:移除"拼多多"前缀(如果有)
|
||||||
String data = input.replaceFirst("^拼多多\\s*[\r\n]+", "").trim();
|
String data = normalizedInput.replaceFirst("^拼多多\\s*[\r\n]+", "").trim();
|
||||||
lines = data.split("\r?\n");
|
lines = data.split("\r?\n");
|
||||||
nameLineIndex = 0;
|
nameLineIndex = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查行数
|
// 检查行数
|
||||||
// 如果第三方单号在第二行(多行格式),需要6行;如果在第一行(一行格式),需要5行
|
// 如果第三方单号在第二行(多行格式),需要6行;如果在第一行(一行格式),需要5行
|
||||||
int requiredLines = isNewFormat ? (nameLineIndex == 2 ? 6 : 5) : 4;
|
int requiredLines = isNewFormat ? (nameLineIndex == 2 ? 6 : 5) : 4;
|
||||||
if (lines.length < requiredLines) {
|
if (lines.length < requiredLines) {
|
||||||
String formatDesc = isNewFormat ?
|
String commandLabel = commandKeyword.trim();
|
||||||
(nameLineIndex == 2 ?
|
String formatDesc = isNewFormat ?
|
||||||
"\n1. 拼多多\n2. 订单号\n3. 姓名[编号]\n4. 电话\n5. 地址[编号]\n6. 型号" :
|
(nameLineIndex == 2 ?
|
||||||
"\n1. 拼多多订单号\n2. 姓名[编号]\n3. 电话\n4. 地址[编号]\n5. 型号") :
|
"\n1. " + commandLabel + "\n2. 订单号\n3. 姓名[编号]\n4. 电话\n5. 地址[编号]\n6. 型号" :
|
||||||
|
"\n1. " + commandLabel + " 订单号\n2. 姓名[编号]\n3. 电话\n4. 地址[编号]\n5. 型号") :
|
||||||
"\n1. 🕒 姓名[编号]\n2. 电话\n3. 地址[编号]\n4. 型号";
|
"\n1. 🕒 姓名[编号]\n2. 电话\n3. 地址[编号]\n4. 型号";
|
||||||
return "拼多多格式错误,需要" + requiredLines + "行数据:" + formatDesc;
|
return commandLabel + " 格式错误,需要" + requiredLines + "行数据:" + formatDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析姓名行
|
// 解析姓名行
|
||||||
String nameLine = lines[nameLineIndex].trim();
|
String nameLine = lines[nameLineIndex].trim();
|
||||||
// 移除emoji和特殊字符,提取中文姓名
|
// 移除emoji和特殊字符,提取中文姓名
|
||||||
@@ -890,23 +933,23 @@ private String handleTF(String input) {
|
|||||||
}
|
}
|
||||||
// 提取编号(如果有)
|
// 提取编号(如果有)
|
||||||
String suffix = extractBetweenBrackets(nameLine);
|
String suffix = extractBetweenBrackets(nameLine);
|
||||||
|
|
||||||
// 解析电话行
|
// 解析电话行
|
||||||
int phoneLineIndex = nameLineIndex + 1;
|
int phoneLineIndex = nameLineIndex + 1;
|
||||||
String phone = lines[phoneLineIndex].trim();
|
String phone = lines[phoneLineIndex].trim();
|
||||||
|
|
||||||
// 解析地址行
|
// 解析地址行
|
||||||
int addressLineIndex = nameLineIndex + 2;
|
int addressLineIndex = nameLineIndex + 2;
|
||||||
String addressLine = lines[addressLineIndex].trim();
|
String addressLine = lines[addressLineIndex].trim();
|
||||||
// 移除编号括号和其中的内容
|
// 移除编号括号和其中的内容
|
||||||
String address = addressLine.replaceAll("\\[.*?]", "").trim();
|
String address = addressLine.replaceAll("\\[.*?]", "").trim();
|
||||||
|
|
||||||
// 解析型号行
|
// 解析型号行
|
||||||
int modelLineIndex = nameLineIndex + 3;
|
int modelLineIndex = nameLineIndex + 3;
|
||||||
String modelNumber = lines[modelLineIndex].trim();
|
String modelNumber = lines[modelLineIndex].trim();
|
||||||
// 清洗型号
|
// 清洗型号
|
||||||
modelNumber = sanitizeModel(modelNumber);
|
modelNumber = sanitizeModel(modelNumber);
|
||||||
|
|
||||||
// 构建完整地址:姓名 + 固定号码(13068923963) + 地址 + 原始电话 + 转 + 编号
|
// 构建完整地址:姓名 + 固定号码(13068923963) + 地址 + 原始电话 + 转 + 编号
|
||||||
// 格式:赵政委 13068923963 安徽省 宿州市 埇桥区 映月湾东区3栋103 17283248756转6947
|
// 格式:赵政委 13068923963 安徽省 宿州市 埇桥区 映月湾东区3栋103 17283248756转6947
|
||||||
StringBuilder fullAddress = new StringBuilder();
|
StringBuilder fullAddress = new StringBuilder();
|
||||||
@@ -926,17 +969,14 @@ private String handleTF(String input) {
|
|||||||
if (!suffix.isEmpty()) {
|
if (!suffix.isEmpty()) {
|
||||||
fullAddress.append("转").append(suffix);
|
fullAddress.append("转").append(suffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取转链链接
|
// 获取转链链接
|
||||||
String jf = productJdConfigService.getJdUrlByProductModel(modelNumber);
|
String jf = productJdConfigService.getJdUrlByProductModel(modelNumber);
|
||||||
|
|
||||||
// 构建分销标记:只保存 PDD,不包含第三方单号
|
|
||||||
String distributionMark = "PDD";
|
|
||||||
|
|
||||||
// 构建"生"指令格式
|
// 构建"生"指令格式
|
||||||
StringBuilder sheng = new StringBuilder();
|
StringBuilder sheng = new StringBuilder();
|
||||||
sheng.append("生\n")
|
sheng.append("生\n")
|
||||||
.append(distributionMark) // 分销标记:PDD
|
.append(distributionMark) // 分销标记
|
||||||
.append("\n")
|
.append("\n")
|
||||||
.append(modelNumber)
|
.append(modelNumber)
|
||||||
.append("\n")
|
.append("\n")
|
||||||
@@ -945,11 +985,40 @@ private String handleTF(String input) {
|
|||||||
.append("1") // 数量默认为1
|
.append("1") // 数量默认为1
|
||||||
.append("\n")
|
.append("\n")
|
||||||
.append(fullAddress.toString());
|
.append(fullAddress.toString());
|
||||||
|
|
||||||
// 传递第三方单号给 generateOrderText
|
// 传递第三方单号给 generateOrderText
|
||||||
return generateOrderText(sheng.toString(), thirdPartyOrderNo);
|
return generateOrderText(sheng.toString(), thirdPartyOrderNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String buildPddHelpMessage(String commandKeyword) {
|
||||||
|
String commandLabel = commandKeyword.trim();
|
||||||
|
String examplePrefix = commandLabel;
|
||||||
|
return "请粘贴" + commandLabel + "格式数据:\n" +
|
||||||
|
"新格式(推荐):\n" +
|
||||||
|
examplePrefix + "251102-457567158704072\n" +
|
||||||
|
"赵政委[6947]\n" +
|
||||||
|
"17283248756\n" +
|
||||||
|
"安徽省 宿州市 埇桥区 映月湾东区3栋103[6947]\n" +
|
||||||
|
"eb150\n\n" +
|
||||||
|
"旧格式(兼容):\n" +
|
||||||
|
"🕒 林[1518]\n" +
|
||||||
|
"17284023487\n" +
|
||||||
|
"广西壮族自治区 柳州市 柳北区 绿城·杨柳郡柳园7栋[1518]\n" +
|
||||||
|
"eb150";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizePddInput(String input, String commandKeyword) {
|
||||||
|
if (input == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String normalized = input;
|
||||||
|
String trimmedKeyword = commandKeyword.trim();
|
||||||
|
if ("拼多多 W".equals(trimmedKeyword)) {
|
||||||
|
normalized = normalized.replaceFirst("^\\s*拼多多\\s*[Ww]", "拼多多");
|
||||||
|
}
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
private String generateOrderText(String shengInput) {
|
private String generateOrderText(String shengInput) {
|
||||||
return generateOrderText(shengInput, null);
|
return generateOrderText(shengInput, null);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user