|
@@ -27,6 +27,7 @@ import shop.alien.entity.store.vo.WebSocketVo;
|
|
|
import shop.alien.mapper.*;
|
|
import shop.alien.mapper.*;
|
|
|
import shop.alien.entity.store.TagsSynonym;
|
|
import shop.alien.entity.store.TagsSynonym;
|
|
|
import shop.alien.store.config.WebSocketProcess;
|
|
import shop.alien.store.config.WebSocketProcess;
|
|
|
|
|
+import shop.alien.store.service.CommonCommentService;
|
|
|
import shop.alien.store.service.CommonRatingService;
|
|
import shop.alien.store.service.CommonRatingService;
|
|
|
import shop.alien.store.util.CommonConstant;
|
|
import shop.alien.store.util.CommonConstant;
|
|
|
import shop.alien.util.common.constant.CommentSourceTypeEnum;
|
|
import shop.alien.util.common.constant.CommentSourceTypeEnum;
|
|
@@ -70,6 +71,8 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
private final LifeCollectMapper lifeCollectMapper;
|
|
private final LifeCollectMapper lifeCollectMapper;
|
|
|
private final LifeFansMapper lifeFansMapper;
|
|
private final LifeFansMapper lifeFansMapper;
|
|
|
private final TagsSynonymMapper tagsSynonymMapper;
|
|
private final TagsSynonymMapper tagsSynonymMapper;
|
|
|
|
|
+ private final CommonCommentService commonCommentService;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final List<String> SERVICES_LIST = ImmutableList.of(
|
|
public static final List<String> SERVICES_LIST = ImmutableList.of(
|
|
@@ -220,7 +223,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
.eq(TagsSynonym::getDeleteFlag, 0)
|
|
.eq(TagsSynonym::getDeleteFlag, 0)
|
|
|
.isNotNull(TagsSynonym::getCommentId); // 确保comment_id不为空
|
|
.isNotNull(TagsSynonym::getCommentId); // 确保comment_id不为空
|
|
|
List<TagsSynonym> tagsSynonymList = tagsSynonymMapper.selectList(tagWrapper);
|
|
List<TagsSynonym> tagsSynonymList = tagsSynonymMapper.selectList(tagWrapper);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (CollectionUtils.isNotEmpty(tagsSynonymList)) {
|
|
if (CollectionUtils.isNotEmpty(tagsSynonymList)) {
|
|
|
// 2. 提取评论ID列表(common_comment.id)
|
|
// 2. 提取评论ID列表(common_comment.id)
|
|
|
List<Long> commentIdList = tagsSynonymList.stream()
|
|
List<Long> commentIdList = tagsSynonymList.stream()
|
|
@@ -228,7 +231,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
.map(synonym -> synonym.getCommentId().longValue())
|
|
.map(synonym -> synonym.getCommentId().longValue())
|
|
|
.distinct()
|
|
.distinct()
|
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (CollectionUtils.isNotEmpty(commentIdList)) {
|
|
if (CollectionUtils.isNotEmpty(commentIdList)) {
|
|
|
// 3. 通过评论ID查询common_comment表,获取source_id(评价ID)
|
|
// 3. 通过评论ID查询common_comment表,获取source_id(评价ID)
|
|
|
LambdaQueryWrapper<CommonComment> commentWrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<CommonComment> commentWrapper = new LambdaQueryWrapper<>();
|
|
@@ -237,7 +240,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
.eq(CommonComment::getIsShow, 1)
|
|
.eq(CommonComment::getIsShow, 1)
|
|
|
.eq(CommonComment::getAuditStatus, 1);
|
|
.eq(CommonComment::getAuditStatus, 1);
|
|
|
List<CommonComment> comments = commonCommentMapper.selectList(commentWrapper);
|
|
List<CommonComment> comments = commonCommentMapper.selectList(commentWrapper);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (CollectionUtils.isNotEmpty(comments)) {
|
|
if (CollectionUtils.isNotEmpty(comments)) {
|
|
|
// 4. 提取评价ID列表(common_comment.source_id = common_rating.id)
|
|
// 4. 提取评价ID列表(common_comment.source_id = common_rating.id)
|
|
|
List<Long> ratingIdList = comments.stream()
|
|
List<Long> ratingIdList = comments.stream()
|
|
@@ -245,7 +248,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
.map(CommonComment::getSourceId)
|
|
.map(CommonComment::getSourceId)
|
|
|
.distinct()
|
|
.distinct()
|
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (CollectionUtils.isNotEmpty(ratingIdList)) {
|
|
if (CollectionUtils.isNotEmpty(ratingIdList)) {
|
|
|
wrapper.in(CommonRating::getId, ratingIdList);
|
|
wrapper.in(CommonRating::getId, ratingIdList);
|
|
|
} else {
|
|
} else {
|
|
@@ -265,11 +268,11 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
wrapper.eq(CommonRating::getId, -1);
|
|
wrapper.eq(CommonRating::getId, -1);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
wrapper.eq(CommonRating::getIsShow, 1);
|
|
wrapper.eq(CommonRating::getIsShow, 1);
|
|
|
wrapper.orderByDesc(CommonRating::getId);
|
|
wrapper.orderByDesc(CommonRating::getId);
|
|
|
IPage<CommonRating> page1 = this.page(page, wrapper);
|
|
IPage<CommonRating> page1 = this.page(page, wrapper);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 处理回复状态筛选
|
|
// 处理回复状态筛选
|
|
|
return doListBusinessWithType(page1, businessType, userId, replyStatus);
|
|
return doListBusinessWithType(page1, businessType, userId, replyStatus);
|
|
|
}
|
|
}
|
|
@@ -290,20 +293,20 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
}
|
|
}
|
|
|
// 获取评价统计信息(总评论数、有图评论数、好评数、中评数、差评数)
|
|
// 获取评价统计信息(总评论数、有图评论数、好评数、中评数、差评数)
|
|
|
ratingCount = commonRatingMapper.getRatingCount(new QueryWrapper<CommonRating>().in("id", collect));
|
|
ratingCount = commonRatingMapper.getRatingCount(new QueryWrapper<CommonRating>().in("id", collect));
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 计算好评、中评、差评占比
|
|
// 计算好评、中评、差评占比
|
|
|
// 注意:数据库返回的 count 可能是 BigDecimal、Long 或 Integer 类型,需要安全转换
|
|
// 注意:数据库返回的 count 可能是 BigDecimal、Long 或 Integer 类型,需要安全转换
|
|
|
int goodCount = getIntValue(ratingCount.get("goodCount"));
|
|
int goodCount = getIntValue(ratingCount.get("goodCount"));
|
|
|
int midCount = getIntValue(ratingCount.get("midCount"));
|
|
int midCount = getIntValue(ratingCount.get("midCount"));
|
|
|
int badCount = getIntValue(ratingCount.get("badCount"));
|
|
int badCount = getIntValue(ratingCount.get("badCount"));
|
|
|
int totalCount = goodCount + midCount + badCount;
|
|
int totalCount = goodCount + midCount + badCount;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (totalCount > 0) {
|
|
if (totalCount > 0) {
|
|
|
// 计算占比(保留2位小数)
|
|
// 计算占比(保留2位小数)
|
|
|
Double goodPercent = Math.round((goodCount * 100.0 / totalCount) * 100.0) / 100.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 midPercent = Math.round((midCount * 100.0 / totalCount) * 100.0) / 100.0;
|
|
|
Double badPercent = Math.round((badCount * 100.0 / totalCount) * 100.0) / 100.0;
|
|
Double badPercent = Math.round((badCount * 100.0 / totalCount) * 100.0) / 100.0;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
ratingCount.put("goodPercent", goodPercent);
|
|
ratingCount.put("goodPercent", goodPercent);
|
|
|
ratingCount.put("midPercent", midPercent);
|
|
ratingCount.put("midPercent", midPercent);
|
|
|
ratingCount.put("badPercent", badPercent);
|
|
ratingCount.put("badPercent", badPercent);
|
|
@@ -312,7 +315,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
ratingCount.put("midPercent", 0.0);
|
|
ratingCount.put("midPercent", 0.0);
|
|
|
ratingCount.put("badPercent", 0.0);
|
|
ratingCount.put("badPercent", 0.0);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if(RatingBusinessTypeEnum.STORE_RATING.getBusinessType() == businessType){
|
|
if(RatingBusinessTypeEnum.STORE_RATING.getBusinessType() == businessType){
|
|
|
// 1店铺评分
|
|
// 1店铺评分
|
|
|
StoreInfo storeInfo = storeInfoMapper.selectById(businessId);
|
|
StoreInfo storeInfo = storeInfoMapper.selectById(businessId);
|
|
@@ -338,7 +341,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
List<Long> collect2 = commonRatings.stream().filter(i -> i.getScore() >= 4.5).map(CommonRating::getUserId).distinct().limit(6).collect(Collectors.toList());
|
|
List<Long> collect2 = commonRatings.stream().filter(i -> i.getScore() >= 4.5).map(CommonRating::getUserId).distinct().limit(6).collect(Collectors.toList());
|
|
|
if(!collect2.isEmpty()) {
|
|
if(!collect2.isEmpty()) {
|
|
|
List<LifeUser> lifeUsers = lifeUserMapper.selectList(new QueryWrapper<LifeUser>().lambda().in(LifeUser::getId, collect2));
|
|
List<LifeUser> lifeUsers = lifeUserMapper.selectList(new QueryWrapper<LifeUser>().lambda().in(LifeUser::getId, collect2));
|
|
|
- ratingCount.put("img", lifeUsers.stream().filter(x -> x.getUserImage() != null).map(LifeUser::getUserImage).collect(Collectors.toList()));
|
|
|
|
|
|
|
+ ratingCount.put("img", lifeUsers.stream().map(LifeUser::getUserImage).collect(Collectors.toList()));
|
|
|
} else {
|
|
} else {
|
|
|
ratingCount.put("img", new ArrayList<>());
|
|
ratingCount.put("img", new ArrayList<>());
|
|
|
}
|
|
}
|
|
@@ -435,64 +438,11 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
commonRatingVo.setIsCollect(0);
|
|
commonRatingVo.setIsCollect(0);
|
|
|
}
|
|
}
|
|
|
// 2查询一级评价
|
|
// 2查询一级评价
|
|
|
- QueryWrapper<CommonCommentVo> commentWrapper = new QueryWrapper<CommonCommentVo>()
|
|
|
|
|
- .eq("cc.source_type", CommentSourceTypeEnum.STORE_COMMENT.getType())
|
|
|
|
|
- .eq("cc.source_id", ratingId)
|
|
|
|
|
- .eq("cc.parent_id", 0);
|
|
|
|
|
- List<CommonCommentVo> commonComments = commonCommentMapper.selectALlComment(commentWrapper,CommonConstant.COMMENT_LIKE, userId);
|
|
|
|
|
-
|
|
|
|
|
- // 定义评论总数
|
|
|
|
|
- AtomicReference<Long> count = new AtomicReference<>(0L);
|
|
|
|
|
- count.updateAndGet(v -> v + commonComments.size());
|
|
|
|
|
- List<CommonCommentVo> commonCommentVos = new ArrayList<>();
|
|
|
|
|
- for (CommonCommentVo commonComment : commonComments) {
|
|
|
|
|
-// CommonCommentVo commonCommentVo = new CommonCommentVo();
|
|
|
|
|
-// BeanUtils.copyProperties(commonComment, commonCommentVo);
|
|
|
|
|
- // 递归获取所有子评论(扁平化)
|
|
|
|
|
- List<CommonCommentVo> allChildComments = getChildCommentsRecursively(commonComment.getId(), userId);
|
|
|
|
|
- count.updateAndGet(v -> v + allChildComments.size());
|
|
|
|
|
- // 一级评论本身的商家/用户标识和商家信息
|
|
|
|
|
- // setStoreUserInfo(first);
|
|
|
|
|
-
|
|
|
|
|
- // 按时间排序后绑定子评论列表
|
|
|
|
|
- allChildComments.sort(Comparator.comparing(CommonCommentVo::getCreatedTime));
|
|
|
|
|
-
|
|
|
|
|
- commonComment.setChildCommonComments(allChildComments);
|
|
|
|
|
- commonCommentVos.add(commonComment);
|
|
|
|
|
- }
|
|
|
|
|
- commonRatingVo.setCommentCount(count.get());
|
|
|
|
|
- commonRatingVo.setChildCommonComments(commonCommentVos);
|
|
|
|
|
|
|
+ List<CommonCommentVo> commonComments = commonCommentService.getFirstLevelComment(CommentSourceTypeEnum.STORE_COMMENT.getType(), ratingId,null,null, userId,CommonConstant.COMMENT_LIKE);
|
|
|
|
|
+ commonCommentService.getAllChildComment(userId, commonRatingVo, commonComments,CommonConstant.COMMENT_LIKE);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private List<CommonCommentVo> getChildCommentsRecursively(Long id, Long userId) {
|
|
|
|
|
- List<CommonCommentVo> allChildComments = new ArrayList<>();
|
|
|
|
|
-
|
|
|
|
|
- // 查询直接回复当前评论的所有记录
|
|
|
|
|
- QueryWrapper<CommonCommentVo> wrapper = new QueryWrapper<>();
|
|
|
|
|
- wrapper.eq("cc.delete_flag", 0)
|
|
|
|
|
- .eq("cc.parent_id", id)
|
|
|
|
|
- .orderByAsc("cc.created_time");
|
|
|
|
|
- List<CommonCommentVo> directChildren = commonCommentMapper.selectALlComment(wrapper,CommonConstant.COMMENT_LIKE, userId);
|
|
|
|
|
-
|
|
|
|
|
- if (CollectionUtils.isEmpty(directChildren)) {
|
|
|
|
|
- return allChildComments;
|
|
|
|
|
- }
|
|
|
|
|
- // 处理每个直接子评论
|
|
|
|
|
- for (CommonCommentVo child : directChildren) {
|
|
|
|
|
- // 设置商家/用户标识
|
|
|
|
|
-// setStoreUserInfo(child);
|
|
|
|
|
- // 递归获取该子评论的所有子评论
|
|
|
|
|
- List<CommonCommentVo> grandChildren = getChildCommentsRecursively(child.getId(), userId);
|
|
|
|
|
- // 将当前子评论添加到结果列表
|
|
|
|
|
- allChildComments.add(child);
|
|
|
|
|
- // 将该子评论的所有子评论也添加到结果列表(扁平化)
|
|
|
|
|
- allChildComments.addAll(grandChildren);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return allChildComments;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
@NotNull
|
|
@NotNull
|
|
|
private Integer getAllCommentsOnCommentsNum(List<Long> collect1) {
|
|
private Integer getAllCommentsOnCommentsNum(List<Long> collect1) {
|
|
|
LambdaQueryWrapper<CommonComment> commentReplyWrapper = new LambdaQueryWrapper<CommonComment>()
|
|
LambdaQueryWrapper<CommonComment> commentReplyWrapper = new LambdaQueryWrapper<CommonComment>()
|
|
@@ -522,7 +472,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
result.setRecords(resultList);
|
|
result.setRecords(resultList);
|
|
|
return R.data(result);
|
|
return R.data(result);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 1. 查询评价用户信息
|
|
// 1. 查询评价用户信息
|
|
|
Set<Long> userIdSet = page1.getRecords().stream()
|
|
Set<Long> userIdSet = page1.getRecords().stream()
|
|
|
.map(CommonRating::getUserId)
|
|
.map(CommonRating::getUserId)
|
|
@@ -536,7 +486,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
lifeUserMap = lifeUsers.stream()
|
|
lifeUserMap = lifeUsers.stream()
|
|
|
.collect(Collectors.toMap(LifeUser::getId, Function.identity()));
|
|
.collect(Collectors.toMap(LifeUser::getId, Function.identity()));
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 2. 查询当前用户点赞列表(仅评价)
|
|
// 2. 查询当前用户点赞列表(仅评价)
|
|
|
List<LifeLikeRecord> lifeLikeRecords = new ArrayList<>();
|
|
List<LifeLikeRecord> lifeLikeRecords = new ArrayList<>();
|
|
|
Map<String, LifeLikeRecord> likeRecordMap = new HashMap<>();
|
|
Map<String, LifeLikeRecord> likeRecordMap = new HashMap<>();
|
|
@@ -553,7 +503,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
Set<Long> ratingIdSet = page1.getRecords().stream()
|
|
Set<Long> ratingIdSet = page1.getRecords().stream()
|
|
|
.map(CommonRating::getId)
|
|
.map(CommonRating::getId)
|
|
|
.collect(Collectors.toSet());
|
|
.collect(Collectors.toSet());
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 查询所有评论(用于统计评论数)
|
|
// 查询所有评论(用于统计评论数)
|
|
|
LambdaQueryWrapper<CommonComment> commentWrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<CommonComment> commentWrapper = new LambdaQueryWrapper<>();
|
|
|
commentWrapper.eq(CommonComment::getSourceType, CommentSourceTypeEnum.STORE_COMMENT.getType())
|
|
commentWrapper.eq(CommonComment::getSourceType, CommentSourceTypeEnum.STORE_COMMENT.getType())
|
|
@@ -561,7 +511,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
.eq(CommonComment::getIsShow, 1)
|
|
.eq(CommonComment::getIsShow, 1)
|
|
|
.eq(CommonComment::getAuditStatus, 1);
|
|
.eq(CommonComment::getAuditStatus, 1);
|
|
|
List<CommonComment> allComments = commonCommentMapper.selectList(commentWrapper);
|
|
List<CommonComment> allComments = commonCommentMapper.selectList(commentWrapper);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 评价ID -> 该评价下的总评论数
|
|
// 评价ID -> 该评价下的总评论数
|
|
|
Map<Long, Long> ratingCommentCountMap = allComments.stream()
|
|
Map<Long, Long> ratingCommentCountMap = allComments.stream()
|
|
|
.collect(Collectors.groupingBy(CommonComment::getSourceId, Collectors.counting()));
|
|
.collect(Collectors.groupingBy(CommonComment::getSourceId, Collectors.counting()));
|
|
@@ -578,14 +528,15 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
.eq("cc.audit_status", 1)
|
|
.eq("cc.audit_status", 1)
|
|
|
.eq("cc.delete_flag", 0)
|
|
.eq("cc.delete_flag", 0)
|
|
|
.orderByDesc("cc.created_time");
|
|
.orderByDesc("cc.created_time");
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 查询所有商户回复(包含用户信息)
|
|
// 查询所有商户回复(包含用户信息)
|
|
|
List<CommonCommentVo> merchantReplies = commonCommentMapper.selectALlComment(
|
|
List<CommonCommentVo> merchantReplies = commonCommentMapper.selectALlComment(
|
|
|
- merchantReplyWrapper,
|
|
|
|
|
- CommonConstant.COMMENT_LIKE,
|
|
|
|
|
|
|
+ null,
|
|
|
|
|
+ merchantReplyWrapper,
|
|
|
|
|
+ CommonConstant.COMMENT_LIKE,
|
|
|
userId != null ? userId : 0L
|
|
userId != null ? userId : 0L
|
|
|
);
|
|
);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 按评价ID分组,每组只取最新的一条(已按时间倒序排序)
|
|
// 按评价ID分组,每组只取最新的一条(已按时间倒序排序)
|
|
|
if (CollectionUtils.isNotEmpty(merchantReplies)) {
|
|
if (CollectionUtils.isNotEmpty(merchantReplies)) {
|
|
|
for (CommonCommentVo reply : merchantReplies) {
|
|
for (CommonCommentVo reply : merchantReplies) {
|
|
@@ -602,23 +553,23 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
for (CommonRating record : page1.getRecords()) {
|
|
for (CommonRating record : page1.getRecords()) {
|
|
|
CommonRatingVo commonRatingVo = new CommonRatingVo();
|
|
CommonRatingVo commonRatingVo = new CommonRatingVo();
|
|
|
BeanUtil.copyProperties(record, commonRatingVo);
|
|
BeanUtil.copyProperties(record, commonRatingVo);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 设置用户信息
|
|
// 设置用户信息
|
|
|
if(lifeUserMap.containsKey(Integer.parseInt(record.getUserId().toString()))){
|
|
if(lifeUserMap.containsKey(Integer.parseInt(record.getUserId().toString()))){
|
|
|
LifeUser lifeUser = lifeUserMap.get(Integer.parseInt(record.getUserId().toString()));
|
|
LifeUser lifeUser = lifeUserMap.get(Integer.parseInt(record.getUserId().toString()));
|
|
|
commonRatingVo.setUserImage(lifeUser.getUserImage());
|
|
commonRatingVo.setUserImage(lifeUser.getUserImage());
|
|
|
commonRatingVo.setUserName(lifeUser.getUserName());
|
|
commonRatingVo.setUserName(lifeUser.getUserName());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 设置点赞状态
|
|
// 设置点赞状态
|
|
|
commonRatingVo.setIsLike(0);
|
|
commonRatingVo.setIsLike(0);
|
|
|
if(likeRecordMap.containsKey(record.getId().toString())){
|
|
if(likeRecordMap.containsKey(record.getId().toString())){
|
|
|
commonRatingVo.setIsLike(1);
|
|
commonRatingVo.setIsLike(1);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 设置评论数
|
|
// 设置评论数
|
|
|
commonRatingVo.setCommentCount(ratingCommentCountMap.getOrDefault(record.getId(), 0L));
|
|
commonRatingVo.setCommentCount(ratingCommentCountMap.getOrDefault(record.getId(), 0L));
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 设置商户最新回复(同一评价下,商家只显示最新的一条回复)
|
|
// 设置商户最新回复(同一评价下,商家只显示最新的一条回复)
|
|
|
CommonCommentVo latestMerchantReply = latestMerchantReplyMap.get(record.getId());
|
|
CommonCommentVo latestMerchantReply = latestMerchantReplyMap.get(record.getId());
|
|
|
if (latestMerchantReply != null) {
|
|
if (latestMerchantReply != null) {
|
|
@@ -628,10 +579,10 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
// 没有商户回复,设置为空列表
|
|
// 没有商户回复,设置为空列表
|
|
|
commonRatingVo.setChildCommonComments(new ArrayList<>());
|
|
commonRatingVo.setChildCommonComments(new ArrayList<>());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
resultList.add(commonRatingVo);
|
|
resultList.add(commonRatingVo);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
result.setRecords(resultList);
|
|
result.setRecords(resultList);
|
|
|
return R.data(result);
|
|
return R.data(result);
|
|
|
}
|
|
}
|
|
@@ -666,11 +617,11 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
|
|
|
|
|
return (long) this.count(wrapper);
|
|
return (long) this.count(wrapper);
|
|
|
}*/
|
|
}*/
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 安全地将数据库返回的数值类型转换为 int
|
|
* 安全地将数据库返回的数值类型转换为 int
|
|
|
* 支持 BigDecimal、Long、Integer、Number 等类型
|
|
* 支持 BigDecimal、Long、Integer、Number 等类型
|
|
|
- *
|
|
|
|
|
|
|
+ *
|
|
|
* @param value 数据库返回的数值对象
|
|
* @param value 数据库返回的数值对象
|
|
|
* @return int 值,如果为 null 或无法转换则返回 0
|
|
* @return int 值,如果为 null 或无法转换则返回 0
|
|
|
*/
|
|
*/
|
|
@@ -678,11 +629,11 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
if (value == null) {
|
|
if (value == null) {
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (value instanceof Number) {
|
|
if (value instanceof Number) {
|
|
|
return ((Number) value).intValue();
|
|
return ((Number) value).intValue();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 尝试字符串转换
|
|
// 尝试字符串转换
|
|
|
try {
|
|
try {
|
|
|
if (value instanceof String) {
|
|
if (value instanceof String) {
|
|
@@ -691,7 +642,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
} catch (NumberFormatException e) {
|
|
} catch (NumberFormatException e) {
|
|
|
log.warn("无法将值转换为 int: {}", value, e);
|
|
log.warn("无法将值转换为 int: {}", value, e);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -705,9 +656,9 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
@Override
|
|
@Override
|
|
|
public RatingPercentVo getRatingPercent(Integer businessId, Integer businessType) {
|
|
public RatingPercentVo getRatingPercent(Integer businessId, Integer businessType) {
|
|
|
log.info("CommonRatingServiceImpl.getRatingPercent?businessId={}&businessType={}", businessId, businessType);
|
|
log.info("CommonRatingServiceImpl.getRatingPercent?businessId={}&businessType={}", businessId, businessType);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
RatingPercentVo vo = new RatingPercentVo();
|
|
RatingPercentVo vo = new RatingPercentVo();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 1. 查询全部评价记录(仅展示的、审核通过的)
|
|
// 1. 查询全部评价记录(仅展示的、审核通过的)
|
|
|
LambdaQueryWrapper<CommonRating> wrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<CommonRating> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(CommonRating::getBusinessId, businessId);
|
|
wrapper.eq(CommonRating::getBusinessId, businessId);
|
|
@@ -715,7 +666,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
wrapper.eq(CommonRating::getIsShow, 1);
|
|
wrapper.eq(CommonRating::getIsShow, 1);
|
|
|
wrapper.eq(CommonRating::getAuditStatus, 1); // 仅统计审核通过的
|
|
wrapper.eq(CommonRating::getAuditStatus, 1); // 仅统计审核通过的
|
|
|
List<CommonRating> commonRatings = commonRatingMapper.selectList(wrapper);
|
|
List<CommonRating> commonRatings = commonRatingMapper.selectList(wrapper);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 如果为空,返回默认值
|
|
// 如果为空,返回默认值
|
|
|
if (CollectionUtils.isEmpty(commonRatings)) {
|
|
if (CollectionUtils.isEmpty(commonRatings)) {
|
|
|
vo.setTotalRatingCount(0);
|
|
vo.setTotalRatingCount(0);
|
|
@@ -729,32 +680,32 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
vo.setReplyRate(0.0);
|
|
vo.setReplyRate(0.0);
|
|
|
return vo;
|
|
return vo;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
List<Long> ratingIdList = commonRatings.stream()
|
|
List<Long> ratingIdList = commonRatings.stream()
|
|
|
.map(CommonRating::getId)
|
|
.map(CommonRating::getId)
|
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 2. 获取评价统计信息(好评、中评、差评数量)
|
|
// 2. 获取评价统计信息(好评、中评、差评数量)
|
|
|
Map<String, Object> ratingCount = commonRatingMapper.getRatingCount(
|
|
Map<String, Object> ratingCount = commonRatingMapper.getRatingCount(
|
|
|
new QueryWrapper<CommonRating>().in("id", ratingIdList));
|
|
new QueryWrapper<CommonRating>().in("id", ratingIdList));
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 3. 计算好评、中评、差评数量和占比
|
|
// 3. 计算好评、中评、差评数量和占比
|
|
|
int goodCount = getIntValue(ratingCount.get("goodCount"));
|
|
int goodCount = getIntValue(ratingCount.get("goodCount"));
|
|
|
int midCount = getIntValue(ratingCount.get("midCount"));
|
|
int midCount = getIntValue(ratingCount.get("midCount"));
|
|
|
int badCount = getIntValue(ratingCount.get("badCount"));
|
|
int badCount = getIntValue(ratingCount.get("badCount"));
|
|
|
int totalCount = goodCount + midCount + badCount;
|
|
int totalCount = goodCount + midCount + badCount;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
vo.setTotalRatingCount(totalCount);
|
|
vo.setTotalRatingCount(totalCount);
|
|
|
vo.setGoodCount(goodCount);
|
|
vo.setGoodCount(goodCount);
|
|
|
vo.setMidCount(midCount);
|
|
vo.setMidCount(midCount);
|
|
|
vo.setBadCount(badCount);
|
|
vo.setBadCount(badCount);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 计算占比(保留2位小数)
|
|
// 计算占比(保留2位小数)
|
|
|
if (totalCount > 0) {
|
|
if (totalCount > 0) {
|
|
|
Double goodPercent = Math.round((goodCount * 100.0 / totalCount) * 100.0) / 100.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 midPercent = Math.round((midCount * 100.0 / totalCount) * 100.0) / 100.0;
|
|
|
Double badPercent = Math.round((badCount * 100.0 / totalCount) * 100.0) / 100.0;
|
|
Double badPercent = Math.round((badCount * 100.0 / totalCount) * 100.0) / 100.0;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
vo.setGoodPercent(goodPercent);
|
|
vo.setGoodPercent(goodPercent);
|
|
|
vo.setMidPercent(midPercent);
|
|
vo.setMidPercent(midPercent);
|
|
|
vo.setBadPercent(badPercent);
|
|
vo.setBadPercent(badPercent);
|
|
@@ -763,7 +714,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
vo.setMidPercent(0.0);
|
|
vo.setMidPercent(0.0);
|
|
|
vo.setBadPercent(0.0);
|
|
vo.setBadPercent(0.0);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 4. 计算回复率
|
|
// 4. 计算回复率
|
|
|
// 查询已回复的评价数(存在商户评论 comment_type=2, parent_id=0)
|
|
// 查询已回复的评价数(存在商户评论 comment_type=2, parent_id=0)
|
|
|
LambdaQueryWrapper<CommonComment> repliedWrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<CommonComment> repliedWrapper = new LambdaQueryWrapper<>();
|
|
@@ -773,26 +724,26 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
.eq(CommonComment::getParentId, 0) // 根评论(直接回复评价)
|
|
.eq(CommonComment::getParentId, 0) // 根评论(直接回复评价)
|
|
|
.eq(CommonComment::getIsShow, 1)
|
|
.eq(CommonComment::getIsShow, 1)
|
|
|
.eq(CommonComment::getAuditStatus, 1);
|
|
.eq(CommonComment::getAuditStatus, 1);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 获取已回复的评价ID列表(去重)
|
|
// 获取已回复的评价ID列表(去重)
|
|
|
Set<Long> repliedRatingIds = commonCommentMapper.selectList(repliedWrapper).stream()
|
|
Set<Long> repliedRatingIds = commonCommentMapper.selectList(repliedWrapper).stream()
|
|
|
.map(CommonComment::getSourceId)
|
|
.map(CommonComment::getSourceId)
|
|
|
.filter(Objects::nonNull)
|
|
.filter(Objects::nonNull)
|
|
|
.collect(Collectors.toSet());
|
|
.collect(Collectors.toSet());
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
int repliedCount = repliedRatingIds.size();
|
|
int repliedCount = repliedRatingIds.size();
|
|
|
vo.setRepliedCount(repliedCount);
|
|
vo.setRepliedCount(repliedCount);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 计算回复率(保留2位小数)
|
|
// 计算回复率(保留2位小数)
|
|
|
Double replyRate = 0.0;
|
|
Double replyRate = 0.0;
|
|
|
if (totalCount > 0) {
|
|
if (totalCount > 0) {
|
|
|
replyRate = Math.round((repliedCount * 100.0 / totalCount) * 100.0) / 100.0;
|
|
replyRate = Math.round((repliedCount * 100.0 / totalCount) * 100.0) / 100.0;
|
|
|
}
|
|
}
|
|
|
vo.setReplyRate(replyRate);
|
|
vo.setReplyRate(replyRate);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
log.info("CommonRatingServiceImpl.getRatingPercent result: totalCount={}, goodCount={}, midCount={}, badCount={}, repliedCount={}, replyRate={}%",
|
|
log.info("CommonRatingServiceImpl.getRatingPercent result: totalCount={}, goodCount={}, midCount={}, badCount={}, repliedCount={}, replyRate={}%",
|
|
|
totalCount, goodCount, midCount, badCount, repliedCount, replyRate);
|
|
totalCount, goodCount, midCount, badCount, repliedCount, replyRate);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return vo;
|
|
return vo;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|