|
|
|
@ -1,24 +1,36 @@
|
|
|
|
|
package cn.teammodel.controller.admin.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.teammodel.common.ErrorCode;
|
|
|
|
|
import cn.teammodel.common.PK;
|
|
|
|
|
import cn.teammodel.config.exception.ServiceException;
|
|
|
|
|
import cn.teammodel.controller.admin.service.TeacherService;
|
|
|
|
|
import cn.teammodel.model.dto.admin.teacher.TeacherDto;
|
|
|
|
|
import cn.teammodel.model.entity.common.GroupList;
|
|
|
|
|
import cn.teammodel.model.entity.school.LessonRecord;
|
|
|
|
|
import cn.teammodel.model.entity.school.School;
|
|
|
|
|
import cn.teammodel.model.entity.school.SchoolTeacher;
|
|
|
|
|
import cn.teammodel.model.vo.appraise.RecordVo;
|
|
|
|
|
import cn.teammodel.repository.LessonRecordRepository;
|
|
|
|
|
import cn.teammodel.repository.SchoolGroupListRepository;
|
|
|
|
|
import cn.teammodel.repository.SchoolRepository;
|
|
|
|
|
import cn.teammodel.repository.SchoolTeacherRepository;
|
|
|
|
|
import cn.teammodel.utils.GroupUtil;
|
|
|
|
|
import cn.teammodel.utils.SchoolDateUtil;
|
|
|
|
|
import com.azure.spring.data.cosmos.core.query.CosmosPageRequest;
|
|
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
|
import org.springframework.data.domain.Slice;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import java.time.*;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
import static cn.teammodel.utils.SchoolDateUtil.calculateWeekNum;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class TeacherServiceImpl implements TeacherService {
|
|
|
|
|
@Resource
|
|
|
|
@ -27,6 +39,8 @@ public class TeacherServiceImpl implements TeacherService {
|
|
|
|
|
private SchoolTeacherRepository schoolTeacherRepository;
|
|
|
|
|
@Resource
|
|
|
|
|
private SchoolRepository schoolRepository;
|
|
|
|
|
@Resource
|
|
|
|
|
private LessonRecordRepository lessonRecordRepository;
|
|
|
|
|
@Autowired
|
|
|
|
|
private Environment env;
|
|
|
|
|
@Override
|
|
|
|
@ -95,6 +109,102 @@ public class TeacherServiceImpl implements TeacherService {
|
|
|
|
|
return teachers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<Long, Integer> getTeacherByRecord(TeacherDto teacherDto) {
|
|
|
|
|
final int SLICE_SIZE = 100;
|
|
|
|
|
// 获取学期起止时间
|
|
|
|
|
List<School.Semester> semesters = schoolRepository.findSemestersById(teacherDto.getCode(), teacherDto.getPeriodId());
|
|
|
|
|
SchoolDateUtil.semesterModel semesterModel = SchoolDateUtil.getSemesterByNow(semesters, LocalDate.now());
|
|
|
|
|
LocalDateTime startDatetime = null;
|
|
|
|
|
LocalDateTime endDatetime = null;
|
|
|
|
|
if(teacherDto.getStartTime() != null) {
|
|
|
|
|
startDatetime = LocalDateTime.ofInstant(Instant.ofEpochMilli(teacherDto.getStartTime()), ZoneId.systemDefault());
|
|
|
|
|
endDatetime = LocalDateTime.ofInstant(Instant.ofEpochMilli(teacherDto.getEndTime()), ZoneId.systemDefault());
|
|
|
|
|
}else {
|
|
|
|
|
startDatetime = semesterModel.getStartDatetime();
|
|
|
|
|
endDatetime = semesterModel.getEndDatetime();
|
|
|
|
|
}
|
|
|
|
|
if (startDatetime == null || endDatetime == null) throw new ServiceException(ErrorCode.PARAMS_ERROR);
|
|
|
|
|
long totalWeek = calculateWeekNum(startDatetime, endDatetime, null);
|
|
|
|
|
|
|
|
|
|
// slice 分段读取
|
|
|
|
|
CosmosPageRequest pageRequest = new CosmosPageRequest(0, SLICE_SIZE, null);
|
|
|
|
|
Slice<LessonRecord> slice;
|
|
|
|
|
Map<Long, Integer> countByWeek = SchoolDateUtil.createEmptyWeekMap(totalWeek);
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
slice = lessonRecordRepository.findAllByAcademicYearId(String.format(PK.PK_LESSON_RECORD, teacherDto.getCode()), teacherDto.getTmdId(),pageRequest);
|
|
|
|
|
List<LessonRecord> content = slice.getContent();
|
|
|
|
|
if (ObjectUtils.isEmpty(content)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 分批次计算
|
|
|
|
|
for (LessonRecord item : content) {
|
|
|
|
|
// 处理每周的课程数
|
|
|
|
|
long weekNum = calculateWeekNum(startDatetime, endDatetime, item.getStartTime());
|
|
|
|
|
countByWeek.put(weekNum, countByWeek.getOrDefault(weekNum, 0) + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (slice.hasNext()) {
|
|
|
|
|
pageRequest = (CosmosPageRequest) slice.nextPageable();
|
|
|
|
|
}
|
|
|
|
|
} while (slice.hasNext());
|
|
|
|
|
countByWeek.entrySet().removeIf(entry -> entry.getKey() == -1);
|
|
|
|
|
return countByWeek;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String, Object> getTeacherLearningCategory(TeacherDto teacherDto) {
|
|
|
|
|
|
|
|
|
|
Map<String, Object> LearningCategory = new HashMap<>(Collections.emptyMap());
|
|
|
|
|
try {
|
|
|
|
|
// 获取学期起止时间
|
|
|
|
|
List<School.Semester> semesters = schoolRepository.findSemestersById(teacherDto.getCode(), teacherDto.getPeriodId());
|
|
|
|
|
SchoolDateUtil.semesterModel semesterModel = SchoolDateUtil.getSemesterByNow(semesters, LocalDate.now());
|
|
|
|
|
LocalDateTime startDatetime = null;
|
|
|
|
|
LocalDateTime endDatetime = null;
|
|
|
|
|
if(teacherDto.getStartTime() != null) {
|
|
|
|
|
startDatetime = LocalDateTime.ofInstant(Instant.ofEpochMilli(teacherDto.getStartTime()), ZoneId.systemDefault());
|
|
|
|
|
endDatetime = LocalDateTime.ofInstant(Instant.ofEpochMilli(teacherDto.getEndTime()), ZoneId.systemDefault());
|
|
|
|
|
}else {
|
|
|
|
|
startDatetime = semesterModel.getStartDatetime();
|
|
|
|
|
endDatetime = semesterModel.getEndDatetime();
|
|
|
|
|
}
|
|
|
|
|
if (startDatetime == null || endDatetime == null) throw new ServiceException(ErrorCode.PARAMS_ERROR);
|
|
|
|
|
|
|
|
|
|
// 将 LocalDateTime 转换为 Long 类型的时间戳
|
|
|
|
|
long startTimestamp = startDatetime.toInstant(ZoneOffset.UTC).toEpochMilli();
|
|
|
|
|
long endTimestamp = endDatetime.toInstant(ZoneOffset.UTC).toEpochMilli();
|
|
|
|
|
|
|
|
|
|
List<LessonRecord> lessonRecords = lessonRecordRepository.getLessonsByConditions(String.format(PK.PK_LESSON_RECORD, teacherDto.getCode()), startTimestamp, endTimestamp, teacherDto.getTmdId());
|
|
|
|
|
int cooperationCount = 0;
|
|
|
|
|
int internetCount = 0;
|
|
|
|
|
int taskCount = 0;
|
|
|
|
|
int examCount = 0;
|
|
|
|
|
int diffentialCount = 0;
|
|
|
|
|
|
|
|
|
|
for (LessonRecord record : lessonRecords) {
|
|
|
|
|
if (record.getLearningCategory() != null) {
|
|
|
|
|
cooperationCount += record.getLearningCategory().getCooperation();
|
|
|
|
|
internetCount += record.getLearningCategory().getInteraction();
|
|
|
|
|
taskCount += record.getLearningCategory().getTask();
|
|
|
|
|
examCount += record.getLearningCategory().getExam();
|
|
|
|
|
diffentialCount += record.getLearningCategory().getDiffential();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
LearningCategory.put("cooperation", cooperationCount);
|
|
|
|
|
LearningCategory.put("internet", internetCount);
|
|
|
|
|
LearningCategory.put("task", taskCount);
|
|
|
|
|
LearningCategory.put("exam", examCount);
|
|
|
|
|
LearningCategory.put("diffential", diffentialCount);
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
throw new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "数据转换错误");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return LearningCategory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static @NotNull Map<String, Integer> getStringIntegerMap(List<School.Subject> subjects, List<SchoolTeacher> schoolTeachers) {
|
|
|
|
|
Map<String, String> subjectNameMap = new HashMap<>();
|
|
|
|
|
for (School.Subject subject : subjects) {
|
|
|
|
|