From def2e1434e5cb72fc8a355e957b07d7565a718e9 Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 8 Apr 2025 20:13:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/van/business/util/JDUtil.java | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/main/java/cn/van/business/util/JDUtil.java b/src/main/java/cn/van/business/util/JDUtil.java index 312a218..d8ece6d 100644 --- a/src/main/java/cn/van/business/util/JDUtil.java +++ b/src/main/java/cn/van/business/util/JDUtil.java @@ -99,7 +99,7 @@ public class JDUtil { *

* 订单号: */ - private static final String WENAN_D = "内部单号:\n" + "\n {单号}" + "分销标记(标记用,勿改):\n" + "\n" + "型号:\n" + "\n" + "价格:\n" + "\n" + "后返:\n" + "\n" + "地址:\n" + "\n" + "物流链接:\n" + "\n" + "订单号:\n" + "\n" + "备注:\n" + "\n"; + private static final String WENAN_D = "内部单号:\n" + "{单号} \n" + "分销标记(标记用,勿改):\n" + "\n" + "型号:\n" + "\n" + "价格:\n" + "\n" + "后返:\n" + "\n" + "地址:\n" + "\n" + "物流链接:\n" + "\n" + "订单号:\n" + "\n" + "备注:\n" + "\n"; final WXUtil wxUtil; private final StringRedisTemplate redisTemplate; @@ -1720,37 +1720,37 @@ public class JDUtil { return JSON.parseObject(json, UserInteractionState.class); } -public void sendOrderToWxByOrderD(String order, String fromWxid) { - String temp = WENAN_D; - // 今天的日期 - String today = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); - String redisKey = "order_count:" + today; - Integer count = 1; + public void sendOrderToWxByOrderD(String order, String fromWxid) { + String temp = WENAN_D; + // 今天的日期 + String today = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd ")); + String redisKey = "order_count:" + today; + Integer count = 1; - try { - // 从 Redis 获取当前日期的订单计数器 - String s = redisTemplate.opsForValue().get(redisKey); - if (s != null) { - count = Integer.parseInt(s) + 1; // 递增计数器 + try { + // 从 Redis 获取当前日期的订单计数器 + String s = redisTemplate.opsForValue().get(redisKey); + if (s != null) { + count = Integer.parseInt(s) + 1; // 递增计数器 + } + + // 将新的计数器值保存回 Redis + redisTemplate.opsForValue().set(redisKey, String.valueOf(count), 1, TimeUnit.DAYS); + + // 生成订单号 + String orderID = today + String.format("%03d", count); // 格式化为 3 位数字,不足补零 + + // 替换模板中的占位符 + temp = temp.replace("{单号}", orderID ); + + // 发送订单信息到微信 + wxUtil.sendTextMessage(fromWxid, temp, 1, fromWxid, false); + + } catch (Exception e) { + logger.error("生成订单号时发生异常 - 用户: {}, 日期: {}", fromWxid, today, e); + wxUtil.sendTextMessage(fromWxid, "生成订单号时发生异常,请重试", 1, fromWxid, false); } - - // 将新的计数器值保存回 Redis - redisTemplate.opsForValue().set(redisKey, String.valueOf(count), 1, TimeUnit.DAYS); - - // 生成订单号 - String orderID = today + String.format("%03d", count); // 格式化为 3 位数字,不足补零 - - // 替换模板中的占位符 - temp = temp.replace("{单号}", orderID); - - // 发送订单信息到微信 - wxUtil.sendTextMessage(fromWxid, temp, 1, fromWxid, false); - - } catch (Exception e) { - logger.error("生成订单号时发生异常 - 用户: {}, 日期: {}", fromWxid, today, e); - wxUtil.sendTextMessage(fromWxid, "生成订单号时发生异常,请重试", 1, fromWxid, false); } -} // 定义一个内部类来存储用户交互状态