Просмотр исходного кода

bugfix:修复sql问题,加校验

刘云鑫 3 месяцев назад
Родитель
Сommit
1ea6d76b35

+ 15 - 7
alien-store/src/main/java/shop/alien/store/service/impl/CommonRatingServiceImpl.java

@@ -355,15 +355,25 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
 
 
     private R doListBusinessWithType(IPage<CommonRating> page1, Integer businessType, Long userId) {
     private R doListBusinessWithType(IPage<CommonRating> page1, Integer businessType, Long userId) {
         if(businessType == RatingBusinessTypeEnum.STORE_RATING.getBusinessType()){
         if(businessType == RatingBusinessTypeEnum.STORE_RATING.getBusinessType()){
+            IPage<CommonRatingVo> result = new Page<>(page1.getPages(), page1.getSize(), page1.getTotal());
+            List resultList = new ArrayList();
+            if(page1.getRecords().isEmpty()){
+                result.setRecords(resultList);
+                return R.data(result);
+            }
             // 1查询评价用户信息
             // 1查询评价用户信息
             Set<Long> userIdSet = page1.getRecords().stream()
             Set<Long> userIdSet = page1.getRecords().stream()
                     .map(CommonRating::getUserId)
                     .map(CommonRating::getUserId)
                     .collect(Collectors.toSet());
                     .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()));
+            List<LifeUser> lifeUsers = new  ArrayList<>();
+            Map<Integer, LifeUser> lifeUserMap = new HashMap<>();
+            if (!userIdSet.isEmpty()){
+                lifeUsers = lifeUserMapper.selectList(
+                        new QueryWrapper<LifeUser>().lambda()
+                                .in(LifeUser::getId, userIdSet));
+                lifeUserMap = lifeUsers.stream()
+                        .collect(Collectors.toMap(LifeUser::getId, Function.identity()));
+            }
             // 2查询当前用户点赞列表(仅评价)
             // 2查询当前用户点赞列表(仅评价)
             List<LifeLikeRecord> lifeLikeRecords = lifeLikeRecordMapper.selectList(
             List<LifeLikeRecord> lifeLikeRecords = lifeLikeRecordMapper.selectList(
                     new QueryWrapper<LifeLikeRecord>().lambda()
                     new QueryWrapper<LifeLikeRecord>().lambda()
@@ -383,8 +393,6 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
             // 评价id对应的所有评论 定义Map存储「评价ID -> 该评价下的总评论数」
             // 评价id对应的所有评论 定义Map存储「评价ID -> 该评价下的总评论数」
             Map<Long, Long> ratingCommentCountMap = commonCommentMapper.selectList(commentWrapper).stream()
             Map<Long, Long> ratingCommentCountMap = commonCommentMapper.selectList(commentWrapper).stream()
                     .collect(Collectors.groupingBy(CommonComment::getSourceId, Collectors.counting()));
                     .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()) {
             for (CommonRating record : page1.getRecords()) {
                 CommonRatingVo commonRatingVo = new CommonRatingVo();
                 CommonRatingVo commonRatingVo = new CommonRatingVo();