|
|
@@ -21,7 +21,6 @@ import shop.alien.entity.result.R;
|
|
|
import shop.alien.entity.store.*;
|
|
|
import shop.alien.entity.store.vo.CommonCommentVo;
|
|
|
import shop.alien.entity.store.vo.CommonRatingVo;
|
|
|
-import shop.alien.entity.store.vo.RatingPercentVo;
|
|
|
import shop.alien.entity.store.vo.StoreInfoScoreVo;
|
|
|
import shop.alien.entity.store.vo.WebSocketVo;
|
|
|
import shop.alien.mapper.*;
|
|
|
@@ -72,6 +71,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
private final LifeFansMapper lifeFansMapper;
|
|
|
private final TagsSynonymMapper tagsSynonymMapper;
|
|
|
private final CommonCommentService commonCommentService;
|
|
|
+ private final StoreCommentAppealMapper storeCommentAppealMapper;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -348,6 +348,30 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
ratingCount.put("img", new ArrayList<>());
|
|
|
}
|
|
|
|
|
|
+ // 4. 计算回复率(已回复的评价数 / 总评价数)
|
|
|
+ LambdaQueryWrapper<CommonComment> repliedWrapper = new LambdaQueryWrapper<>();
|
|
|
+ repliedWrapper.eq(CommonComment::getSourceType, CommentSourceTypeEnum.STORE_COMMENT.getType())
|
|
|
+ .in(CommonComment::getSourceId, collect)
|
|
|
+ .eq(CommonComment::getCommentType, 2) // 商户评论
|
|
|
+ .eq(CommonComment::getParentId, 0) // 根评论(直接回复评价)
|
|
|
+ .eq(CommonComment::getDeleteFlag, 0); // 未删除
|
|
|
+
|
|
|
+ // 获取已回复的评价ID列表(去重)
|
|
|
+ Set<Long> repliedRatingIds = commonCommentMapper.selectList(repliedWrapper).stream()
|
|
|
+ .map(CommonComment::getSourceId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ int repliedCount = repliedRatingIds.size();
|
|
|
+ ratingCount.put("repliedCount", repliedCount);
|
|
|
+
|
|
|
+ // 计算回复率(保留2位小数)
|
|
|
+ Double replyRate = 0.0;
|
|
|
+ int ratingTotalCount = collect.size();
|
|
|
+ if (ratingTotalCount > 0) {
|
|
|
+ replyRate = Math.round((repliedCount * 100.0 / ratingTotalCount) * 100.0) / 100.0;
|
|
|
+ }
|
|
|
+ ratingCount.put("replyRate", replyRate);
|
|
|
|
|
|
}
|
|
|
return ratingCount;
|
|
|
@@ -551,7 +575,44 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 4. 组装评价列表数据
|
|
|
+ // 4. 查询申诉信息(关联 store_comment_appeal 表)
|
|
|
+ Map<Long, StoreCommentAppeal> appealMap = new HashMap<>();
|
|
|
+ if (!ratingIdSet.isEmpty()) {
|
|
|
+ // 将 Long 类型的评价ID转换为 Integer 类型(因为 comment_id 是 Integer)
|
|
|
+ List<Integer> ratingIdList = ratingIdSet.stream()
|
|
|
+ .map(Long::intValue)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 查询申诉记录(comment_id 关联 common_rating.id)
|
|
|
+ LambdaQueryWrapper<StoreCommentAppeal> appealWrapper = new LambdaQueryWrapper<>();
|
|
|
+ appealWrapper.in(StoreCommentAppeal::getCommentId, ratingIdList)
|
|
|
+ .eq(StoreCommentAppeal::getDeleteFlag, 0);
|
|
|
+ List<StoreCommentAppeal> appeals = storeCommentAppealMapper.selectList(appealWrapper);
|
|
|
+
|
|
|
+ // 构建评价ID -> 申诉记录的映射(一个评价可能有多条申诉,取最新的一条)
|
|
|
+ if (CollectionUtils.isNotEmpty(appeals)) {
|
|
|
+ // 按评价ID分组,每组只取最新的一条申诉记录
|
|
|
+ Map<Integer, StoreCommentAppeal> tempAppealMap = new HashMap<>();
|
|
|
+ for (StoreCommentAppeal appeal : appeals) {
|
|
|
+ Integer commentId = appeal.getCommentId();
|
|
|
+ if (commentId != null) {
|
|
|
+ // 如果该评价还没有申诉记录,或者当前申诉记录更新,则更新
|
|
|
+ if (!tempAppealMap.containsKey(commentId) ||
|
|
|
+ (appeal.getUpdatedTime() != null &&
|
|
|
+ tempAppealMap.get(commentId).getUpdatedTime() != null &&
|
|
|
+ appeal.getUpdatedTime().after(tempAppealMap.get(commentId).getUpdatedTime()))) {
|
|
|
+ tempAppealMap.put(commentId, appeal);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 转换为 Long 类型的 key
|
|
|
+ for (Map.Entry<Integer, StoreCommentAppeal> entry : tempAppealMap.entrySet()) {
|
|
|
+ appealMap.put(entry.getKey().longValue(), entry.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 组装评价列表数据
|
|
|
for (CommonRating record : page1.getRecords()) {
|
|
|
CommonRatingVo commonRatingVo = new CommonRatingVo();
|
|
|
BeanUtil.copyProperties(record, commonRatingVo);
|
|
|
@@ -582,6 +643,18 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
commonRatingVo.setChildCommonComments(new ArrayList<>());
|
|
|
}
|
|
|
|
|
|
+ // 设置申诉状态和申诉标识
|
|
|
+ StoreCommentAppeal appeal = appealMap.get(record.getId());
|
|
|
+ if (appeal != null) {
|
|
|
+ // 已申诉,设置申诉状态
|
|
|
+ commonRatingVo.setAppealStatus(appeal.getAppealStatus());
|
|
|
+ commonRatingVo.setAppealFlag(1);
|
|
|
+ } else {
|
|
|
+ // 未申诉
|
|
|
+ commonRatingVo.setAppealStatus(null);
|
|
|
+ commonRatingVo.setAppealFlag(0);
|
|
|
+ }
|
|
|
+
|
|
|
resultList.add(commonRatingVo);
|
|
|
}
|
|
|
|
|
|
@@ -647,106 +720,5 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取回复率和评价比例
|
|
|
- *
|
|
|
- * @param businessId 业务ID(店铺ID)
|
|
|
- * @param businessType 业务类型:1-店铺评价
|
|
|
- * @return 回复率和评价比例信息
|
|
|
- */
|
|
|
- @Override
|
|
|
- public RatingPercentVo getRatingPercent(Integer businessId, Integer businessType) {
|
|
|
- log.info("CommonRatingServiceImpl.getRatingPercent?businessId={}&businessType={}", businessId, businessType);
|
|
|
-
|
|
|
- RatingPercentVo vo = new RatingPercentVo();
|
|
|
-
|
|
|
- // 1. 查询全部评价记录(仅展示的、审核通过的)
|
|
|
- LambdaQueryWrapper<CommonRating> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(CommonRating::getBusinessId, businessId);
|
|
|
- wrapper.eq(CommonRating::getBusinessType, businessType);
|
|
|
- wrapper.eq(CommonRating::getIsShow, 1);
|
|
|
- wrapper.eq(CommonRating::getAuditStatus, 1); // 仅统计审核通过的
|
|
|
- List<CommonRating> commonRatings = commonRatingMapper.selectList(wrapper);
|
|
|
-
|
|
|
- // 如果为空,返回默认值
|
|
|
- if (CollectionUtils.isEmpty(commonRatings)) {
|
|
|
- vo.setTotalRatingCount(0);
|
|
|
- vo.setGoodCount(0);
|
|
|
- vo.setMidCount(0);
|
|
|
- vo.setBadCount(0);
|
|
|
- vo.setGoodPercent(0.0);
|
|
|
- vo.setMidPercent(0.0);
|
|
|
- vo.setBadPercent(0.0);
|
|
|
- vo.setRepliedCount(0);
|
|
|
- vo.setReplyRate(0.0);
|
|
|
- return vo;
|
|
|
- }
|
|
|
-
|
|
|
- List<Long> ratingIdList = commonRatings.stream()
|
|
|
- .map(CommonRating::getId)
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- // 2. 获取评价统计信息(好评、中评、差评数量)
|
|
|
- Map<String, Object> ratingCount = commonRatingMapper.getRatingCount(
|
|
|
- new QueryWrapper<CommonRating>().in("id", ratingIdList));
|
|
|
-
|
|
|
- // 3. 计算好评、中评、差评数量和占比
|
|
|
- int goodCount = getIntValue(ratingCount.get("goodCount"));
|
|
|
- int midCount = getIntValue(ratingCount.get("midCount"));
|
|
|
- int badCount = getIntValue(ratingCount.get("badCount"));
|
|
|
- int totalCount = goodCount + midCount + badCount;
|
|
|
-
|
|
|
- vo.setTotalRatingCount(totalCount);
|
|
|
- vo.setGoodCount(goodCount);
|
|
|
- vo.setMidCount(midCount);
|
|
|
- vo.setBadCount(badCount);
|
|
|
-
|
|
|
- // 计算占比(保留2位小数)
|
|
|
- if (totalCount > 0) {
|
|
|
- Double goodPercent = Math.round((goodCount * 100.0 / totalCount) * 100.0) / 100.0;
|
|
|
- Double midPercent = Math.round((midCount * 100.0 / totalCount) * 100.0) / 100.0;
|
|
|
- Double badPercent = Math.round((badCount * 100.0 / totalCount) * 100.0) / 100.0;
|
|
|
-
|
|
|
- vo.setGoodPercent(goodPercent);
|
|
|
- vo.setMidPercent(midPercent);
|
|
|
- vo.setBadPercent(badPercent);
|
|
|
- } else {
|
|
|
- vo.setGoodPercent(0.0);
|
|
|
- vo.setMidPercent(0.0);
|
|
|
- vo.setBadPercent(0.0);
|
|
|
- }
|
|
|
-
|
|
|
- // 4. 计算回复率
|
|
|
- // 查询已回复的评价数(存在商户评论 comment_type=2, parent_id=0)
|
|
|
- LambdaQueryWrapper<CommonComment> repliedWrapper = new LambdaQueryWrapper<>();
|
|
|
- repliedWrapper.eq(CommonComment::getSourceType, CommentSourceTypeEnum.STORE_COMMENT.getType())
|
|
|
- .in(CommonComment::getSourceId, ratingIdList)
|
|
|
- .eq(CommonComment::getCommentType, 2) // 商户评论
|
|
|
- .eq(CommonComment::getParentId, 0) // 根评论(直接回复评价)
|
|
|
- .eq(CommonComment::getIsShow, 1)
|
|
|
- .eq(CommonComment::getAuditStatus, 1);
|
|
|
-
|
|
|
- // 获取已回复的评价ID列表(去重)
|
|
|
- Set<Long> repliedRatingIds = commonCommentMapper.selectList(repliedWrapper).stream()
|
|
|
- .map(CommonComment::getSourceId)
|
|
|
- .filter(Objects::nonNull)
|
|
|
- .collect(Collectors.toSet());
|
|
|
-
|
|
|
- int repliedCount = repliedRatingIds.size();
|
|
|
- vo.setRepliedCount(repliedCount);
|
|
|
-
|
|
|
- // 计算回复率(保留2位小数)
|
|
|
- Double replyRate = 0.0;
|
|
|
- if (totalCount > 0) {
|
|
|
- replyRate = Math.round((repliedCount * 100.0 / totalCount) * 100.0) / 100.0;
|
|
|
- }
|
|
|
- vo.setReplyRate(replyRate);
|
|
|
-
|
|
|
- log.info("CommonRatingServiceImpl.getRatingPercent result: totalCount={}, goodCount={}, midCount={}, badCount={}, repliedCount={}, replyRate={}%",
|
|
|
- totalCount, goodCount, midCount, badCount, repliedCount, replyRate);
|
|
|
-
|
|
|
- return vo;
|
|
|
- }
|
|
|
}
|
|
|
|