1
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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("订单指令执行完成");
|
||||||
|
|
||||||
// 记录执行结果
|
// 记录执行结果
|
||||||
|
|||||||
@@ -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(响应)
|
||||||
|
|||||||
@@ -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()) {
|
||||||
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,获取京粉实际价格
|
// 根据订单号查询order_rows,获取京粉实际价格
|
||||||
|
|||||||
Reference in New Issue
Block a user