Browse Source

vip定制课

zouxuan 4 months ago
parent
commit
c5b0482ca4

+ 15 - 17
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/SysMusicCompareRecordServiceImpl.java

@@ -566,34 +566,32 @@ public class SysMusicCompareRecordServiceImpl extends BaseServiceImpl<Long, SysM
 		}
 		List<TeacherIndexWrapper.PracticeTimeDto> studentTrainTime = sysMusicCompareRecordDao.getStudentTrainTime(studentIds, summarySearch, groupBy);
 		//补全时间段
-		fillData(studentTrainTime,dateList);
-		teacherPracticeHome.setPracticeTimes(studentTrainTime);
+		teacherPracticeHome.setPracticeTimes(fillData(studentTrainTime,dateList));
 		//练习人数
 		List<TeacherIndexWrapper.PracticeTimeDto> studentTrainCount = sysMusicCompareRecordDao.getStudentTrainCount(studentIds, summarySearch, groupBy);
 		//补全时间段
-		fillData(studentTrainCount,dateList);
-		teacherPracticeHome.setPracticeCounts(studentTrainCount);
+		teacherPracticeHome.setPracticeCounts(fillData(studentTrainCount,dateList));
 
         return teacherPracticeHome;
     }
 
-	//数据补全
-	private void fillData(List<TeacherIndexWrapper.PracticeTimeDto> studentTrainTime, List<String> dateList) {
+	//数据补全,按时间顺序
+	private List<TeacherIndexWrapper.PracticeTimeDto> fillData(List<TeacherIndexWrapper.PracticeTimeDto> studentTrainTime, List<String> dateList) {
 		if(CollectionUtils.isEmpty(studentTrainTime)){
-			return;
+			return studentTrainTime;
 		}
-		for (String date : dateList) {
-			boolean flag = false;
-			for (TeacherIndexWrapper.PracticeTimeDto practiceTimeDto : studentTrainTime) {
-				if(StringUtils.equals(date,practiceTimeDto.getDate())){
-					flag = true;
-					break;
-				}
-			}
-			if(!flag){
-				studentTrainTime.add(new TeacherIndexWrapper.PracticeTimeDto(date,0L));
+		Map<String,TeacherIndexWrapper.PracticeTimeDto> timeMap = studentTrainTime.stream()
+				.collect(Collectors.toMap(TeacherIndexWrapper.PracticeTimeDto::getDate, o -> o));
+		List<TeacherIndexWrapper.PracticeTimeDto> result = new ArrayList<>();
+		for (String s : dateList) {
+			TeacherIndexWrapper.PracticeTimeDto practiceTimeDto = timeMap.get(s);
+			if(Objects.nonNull(practiceTimeDto)){
+				result.add(practiceTimeDto);
+			}else {
+				result.add(new TeacherIndexWrapper.PracticeTimeDto(s,0L));
 			}
 		}
+		return result;
 	}
 
 	@Override