|
|
@@ -1,19 +1,25 @@
|
|
|
package shop.alien.store.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.multipart.MultipartRequest;
|
|
|
import shop.alien.entity.store.*;
|
|
|
+import shop.alien.entity.store.vo.LifeCouponVo;
|
|
|
+import shop.alien.entity.store.vo.StoreCommentAppealVo;
|
|
|
import shop.alien.entity.store.vo.StoreCommentVo;
|
|
|
import shop.alien.entity.store.vo.StoreCommitPercentVo;
|
|
|
import shop.alien.mapper.*;
|
|
|
@@ -22,6 +28,9 @@ import shop.alien.store.util.FileUploadUtil;
|
|
|
import shop.alien.util.common.DateUtils;
|
|
|
import shop.alien.util.common.netease.ImageCheckUtil;
|
|
|
import shop.alien.util.common.netease.TextCheckUtil;
|
|
|
+import shop.alien.util.common.safe.TextModerationResultVO;
|
|
|
+import shop.alien.util.common.safe.TextModerationUtil;
|
|
|
+import shop.alien.util.common.safe.TextReviewServiceEnum;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
@@ -55,6 +64,13 @@ public class StoreCommentServiceImpl extends ServiceImpl<StoreCommentMapper, Sto
|
|
|
|
|
|
private final LifeUserMapper lifeUserMapper;
|
|
|
|
|
|
+ private final StoreCommentAppealMapper storeCommentAppealMapper;
|
|
|
+
|
|
|
+ private final StoreInfoMapper storeInfoMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TextModerationUtil textModerationUtil;
|
|
|
+
|
|
|
/**
|
|
|
* 评论列表
|
|
|
*
|
|
|
@@ -78,11 +94,11 @@ public class StoreCommentServiceImpl extends ServiceImpl<StoreCommentMapper, Sto
|
|
|
queryWrapper.eq(null != businessType, "a.business_type", businessType);
|
|
|
queryWrapper.eq(null != storeId, "a.store_id", storeId);
|
|
|
//好评 a>=4
|
|
|
- queryWrapper.ge(null != commentLevel && 1 == commentLevel, "a.score", 4);
|
|
|
+ queryWrapper.ge(null != commentLevel && 1 == commentLevel, "a.score", 4.5);
|
|
|
//中评 a>=2&& a<4
|
|
|
- queryWrapper.ge(null != commentLevel && 2 == commentLevel, "a.score", 3).lt(null != commentLevel && 2 == commentLevel, "a.score", 4);
|
|
|
+ queryWrapper.ge(null != commentLevel && 2 == commentLevel, "a.score", 3).le(null != commentLevel && 2 == commentLevel, "a.score", 4);
|
|
|
//差评 a<2
|
|
|
- queryWrapper.lt(null != commentLevel && 3 == commentLevel, "a.score", 2);
|
|
|
+ queryWrapper.ge(null != commentLevel && 3 == commentLevel, "a.score", 0.5).le(null != commentLevel && 3 == commentLevel, "a.score", 2.5);
|
|
|
if (null != days) {
|
|
|
Date date = DateUtils.calcDays(new Date(), -days);
|
|
|
queryWrapper.ge("a.created_time", DateUtils.formatDate(date, "yyyy-MM-dd"));
|
|
|
@@ -148,6 +164,17 @@ public class StoreCommentServiceImpl extends ServiceImpl<StoreCommentMapper, Sto
|
|
|
//低分
|
|
|
storeCommentVo.setLowScore(records.get(i).getScore() <= 1);
|
|
|
storeCommentVoList.add(storeCommentVo);
|
|
|
+
|
|
|
+ QueryWrapper<StoreCommentAppealVo> storeCommentAppealVoQueryWrapper = new QueryWrapper<>();
|
|
|
+ storeCommentAppealVoQueryWrapper.eq("a.comment_id", storeCommentVo.getId()).eq("a.delete_flag", 0).orderByDesc("a.created_time").last("limit 1");
|
|
|
+ StoreCommentAppealVo commentDetail = storeCommentAppealMapper.getCommentDetail(storeCommentAppealVoQueryWrapper);
|
|
|
+ if (ObjectUtils.isNotEmpty(commentDetail)) {
|
|
|
+ storeCommentVo.setAppealFlag(1);
|
|
|
+ storeCommentVo.setAppealStatusStr(commentDetail.getAppealStatusStr());
|
|
|
+ storeCommentVo.setAppealStatus(commentDetail.getAppealStatus());
|
|
|
+ }else {
|
|
|
+ storeCommentVo.setAppealFlag(0);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//塞图片
|
|
|
@@ -233,10 +260,10 @@ public class StoreCommentServiceImpl extends ServiceImpl<StoreCommentMapper, Sto
|
|
|
if (replyStatus != null) {
|
|
|
if (1 == replyStatus) {
|
|
|
//只查询有回复的评论
|
|
|
- collect = storeCommentVoList.stream().filter(storeCommentVo -> !storeCommentVo.getStoreComment().isEmpty()).collect(Collectors.toList());
|
|
|
+ collect = storeCommentVoList.stream().filter(storeCommentVo -> ObjectUtils.isNotEmpty(storeCommentVo.getStoreComment())).collect(Collectors.toList());
|
|
|
} else if (2 == replyStatus) {
|
|
|
//只查询无回复的评论
|
|
|
- collect = storeCommentVoList.stream().filter(storeCommentVo -> storeCommentVo.getStoreComment().isEmpty()).collect(Collectors.toList());
|
|
|
+ collect = storeCommentVoList.stream().filter(storeCommentVo -> ObjectUtils.isEmpty(storeCommentVo.getStoreComment())).collect(Collectors.toList());
|
|
|
} else {
|
|
|
collect = storeCommentVoList;
|
|
|
}
|
|
|
@@ -482,10 +509,18 @@ public class StoreCommentServiceImpl extends ServiceImpl<StoreCommentMapper, Sto
|
|
|
@Override
|
|
|
public Integer addComment(MultipartRequest multipartRequest, Integer id, Integer businessId, Integer businessType, Integer storeId, Integer userId, Integer replyId, String commentContent, Double score, String otherScore, Integer isAnonymous, String evaluationTags, String phoneId) {
|
|
|
try {
|
|
|
- Map<String, String> checkText = TextCheckUtil.check(commentContent);
|
|
|
- if (null == checkText || checkText.get("result").equals("1")) {
|
|
|
+ List<String> servicesList = Lists.newArrayList();
|
|
|
+ servicesList.add(TextReviewServiceEnum.COMMENT_DETECTION_PRO.getService());
|
|
|
+ servicesList.add(TextReviewServiceEnum.LLM_QUERY_MODERATION.getService());
|
|
|
+ TextModerationResultVO textCheckResult = textModerationUtil.invokeFunction(commentContent, servicesList);
|
|
|
+ if ("high".equals(textCheckResult.getRiskLevel())) {
|
|
|
return 2;
|
|
|
}
|
|
|
+
|
|
|
+ /*Map<String, String> checkText = TextCheckUtil.check(commentContent);
|
|
|
+ if (null == checkText || checkText.get("result").equals("1")) {
|
|
|
+ return 2;
|
|
|
+ }*/
|
|
|
StoreComment storeComment = new StoreComment();
|
|
|
storeComment.setId(id);
|
|
|
storeComment.setStoreId(storeId);
|
|
|
@@ -495,6 +530,13 @@ public class StoreCommentServiceImpl extends ServiceImpl<StoreCommentMapper, Sto
|
|
|
storeComment.setBusinessId(businessId);
|
|
|
storeComment.setBusinessType(businessType);
|
|
|
storeComment.setScore(score);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(otherScore)) {
|
|
|
+ List<LifeCouponVo> lifeCouponVos = JSONArray.parseArray(otherScore, LifeCouponVo.class);
|
|
|
+ lifeCouponVos.stream().filter(i -> "口味".equals(i.getName())).findFirst().ifPresent(item -> storeComment.setTasteScore(Double.valueOf(item.getRateScore())));
|
|
|
+ lifeCouponVos.stream().filter(i -> "环境".equals(i.getName())).findFirst().ifPresent(item -> storeComment.setEnScore(Double.valueOf(item.getRateScore())));
|
|
|
+ lifeCouponVos.stream().filter(i -> "服务".equals(i.getName())).findFirst().ifPresent(item -> storeComment.setServiceScore(Double.valueOf(item.getRateScore())));
|
|
|
+ }
|
|
|
storeComment.setOtherScore(otherScore);
|
|
|
storeComment.setIsAnonymous(isAnonymous);
|
|
|
storeComment.setEvaluationTags(evaluationTags);
|
|
|
@@ -534,6 +576,21 @@ public class StoreCommentServiceImpl extends ServiceImpl<StoreCommentMapper, Sto
|
|
|
}
|
|
|
}
|
|
|
storeComment.setCreatedUserId(storeComment.getUserId());
|
|
|
+
|
|
|
+ Map<String, String> commentCountAndScore = storeCommentMapper.getCommentCountAndScore(storeId);
|
|
|
+ double total = StringUtils.isNotEmpty(commentCountAndScore.get("total")) ? Double.parseDouble(commentCountAndScore.get("total")) : 0;
|
|
|
+ double scoreAvg = StringUtils.isNotEmpty(commentCountAndScore.get("score")) ? Double.parseDouble(commentCountAndScore.get("score")) / total : 0;
|
|
|
+ double tasteScore = StringUtils.isNotEmpty(commentCountAndScore.get("tasteScore")) ? Double.parseDouble(commentCountAndScore.get("tasteScore")) / total : 0;
|
|
|
+ double enScore = StringUtils.isNotEmpty(commentCountAndScore.get("enScore")) ? Double.parseDouble(commentCountAndScore.get("enScore")) / total : 0;
|
|
|
+ double serviceScore = StringUtils.isNotEmpty(commentCountAndScore.get("serviceScore")) ? Double.parseDouble(commentCountAndScore.get("serviceScore")) / total : 0;
|
|
|
+ StoreInfo storeInfo = new StoreInfo();
|
|
|
+ storeInfo.setId(storeId);
|
|
|
+ storeInfo.setScoreAvg(scoreAvg);
|
|
|
+ storeInfo.setTasteScore(tasteScore);
|
|
|
+ storeInfo.setEnScore(enScore);
|
|
|
+ storeInfo.setServiceScore(serviceScore);
|
|
|
+ storeInfoMapper.updateById(storeInfo);
|
|
|
+
|
|
|
return this.save(storeComment) ? 0 : 1;
|
|
|
} catch (Exception e) {
|
|
|
log.error("StoreCommentService.userComment ERROR Msg={}", e.getMessage());
|