diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/jarvis/InstructionController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/jarvis/InstructionController.java index 0f9ece5..3503370 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/jarvis/InstructionController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/jarvis/InstructionController.java @@ -22,12 +22,13 @@ public class InstructionController extends BaseController { /** * 执行文本指令 - * body: { command: "京今日统计" } + * body: { command: "京今日统计", forceGenerate: false } */ @PostMapping("/execute") - public AjaxResult execute(@RequestBody Map body) { - String cmd = body != null ? body.get("command") : null; - java.util.List result = instructionService.execute(cmd); + public AjaxResult execute(@RequestBody Map 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 result = instructionService.execute(cmd, forceGenerate); return AjaxResult.success(result); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/public_/PublicOrderController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/public_/PublicOrderController.java index ab832a5..195b685 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/public_/PublicOrderController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/public_/PublicOrderController.java @@ -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 result; try { - log.info("开始执行订单指令..."); - result = instructionService.execute(trimmedCmd); + log.info("开始执行订单指令... forceGenerate={}", forceGenerate); + result = instructionService.execute(trimmedCmd, forceGenerate); log.info("订单指令执行完成"); // 记录执行结果 diff --git a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/IInstructionService.java b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/IInstructionService.java index 42c1102..ffb484e 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/IInstructionService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/IInstructionService.java @@ -11,6 +11,14 @@ public interface IInstructionService { */ java.util.List execute(String command); + /** + * 执行文本指令,返回结果文本(支持强制生成参数) + * @param command 指令内容 + * @param forceGenerate 是否强制生成表单(跳过地址重复检查) + * @return 执行结果文本列表(可能为单条或多条) + */ + java.util.List execute(String command, boolean forceGenerate); + /** * 获取历史消息记录 * @param type 消息类型:request(请求) 或 response(响应) diff --git a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/InstructionServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/InstructionServiceImpl.java index 873b26d..8dd0bc3 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/InstructionServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/InstructionServiceImpl.java @@ -58,6 +58,11 @@ public class InstructionServiceImpl implements IInstructionService { @Override public List execute(String command) { + return execute(command, false); + } + + @Override + public List 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 handleRecordLikeMulti(String input) { + return handleRecordLikeMulti(input, false); + } + + private List 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 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,获取京粉实际价格