重构评论

This commit is contained in:
Van0313
2025-05-06 12:04:30 +08:00
parent f84910a678
commit fedd739018

View File

@@ -1640,10 +1640,6 @@ public class JDUtil {
// 检查是否命中“评”指令 // 检查是否命中“评”指令
UserInteractionState state = null; UserInteractionState state = null;
if (!productTypeMap.containsKey(order.trim())) { if (!productTypeMap.containsKey(order.trim())) {
// 初始化用户交互状态
String key = INTERACTION_STATE_PREFIX + fromWxid;
state = loadOrCreateState(key);
logger.info("loadOrCreateState - 用户: {}, 状态: {}", fromWxid, state);
try { try {
StringBuilder productTypeStr = new StringBuilder(); StringBuilder productTypeStr = new StringBuilder();
@@ -1658,20 +1654,8 @@ public class JDUtil {
} catch (Exception e) { } catch (Exception e) {
logger.error("生成评论流程初始化异常 - 用户: {}, 状态: {}", fromWxid, state, e); logger.error("生成评论流程初始化异常 - 用户: {}, 状态: {}", fromWxid, state, e);
wxUtil.sendTextMessage(fromWxid, "处理异常,请重新开始", 1, fromWxid, false); wxUtil.sendTextMessage(fromWxid, "处理异常,请重新开始", 1, fromWxid, false);
resetState(fromWxid, state);
} finally {
saveState(key, state);
} }
} else { } else {
// 初始化用户交互状态
String key = INTERACTION_STATE_PREFIX + fromWxid;
state = loadOrCreateState(key);
logger.info("loadOrCreateState - 用户: {}, 状态: {}", fromWxid, state);
// 设置当前状态为生成评论流程
state.setCurrentState(UserInteractionState.ProcessState.COMMENT_GENERATION);
state.setCurrentField("commentTypeSelection");
saveState(key, state);
// 如果未命中“评”指令,检查是否在生成评论流程中 // 如果未命中“评”指令,检查是否在生成评论流程中
handleCommentInteraction(fromWxid, order, state); handleCommentInteraction(fromWxid, order, state);
} }
@@ -1695,14 +1679,10 @@ public class JDUtil {
/** /**
* 处理生成评论流程中的用户交互 * 处理生成评论流程中的用户交互
*/ */
private void handleCommentInteraction(String fromWxid, String message, UserInteractionState state) { private void handleCommentInteraction(String fromWxid, String message) {
String key = INTERACTION_STATE_PREFIX + fromWxid;
logger.info("handleCommentInteraction 处理生成评论流程中的用户交互 - 用户: {}, 状态: {},message: {}", fromWxid, state, message); logger.info("handleCommentInteraction 处理生成评论流程中的用户交互 - 用户: {}, 状态: {},message: {}", fromWxid, state, message);
try { try {
// 检查当前状态是否为生成评论流程
//if (!"commentTypeSelection".equals(state.getCurrentField())) {
// return;
//}
getProductTypeMap(); getProductTypeMap();
if (productTypeMap == null) { if (productTypeMap == null) {
wxUtil.sendTextMessage(fromWxid, "productTypeMap 为空 ", 1, fromWxid, false); wxUtil.sendTextMessage(fromWxid, "productTypeMap 为空 ", 1, fromWxid, false);
@@ -1715,11 +1695,8 @@ public class JDUtil {
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("生成评论流程处理异常 - 用户: {}, 状态: {}", fromWxid, state, e); logger.error("生成评论流程处理异常 - 用户: {}", fromWxid, e);
wxUtil.sendTextMessage(fromWxid, "处理异常,请重新开始", 1, fromWxid, false); wxUtil.sendTextMessage(fromWxid, "处理异常,请重新开始", 1, fromWxid, false);
resetState(fromWxid, state);
} finally {
saveState(key, state);
} }
} }