|
@@ -76,28 +76,42 @@ public class SysMusicCompareRecordServiceImpl extends BaseServiceImpl<Long, SysM
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public StatDto rankingList(Integer headUserId, String startDate, String endDate) {
|
|
|
- SysUser user = teacherDao.getUser(headUserId);
|
|
|
+ public StatDto rankingList(Integer headUserId,int type, String startDate, String endDate) {
|
|
|
StatDto result = new StatDto();
|
|
|
MusicCompareRankingDto head = new MusicCompareRankingDto();
|
|
|
head.setUserId(headUserId);
|
|
|
List<MusicCompareRankingDto> userTrainStat = sysMusicCompareRecordDao.getUserTrainStat(startDate, endDate);
|
|
|
List<MusicCompareRankingDto> detail = new ArrayList<>();
|
|
|
- userTrainStat.sort(Comparator.comparing(m->m.getTrainDays()+m.getTrainNum()+m.getTrainTime()));
|
|
|
- for (int i = 0; i < userTrainStat.size(); i++) {
|
|
|
- userTrainStat.get(i).setRankNum(userTrainStat.size()-i);
|
|
|
- userTrainStat.get(i).setTrainTime(userTrainStat.get(i).getTrainTime()/60);
|
|
|
- if(userTrainStat.get(i).getUserId().equals(headUserId)){
|
|
|
- head = userTrainStat.get(i);
|
|
|
+ switch (type){
|
|
|
+ case 1:
|
|
|
+ userTrainStat.sort(Comparator.comparing(m->m.getScore(), Comparator.reverseOrder()));
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ userTrainStat.sort(Comparator.comparing(m->m.getTrainDays(), Comparator.reverseOrder()));
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ userTrainStat.sort(Comparator.comparing(m->m.getTrainTime(), Comparator.reverseOrder()));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ detail = userTrainStat.subList(0, 10);
|
|
|
+ List<Integer> studentIds = detail.stream().map(MusicCompareRankingDto::getUserId).collect(Collectors.toList());
|
|
|
+ Map<Integer, String> studentSubjectMap = new HashMap<>();
|
|
|
+ if(!CollectionUtils.isEmpty(studentIds)){
|
|
|
+ List<Map<Integer, String>> studentSubjectMapList = studentDao.getStudentSubjectMapList(studentIds);
|
|
|
+ studentSubjectMap = MapUtil.convertIntegerMap(studentSubjectMapList);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < detail.size(); i++) {
|
|
|
+ detail.get(i).setRankNum(i+1);
|
|
|
+ detail.get(i).setTrainTime(detail.get(i).getTrainTime()/60);
|
|
|
+ if(detail.get(i).getUserId().equals(headUserId)){
|
|
|
+ head = detail.get(i);
|
|
|
}
|
|
|
- if(userTrainStat.get(i).getRankNum()<=10){
|
|
|
- detail.add(userTrainStat.get(i));
|
|
|
+ if(studentSubjectMap.containsKey(detail.get(i).getUserId())){
|
|
|
+ detail.get(i).setSubjectName(studentSubjectMap.get(detail.get(i).getUserId()));
|
|
|
}
|
|
|
}
|
|
|
- if(Objects.isNull(head.getRankNum())&&Objects.nonNull(user)){
|
|
|
- head.setAvatar(user.getAvatar());
|
|
|
- head.setStudentName(user.getUsername());
|
|
|
- }
|
|
|
result.setHead(head);
|
|
|
detail.sort(Comparator.comparing(MusicCompareRankingDto::getRankNum).thenComparing(MusicCompareRankingDto::getUserId));
|
|
|
result.setDetail(detail);
|