重构评论
This commit is contained in:
@@ -97,19 +97,7 @@ public class JDUtil {
|
|||||||
5:价格有浮动,不支持补差价,谢谢理解。
|
5:价格有浮动,不支持补差价,谢谢理解。
|
||||||
6:全国联保,全国统一安装标准。支持官方 400,服务号查询,假一赔十。
|
6:全国联保,全国统一安装标准。支持官方 400,服务号查询,假一赔十。
|
||||||
""";
|
""";
|
||||||
private static final String WENAN_FANAN_BX ="本人提供免费指导下单服务,一台也是团购价,细心指导\n" +
|
private static final String WENAN_FANAN_BX = "本人提供免费指导下单服务,一台也是团购价,细心指导\n" + "\n" + "【质量】官旗下单,包正的\n" + "【物流】您自己账户可跟踪,24小时发货\n" + "【售后】您自己账户直接联系,无忧售后\n" + "【安装】专业人员安装,全程无需您操心\n" + "【价格】标价就是到手价,骑共享单车去酒吧,该省省该花花\n" + "【服务】手把手教您下单,有问题随时咨询\n" + "【体验】所有服务都是官旗提供,价格有内部渠道优惠,同品质更优惠!\n" + "\n" + "信息更新日期:\n" + "\n" + "捡漏价格不定时有变动,优惠不等人,发「省份+型号」免费咨询当日最低价!";
|
||||||
"\n" +
|
|
||||||
"【质量】官旗下单,包正的\n" +
|
|
||||||
"【物流】您自己账户可跟踪,24小时发货\n" +
|
|
||||||
"【售后】您自己账户直接联系,无忧售后\n" +
|
|
||||||
"【安装】专业人员安装,全程无需您操心\n" +
|
|
||||||
"【价格】标价就是到手价,骑共享单车去酒吧,该省省该花花\n" +
|
|
||||||
"【服务】手把手教您下单,有问题随时咨询\n" +
|
|
||||||
"【体验】所有服务都是官旗提供,价格有内部渠道优惠,同品质更优惠!\n" +
|
|
||||||
"\n" +
|
|
||||||
"信息更新日期:\n" +
|
|
||||||
"\n" +
|
|
||||||
"捡漏价格不定时有变动,优惠不等人,发「省份+型号」免费咨询当日最低价!";
|
|
||||||
private static final String FANAN_COMMON = "\n1 文案复制到微,点击领券,到J东APP结算\n" + "2 换新可直接代消单,不用提供回收\n " + "3 独家虹包 https://u.jd.com/raa0eI4 至高可领618 \n";
|
private static final String FANAN_COMMON = "\n1 文案复制到微,点击领券,到J东APP结算\n" + "2 换新可直接代消单,不用提供回收\n " + "3 独家虹包 https://u.jd.com/raa0eI4 至高可领618 \n";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -185,7 +173,7 @@ public class JDUtil {
|
|||||||
// 生成日期
|
// 生成日期
|
||||||
String date = DateUtil.format(new Date(), "HH:mm:ss yyyy-MM-dd");
|
String date = DateUtil.format(new Date(), "HH:mm:ss yyyy-MM-dd");
|
||||||
|
|
||||||
wxUtil.sendTextMessage(chatRoom_BY, chatRoomRemark +" "+ date+ "\n\n " + message, 1, chatRoom_BY, true);
|
wxUtil.sendTextMessage(chatRoom_BY, chatRoomRemark + " " + date + "\n\n " + message, 1, chatRoom_BY, true);
|
||||||
|
|
||||||
// 2. 生成推广内容
|
// 2. 生成推广内容
|
||||||
HashMap<String, List<String>> contentResult = generatePromotionContent(message, true);
|
HashMap<String, List<String>> contentResult = generatePromotionContent(message, true);
|
||||||
@@ -1238,7 +1226,8 @@ public class JDUtil {
|
|||||||
try {
|
try {
|
||||||
priceList = extractPrices(message);
|
priceList = extractPrices(message);
|
||||||
finallyMessage.put("priceList", priceList);
|
finallyMessage.put("priceList", priceList);
|
||||||
} catch (Exception ignored) { }
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (String url : urls) {
|
for (String url : urls) {
|
||||||
try {
|
try {
|
||||||
@@ -1333,7 +1322,7 @@ public class JDUtil {
|
|||||||
textList.add(String.valueOf(sb3));
|
textList.add(String.valueOf(sb3));
|
||||||
|
|
||||||
StringBuilder sb4 = new StringBuilder();
|
StringBuilder sb4 = new StringBuilder();
|
||||||
sb4.append("【教你下单】 ").append(title).append(replaceAll).append("\n").append(WENAN_FANAN_BX.replaceAll("信息更新日期:", "信息更新日期:" + format ));
|
sb4.append("【教你下单】 ").append(title).append(replaceAll).append("\n").append(WENAN_FANAN_BX.replaceAll("信息更新日期:", "信息更新日期:" + format));
|
||||||
textList.add(String.valueOf(sb4));
|
textList.add(String.valueOf(sb4));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1606,13 +1595,13 @@ public class JDUtil {
|
|||||||
getProductTypeMap();
|
getProductTypeMap();
|
||||||
// 检查是否命中“评”指令
|
// 检查是否命中“评”指令
|
||||||
if (!productTypeMap.containsKey(order.trim())) {
|
if (!productTypeMap.containsKey(order.trim())) {
|
||||||
if (order.startsWith("添加型号")){
|
if (order.startsWith("添加型号")) {
|
||||||
String replace = order.replace("添加型号-", "");
|
String replace = order.replace("添加型号-", "");
|
||||||
String[] split = replace.split("-");
|
String[] split = replace.split("-");
|
||||||
if (split.length == 2){
|
if (split.length == 2) {
|
||||||
addProductTypeMap(split[0], split[1]);
|
addProductTypeMap(split[0], split[1]);
|
||||||
wxUtil.sendTextMessage(fromWxid, "添加型号成功", 1, fromWxid, false);
|
wxUtil.sendTextMessage(fromWxid, "添加型号成功", 1, fromWxid, false);
|
||||||
}else {
|
} else {
|
||||||
wxUtil.sendTextMessage(fromWxid, "添加型号格式错误,请输入正确的格式:添加型号-型号名称-型号SKU", 1, fromWxid, false);
|
wxUtil.sendTextMessage(fromWxid, "添加型号格式错误,请输入正确的格式:添加型号-型号名称-型号SKU", 1, fromWxid, false);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -1649,6 +1638,7 @@ public class JDUtil {
|
|||||||
logger.warn("Redis 中未找到键为 {} 的 Hash 数据", PRODUCT_TYPE_MAP_PREFIX);
|
logger.warn("Redis 中未找到键为 {} 的 Hash 数据", PRODUCT_TYPE_MAP_PREFIX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addProductTypeMap(String key, String value) {
|
public void addProductTypeMap(String key, String value) {
|
||||||
redisTemplate.opsForHash().put(PRODUCT_TYPE_MAP_PREFIX, key, value);
|
redisTemplate.opsForHash().put(PRODUCT_TYPE_MAP_PREFIX, key, value);
|
||||||
}
|
}
|
||||||
@@ -1683,7 +1673,10 @@ public class JDUtil {
|
|||||||
*/
|
*/
|
||||||
private synchronized void generateComment(String fromWxid, String productType) {
|
private synchronized void generateComment(String fromWxid, String productType) {
|
||||||
wxUtil.sendTextMessage(fromWxid, "已接收到评论生成指令,等候过程请勿重复输入", 1, fromWxid, true);
|
wxUtil.sendTextMessage(fromWxid, "已接收到评论生成指令,等候过程请勿重复输入", 1, fromWxid, true);
|
||||||
|
int allCommentCount = 0;
|
||||||
|
int usedCommentCount = 0;
|
||||||
|
int canUseComentCount = 0;
|
||||||
|
int addCommentCount = 0;
|
||||||
// 获取产品ID
|
// 获取产品ID
|
||||||
getProductTypeMap();
|
getProductTypeMap();
|
||||||
String product_id = productTypeMap.get(productType);
|
String product_id = productTypeMap.get(productType);
|
||||||
@@ -1694,6 +1687,10 @@ public class JDUtil {
|
|||||||
|
|
||||||
// 从数据库获取可用评论
|
// 从数据库获取可用评论
|
||||||
List<Comment> availableComments = commentRepository.findByProductIdAndIsUseNotAndPictureUrlsIsNotNull(product_id, 1);
|
List<Comment> availableComments = commentRepository.findByProductIdAndIsUseNotAndPictureUrlsIsNotNull(product_id, 1);
|
||||||
|
List<Comment> usedComments = commentRepository.findByProductIdAndIsUseNotAndPictureUrlsIsNotNull(product_id, 0);
|
||||||
|
canUseComentCount = availableComments.size();
|
||||||
|
usedCommentCount = usedComments.size();
|
||||||
|
|
||||||
|
|
||||||
Comment commentToUse = null;
|
Comment commentToUse = null;
|
||||||
|
|
||||||
@@ -1716,6 +1713,7 @@ public class JDUtil {
|
|||||||
// ✅ 关键修改:重新从数据库中查询,而不是使用内存中的 fetchedComments
|
// ✅ 关键修改:重新从数据库中查询,而不是使用内存中的 fetchedComments
|
||||||
availableComments = commentRepository.findByProductIdAndIsUseNotAndPictureUrlsIsNotNull(product_id, 1);
|
availableComments = commentRepository.findByProductIdAndIsUseNotAndPictureUrlsIsNotNull(product_id, 1);
|
||||||
if (!availableComments.isEmpty()) {
|
if (!availableComments.isEmpty()) {
|
||||||
|
addCommentCount = canUseComentCount - availableComments.size();
|
||||||
Collections.shuffle(availableComments);
|
Collections.shuffle(availableComments);
|
||||||
commentToUse = availableComments.get(0);
|
commentToUse = availableComments.get(0);
|
||||||
}
|
}
|
||||||
@@ -1749,15 +1747,17 @@ public class JDUtil {
|
|||||||
StringBuilder deepSeekPrompt = new StringBuilder(COMMENT_TEMPLATES_DS + commentToUse.getCommentText());
|
StringBuilder deepSeekPrompt = new StringBuilder(COMMENT_TEMPLATES_DS + commentToUse.getCommentText());
|
||||||
//String deepSeekResponse = "";
|
//String deepSeekResponse = "";
|
||||||
String gptResponse = "";
|
String gptResponse = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//deepSeekResponse = deepSeekClientUtil.getDeepSeekResponse(deepSeekPrompt);
|
//deepSeekResponse = deepSeekClientUtil.getDeepSeekResponse(deepSeekPrompt);
|
||||||
List<Comment> comments = commentRepository.findByProductIdAndPictureUrlsIsNotNull(product_id);
|
List<Comment> comments = commentRepository.findByProductIdAndPictureUrlsIsNotNull(product_id);
|
||||||
|
allCommentCount = comments.size();
|
||||||
// 随机截取至多10个
|
// 随机截取至多10个
|
||||||
comments = comments.subList(0, Math.min(10, comments.size()));
|
comments = comments.subList(0, Math.min(10, comments.size()));
|
||||||
for (Comment comment : comments) {
|
for (Comment comment : comments) {
|
||||||
String commentText = comment.getCommentText();
|
String commentText = comment.getCommentText();
|
||||||
if (commentText != null && !commentText.isEmpty()) {
|
if (commentText != null && !commentText.isEmpty()) {
|
||||||
deepSeekPrompt.append("\n" ).append(commentText);
|
deepSeekPrompt.append("\n").append(commentText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gptResponse = gptClientUtil.getGPTResponse(deepSeekPrompt.toString());
|
gptResponse = gptClientUtil.getGPTResponse(deepSeekPrompt.toString());
|
||||||
@@ -1766,9 +1766,8 @@ public class JDUtil {
|
|||||||
wxUtil.sendTextMessage(fromWxid, "AI 评论生成失败", 1, fromWxid, false);
|
wxUtil.sendTextMessage(fromWxid, "AI 评论生成失败", 1, fromWxid, false);
|
||||||
}
|
}
|
||||||
// 发送生成的评论文本
|
// 发送生成的评论文本
|
||||||
//wxUtil.sendTextMessage(fromWxid, "DS回复:\n" + deepSeekResponse, 1, fromWxid, true);
|
|
||||||
wxUtil.sendTextMessage(fromWxid, "GPT回复:\n" + gptResponse, 1, fromWxid, true);
|
wxUtil.sendTextMessage(fromWxid, "GPT回复:\n" + gptResponse, 1, fromWxid, true);
|
||||||
|
wxUtil.sendTextMessage(fromWxid, "评论统计:\n" + "型号 " + productType + "\n" + "新增:" + addCommentCount + "\n" + "已使用:" + usedCommentCount + "\n" + "可用:" + canUseComentCount + "\n" + "总数:" + allCommentCount, 1, fromWxid, true);
|
||||||
// 更新评论状态为已使用
|
// 更新评论状态为已使用
|
||||||
commentToUse.setIsUse(1);
|
commentToUse.setIsUse(1);
|
||||||
commentRepository.save(commentToUse);
|
commentRepository.save(commentToUse);
|
||||||
|
|||||||
Reference in New Issue
Block a user