This commit is contained in:
Van0313
2025-04-27 16:58:00 +08:00
parent c6f64218db
commit d55eacd0b1

View File

@@ -96,7 +96,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" + "\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" + "\n";
final WXUtil wxUtil;
private final StringRedisTemplate redisTemplate;
@@ -1556,11 +1556,12 @@ public class JDUtil {
// 今天的日期
String today = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd "));
String redisKey = "order_count:" + today;
Integer count = 1;
Integer count;
try {
// 从 Redis 获取当前日期的订单计数器
String s = redisTemplate.opsForValue().get(redisKey);
count = s != null ? Integer.parseInt(s) : 1;
Integer num = 1;
try {
num = Integer.valueOf(split[4].trim());
@@ -1569,7 +1570,7 @@ public class JDUtil {
}
for (int i = 0; i < num; i++) {
if (s != null) {
count = num + 1; // 递增计数器
count++; // 递增计数器
}
// 将新的计数器值保存回 Redis
@@ -1597,88 +1598,87 @@ public class JDUtil {
}
}
public void sendOrderToWxByOrderP(String order, String fromWxid) {
// 检查是否命中“评”指令
if ("".equals(order)) {
// 初始化用户交互状态
public void sendOrderToWxByOrderP(String order, String fromWxid) {
// 检查是否命中“评”指令
if ("".equals(order)) {
// 初始化用户交互状态
String key = INTERACTION_STATE_PREFIX + fromWxid;
UserInteractionState state = loadOrCreateState(key);
try {
// 设置当前状态为生成评论流程
state.setCurrentState(UserInteractionState.ProcessState.PRODUCT_PROMOTION);
state.setCurrentField("commentTypeSelection");
// 提示用户选择评论类型
wxUtil.sendTextMessage(fromWxid, "请选择要生成的评论类型:\n回复 1 - 消毒柜评论\n回复 2 - 油烟机评论", 1, fromWxid, false);
logger.info("进入生成评论流程 - 用户: {}", fromWxid);
} catch (Exception e) {
logger.error("生成评论流程初始化异常 - 用户: {}, 状态: {}", fromWxid, state, e);
wxUtil.sendTextMessage(fromWxid, "处理异常,请重新开始", 1, fromWxid, false);
resetState(fromWxid, state);
} finally {
saveState(key, state);
}
} else {
// 如果未命中“评”指令,检查是否在生成评论流程中
handleCommentInteraction(fromWxid, order);
}
}
/**
* 处理生成评论流程中的用户交互
*/
private void handleCommentInteraction(String fromWxid, String message) {
String key = INTERACTION_STATE_PREFIX + fromWxid;
UserInteractionState state = loadOrCreateState(key);
try {
// 设置当前状态为生成评论流程
state.setCurrentState(UserInteractionState.ProcessState.PRODUCT_PROMOTION);
state.setCurrentField("commentTypeSelection");
// 检查当前状态是否为生成评论流程
if (!"commentTypeSelection".equals(state.getCurrentField())) {
return;
}
// 提示用户选择评论类型
wxUtil.sendTextMessage(fromWxid, "请选择要生成的评论类型:\n回复 1 - 消毒柜评论\n回复 2 - 油烟机评论", 1, fromWxid, false);
logger.info("进入生成评论流程 - 用户: {}", fromWxid);
// 根据用户输入生成对应的评论
switch (message) {
case "1":
generateComment(fromWxid, "消毒柜");
break;
case "2":
generateComment(fromWxid, "油烟机");
break;
default:
wxUtil.sendTextMessage(fromWxid, "无效的选择,请回复 1 或 2", 1, fromWxid, false);
return;
}
} catch (Exception e) {
logger.error("生成评论流程初始化异常 - 用户: {}, 状态: {}", fromWxid, state, e);
logger.error("生成评论流程处理异常 - 用户: {}, 状态: {}", fromWxid, state, e);
wxUtil.sendTextMessage(fromWxid, "处理异常,请重新开始", 1, fromWxid, false);
resetState(fromWxid, state);
} finally {
saveState(key, state);
}
} else {
// 如果未命中“评”指令,检查是否在生成评论流程中
handleCommentInteraction(fromWxid, order);
}
}
/**
* 处理生成评论流程中的用户交互
*/
private void handleCommentInteraction(String fromWxid, String message) {
String key = INTERACTION_STATE_PREFIX + fromWxid;
UserInteractionState state = loadOrCreateState(key);
/**
* 生成评论内容
*/
private void generateComment(String fromWxid, String productType) {
// 这里可以调用缓存或AI生成文案目前先返回固定模板
String commentTemplate = "这是一条关于%s的评论\n" +
"1. 性能非常出色,使用体验极佳。\n" +
"2. 安装方便,操作简单。\n" +
"3. 售后服务到位,值得信赖。\n" +
"感谢您的购买与支持!";
try {
// 检查当前状态是否为生成评论流程
if (!"commentTypeSelection".equals(state.getCurrentField())) {
return;
}
String comment = String.format(commentTemplate, productType);
wxUtil.sendTextMessage(fromWxid, comment, 1, fromWxid, false);
// 根据用户输入生成对应的评论
switch (message) {
case "1":
generateComment(fromWxid, "消毒柜");
break;
case "2":
generateComment(fromWxid, "油烟机");
break;
default:
wxUtil.sendTextMessage(fromWxid, "无效的选择,请回复 1 或 2", 1, fromWxid, false);
return;
}
} catch (Exception e) {
logger.error("生成评论流程处理异常 - 用户: {}, 状态: {}", fromWxid, state, e);
wxUtil.sendTextMessage(fromWxid, "处理异常,请重新开始", 1, fromWxid, false);
resetState(fromWxid, state);
} finally {
saveState(key, state);
// 重置状态
resetState(fromWxid, loadOrCreateState(INTERACTION_STATE_PREFIX + fromWxid));
}
}
/**
* 生成评论内容
*/
private void generateComment(String fromWxid, String productType) {
// 这里可以调用缓存或AI生成文案目前先返回固定模板
String commentTemplate = "这是一条关于%s的评论\n" +
"1. 性能非常出色,使用体验极佳。\n" +
"2. 安装方便,操作简单。\n" +
"3. 售后服务到位,值得信赖。\n" +
"感谢您的购买与支持!";
String comment = String.format(commentTemplate, productType);
wxUtil.sendTextMessage(fromWxid, comment, 1, fromWxid, false);
// 重置状态
resetState(fromWxid, loadOrCreateState(INTERACTION_STATE_PREFIX + fromWxid));
}
// 定义一个内部类来存储用户交互状态