|
|
@@ -0,0 +1,441 @@
|
|
|
+package shop.alien.store.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+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.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.google.common.collect.ImmutableList;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+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.StoreInfoScoreVo;
|
|
|
+import shop.alien.entity.store.vo.WebSocketVo;
|
|
|
+import shop.alien.mapper.*;
|
|
|
+import shop.alien.store.config.WebSocketProcess;
|
|
|
+import shop.alien.store.service.CommonRatingService;
|
|
|
+import shop.alien.store.util.CommonConstant;
|
|
|
+import shop.alien.util.common.constant.CommentSourceTypeEnum;
|
|
|
+import shop.alien.util.common.constant.RatingBusinessTypeEnum;
|
|
|
+import shop.alien.util.common.safe.TextModerationResultVO;
|
|
|
+import shop.alien.util.common.safe.TextModerationUtil;
|
|
|
+import shop.alien.util.common.safe.TextReviewServiceEnum;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 评价表 服务实现类
|
|
|
+ *
|
|
|
+ * @author system
|
|
|
+ * @since 2025-01-XX
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Transactional
|
|
|
+public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, CommonRating> implements CommonRatingService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TextModerationUtil textModerationUtil;
|
|
|
+
|
|
|
+ private final CommonRatingMapper commonRatingMapper;
|
|
|
+ private final StoreInfoMapper storeInfoMapper;
|
|
|
+ private final StoreUserMapper storeUserMapper;
|
|
|
+ private final LifeNoticeMapper lifeNoticeMapper;
|
|
|
+ private final WebSocketProcess webSocketProcess;
|
|
|
+ private final LifeUserMapper lifeUserMapper;
|
|
|
+ private final CommonCommentMapper commonCommentMapper;
|
|
|
+ private final LifeLikeRecordMapper lifeLikeRecordMapper;
|
|
|
+ private final LifeCollectMapper lifeCollectMapper;
|
|
|
+
|
|
|
+
|
|
|
+ public static final List<String> SERVICES_LIST = ImmutableList.of(
|
|
|
+ TextReviewServiceEnum.COMMENT_DETECTION_PRO.getService(),
|
|
|
+ TextReviewServiceEnum.LLM_QUERY_MODERATION.getService()
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer saveCommonRating(CommonRating commonRating) {
|
|
|
+ // 1. 文本审核
|
|
|
+ try {
|
|
|
+ TextModerationResultVO textCheckResult = textModerationUtil.invokeFunction(commonRating.getContent(), SERVICES_LIST);
|
|
|
+ if ("high".equals(textCheckResult.getRiskLevel())) {
|
|
|
+ return 2;
|
|
|
+ }
|
|
|
+ // 手动存评分1,2,3
|
|
|
+ if (StringUtils.isNotEmpty(commonRating.getOtherScore())) {
|
|
|
+ JSONObject parse = JSONObject.parse(commonRating.getOtherScore());
|
|
|
+ commonRating.setScoreOne(parse.getDouble("scoreOne"));
|
|
|
+ commonRating.setScoreTwo(parse.getDouble("scoreTwo"));
|
|
|
+ commonRating.setScoreThree(parse.getDouble("scoreThree"));
|
|
|
+ }
|
|
|
+ int i = this.save(commonRating) ? 0 : 1;
|
|
|
+ // 对不同的businessType进行不同的处理,
|
|
|
+ doBusinessWithType(commonRating);
|
|
|
+ return i;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("CommonRatingService.saveCommonRating ERROR Msg={}", e.getMessage());
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据不同的businessType进行不同的处理
|
|
|
+ * @param commonRating 评价信息
|
|
|
+ */
|
|
|
+ private void doBusinessWithType(CommonRating commonRating) throws Exception {
|
|
|
+ Integer businessId = commonRating.getBusinessId();
|
|
|
+ Double score = commonRating.getScore();
|
|
|
+ if(1 == commonRating.getBusinessType()){
|
|
|
+ // 更新门店评价信息
|
|
|
+ StoreInfoScoreVo storeInfoScoreVo = commonRatingMapper.getCommentCountAndScoreInfo(commonRating.getBusinessType(),businessId);
|
|
|
+ double total = storeInfoScoreVo.getTotal();
|
|
|
+ double scoreAvg = (total == 0 ? 0 : storeInfoScoreVo.getScore() / total);
|
|
|
+ double scoreOne = (total == 0 ? 0 : storeInfoScoreVo.getScoreOne() / total);
|
|
|
+ double scoreTwo = (total == 0 ? 0 : storeInfoScoreVo.getScoreTwo() / total);
|
|
|
+ double scoreThree = (total == 0 ? 0 : storeInfoScoreVo.getScoreThree() / total);
|
|
|
+ StoreInfo storeInfo = new StoreInfo();
|
|
|
+ storeInfo.setId(businessId);
|
|
|
+ storeInfo.setScoreAvg(new BigDecimal(scoreAvg).setScale(2, RoundingMode.HALF_UP).doubleValue());
|
|
|
+ storeInfo.setScoreOne(new BigDecimal(scoreOne).setScale(2, RoundingMode.HALF_UP).doubleValue());
|
|
|
+ storeInfo.setScoreTwo(new BigDecimal(scoreTwo).setScale(2, RoundingMode.HALF_UP).doubleValue());
|
|
|
+ storeInfo.setScoreThree(new BigDecimal(scoreThree).setScale(2, RoundingMode.HALF_UP).doubleValue());
|
|
|
+ storeInfoMapper.updateById(storeInfo);
|
|
|
+ StoreUser storeUser = storeUserMapper.selectOne(new LambdaQueryWrapper<StoreUser>().eq(StoreUser::getStoreId, storeInfo.getId()).eq(StoreUser::getDeleteFlag, 0));
|
|
|
+
|
|
|
+ // 如果差评,则发送差评提醒
|
|
|
+ if(score != null && score >= 0.5 && score <= 2.5){
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String commonDate = simpleDateFormat.format(new Date());
|
|
|
+ LifeNotice lifeMessage = new LifeNotice();
|
|
|
+ lifeMessage.setReceiverId("store_" + storeUser.getPhone());
|
|
|
+ String text = "在"+commonDate+",您的店铺有一条差评记录,您可查看评价内容是否属实,如不属实,可向平台进行申诉。";
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("message", text);
|
|
|
+ lifeMessage.setContext(jsonObject.toJSONString());
|
|
|
+ lifeMessage.setTitle("差评通知");
|
|
|
+ lifeMessage.setSenderId("system");
|
|
|
+ lifeMessage.setIsRead(0);
|
|
|
+ lifeMessage.setNoticeType(1);
|
|
|
+ lifeNoticeMapper.insert(lifeMessage);
|
|
|
+
|
|
|
+ WebSocketVo websocketVo = new WebSocketVo();
|
|
|
+ websocketVo.setSenderId("system");
|
|
|
+ websocketVo.setReceiverId("store_" + storeUser.getPhone());
|
|
|
+ websocketVo.setCategory("notice");
|
|
|
+ websocketVo.setNoticeType("1");
|
|
|
+ websocketVo.setIsRead(0);
|
|
|
+ websocketVo.setText(JSONObject.from(lifeMessage).toJSONString());
|
|
|
+ webSocketProcess.sendMessage("store_" + storeUser.getPhone(), JSONObject.from(websocketVo).toJSONString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R getRatingList(Integer pageNum, Integer pageSize, Integer businessType, Long businessId, Long userId, Integer auditStatus, Integer searchScore) {
|
|
|
+ Page<CommonRating> page = new Page<>(pageNum, pageSize);
|
|
|
+ LambdaQueryWrapper<CommonRating> wrapper = new LambdaQueryWrapper<>();
|
|
|
+
|
|
|
+ if (businessType != null) {
|
|
|
+ wrapper.eq(CommonRating::getBusinessType, businessType);
|
|
|
+ }
|
|
|
+ if (businessId != null) {
|
|
|
+ wrapper.eq(CommonRating::getBusinessId, businessId);
|
|
|
+ }
|
|
|
+ if (auditStatus != null) {
|
|
|
+ wrapper.eq(CommonRating::getAuditStatus, auditStatus);
|
|
|
+ }
|
|
|
+ if (searchScore != null) {
|
|
|
+ if(searchScore == 1){
|
|
|
+ // 1-好评
|
|
|
+ wrapper.ge(CommonRating::getScore, 4.5);
|
|
|
+ }else if(searchScore == 2){
|
|
|
+ // 2-中评
|
|
|
+ wrapper.ge(CommonRating::getScore, 3.5);
|
|
|
+ wrapper.lt(CommonRating::getScore, 4.5);
|
|
|
+ }else if(searchScore == 3){
|
|
|
+ // 3-差评
|
|
|
+ wrapper.lt(CommonRating::getScore, 3.5);
|
|
|
+ }else if(searchScore == 4){
|
|
|
+ // 4-有图
|
|
|
+ wrapper.isNotNull(CommonRating::getImageUrls);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ wrapper.eq(CommonRating::getIsShow, 1);
|
|
|
+ wrapper.orderByDesc(CommonRating::getId);
|
|
|
+ IPage<CommonRating> page1 = this.page(page, wrapper);
|
|
|
+ return doListBusinessWithType(page1, businessType,userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object getRatingCount(Integer businessId, Integer businessType) {
|
|
|
+ // 查询全部评价记录
|
|
|
+ LambdaQueryWrapper<CommonRating> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(CommonRating::getBusinessId, businessId);
|
|
|
+ wrapper.eq(CommonRating::getBusinessType, businessType);
|
|
|
+ wrapper.eq(CommonRating::getIsShow, 1);
|
|
|
+ List<CommonRating> commonRatings = commonRatingMapper.selectList(wrapper);
|
|
|
+ List<Long> collect = commonRatings.stream().map(x -> x.getId()).collect(Collectors.toList());
|
|
|
+ // 获取评价统计信息(总评论数、有图评论数、好评数、中评数、差评数)
|
|
|
+ Map<String, Object> ratingCount = commonRatingMapper.getRatingCount(new QueryWrapper<CommonRating>().in("id", collect));
|
|
|
+ if(RatingBusinessTypeEnum.STORE_RATING.getBusinessType() == businessType){
|
|
|
+ // 1店铺评分
|
|
|
+ StoreInfo storeInfo = storeInfoMapper.selectById(businessId);
|
|
|
+ ratingCount.put("storeScore", storeInfo.getScoreAvg());
|
|
|
+
|
|
|
+ // 2统计评价数量
|
|
|
+ AtomicReference<Integer> count = new AtomicReference<>(0);
|
|
|
+ count.updateAndGet(v -> v + collect.size());
|
|
|
+ // 1.查询评价的评论的记录
|
|
|
+ LambdaQueryWrapper<CommonComment> commentWrapper = new LambdaQueryWrapper<CommonComment>()
|
|
|
+ .eq(CommonComment::getSourceType, CommentSourceTypeEnum.STORE_COMMENT.getType())
|
|
|
+ .in(CommonComment::getSourceId, collect);
|
|
|
+ List<Long> collect1 = commonCommentMapper.selectList(commentWrapper).stream().map(x -> x.getId()).collect(Collectors.toList());
|
|
|
+ if(!collect1.isEmpty()) {
|
|
|
+ count.updateAndGet(v -> v + collect1.size());
|
|
|
+ // 2.在再评论的表中查询评论的回复(根评论)
|
|
|
+ Integer allCommentsOnCommentsNum = getAllCommentsOnCommentsNum(collect1);
|
|
|
+ count.updateAndGet(v -> v + allCommentsOnCommentsNum);
|
|
|
+ }
|
|
|
+ ratingCount.put("totalCount", count.get());
|
|
|
+
|
|
|
+ // 3用户图片
|
|
|
+ List<Long> collect2 = commonRatings.stream().filter(i -> i.getScore() >= 4.5).map(CommonRating::getUserId).distinct().limit(6).collect(Collectors.toList());
|
|
|
+ if(!collect2.isEmpty()) {
|
|
|
+ List<LifeUser> lifeUsers = lifeUserMapper.selectList(new QueryWrapper<LifeUser>().lambda().in(LifeUser::getId, collect2));
|
|
|
+ ratingCount.put("img", lifeUsers.stream().map(LifeUser::getUserImage).collect(Collectors.toList()));
|
|
|
+ } else {
|
|
|
+ ratingCount.put("img", new ArrayList<>());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ return ratingCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object getRatingDetail(Integer ratingId, Long userId) {
|
|
|
+ CommonRating commonRating = commonRatingMapper.selectById(ratingId);
|
|
|
+ if(commonRating == null){
|
|
|
+ throw new IllegalArgumentException("评价不存在");
|
|
|
+ }
|
|
|
+ CommonRatingVo commonRatingVo = new CommonRatingVo();
|
|
|
+ BeanUtils.copyProperties(commonRating, commonRatingVo);
|
|
|
+ LifeUser lifeUser = lifeUserMapper.selectById(Integer.parseInt(commonRating.getUserId().toString()));
|
|
|
+ // 设置评论用户信息
|
|
|
+ commonRatingVo.setUserImage(lifeUser.getUserImage());
|
|
|
+ commonRatingVo.setUserName(lifeUser.getUserName());
|
|
|
+ // 查询当前用户点赞列表(仅评价)
|
|
|
+ List<LifeLikeRecord> lifeLikeRecords = lifeLikeRecordMapper.selectList(new QueryWrapper<LifeLikeRecord>().lambda()
|
|
|
+ .eq(LifeLikeRecord::getDianzanId, userId)
|
|
|
+ .eq(LifeLikeRecord::getHuifuId, ratingId)
|
|
|
+ .eq(LifeLikeRecord::getDeleteFlag, 0)
|
|
|
+ .eq(LifeLikeRecord::getType, CommonConstant.RATING_LIKE));
|
|
|
+ if(lifeLikeRecords.size() > 0){
|
|
|
+ commonRatingVo.setIsLike(1);
|
|
|
+ } else {
|
|
|
+ commonRatingVo.setIsLike(0);
|
|
|
+ }
|
|
|
+ // 根据业务类型处理
|
|
|
+ if(commonRatingVo.getBusinessType().equals(RatingBusinessTypeEnum.STORE_RATING.getBusinessType())){
|
|
|
+ // 1店铺信息
|
|
|
+ StoreInfo storeInfo = storeInfoMapper.selectById(commonRatingVo.getBusinessId());
|
|
|
+ if( null != storeInfo) {
|
|
|
+ commonRatingVo.setStoreName(storeInfo.getStoreName());
|
|
|
+ commonRatingVo.setStoreEvaluate(storeInfo.getStoreEvaluate());
|
|
|
+ commonRatingVo.setStoreScore(storeInfo.getScoreAvg());
|
|
|
+ commonRatingVo.setScoreOne(storeInfo.getScoreOne());
|
|
|
+ commonRatingVo.setScoreTwo(storeInfo.getScoreTwo());
|
|
|
+ commonRatingVo.setScoreThree(storeInfo.getScoreThree());
|
|
|
+ }
|
|
|
+ // 1.1 查询是否收藏该店铺
|
|
|
+ LambdaQueryWrapper<LifeCollect> collectWrapper = new LambdaQueryWrapper<LifeCollect>()
|
|
|
+ .eq(LifeCollect::getUserId, userId)
|
|
|
+ .eq(LifeCollect::getStoreId, storeInfo.getId())
|
|
|
+ .eq(LifeCollect::getDeleteFlag, 0);
|
|
|
+ LifeCollect lifeCollect = lifeCollectMapper.selectOne(collectWrapper);
|
|
|
+ if(lifeCollect != null){
|
|
|
+ commonRatingVo.setIsCollect(1);
|
|
|
+ } else {
|
|
|
+ commonRatingVo.setIsCollect(0);
|
|
|
+ }
|
|
|
+ // 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);
|
|
|
+ }
|
|
|
+ return commonRatingVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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
|
|
|
+ private Integer getAllCommentsOnCommentsNum(List<Long> collect1) {
|
|
|
+ LambdaQueryWrapper<CommonComment> commentReplyWrapper = new LambdaQueryWrapper<CommonComment>()
|
|
|
+ .in(CommonComment::getParentId, collect1);
|
|
|
+ List<Long> collect2 = commonCommentMapper.selectList(commentReplyWrapper).stream().map(x -> x.getId()).collect(Collectors.toList());
|
|
|
+ if(collect2.isEmpty()){
|
|
|
+ return 0;
|
|
|
+ } else {
|
|
|
+ return collect2.size() + getAllCommentsOnCommentsNum(collect2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private R doListBusinessWithType(IPage<CommonRating> page1, Integer businessType, Long userId) {
|
|
|
+ if(businessType == RatingBusinessTypeEnum.STORE_RATING.getBusinessType()){
|
|
|
+ // 1查询评价用户信息
|
|
|
+ Set<Long> userIdSet = page1.getRecords().stream()
|
|
|
+ .map(CommonRating::getUserId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ List<LifeUser> lifeUsers = lifeUserMapper.selectList(
|
|
|
+ new QueryWrapper<LifeUser>().lambda()
|
|
|
+ .in(LifeUser::getId, userIdSet));
|
|
|
+ Map<Integer, LifeUser> lifeUserMap = lifeUsers.stream()
|
|
|
+ .collect(Collectors.toMap(LifeUser::getId, Function.identity()));
|
|
|
+ // 2查询当前用户点赞列表(仅评价)
|
|
|
+ List<LifeLikeRecord> lifeLikeRecords = lifeLikeRecordMapper.selectList(
|
|
|
+ new QueryWrapper<LifeLikeRecord>().lambda()
|
|
|
+ .eq(LifeLikeRecord::getDianzanId, userId)
|
|
|
+ .eq(LifeLikeRecord::getType, CommonConstant.RATING_LIKE));
|
|
|
+ Map<String, LifeLikeRecord> likeRecordMap = lifeLikeRecords.stream()
|
|
|
+ .collect(Collectors.toMap(LifeLikeRecord::getHuifuId, Function.identity()));
|
|
|
+
|
|
|
+
|
|
|
+ // 1.查询评价的评论的记录个数
|
|
|
+ Set<Long> ratingIdSet = page1.getRecords().stream()
|
|
|
+ .map(CommonRating::getId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ LambdaQueryWrapper<CommonComment> commentWrapper = new LambdaQueryWrapper<CommonComment>()
|
|
|
+ .eq(CommonComment::getSourceType, CommentSourceTypeEnum.STORE_COMMENT.getType())
|
|
|
+ .in(CommonComment::getSourceId, ratingIdSet);
|
|
|
+ // 评价id对应的所有评论 定义Map存储「评价ID -> 该评价下的总评论数」
|
|
|
+ Map<Long, Long> ratingCommentCountMap = commonCommentMapper.selectList(commentWrapper).stream()
|
|
|
+ .collect(Collectors.groupingBy(CommonComment::getSourceId, Collectors.counting()));
|
|
|
+ IPage<CommonRatingVo> result = new Page<>(page1.getPages(), page1.getSize(), page1.getTotal());
|
|
|
+ List resultList = new ArrayList();
|
|
|
+
|
|
|
+ for (CommonRating record : page1.getRecords()) {
|
|
|
+ CommonRatingVo commonRatingVo = new CommonRatingVo();
|
|
|
+ BeanUtil.copyProperties(record, commonRatingVo);
|
|
|
+ // 判断用户信息
|
|
|
+ if(lifeUserMap.containsKey(Integer.parseInt(record.getUserId().toString()))){
|
|
|
+ LifeUser lifeUser = lifeUserMap.get(Integer.parseInt(record.getUserId().toString()));
|
|
|
+ // 设置评论用户信息
|
|
|
+ commonRatingVo.setUserImage(lifeUser.getUserImage());
|
|
|
+ commonRatingVo.setUserName(lifeUser.getUserName());
|
|
|
+ }
|
|
|
+ // 判断当前登录人是否点赞过
|
|
|
+ commonRatingVo.setIsLike(0);
|
|
|
+ if(likeRecordMap.containsKey(record.getId().toString())){
|
|
|
+ commonRatingVo.setIsLike(1);
|
|
|
+ }
|
|
|
+ // 3.1 从映射中获取该评价的总评论数(默认0)
|
|
|
+ commonRatingVo.setCommentCount(ratingCommentCountMap.getOrDefault(record.getId(), 0L));
|
|
|
+ resultList.add(commonRatingVo);
|
|
|
+ }
|
|
|
+ result.setRecords(resultList);
|
|
|
+ return R.data(result);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+/*
|
|
|
+ @Override
|
|
|
+ public Double getAverageScore(Integer businessType, Long businessId) {
|
|
|
+ LambdaQueryWrapper<CommonRating> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(CommonRating::getBusinessType, businessType)
|
|
|
+ .eq(CommonRating::getBusinessId, businessId)
|
|
|
+ .eq(CommonRating::getIsShow, 1)
|
|
|
+ .eq(CommonRating::getAuditStatus, 1);
|
|
|
+
|
|
|
+ return this.list(wrapper).stream()
|
|
|
+ .map(CommonRating::getScore)
|
|
|
+ .filter(score -> score != null)
|
|
|
+ .mapToDouble(BigDecimal::doubleValue)
|
|
|
+ .average()
|
|
|
+ .orElse(0.0);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long getRatingCount(Integer businessType, Long businessId) {
|
|
|
+ LambdaQueryWrapper<CommonRating> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(CommonRating::getBusinessType, businessType)
|
|
|
+ .eq(CommonRating::getBusinessId, businessId)
|
|
|
+ .eq(CommonRating::getIsShow, 1)
|
|
|
+ .eq(CommonRating::getAuditStatus, 1);
|
|
|
+
|
|
|
+ return (long) this.count(wrapper);
|
|
|
+ }*/
|
|
|
+}
|
|
|
+
|