重构评论
This commit is contained in:
@@ -1752,6 +1752,7 @@ public class JDUtil {
|
|||||||
Collections.shuffle(availableComments);
|
Collections.shuffle(availableComments);
|
||||||
commentToUse = availableComments.get(0);
|
commentToUse = availableComments.get(0);
|
||||||
} else {
|
} else {
|
||||||
|
wxUtil.sendTextMessage(fromWxid, "没有本地评论,调用外部接口抓取", 1, fromWxid, false);
|
||||||
// 没有本地评论,调用外部接口抓取
|
// 没有本地评论,调用外部接口抓取
|
||||||
try {
|
try {
|
||||||
String fetchUrl = "http://192.168.8.6:5000/fetch_comments?product_id=" + product_id;
|
String fetchUrl = "http://192.168.8.6:5000/fetch_comments?product_id=" + product_id;
|
||||||
@@ -1761,6 +1762,7 @@ public class JDUtil {
|
|||||||
logger.info("fetchUrl: {}", fetchUrl);
|
logger.info("fetchUrl: {}", fetchUrl);
|
||||||
// code = 200 表示成功,-200 表示失败
|
// code = 200 表示成功,-200 表示失败
|
||||||
if (response.getStatus() == 200) {
|
if (response.getStatus() == 200) {
|
||||||
|
wxUtil.sendTextMessage(fromWxid, "已获取新的评论,请稍等", 1, fromWxid, false);
|
||||||
// ✅ 关键修改:重新从数据库中查询,而不是使用内存中的 fetchedComments
|
// ✅ 关键修改:重新从数据库中查询,而不是使用内存中的 fetchedComments
|
||||||
availableComments = commentRepository.findByProductIdAndIsUseNotAndPictureUrlsIsNotNull(product_id, 1);
|
availableComments = commentRepository.findByProductIdAndIsUseNotAndPictureUrlsIsNotNull(product_id, 1);
|
||||||
if (!availableComments.isEmpty()) {
|
if (!availableComments.isEmpty()) {
|
||||||
@@ -1800,12 +1802,15 @@ public class JDUtil {
|
|||||||
// 发送图片(如果有)
|
// 发送图片(如果有)
|
||||||
String pictureUrls = commentToUse.getPictureUrls();
|
String pictureUrls = commentToUse.getPictureUrls();
|
||||||
if (pictureUrls != null && !pictureUrls.isEmpty()) {
|
if (pictureUrls != null && !pictureUrls.isEmpty()) {
|
||||||
String[] urls = pictureUrls.split(",");
|
// 使用 fastjson 将 JSON 字符串解析为 List<String>
|
||||||
for (String url : urls) {
|
List<String> urlList = JSON.parseArray(pictureUrls, String.class);
|
||||||
|
|
||||||
|
for (String url : urlList) {
|
||||||
wxUtil.sendImageMessage(fromWxid, url.trim()); // 假设 sendImageMessage 支持 URL
|
wxUtil.sendImageMessage(fromWxid, url.trim()); // 假设 sendImageMessage 支持 URL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 更新评论状态为已使用
|
// 更新评论状态为已使用
|
||||||
commentToUse.setIsUse(1);
|
commentToUse.setIsUse(1);
|
||||||
commentRepository.save(commentToUse);
|
commentRepository.save(commentToUse);
|
||||||
|
|||||||
Reference in New Issue
Block a user