重构评论

This commit is contained in:
Van0313
2025-05-06 14:25:31 +08:00
parent 978b19d110
commit e62e6aa3fc

View File

@@ -1699,7 +1699,7 @@ public class JDUtil {
/**
* 生成评论内容
*/
private void generateComment(String fromWxid, String productType) {
private synchronized void generateComment(String fromWxid, String productType) {
wxUtil.sendTextMessage(fromWxid, "已接收到评论生成指令,等候过程请勿重复输入", 1, fromWxid, false);
// 获取产品ID
@@ -1757,7 +1757,16 @@ public class JDUtil {
return;
}
wxUtil.sendTextMessage(fromWxid, "原评论:\n" + commentToUse.getCommentText(), 1, fromWxid, false);
// 发送图片(如果有)
String pictureUrls = commentToUse.getPictureUrls();
if (pictureUrls != null && !pictureUrls.isEmpty()) {
// 使用 fastjson 将 JSON 字符串解析为 List<String>
List<String> urlList = JSON.parseArray(pictureUrls, String.class);
for (String url : urlList) {
wxUtil.sendImageMessage(fromWxid, url.trim()); // 假设 sendImageMessage 支持 URL
}
}
// 调用 DeepSeek 生成新的评论内容
String deepSeekPrompt = COMMENT_TEMPLATES_DS + commentToUse.getCommentText();
String deepSeekResponse = "";
@@ -1770,24 +1779,10 @@ public class JDUtil {
// 发送生成的评论文本
wxUtil.sendTextMessage(fromWxid, "DS回复\n" + deepSeekResponse, 1, fromWxid, false);
// 发送图片(如果有)
String pictureUrls = commentToUse.getPictureUrls();
if (pictureUrls != null && !pictureUrls.isEmpty()) {
// 使用 fastjson 将 JSON 字符串解析为 List<String>
List<String> urlList = JSON.parseArray(pictureUrls, String.class);
for (String url : urlList) {
wxUtil.sendImageMessage(fromWxid, url.trim()); // 假设 sendImageMessage 支持 URL
}
}
// 更新评论状态为已使用
commentToUse.setIsUse(1);
commentRepository.save(commentToUse);
// 重置状态
resetState(fromWxid, loadOrCreateState(INTERACTION_STATE_PREFIX + fromWxid));
}