This commit is contained in:
Leo
2025-11-13 16:08:45 +08:00
parent e184c7926f
commit 8889791a83
4 changed files with 49 additions and 13 deletions

View File

@@ -11,6 +11,14 @@ public interface IInstructionService {
*/
java.util.List<String> execute(String command);
/**
* 执行文本指令,返回结果文本(支持强制生成参数)
* @param command 指令内容
* @param forceGenerate 是否强制生成表单(跳过地址重复检查)
* @return 执行结果文本列表(可能为单条或多条)
*/
java.util.List<String> execute(String command, boolean forceGenerate);
/**
* 获取历史消息记录
* @param type 消息类型request(请求) 或 response(响应)

View File

@@ -58,6 +58,11 @@ public class InstructionServiceImpl implements IInstructionService {
@Override
public List<String> execute(String command) {
return execute(command, false);
}
@Override
public List<String> execute(String command, boolean forceGenerate) {
// 存储接收的消息到Redis队列
storeMessageToRedis("instruction:request", command);
@@ -86,7 +91,7 @@ public class InstructionServiceImpl implements IInstructionService {
} else if (input.equals("拼多多") || input.startsWith("拼多多\n") || input.startsWith("拼多多\r\n") || isPDDFormat(input)) {
result = Collections.singletonList(handlePDD(input));
} else if (input.startsWith("录单") || input.startsWith("慢单") || input.startsWith("慢搜") || input.startsWith("慢查") || input.startsWith("")) {
result = handleRecordLikeMulti(input);
result = handleRecordLikeMulti(input, forceGenerate);
} else if (input.startsWith("转链") || input.startsWith("文案") || input.startsWith("")) {
result = Collections.singletonList(handleTransferLike(input));
} else {
@@ -204,6 +209,10 @@ public class InstructionServiceImpl implements IInstructionService {
}
private List<String> handleRecordLikeMulti(String input) {
return handleRecordLikeMulti(input, false);
}
private List<String> handleRecordLikeMulti(String input, boolean forceGenerate) {
// 仅实现“慢搜/慢查 关键词”与“录单/慢单 日期范围”的只读输出,避免侵入写库
if (input.startsWith("慢搜") || input.startsWith("慢查")) {
String kw = input.replaceFirst("^慢搜|^慢查", "").trim();
@@ -601,7 +610,7 @@ public class InstructionServiceImpl implements IInstructionService {
return outputs.isEmpty() ? Collections.singletonList("无数据") : outputs;
}
if (input.startsWith("")) {
return Collections.singletonList(handleDanWriteDb(input));
return Collections.singletonList(handleDanWriteDb(input, forceGenerate));
}
return Collections.singletonList(helpText());
}
@@ -1206,8 +1215,12 @@ public class InstructionServiceImpl implements IInstructionService {
return s.replaceAll("[\\t ]+", " ").replaceAll("\n{3,}", "\n\n").trim();
}
// ===== 单 … 写库 =====
// ===== "单 …" 写库 =====
private String handleDanWriteDb(String input) {
return handleDanWriteDb(input, false);
}
private String handleDanWriteDb(String input, boolean forceGenerate) {
// 保存原始输入,用于返回前端时保留完整物流链接
String originalInput = input.trim().replace("", "");
// 与 JDUtil.parseOrderFromText 一致的模板字段
@@ -1257,12 +1270,23 @@ public class InstructionServiceImpl implements IInstructionService {
}
}
// 地址重复提示(不阻断写入,与 JDUtil 提示一致)
// 地址重复检查
List<JDOrder> byAddress = jdOrderService.selectJDOrderListByAddress(order.getAddress());
if (byAddress != null && !byAddress.isEmpty()) {
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String latest = sdf.format(byAddress.get(0).getOrderTime());
// 仅提示
// 如果强制生成,跳过地址重复检查
if (!forceGenerate) {
// 返回特殊错误码,前端会识别并弹出验证码
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
int count = byAddress.size();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < Math.min(count, 3); i++) {
if (i > 0) sb.append("\n");
sb.append(sdf.format(byAddress.get(i).getOrderTime()));
}
// 使用特殊错误码标识地址重复
return "ERROR_CODE:ADDRESS_DUPLICATE\n收货地址重复此地址共" + count + "个订单,最近的订单时间:" + sb.toString();
}
// forceGenerate为true时跳过地址重复检查继续执行
}
// 根据订单号查询order_rows获取京粉实际价格