This commit is contained in:
Leo
2025-04-08 20:13:54 +08:00
parent 3204de5f56
commit def2e1434e

View File

@@ -99,7 +99,7 @@ public class JDUtil {
* <p>
* 订单号:
*/
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);
}
}
// 定义一个内部类来存储用户交互状态