From dba9b085615a0617139d3dcd305535a4b86eb06e Mon Sep 17 00:00:00 2001 From: Van0313 <60689272+Van0313@users.noreply.github.com> Date: Fri, 2 May 2025 20:56:35 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E8=AF=84=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/van/business/util/JDUtil.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/cn/van/business/util/JDUtil.java b/src/main/java/cn/van/business/util/JDUtil.java index e69379e..348ecfe 100644 --- a/src/main/java/cn/van/business/util/JDUtil.java +++ b/src/main/java/cn/van/business/util/JDUtil.java @@ -83,7 +83,7 @@ public class JDUtil { private static final String ACCESS_TOKEN = ""; private static final Logger logger = LoggerFactory.getLogger(JDUtil.class); private static final String INTERACTION_STATE_PREFIX = "interaction_state:"; - private static final String PRODUCT_TYPE_MAP_PREFIX = "product_type_map" ; + private static final String PRODUCT_TYPE_MAP_PREFIX = "product_type_map"; private static HashMap productTypeMap = new HashMap<>(); private static final String COMMENT_TEMPLATES_DS = "我需要为我的商品模拟一些商品评论。你协助我生成3条评价内容,京东商品评价的风格,每条评价100字即可,不需要太浮夸,也不要太像ai生成,尽量模拟真实客户评价,不要提到以旧换新和国家补贴。我会为你提供其他真实用户的评论:"; private static final long TIMEOUT_MINUTES = 2; @@ -1651,7 +1651,7 @@ public class JDUtil { state.setCurrentField("commentTypeSelection"); // 提示用户选择评论类型 getProductTypeMap(); - if (productTypeMap == null){ + if (productTypeMap == null) { wxUtil.sendTextMessage(fromWxid, "productTypeMap 为空 ", 1, fromWxid, false); return; } @@ -1679,10 +1679,19 @@ public class JDUtil { //getProductTypeMap 从redis中获取PRODUCT_TYPE_MAP_PREFIX public void getProductTypeMap() { - String json = redisTemplate.opsForValue().get(PRODUCT_TYPE_MAP_PREFIX); - productTypeMap = JSON.parseObject(json, new TypeReference>() { - }); + Map rawMap = redisTemplate.opsForHash().entries(PRODUCT_TYPE_MAP_PREFIX); + + if (rawMap != null && !rawMap.isEmpty()) { + productTypeMap.clear(); + for (Map.Entry entry : rawMap.entrySet()) { + productTypeMap.put(entry.getKey().toString(), entry.getValue().toString()); + } + } else { + logger.warn("Redis 中未找到键为 {} 的 Hash 数据", PRODUCT_TYPE_MAP_PREFIX); + } } + + /** * 处理生成评论流程中的用户交互 */ @@ -1695,7 +1704,7 @@ public class JDUtil { return; } getProductTypeMap(); - if (productTypeMap == null){ + if (productTypeMap == null) { wxUtil.sendTextMessage(fromWxid, "productTypeMap 为空 ", 1, fromWxid, false); return; } @@ -1723,7 +1732,7 @@ public class JDUtil { // 获取产品ID getProductTypeMap(); - if (productTypeMap == null){ + if (productTypeMap == null) { wxUtil.sendTextMessage(fromWxid, "productTypeMap 为空 ", 1, fromWxid, false); return; }