1
This commit is contained in:
@@ -137,33 +137,45 @@ public class JDInnerController {
|
|||||||
|
|
||||||
Comment commentToUse = null;
|
Comment commentToUse = null;
|
||||||
|
|
||||||
// 1️⃣ 先尝试使用本地可用的京东评论
|
// 按优先级获取评论:
|
||||||
|
// 1️⃣ 先尝试使用未使用过的京东评论
|
||||||
if (!availableComments.isEmpty()) {
|
if (!availableComments.isEmpty()) {
|
||||||
Collections.shuffle(availableComments);
|
Collections.shuffle(availableComments);
|
||||||
commentToUse = availableComments.get(0);
|
commentToUse = availableComments.get(0);
|
||||||
} else {
|
logger.info("使用未使用过的京东评论");
|
||||||
/**
|
}
|
||||||
* ✅ 新增逻辑:先尝试从淘宝获取评论,但前提是 productTypeMapTB 存在对应映射
|
// 2️⃣ 尝试使用未使用过的淘宝评论
|
||||||
*/
|
else {
|
||||||
String taobaoProductIdMap = tbMap.getOrDefault(productId, null);
|
String taobaoProductIdMap = tbMap.getOrDefault(productId, null);
|
||||||
|
|
||||||
if (taobaoProductIdMap != null && !taobaoProductIdMap.isEmpty()) {
|
if (taobaoProductIdMap != null && !taobaoProductIdMap.isEmpty()) {
|
||||||
logger.info("发现淘宝映射ID,尝试从淘宝获取评论");
|
logger.info("发现淘宝映射ID,尝试获取未使用过的淘宝评论");
|
||||||
Comment taobaoComment = generateTaobaoComment(productType);
|
Comment taobaoComment = generateTaobaoComment(productType, false);
|
||||||
if (taobaoComment != null) {
|
if (taobaoComment != null) {
|
||||||
commentToUse = taobaoComment;
|
commentToUse = taobaoComment;
|
||||||
isTb = true;
|
isTb = true;
|
||||||
|
logger.info("使用未使用过的淘宝评论");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
logger.info("未找到淘宝映射ID,继续使用京东评论流程");
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
// 3️⃣ 尝试使用已使用过的京东评论
|
||||||
* 2️⃣ 如果淘宝也没有,则使用已使用过的京东评论作为兜底
|
if (commentToUse == null && !usedComments.isEmpty()) {
|
||||||
*/
|
Collections.shuffle(usedComments);
|
||||||
if (commentToUse == null && !usedComments.isEmpty()) {
|
commentToUse = usedComments.get(0);
|
||||||
Collections.shuffle(usedComments);
|
logger.info("使用已使用过的京东评论");
|
||||||
commentToUse = availableComments.get(0);
|
}
|
||||||
|
|
||||||
|
// 4️⃣ 尝试使用已使用过的淘宝评论
|
||||||
|
if (commentToUse == null) {
|
||||||
|
String taobaoProductIdMap = tbMap.getOrDefault(productId, null);
|
||||||
|
if (taobaoProductIdMap != null && !taobaoProductIdMap.isEmpty()) {
|
||||||
|
logger.info("尝试获取已使用过的淘宝评论");
|
||||||
|
Comment taobaoComment = generateTaobaoComment(productType, true);
|
||||||
|
if (taobaoComment != null) {
|
||||||
|
commentToUse = taobaoComment;
|
||||||
|
isTb = true;
|
||||||
|
logger.info("使用已使用过的淘宝评论");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,8 +241,10 @@ public class JDInnerController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 从淘宝评论中生成Comment对象(参考JDUtil.generateTaobaoComment)
|
* 从淘宝评论中生成Comment对象(参考JDUtil.generateTaobaoComment)
|
||||||
|
* @param productType 商品类型
|
||||||
|
* @param includeUsed 是否包含已使用的评论(true=获取已使用的,false=获取未使用的)
|
||||||
*/
|
*/
|
||||||
private Comment generateTaobaoComment(String productType) {
|
private Comment generateTaobaoComment(String productType, boolean includeUsed) {
|
||||||
HashMap<String, String> map = jdUtil.getProductTypeMap(); // 加载京东的 productTypeMap
|
HashMap<String, String> map = jdUtil.getProductTypeMap(); // 加载京东的 productTypeMap
|
||||||
HashMap<String, String> tbMap = jdUtil.getProductTypeMapForTB(); // 加载淘宝的 productTypeMapTB
|
HashMap<String, String> tbMap = jdUtil.getProductTypeMapForTB(); // 加载淘宝的 productTypeMapTB
|
||||||
|
|
||||||
@@ -244,9 +258,18 @@ public class JDInnerController {
|
|||||||
// ✅ 在这里进行淘宝的 product_id 映射转换
|
// ✅ 在这里进行淘宝的 product_id 映射转换
|
||||||
String taobaoProductId = tbMap.getOrDefault(product_id, product_id);
|
String taobaoProductId = tbMap.getOrDefault(product_id, product_id);
|
||||||
|
|
||||||
// 然后使用 taobaoProductId 去查询 TaobaoComment
|
// 根据 includeUsed 参数查询不同的淘宝评论
|
||||||
List<TaobaoComment> taobaoComments = taobaoCommentRepository.findByProductIdAndIsUseNotAndPictureUrlsIsNotNull(taobaoProductId, 1);
|
List<TaobaoComment> taobaoComments;
|
||||||
logger.info("taobaoComments.size() {}", taobaoComments.size());
|
if (includeUsed) {
|
||||||
|
// 查询已使用的评论(isUse = 1)
|
||||||
|
taobaoComments = taobaoCommentRepository.findByProductIdAndIsUseNotAndPictureUrlsIsNotNull(taobaoProductId, 0);
|
||||||
|
} else {
|
||||||
|
// 查询未使用的评论(isUse != 1,即0或null)
|
||||||
|
taobaoComments = taobaoCommentRepository.findByProductIdAndIsUseNotAndPictureUrlsIsNotNull(taobaoProductId, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("taobaoComments.size() {} (includeUsed={})", taobaoComments.size(), includeUsed);
|
||||||
|
|
||||||
if (!taobaoComments.isEmpty()) {
|
if (!taobaoComments.isEmpty()) {
|
||||||
Collections.shuffle(taobaoComments);
|
Collections.shuffle(taobaoComments);
|
||||||
TaobaoComment selected = taobaoComments.get(0);
|
TaobaoComment selected = taobaoComments.get(0);
|
||||||
@@ -262,9 +285,12 @@ public class JDInnerController {
|
|||||||
comment.setProductId(product_id);
|
comment.setProductId(product_id);
|
||||||
comment.setUserName(selected.getUserName());
|
comment.setUserName(selected.getUserName());
|
||||||
comment.setCreatedAt(selected.getCreatedAt());
|
comment.setCreatedAt(selected.getCreatedAt());
|
||||||
// 保存淘宝评论为已使用
|
|
||||||
selected.setIsUse(1);
|
// 只在获取未使用的评论时才标记为已使用
|
||||||
taobaoCommentRepository.save(selected);
|
if (!includeUsed) {
|
||||||
|
selected.setIsUse(1);
|
||||||
|
taobaoCommentRepository.save(selected);
|
||||||
|
}
|
||||||
|
|
||||||
// 返回京东评论
|
// 返回京东评论
|
||||||
return comment;
|
return comment;
|
||||||
|
|||||||
Reference in New Issue
Block a user