|  | @@ -9,11 +9,14 @@ import com.ym.mec.biz.dal.enums.StudentMusicGroupStatusEnum;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.wrapper.SchoolIndexStatWrapper;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.service.SchoolIndexStatService;
 | 
	
		
			
				|  |  |  import com.ym.mec.util.collection.MapUtil;
 | 
	
		
			
				|  |  | +import com.ym.mec.util.date.DateUtil;
 | 
	
		
			
				|  |  |  import org.apache.commons.collections.CollectionUtils;
 | 
	
		
			
				|  |  |  import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import javax.annotation.Resource;
 | 
	
		
			
				|  |  | +import java.math.BigDecimal;
 | 
	
		
			
				|  |  | +import java.text.Collator;
 | 
	
		
			
				|  |  |  import java.util.*;
 | 
	
		
			
				|  |  |  import java.util.stream.Collectors;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -53,6 +56,12 @@ public class SchoolIndexStatServiceImpl implements SchoolIndexStatService {
 | 
	
		
			
				|  |  |          Map<Integer, String> subjectMap = subjectDao.findBySubjectIds(subjectIdList).stream().collect(Collectors.toMap(Subject::getId, s -> s.getName(), (s1, s2) -> s1));
 | 
	
		
			
				|  |  |          //年级分布
 | 
	
		
			
				|  |  |          List<SchoolIndexStatWrapper.GradeDistribution> gradeDistributions = studentRegistrations.stream()
 | 
	
		
			
				|  |  | +                .map(e -> {
 | 
	
		
			
				|  |  | +                    if (e.getCurrentGrade() == null) {
 | 
	
		
			
				|  |  | +                        e.setCurrentGrade("一年级");
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    return e;
 | 
	
		
			
				|  |  | +                })
 | 
	
		
			
				|  |  |                  .collect(Collectors.groupingBy(
 | 
	
		
			
				|  |  |                          e -> e.getCurrentGrade(),
 | 
	
		
			
				|  |  |                          Collectors.collectingAndThen(
 | 
	
	
		
			
				|  | @@ -67,9 +76,10 @@ public class SchoolIndexStatServiceImpl implements SchoolIndexStatService {
 | 
	
		
			
				|  |  |                      distribution.setStudentNum(entry.getValue());
 | 
	
		
			
				|  |  |                      return distribution;
 | 
	
		
			
				|  |  |                  })
 | 
	
		
			
				|  |  | -                .sorted(Comparator.comparing(SchoolIndexStatWrapper.GradeDistribution::getGrade))
 | 
	
		
			
				|  |  | +                .sorted(Comparator.comparingInt(entry -> gradeOrder.indexOf(entry.getGrade())))
 | 
	
		
			
				|  |  |                  .collect(Collectors.toList());
 | 
	
		
			
				|  |  |          result.setGradeDistributions(gradeDistributions);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          //声部分布
 | 
	
		
			
				|  |  |          List<SchoolIndexStatWrapper.SubjectDistribution> subjectDistributions = studentRegistrations.stream()
 | 
	
		
			
				|  |  |                  .collect(Collectors.groupingBy(
 | 
	
	
		
			
				|  | @@ -121,6 +131,7 @@ public class SchoolIndexStatServiceImpl implements SchoolIndexStatService {
 | 
	
		
			
				|  |  |                  });
 | 
	
		
			
				|  |  |              });
 | 
	
		
			
				|  |  |          });
 | 
	
		
			
				|  |  | +        musicGradeDistributions.sort(Comparator.comparingInt(entry -> gradeOrder.indexOf(entry.getGrade())));
 | 
	
		
			
				|  |  |          result.setMusicGradeDistributions(musicGradeDistributions);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          //声部年级分组
 | 
	
	
		
			
				|  | @@ -145,6 +156,7 @@ public class SchoolIndexStatServiceImpl implements SchoolIndexStatService {
 | 
	
		
			
				|  |  |                  subjectGradeDistributions.add(gradeDistribution);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        subjectGradeDistributions.sort(Comparator.comparingInt(entry -> gradeOrder.indexOf(entry.getGrade())));
 | 
	
		
			
				|  |  |          result.setSubjectGradeDistributions(subjectGradeDistributions);
 | 
	
		
			
				|  |  |          return result;
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -160,12 +172,14 @@ public class SchoolIndexStatServiceImpl implements SchoolIndexStatService {
 | 
	
		
			
				|  |  |          if(CollectionUtils.isEmpty(musicGroupIds)){
 | 
	
		
			
				|  |  |              return new SchoolIndexStatWrapper.StudentAttendance();
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        this.setTime(queryDto);
 | 
	
		
			
				|  |  |          //获取学员考勤数据
 | 
	
		
			
				|  |  |          SchoolIndexStatWrapper.StudentAttendance studentAttendance = studentAttendanceDao.statCoopAttendance(musicGroupIds,queryDto);
 | 
	
		
			
				|  |  |          if(Objects.nonNull(studentAttendance)){
 | 
	
		
			
				|  |  | -            int num = studentAttendance.getNormalNum() + studentAttendance.getLateNum();
 | 
	
		
			
				|  |  | +            Integer num = studentAttendance.getNormalNum() + studentAttendance.getLateNum();
 | 
	
		
			
				|  |  |              if(num > 0){
 | 
	
		
			
				|  |  | -                studentAttendance.setAttendanceRate(num / studentAttendance.getTotalNum());
 | 
	
		
			
				|  |  | +                studentAttendance.setAttendanceRate(new BigDecimal(num).
 | 
	
		
			
				|  |  | +                        divide(new BigDecimal(studentAttendance.getTotalNum()),4,BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).setScale(2));
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return studentAttendance;
 | 
	
	
		
			
				|  | @@ -182,6 +196,59 @@ public class SchoolIndexStatServiceImpl implements SchoolIndexStatService {
 | 
	
		
			
				|  |  |          if(CollectionUtils.isEmpty(musicGroupIds)){
 | 
	
		
			
				|  |  |              return new SchoolIndexStatWrapper.StudentLesson();
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        return lessonExaminationDao.schoolLessonStat(musicGroupIds,queryDto);
 | 
	
		
			
				|  |  | +        this.setTime(queryDto);
 | 
	
		
			
				|  |  | +        SchoolIndexStatWrapper.StudentLesson studentLesson = lessonExaminationDao.schoolLessonStat(musicGroupIds, queryDto);
 | 
	
		
			
				|  |  | +        if(Objects.nonNull(studentLesson)){
 | 
	
		
			
				|  |  | +            if(studentLesson.getActualNum() > 0){
 | 
	
		
			
				|  |  | +                studentLesson.setCommitRate(new BigDecimal(studentLesson.getActualNum()).
 | 
	
		
			
				|  |  | +                        divide(new BigDecimal(studentLesson.getExpectNum()),4,BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).setScale(2));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if(studentLesson.getPassNum() > 0){
 | 
	
		
			
				|  |  | +                studentLesson.setPassRate(new BigDecimal(studentLesson.getPassNum()).
 | 
	
		
			
				|  |  | +                        divide(new BigDecimal(studentLesson.getExpectNum()),4,BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).setScale(2));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return studentLesson;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void setTime(SchoolIndexStatWrapper.QueryDto queryDto){
 | 
	
		
			
				|  |  | +        if(StringUtils.isNotEmpty(queryDto.getPeriod())){
 | 
	
		
			
				|  |  | +            Date now = new Date();
 | 
	
		
			
				|  |  | +            if(queryDto.getPeriod().equals("week")){
 | 
	
		
			
				|  |  | +                queryDto.setStartTime(DateUtil.format(DateUtil.getWeekDayWithDate(now,Calendar.MONDAY),DateUtil.DEFAULT_PATTERN));
 | 
	
		
			
				|  |  | +                queryDto.setEndTime(DateUtil.format(DateUtil.getWeekDayWithDate(now,Calendar.SUNDAY),DateUtil.DEFAULT_PATTERN));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if(queryDto.getPeriod().equals("month")){
 | 
	
		
			
				|  |  | +                DateUtil.getFirstDayOfMonth(now);
 | 
	
		
			
				|  |  | +                queryDto.setStartTime(DateUtil.format(DateUtil.getFirstDayOfMonth(now),DateUtil.DEFAULT_PATTERN));
 | 
	
		
			
				|  |  | +                queryDto.setEndTime(DateUtil.format(DateUtil.getLastDayOfMonth(now),DateUtil.DEFAULT_PATTERN));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if(queryDto.getPeriod().equals("term")){
 | 
	
		
			
				|  |  | +                queryDto.setStartTime(DateUtil.getStartTerm(now));
 | 
	
		
			
				|  |  | +                queryDto.setEndTime(DateUtil.getEndTerm(now));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    // 定义自定义顺序的列表
 | 
	
		
			
				|  |  | +    List<String> gradeOrder = Arrays.asList(
 | 
	
		
			
				|  |  | +            "一年级",
 | 
	
		
			
				|  |  | +            "二年级",
 | 
	
		
			
				|  |  | +            "三年级",
 | 
	
		
			
				|  |  | +            "四年级",
 | 
	
		
			
				|  |  | +            "五年级",
 | 
	
		
			
				|  |  | +            "六年级",
 | 
	
		
			
				|  |  | +            "六年级/初一",
 | 
	
		
			
				|  |  | +            "七年级/初一",
 | 
	
		
			
				|  |  | +            "初一/七年级",
 | 
	
		
			
				|  |  | +            "七年级/初二",
 | 
	
		
			
				|  |  | +            "八年级/初二",
 | 
	
		
			
				|  |  | +            "初二/八年级",
 | 
	
		
			
				|  |  | +            "八年级/初三",
 | 
	
		
			
				|  |  | +            "初三/九年级",
 | 
	
		
			
				|  |  | +            "九年级/初三",
 | 
	
		
			
				|  |  | +            "高一",
 | 
	
		
			
				|  |  | +            "高二",
 | 
	
		
			
				|  |  | +            "高三"
 | 
	
		
			
				|  |  | +    );
 | 
	
		
			
				|  |  |  }
 |