Browse Source

增加学生声部信息

Eric 2 years ago
parent
commit
432fc98863

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

@@ -6,16 +6,20 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.google.common.collect.Lists;
 import com.yonge.cooleshow.biz.dal.dao.ActivityEvaluationRecordDao;
 import com.yonge.cooleshow.biz.dal.dao.ActivityPlanDao;
+import com.yonge.cooleshow.biz.dal.dao.StudentDao;
 import com.yonge.cooleshow.biz.dal.dto.search.ActivityEvaluationRecordSearch;
 import com.yonge.cooleshow.biz.dal.entity.ActivityEvaluation;
 import com.yonge.cooleshow.biz.dal.entity.ActivityEvaluationRecord;
 import com.yonge.cooleshow.biz.dal.entity.ActivityPlan;
 import com.yonge.cooleshow.biz.dal.entity.MusicSheet;
+import com.yonge.cooleshow.biz.dal.entity.Student;
+import com.yonge.cooleshow.biz.dal.entity.Subject;
 import com.yonge.cooleshow.biz.dal.enums.activity.ActivityRankingMethodEnum;
 import com.yonge.cooleshow.biz.dal.service.ActivityEvaluationRecordService;
 import com.yonge.cooleshow.biz.dal.service.ActivityEvaluationService;
 import com.yonge.cooleshow.biz.dal.service.ActivityPlanService;
 import com.yonge.cooleshow.biz.dal.service.MusicSheetService;
+import com.yonge.cooleshow.biz.dal.service.SubjectService;
 import com.yonge.cooleshow.biz.dal.vo.ActivityEvaluationRecordVo;
 import com.yonge.cooleshow.biz.dal.vo.ActivityRankingVo;
 import com.yonge.cooleshow.common.enums.ActivityResourceEnum;
@@ -50,6 +54,10 @@ public class ActivityEvaluationRecordServiceImpl extends ServiceImpl<ActivityEva
     private MusicSheetService musicSheetService;
     @Autowired
     private ActivityPlanDao activityPlanMapper;
+    @Autowired
+    private StudentDao studentMapper;
+    @Autowired
+    private SubjectService subjectService;
 
 	@Override
     public ActivityEvaluationRecordVo detail(Long id) {
@@ -221,6 +229,21 @@ public class ActivityEvaluationRecordServiceImpl extends ServiceImpl<ActivityEva
             // 总分排名, 根据声部ID进行查询
             activityRankings = activityPlanMapper.selectActivityHighestScoreRankingInfo(activityPlanId, activityEvaluationId,
                     0D, limit);
+
+            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));
+
+
+            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) {
+
+                item.setUserSubject(subjectNameMap.getOrDefault(userSubjectMap.get(item.getUserId()), ""));
+            }
         } else {
 
             // 单曲排名
@@ -245,6 +268,18 @@ public class ActivityEvaluationRecordServiceImpl extends ServiceImpl<ActivityEva
             // 总分排名
             userRanking = activityPlanMapper.selectActivityHighestScoreUserRanking(activityPlanId, activityEvaluationId,
                     0D, userId);
+
+            // 学生声部信息
+            Student student = studentMapper.selectOne(Wrappers.<Student>lambdaQuery().eq(Student::getUserId, userId));
+
+            long subjectId = 0;
+            if (Objects.nonNull(student.getSubjectId())) {
+                subjectId = Long.parseLong(student.getSubjectId().split(",")[0]);
+            }
+            Subject subject = subjectService.get(subjectId);
+
+            userRanking.setUserSubject(Optional.ofNullable(subject).map(Subject::getName).orElse(""));
+
         } else {
 
             // 单曲排名

+ 2 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/ActivityEvaluationServiceImpl.java

@@ -251,6 +251,8 @@ public class ActivityEvaluationServiceImpl extends ServiceImpl<ActivityEvaluatio
 
                     item.setScore(collect.getOrDefault(item.getEvaluationId(), 0D));
                 }
+
+
             }
 
         }

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

@@ -10,6 +10,8 @@ import com.google.common.collect.Maps;
 import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
 import com.yonge.cooleshow.auth.api.entity.SysUser;
 import com.yonge.cooleshow.biz.dal.dao.ActivityPlanDao;
+import com.yonge.cooleshow.biz.dal.dao.StudentDao;
+import com.yonge.cooleshow.biz.dal.dao.SubjectDao;
 import com.yonge.cooleshow.biz.dal.dto.ActivityPlanDto;
 import com.yonge.cooleshow.biz.dal.dto.ActivityPlanPayDto;
 import com.yonge.cooleshow.biz.dal.dto.ActivityPlanRewardDto;
@@ -23,6 +25,8 @@ import com.yonge.cooleshow.biz.dal.entity.ActivityPlan;
 import com.yonge.cooleshow.biz.dal.entity.ActivityPlanReward;
 import com.yonge.cooleshow.biz.dal.entity.ActivityRegistration;
 import com.yonge.cooleshow.biz.dal.entity.ActivityReward;
+import com.yonge.cooleshow.biz.dal.entity.Student;
+import com.yonge.cooleshow.biz.dal.entity.Subject;
 import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
 import com.yonge.cooleshow.biz.dal.enums.EQueryOp;
 import com.yonge.cooleshow.biz.dal.enums.MK;
@@ -36,6 +40,7 @@ import com.yonge.cooleshow.biz.dal.service.ActivityPlanService;
 import com.yonge.cooleshow.biz.dal.service.ActivityPlanStandardService;
 import com.yonge.cooleshow.biz.dal.service.ActivityRegistrationService;
 import com.yonge.cooleshow.biz.dal.service.ActivityRewardService;
+import com.yonge.cooleshow.biz.dal.service.SubjectService;
 import com.yonge.cooleshow.biz.dal.service.SysMessageService;
 import com.yonge.cooleshow.biz.dal.vo.ActivityMusicVo;
 import com.yonge.cooleshow.biz.dal.vo.ActivityPlanVo;
@@ -119,6 +124,10 @@ public class ActivityPlanServiceImpl extends ServiceImpl<ActivityPlanDao, Activi
 
     @Autowired
     private RedissonClient redissonClient;
+    @Autowired
+    private StudentDao studentMapper;
+    @Autowired
+    private SubjectService subjectService;
 
     //保存/更新拓展字段
     private static final Map<ActivityTypeEnum, Consumer<ActivityPlanDto>> saveOrUpdateExpand = new HashMap<>();
@@ -539,7 +548,16 @@ 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, 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;
@@ -559,6 +577,7 @@ public class ActivityPlanServiceImpl extends ServiceImpl<ActivityPlanDao, Activi
                             .userId(0L)
                             .username("")
                             .userAvatar("")
+                            .userSubject("")
                             .score(0D)
                             .musicNums(entry.getValue().size())
                             .build();
@@ -572,6 +591,7 @@ public class ActivityPlanServiceImpl extends ServiceImpl<ActivityPlanDao, Activi
                         subjectInfo.userId(ranking.getUserId())
                                 .username(ranking.getUsername())
                                 .userAvatar(ranking.getUserAvatar())
+                                .userSubject(subjectNameMap.getOrDefault(userSubjectMap.get(ranking.getUserId()), ""))
                                 .score(ranking.getScore());
                     }
                 }

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

@@ -1,13 +1,20 @@
 package com.yonge.cooleshow.biz.dal.service.impl;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.yonge.cooleshow.biz.dal.dao.ActivityRegistrationDao;
+import com.yonge.cooleshow.biz.dal.dao.SubjectDao;
 import com.yonge.cooleshow.biz.dal.dto.search.ActivityRegistrationSearch;
 import com.yonge.cooleshow.biz.dal.entity.ActivityEvaluationRecord;
+import com.yonge.cooleshow.biz.dal.entity.ActivityPlan;
 import com.yonge.cooleshow.biz.dal.entity.ActivityRegistration;
+import com.yonge.cooleshow.biz.dal.entity.Subject;
+import com.yonge.cooleshow.biz.dal.enums.activity.ActivityRankingMethodEnum;
 import com.yonge.cooleshow.biz.dal.service.ActivityEvaluationRecordService;
+import com.yonge.cooleshow.biz.dal.service.ActivityPlanService;
 import com.yonge.cooleshow.biz.dal.service.ActivityRegistrationService;
+import com.yonge.cooleshow.biz.dal.service.SubjectService;
 import com.yonge.cooleshow.biz.dal.vo.ActivityRegistrationVo;
 import com.yonge.cooleshow.common.enums.YesOrNoEnum;
 import lombok.extern.slf4j.Slf4j;
@@ -17,6 +24,7 @@ import org.springframework.stereotype.Service;
 
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -26,6 +34,10 @@ public class ActivityRegistrationServiceImpl extends ServiceImpl<ActivityRegistr
 
     @Autowired
     private ActivityEvaluationRecordService activityEvaluationRecordService;
+    @Autowired
+    private ActivityPlanService activityPlanService;
+    @Autowired
+    private SubjectService subjectService;
 	@Override
     public ActivityRegistrationVo detail(Long id) {
         return baseMapper.detail(id);
@@ -40,22 +52,58 @@ public class ActivityRegistrationServiceImpl extends ServiceImpl<ActivityRegistr
         List<Long> userIds = activityUserInfos.stream()
                 .map(ActivityRegistration::getUserId).distinct().collect(Collectors.toList());
 
+        ActivityPlan activity = activityPlanService.getById(query.getActivityId());
         // 查询用户活动评测获排名最高记录
-        if (CollectionUtils.isNotEmpty(userIds)) {
+        if (CollectionUtils.isNotEmpty(userIds) && Objects.nonNull(activity)) {
+
+            if (ActivityRankingMethodEnum.TOTAL_SCORE == activity.getRankingMethod()) {
+
+                // 总分排名
+                Map<Long, ActivityEvaluationRecord> collect = activityEvaluationRecordService.list(Wrappers.<ActivityEvaluationRecord>lambdaQuery()
+                        .eq(ActivityEvaluationRecord::getActivityId, activity.getId())
+                        .in(ActivityEvaluationRecord::getUserId, userIds)
+                        .eq(ActivityEvaluationRecord::getRankingMethod, activity.getRankingMethod().getCode())).stream()
+                        .collect(Collectors.toMap(ActivityEvaluationRecord::getUserId, Function.identity(), (o, n) -> n));
+
+                // 声部信息
+                List<Long> subjectIds = collect.values().stream()
+                        .map(ActivityEvaluationRecord::getResourceId)
+                        .filter(Objects::nonNull).distinct().collect(Collectors.toList());
+
+                Map<Long, String> subjectNameMap = subjectService.findBySubjectByIdList(subjectIds).stream()
+                        .collect(Collectors.toMap(Subject::getId, Subject::getName, (o, n) -> n));
+
+                ActivityEvaluationRecord record;
+                for (ActivityRegistrationVo item : activityUserInfos) {
+
+                    if (collect.containsKey(item.getUserId())) {
+
+                        record = collect.get(item.getUserId());
+                        // 重置当前时间为用户最高排名时间
+                        item.score(record.getScore())
+                                .subjectName(subjectNameMap.getOrDefault(record.getResourceId(), ""))
+                                .scoreTime(record.getCreateTime());
+
+                    }
+                }
+
+            } else {
 
-            Map<Long, ActivityEvaluationRecord> collect = activityEvaluationRecordService.queryActivityUserHighestRankingInfo(query.getActivityId(), userIds).stream()
-                    .collect(Collectors.toMap(ActivityEvaluationRecord::getUserId, Function.identity(), (o, n) -> n));
+                // 单曲排名
+                Map<Long, ActivityEvaluationRecord> collect = activityEvaluationRecordService.queryActivityUserHighestRankingInfo(query.getActivityId(), userIds).stream()
+                        .collect(Collectors.toMap(ActivityEvaluationRecord::getUserId, Function.identity(), (o, n) -> n));
 
-            ActivityEvaluationRecord record;
-            for (ActivityRegistrationVo item : activityUserInfos) {
+                ActivityEvaluationRecord record;
+                for (ActivityRegistrationVo item : activityUserInfos) {
 
-                if (collect.containsKey(item.getUserId())) {
+                    if (collect.containsKey(item.getUserId())) {
 
-                    record = collect.get(item.getUserId());
-                    // 重置当前时间为用户最高排名时间
-                    item.score(record.getScore())
-                            .times(record.getTimes())
-                            .setCreateTime(record.getCreateTime());
+                        record = collect.get(item.getUserId());
+                        // 重置当前时间为用户最高排名时间
+                        item.score(record.getScore())
+                                .times(record.getTimes())
+                                .setCreateTime(record.getCreateTime());
+                    }
                 }
             }
         }

+ 26 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/vo/ActivityMusicVo.java

@@ -159,4 +159,30 @@ public class ActivityMusicVo {
     public void setMusicImage(String musicImage) {
         this.musicImage = musicImage;
     }
+
+
+    public ActivityMusicVo score(double score) {
+        this.score = score;
+        return this;
+    }
+
+    public ActivityMusicVo userId(Long userId) {
+        this.userId = userId;
+        return this;
+    }
+
+    public ActivityMusicVo userAvatar(String userAvatar) {
+        this.userAvatar = userAvatar;
+        return this;
+    }
+
+    public ActivityMusicVo username(String username) {
+        this.username = username;
+        return this;
+    }
+
+    public ActivityMusicVo userSubject(String userSubject) {
+        this.userSubject = userSubject;
+        return this;
+    }
 }

+ 38 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/vo/ActivityRegistrationVo.java

@@ -1,9 +1,13 @@
 package com.yonge.cooleshow.biz.dal.vo;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
 import com.yonge.cooleshow.biz.dal.entity.ActivityRegistration;
+import com.yonge.cooleshow.biz.dal.enums.MK;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
+import java.util.Date;
+
 /**
  * @Author: liweifan
  * @Data: 2022-08-04 10:19:49
@@ -39,9 +43,17 @@ public class ActivityRegistrationVo extends ActivityRegistration{
 	// 用户高最排名信息
 	@ApiModelProperty("最高排名分数")
 	private Double score;
+	
 	@ApiModelProperty("最高排名次数")
 	private Integer times;
 
+	@ApiModelProperty("曲子声部")
+	private String subjectName;
+
+	@ApiModelProperty("最高分时间")
+	@JsonFormat(pattern = MK.TIME_PATTERN, timezone = MK.TIME_ZONE)
+	private Date scoreTime;
+
 	public String getRealName() {
 		return realName;
 	}
@@ -122,6 +134,22 @@ public class ActivityRegistrationVo extends ActivityRegistration{
 		this.times = times;
 	}
 
+	public String getSubjectName() {
+		return subjectName;
+	}
+
+	public void setSubjectName(String subjectName) {
+		this.subjectName = subjectName;
+	}
+
+	public Date getScoreTime() {
+		return scoreTime;
+	}
+
+	public void setScoreTime(Date scoreTime) {
+		this.scoreTime = scoreTime;
+	}
+
 	public ActivityRegistrationVo score(Double score) {
 		this.score = score;
 		return this;
@@ -131,4 +159,14 @@ public class ActivityRegistrationVo extends ActivityRegistration{
 		this.times = times;
 		return this;
 	}
+
+	public ActivityRegistrationVo subjectName(String subjectName) {
+		this.subjectName = subjectName;
+		return this;
+	}
+
+	public ActivityRegistrationVo scoreTime(Date scoreTime) {
+		this.scoreTime = scoreTime;
+		return this;
+	}
 }

+ 8 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/vo/MusicActivityVo.java

@@ -104,6 +104,9 @@ public class MusicActivityVo extends ActivityPlan {
         @ApiModelProperty("最高分用户头像")
         private String userAvatar;
 
+        @ApiModelProperty("最高分用户声部")
+        private String userSubject;
+
         @ApiModelProperty("最高分用户名")
         private String username;
 
@@ -130,5 +133,10 @@ public class MusicActivityVo extends ActivityPlan {
             this.username = username;
             return this;
         }
+
+        public SubjectInfo userSubject(String userSubject) {
+            this.userSubject = userSubject;
+            return this;
+        }
     }
 }