评论
This commit is contained in:
@@ -1881,6 +1881,7 @@ public class JDUtil {
|
||||
public void delProductTypeMap(String key) {
|
||||
redisTemplate.opsForHash().delete(PRODUCT_TYPE_MAP_PREFIX, key);
|
||||
}
|
||||
|
||||
public HashMap<String, String> getProductTypeMapForTB() {
|
||||
Map<Object, Object> rawMap = redisTemplate.opsForHash().entries(PRODUCT_TYPE_MAP_PREFIX_TB);
|
||||
|
||||
@@ -1897,6 +1898,7 @@ public class JDUtil {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据原始的 product_id 查询淘宝映射后的 ID
|
||||
*
|
||||
@@ -1981,7 +1983,7 @@ private synchronized void generateComment(String fromWxid, String productType) {
|
||||
if (taobaoProductId != null && !taobaoProductId.isEmpty()) {
|
||||
logger.info("发现淘宝映射ID,尝试从淘宝获取评论");
|
||||
wxUtil.sendTextMessage(fromWxid, "本地无未用评论,已发现淘宝映射ID,从淘宝获取评论", 1, null, true);
|
||||
Comment taobaoComment = generateTaobaoComment(fromWxid, productType);
|
||||
Comment taobaoComment = generateTaobaoComment(productType);
|
||||
if (taobaoComment != null) {
|
||||
commentToUse = taobaoComment;
|
||||
isTb = true;
|
||||
@@ -1993,6 +1995,7 @@ private synchronized void generateComment(String fromWxid, String productType) {
|
||||
/**
|
||||
* 2️⃣ 然后尝试从京东外部接口获取新的评论
|
||||
*/
|
||||
if (!isTb) {
|
||||
try {
|
||||
String fetchUrl = "http://192.168.8.6:5000/fetch_comments?product_id=" + product_id;
|
||||
HttpResponse response = HttpRequest.post(fetchUrl).timeout(1000 * 60).execute();
|
||||
@@ -2025,6 +2028,7 @@ private synchronized void generateComment(String fromWxid, String productType) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 🚀 如果京东本地和接口都没有,则再次尝试从淘宝评论获取(兜底逻辑)
|
||||
@@ -2038,8 +2042,8 @@ private synchronized void generateComment(String fromWxid, String productType) {
|
||||
/**
|
||||
* ✨ 发送最终评论内容及图片
|
||||
*/
|
||||
if (commentToUse != null) {
|
||||
wxUtil.sendTextMessage(fromWxid, commentToUse.getCommentText(), 1, fromWxid, true);
|
||||
|
||||
String pictureUrls = commentToUse.getPictureUrls();
|
||||
if (pictureUrls != null && !pictureUrls.isEmpty()) {
|
||||
List<String> urlList = JSON.parseArray(pictureUrls, String.class);
|
||||
@@ -2069,14 +2073,17 @@ private synchronized void generateComment(String fromWxid, String productType) {
|
||||
}
|
||||
|
||||
|
||||
private Comment generateTaobaoComment(String fromWxid, String productType) {
|
||||
}
|
||||
|
||||
|
||||
private Comment generateTaobaoComment(String productType) {
|
||||
getProductTypeMap(); // 加载京东的 productTypeMap
|
||||
getProductTypeMapForTB(); // 加载淘宝的 productTypeMapTB
|
||||
|
||||
String product_id = productTypeMap.get(productType); // 先查京东SKU
|
||||
|
||||
if (product_id == null) {
|
||||
wxUtil.sendTextMessage(fromWxid, "未找到对应的商品ID", 1, fromWxid, false);
|
||||
logger.info("未找到对应的京东商品ID:{}", productType);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -2085,7 +2092,7 @@ private Comment generateTaobaoComment(String fromWxid, String productType) {
|
||||
|
||||
// 然后使用 taobaoProductId 去查询 TaobaoComment
|
||||
List<TaobaoComment> taobaoComments = taobaoCommentRepository.findByProductIdAndIsUseNotAndPictureUrlsIsNotNull(taobaoProductId, 1);
|
||||
|
||||
logger.info("taobaoComments.size() {}", taobaoComments.size());
|
||||
if (!taobaoComments.isEmpty()) {
|
||||
Collections.shuffle(taobaoComments);
|
||||
TaobaoComment selected = taobaoComments.get(0);
|
||||
@@ -2107,14 +2114,12 @@ private Comment generateTaobaoComment(String fromWxid, String productType) {
|
||||
|
||||
// 返回京东评论
|
||||
return comment;
|
||||
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 定义一个内部类来存储用户交互状态
|
||||
@Getter
|
||||
@Setter
|
||||
|
||||
Reference in New Issue
Block a user