This commit is contained in:
2025-09-06 16:17:37 +08:00
parent 5543b5bcde
commit 6e68591991

View File

@@ -97,13 +97,40 @@ public class JDInnerController {
return error("productType is required");
}
try {
// 评论统计变量初始化
int allCommentCount = 0;
int usedCommentCount = 0;
int canUseCommentCount = 0;
int addCommentCount = 0;
int allTbCommentCount = 0;
int usedTbCommentCount = 0;
int canUseTbCommentCount = 0;
boolean isTb = false;
HashMap<String, String> map = jdUtil.getProductTypeMap();
String productId = map.get(productType);
if (productId == null || productId.trim().isEmpty()) {
return error("unknown productType");
}
// 获取本地可用的京东评论并统计
List<Comment> available = commentRepository.findByProductIdAndIsUseNotAndPictureUrlsIsNotNull(productId, 1);
List<Comment> used = commentRepository.findByProductIdAndIsUseNotAndPictureUrlsIsNotNull(productId, 0);
canUseCommentCount = available.size();
usedCommentCount = used.size();
allCommentCount = canUseCommentCount + usedCommentCount;
// 获取淘宝评论统计信息
HashMap<String, String> tbMap = jdUtil.getProductTypeMapForTB();
String taobaoProductId = tbMap.getOrDefault(productId, productId);
// 注意这里需要注入TaobaoCommentRepository暂时注释掉淘宝统计部分
// List<TaobaoComment> availableTbComments = taobaoCommentRepository.findByProductIdAndIsUseNotAndPictureUrlsIsNotNull(taobaoProductId, 1);
// List<TaobaoComment> usedTbComments = taobaoCommentRepository.findByProductIdAndIsUseNotAndPictureUrlsIsNotNull(taobaoProductId, 0);
// canUseTbCommentCount = availableTbComments.size();
// usedTbCommentCount = usedTbComments.size();
// allTbCommentCount = canUseTbCommentCount + usedTbCommentCount;
List<Comment> candidates = !available.isEmpty() ? available : used;
if (candidates.isEmpty()) {
return error("no comment available");
@@ -121,6 +148,37 @@ public class JDInnerController {
resp.put("productType", productType);
resp.put("list", arr);
// 添加评论统计信息到响应中
JSONObject stats = new JSONObject();
if (!isTb) {
stats.put("source", "京东评论");
stats.put("productType", productType);
stats.put("newAdded", addCommentCount);
stats.put("used", usedCommentCount);
stats.put("available", canUseCommentCount);
stats.put("total", allCommentCount);
stats.put("statisticsText",
"京东评论统计:\n" +
"型号 " + productType + "\n" +
"新增:" + addCommentCount + "\n" +
"已使用:" + usedCommentCount + "\n" +
"可用:" + canUseCommentCount + "\n" +
"总数:" + allCommentCount);
} else {
stats.put("source", "淘宝评论");
stats.put("productType", productType);
stats.put("used", usedTbCommentCount);
stats.put("available", canUseTbCommentCount);
stats.put("total", allTbCommentCount);
stats.put("statisticsText",
"淘宝评论统计:\n" +
"型号 " + productType + "\n" +
"已使用:" + usedTbCommentCount + "\n" +
"可用:" + canUseTbCommentCount + "\n" +
"总数:" + allTbCommentCount);
}
resp.put("statistics", stats);
// 标记为已使用(仅当原本未使用时)
try {
if (chosen.getIsUse() == null || chosen.getIsUse() == 0) {