update 五育数据整合

develop
hhb@hotmail.com 2 weeks ago
parent 527f6ecd69
commit b62bf53ca6

@ -202,6 +202,15 @@ public class LaborEducationServiceImpl implements LaborEducationService {
resMap.put("rightCount", rightCount);//表扬评价数 resMap.put("rightCount", rightCount);//表扬评价数
resMap.put("wrongCount", wrongCount);//待改进评价数 resMap.put("wrongCount", wrongCount);//待改进评价数
resMap.put("uniqueTargetIdCount", uniqueTargetIdCount);//评价学生数 resMap.put("uniqueTargetIdCount", uniqueTargetIdCount);//评价学生数
//处理单个学生评价内容列表信息
List<RecordVo> studentAppraise = new ArrayList<>();
if (laborDto.getStudentId() != null) {
studentAppraise = res.stream()
.filter(record -> record.getTargetId().equals(laborDto.getStudentId()))
.collect(Collectors.toList());
resMap.put("studentAppraise", studentAppraise);//学生评价内容
//res= appraiseRecordRepository.getRecords(String.format(PK.PK_APPRAISE_RECORD, laborDto.getCode()),laborDto.getAcademicYearId(), laborDto.getClassId(), laborDto.getStudentId(),"德育");
}
Appraise appraise = appraiseRepository.findAppraiseBySchoolIdAndPeriodIdAndCode(schoolId, periodId, PK.PK_APPRAISE); Appraise appraise = appraiseRepository.findAppraiseBySchoolIdAndPeriodIdAndCode(schoolId, periodId, PK.PK_APPRAISE);
if (appraise != null) { if (appraise != null) {
appraise = evaluationService.buildTree(appraise); appraise = evaluationService.buildTree(appraise);

@ -201,6 +201,16 @@ public class MoralEducationServiceImpl implements MoralEducationService {
resMap.put("rightCount", rightCount);//表扬评价数 resMap.put("rightCount", rightCount);//表扬评价数
resMap.put("wrongCount", wrongCount);//待改进评价数 resMap.put("wrongCount", wrongCount);//待改进评价数
resMap.put("uniqueTargetIdCount", uniqueTargetIdCount);//评价学生数 resMap.put("uniqueTargetIdCount", uniqueTargetIdCount);//评价学生数
//处理单个学生评价内容列表信息
List<RecordVo> studentAppraise = new ArrayList<>();
if (moralDto.getStudentId() != null) {
studentAppraise = res.stream()
.filter(record -> record.getTargetId().equals(moralDto.getStudentId()))
.collect(Collectors.toList());
resMap.put("studentAppraise", studentAppraise);//学生评价内容
//res= appraiseRecordRepository.getRecords(String.format(PK.PK_APPRAISE_RECORD, laborDto.getCode()),laborDto.getAcademicYearId(), laborDto.getClassId(), laborDto.getStudentId(),"德育");
}
Appraise appraise = appraiseRepository.findAppraiseBySchoolIdAndPeriodIdAndCode(schoolId, periodId, PK.PK_APPRAISE); Appraise appraise = appraiseRepository.findAppraiseBySchoolIdAndPeriodIdAndCode(schoolId, periodId, PK.PK_APPRAISE);
if (appraise != null) { if (appraise != null) {
appraise = evaluationService.buildTree(appraise); appraise = evaluationService.buildTree(appraise);

@ -87,19 +87,30 @@ public class TeacherServiceImpl implements TeacherService {
private static final double PAPER_COEFFICIENT = 10.0; private static final double PAPER_COEFFICIENT = 10.0;
private static final double BASE_SCORE = 60.0; private static final double BASE_SCORE = 60.0;
private static final int CACHE_EXPIRATION_HOURS = 8;
private static final int CACHE_MAXIMUM_SIZE = 1000;
private static final TimeUnit CACHE_EXPIRATION_UNIT = TimeUnit.HOURS;
// 添加日志对象 // 添加日志对象
private static final Logger logger = LoggerFactory.getLogger(TeacherServiceImpl.class); private static final Logger logger = LoggerFactory.getLogger(TeacherServiceImpl.class);
// 引入缓存,需根据实际情况配置大小和过期时间 每次服务重启时 缓存会清空 // 引入缓存,需根据实际情况配置大小和过期时间 每次服务重启时 缓存会清空
// 初始化Guava Cache
private Cache<String, Map<String, Object>> teacherCache; private Cache<String, Map<String, Object>> teacherCache;
private Cache<String, List<Map<String, Object>>> ptTeacherCache;
private Cache<String, Map<Long, Integer>> lessonRecordCache;
@PostConstruct @PostConstruct
public void init() { public void init() {
teacherCache = CacheBuilder.newBuilder() // 创建公共配置的CacheBuilder
.expireAfterWrite(1, TimeUnit.HOURS) // 缓存1小时 CacheBuilder<Object, Object> cacheBuilder = CacheBuilder.newBuilder()
.maximumSize(1000) // 最大缓存数量 .expireAfterWrite(CACHE_EXPIRATION_HOURS, CACHE_EXPIRATION_UNIT)
.build(); .maximumSize(CACHE_MAXIMUM_SIZE);
// 构建各缓存实例
teacherCache = cacheBuilder.build();
ptTeacherCache = cacheBuilder.build();
lessonRecordCache = cacheBuilder.build();
} }
@Cacheable(value = "schoolGroupCache", key = "#code") @Cacheable(value = "schoolGroupCache", key = "#code")
@ -569,6 +580,16 @@ public class TeacherServiceImpl implements TeacherService {
public Map<Long, Integer> getTeacherByRecord(TeacherDto teacherDto) { public Map<Long, Integer> getTeacherByRecord(TeacherDto teacherDto) {
final int SLICE_SIZE = 10000; final int SLICE_SIZE = 10000;
// 获取学期起止时间 // 获取学期起止时间
String cacheKey = String.format("ptTeachers:%s:%s:%s:%s",
teacherDto.getCode(),
teacherDto.getPeriodId(),
teacherDto.getStartTime(),
teacherDto.getEndTime()); // 基于学校代码的缓存键
Map<Long, Integer> cachedResult = lessonRecordCache.getIfPresent(cacheKey);
if (cachedResult != null) {
return cachedResult;
}
List<School.Semester> semesters = schoolRepository.findSemestersById(teacherDto.getCode(), teacherDto.getPeriodId()); List<School.Semester> semesters = schoolRepository.findSemestersById(teacherDto.getCode(), teacherDto.getPeriodId());
SchoolDateUtil.semesterModel semesterModel = SchoolDateUtil.getSemesterByNow(semesters, LocalDate.now()); SchoolDateUtil.semesterModel semesterModel = SchoolDateUtil.getSemesterByNow(semesters, LocalDate.now());
LocalDateTime startDatetime; LocalDateTime startDatetime;
@ -612,6 +633,7 @@ public class TeacherServiceImpl implements TeacherService {
} }
} while (slice.hasNext() && !Thread.currentThread().isInterrupted()); } while (slice.hasNext() && !Thread.currentThread().isInterrupted());
countByWeek.entrySet().removeIf(entry -> entry.getKey() == -1); countByWeek.entrySet().removeIf(entry -> entry.getKey() == -1);
lessonRecordCache.put(cacheKey, countByWeek);
return countByWeek; return countByWeek;
} }
@ -1052,7 +1074,7 @@ public class TeacherServiceImpl implements TeacherService {
lessonRecordKey, startTime, endTime, subjectId, tmdId, grade, periodId lessonRecordKey, startTime, endTime, subjectId, tmdId, grade, periodId
); );
System.out.println("查询到的记录数量: " + records.size()); //System.out.println("查询到的记录数量: " + records.size());
} catch (InterruptedException | ExecutionException e) { } catch (InterruptedException | ExecutionException e) {
throw new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "数据查询异常"); throw new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "数据查询异常");
} finally { } finally {
@ -2062,7 +2084,17 @@ public class TeacherServiceImpl implements TeacherService {
String code = String.format(PK.PTTEACHER, teacherDto.getCode()); String code = String.format(PK.PTTEACHER, teacherDto.getCode());
String LessonCode = String.format(PK.PK_LESSON_RECORD, teacherDto.getCode()); String LessonCode = String.format(PK.PK_LESSON_RECORD, teacherDto.getCode());
List<Map<String, Object>> ptTeachers = new ArrayList<>(); List<Map<String, Object>> ptTeachers = new ArrayList<>();
String cacheKey = String.format("ptTeachers:%s:%s:%s:%s",
teacherDto.getCode(),
teacherDto.getPeriodId(),
teacherDto.getStartTime(),
teacherDto.getEndTime()); // 基于学校代码的缓存键
try { try {
List<Map<String, Object>> cachedResult = ptTeacherCache.getIfPresent(cacheKey);
if (cachedResult != null) {
return cachedResult;
}
// 检查缓存
List<PtTeacherInfo> ptTeacherInfos = ptTeacherRepository.findAllTeacher(teacherDto.getCode(), code,teacherDto.getPeriodId()); List<PtTeacherInfo> ptTeacherInfos = ptTeacherRepository.findAllTeacher(teacherDto.getCode(), code,teacherDto.getPeriodId());
//获取ptTeacherInfos中所有的老师ID //获取ptTeacherInfos中所有的老师ID
List<String> teacherIds = ptTeacherInfos.stream().map(PtTeacherInfo::getId).collect(Collectors.toList()); List<String> teacherIds = ptTeacherInfos.stream().map(PtTeacherInfo::getId).collect(Collectors.toList());
@ -2178,6 +2210,7 @@ public class TeacherServiceImpl implements TeacherService {
ptTeachers.add(ptTeacher); ptTeachers.add(ptTeacher);
} }
} }
ptTeacherCache.put(cacheKey, ptTeachers);
return ptTeachers; return ptTeachers;
} catch (Exception e) { } catch (Exception e) {
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "获取数据异常"); throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "获取数据异常");
@ -2471,10 +2504,10 @@ public class TeacherServiceImpl implements TeacherService {
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// 引入缓存,需根据实际情况配置大小和过期时间 每次服务重启时 缓存会清空 // 引入缓存,需根据实际情况配置大小和过期时间 每次服务重启时 缓存会清空
private static final Cache<String, Map<String, Object>> REQUEST_CACHE = CacheBuilder.newBuilder() // private static final Cache<String, Map<String, Object>> REQUEST_CACHE = CacheBuilder.newBuilder()
.maximumSize(500) // .maximumSize(500)
.expireAfterWrite(8, TimeUnit.HOURS) // .expireAfterWrite(8, TimeUnit.HOURS)
.build(); // .build();
@NotNull @NotNull
private List<SugVo> getSugVos(TeacherDto teacherDto, HttpServletRequest request) { private List<SugVo> getSugVos(TeacherDto teacherDto, HttpServletRequest request) {
@ -2493,7 +2526,7 @@ public class TeacherServiceImpl implements TeacherService {
// 生成缓存键,根据实际参数组合 // 生成缓存键,根据实际参数组合
String cacheKey = generateCacheKey(teacherDto); String cacheKey = generateCacheKey(teacherDto);
overView = REQUEST_CACHE.get(cacheKey, () -> { overView = teacherCache.get(cacheKey, () -> {
// 缓存未命中时调用第三方接口 // 缓存未命中时调用第三方接口
return GroupUtil.getGroupId(teacherDto, new GroupUtil(env), request, url); return GroupUtil.getGroupId(teacherDto, new GroupUtil(env), request, url);
}); });

Loading…
Cancel
Save