Przeglądaj źródła

修复用户声部查询异常

Eric 2 lat temu
rodzic
commit
99a4f25935

+ 11 - 6
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/ActivityEvaluationRecordServiceImpl.java

@@ -233,17 +233,22 @@ public class ActivityEvaluationRecordServiceImpl extends ServiceImpl<ActivityEva
             List<Long> userIds = activityRankings.stream()
                     .map(ActivityRankingVo::getUserId).distinct().collect(Collectors.toList());
 
-            Map<Long, Long> userSubjectMap = studentMapper.selectList(Wrappers.<Student>lambdaQuery().in(Student::getUserId, userIds)).stream()
-                    .collect(Collectors.toMap(Student::getUserId, x -> Long.parseLong(Optional.ofNullable(x.getSubjectId()).orElse("").split(",")[0]), (o, n) -> n));
+            if (CollectionUtils.isNotEmpty(userIds)) {
 
+                Map<Long, Long> userSubjectMap = studentMapper.selectList(Wrappers.<Student>lambdaQuery().in(Student::getUserId, userIds)).stream()
+                        .filter(x -> Objects.nonNull(x.getSubjectId()))
+                        .collect(Collectors.toMap(Student::getUserId, x -> Long.parseLong(Optional.ofNullable(x.getSubjectId()).orElse("0").split(",")[0]), (o, n) -> n));
 
-            Map<Long, String> subjectNameMap = subjectService.findBySubjectByIdList(Lists.newArrayList(userSubjectMap.values())).stream()
-                    .collect(Collectors.toMap(Subject::getId, Subject::getName, (o, n) -> n));
 
-            for (ActivityRankingVo item : activityRankings) {
+                Map<Long, String> subjectNameMap = subjectService.findBySubjectByIdList(Lists.newArrayList(userSubjectMap.values())).stream()
+                        .collect(Collectors.toMap(Subject::getId, Subject::getName, (o, n) -> n));
 
-                item.setUserSubject(subjectNameMap.getOrDefault(userSubjectMap.get(item.getUserId()), ""));
+                for (ActivityRankingVo item : activityRankings) {
+
+                    item.setUserSubject(subjectNameMap.getOrDefault(userSubjectMap.get(item.getUserId()), ""));
+                }
             }
+
         } else {
 
             // 单曲排名

+ 11 - 4
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/ActivityPlanServiceImpl.java

@@ -552,12 +552,19 @@ public class ActivityPlanServiceImpl extends ServiceImpl<ActivityPlanDao, Activi
                 List<Long> userIds = highestScoreMap.values().stream()
                         .map(ActivityRankingVo::getUserId).distinct().collect(Collectors.toList());
 
-                Map<Long, Long> userSubjectMap = studentMapper.selectList(Wrappers.<Student>lambdaQuery().in(Student::getUserId, userIds)).stream()
-                        .collect(Collectors.toMap(Student::getUserId, x -> Long.parseLong(Optional.ofNullable(x.getSubjectId()).orElse("").split(",")[0]), (o, n) -> n));
+                Map<Long, Long> userSubjectMap = Maps.newHashMap();
+                Map<Long, String> subjectNameMap = Maps.newHashMap();
+                if (CollectionUtils.isNotEmpty(userIds)) {
 
+                    userSubjectMap = studentMapper.selectList(Wrappers.<Student>lambdaQuery().in(Student::getUserId, userIds)).stream()
+                            .filter(x -> Objects.nonNull(x.getSubjectId()))
+                            .collect(Collectors.toMap(Student::getUserId, x -> Long.parseLong(Optional.ofNullable(x.getSubjectId()).orElse("0").split(",")[0]), (o, n) -> n));
+
+
+                    subjectNameMap = subjectService.findBySubjectByIdList(Lists.newArrayList(userSubjectMap.values())).stream()
+                            .collect(Collectors.toMap(Subject::getId, Subject::getName, (o, n) -> n));
+                }
 
-                Map<Long, String> subjectNameMap = subjectService.findBySubjectByIdList(Lists.newArrayList(userSubjectMap.values())).stream()
-                        .collect(Collectors.toMap(Subject::getId, Subject::getName, (o, n) -> n));
 
                 List<MusicActivityVo.SubjectInfo> subjectInfos = Lists.newArrayList();
                 ActivityMusicVo musicVo;