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

@@ -22,12 +22,13 @@ public class InstructionController extends BaseController {
/** /**
* 执行文本指令 * 执行文本指令
* body: { command: "京今日统计" } * body: { command: "京今日统计", forceGenerate: false }
*/ */
@PostMapping("/execute") @PostMapping("/execute")
public AjaxResult execute(@RequestBody Map<String, String> body) { public AjaxResult execute(@RequestBody Map<String, Object> body) {
String cmd = body != null ? body.get("command") : null; String cmd = body != null ? (body.get("command") != null ? String.valueOf(body.get("command")) : null) : null;
java.util.List<String> result = instructionService.execute(cmd); boolean forceGenerate = body != null && body.get("forceGenerate") != null && Boolean.parseBoolean(String.valueOf(body.get("forceGenerate")));
java.util.List<String> result = instructionService.execute(cmd, forceGenerate);
return AjaxResult.success(result); return AjaxResult.success(result);
} }

View File

@@ -111,11 +111,14 @@ public class PublicOrderController extends BaseController {
log.info("日期验证通过: 订单日期[{}]", orderDate); log.info("日期验证通过: 订单日期[{}]", orderDate);
// 获取forceGenerate参数默认为false
boolean forceGenerate = body != null && body.get("forceGenerate") != null && Boolean.parseBoolean(String.valueOf(body.get("forceGenerate")));
// 执行指令 // 执行指令
List<String> result; List<String> result;
try { try {
log.info("开始执行订单指令..."); log.info("开始执行订单指令... forceGenerate={}", forceGenerate);
result = instructionService.execute(trimmedCmd); result = instructionService.execute(trimmedCmd, forceGenerate);
log.info("订单指令执行完成"); log.info("订单指令执行完成");
// 记录执行结果 // 记录执行结果

View File

@@ -11,6 +11,14 @@ public interface IInstructionService {
*/ */
java.util.List<String> execute(String command); 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(响应) * @param type 消息类型request(请求) 或 response(响应)

View File

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