1
This commit is contained in:
@@ -22,12 +22,13 @@ public class InstructionController extends BaseController {
|
||||
|
||||
/**
|
||||
* 执行文本指令
|
||||
* body: { command: "京今日统计" }
|
||||
* body: { command: "京今日统计", forceGenerate: false }
|
||||
*/
|
||||
@PostMapping("/execute")
|
||||
public AjaxResult execute(@RequestBody Map<String, String> body) {
|
||||
String cmd = body != null ? body.get("command") : null;
|
||||
java.util.List<String> result = instructionService.execute(cmd);
|
||||
public AjaxResult execute(@RequestBody Map<String, Object> body) {
|
||||
String cmd = body != null ? (body.get("command") != null ? String.valueOf(body.get("command")) : null) : null;
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -111,11 +111,14 @@ public class PublicOrderController extends BaseController {
|
||||
|
||||
log.info("日期验证通过: 订单日期[{}]", orderDate);
|
||||
|
||||
// 获取forceGenerate参数(默认为false)
|
||||
boolean forceGenerate = body != null && body.get("forceGenerate") != null && Boolean.parseBoolean(String.valueOf(body.get("forceGenerate")));
|
||||
|
||||
// 执行指令
|
||||
List<String> result;
|
||||
try {
|
||||
log.info("开始执行订单指令...");
|
||||
result = instructionService.execute(trimmedCmd);
|
||||
log.info("开始执行订单指令... forceGenerate={}", forceGenerate);
|
||||
result = instructionService.execute(trimmedCmd, forceGenerate);
|
||||
log.info("订单指令执行完成");
|
||||
|
||||
// 记录执行结果
|
||||
|
||||
@@ -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(响应)
|
||||
|
||||
@@ -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,获取京粉实际价格
|
||||
|
||||
Reference in New Issue
Block a user