fuliqi
2024-07-11 83024eccacc54be0e60eee14d19d03bf9d63ba78
src/main/java/com/ycl/jxkg/job/StudyRecordJob.java
@@ -38,30 +38,31 @@
        log.info("开始存学习时长");
        List<StudyRecord> cacheList = new ArrayList<>();
        // 取出所有学习记录缓存项
        ConcurrentMap<String, Object> map = caffeineCache.asMap();
        Map<String,StudyRecord> studyMap = (Map<String, StudyRecord>) map.get(CaffeineConstant.STUDY_RECORD);
        for (Map.Entry<String, StudyRecord> entry : studyMap.entrySet()) {
            cacheList.add(entry.getValue());
        }
        Map<String, StudyRecord> studyMap = (Map<String, StudyRecord>) caffeineCache.getIfPresent(CaffeineConstant.STUDY_RECORD);
        if (!CollectionUtils.isEmpty(studyMap)) {
            for (Map.Entry<String, StudyRecord> entry : studyMap.entrySet()) {
                cacheList.add(entry.getValue());
            }
        List<Integer> studentIds = cacheList.stream().map(StudyRecord::getStudentId).collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(studentIds)) {
            //数据库中已经存在的学生数据
            QueryWrapper<StudyRecord> wrapper = new QueryWrapper<>();
            wrapper.in("student_id", studentIds);
            List<StudyRecord> studyRecords = studyRecordMapper.selectList(wrapper);
            for (StudyRecord record : studyRecords) {
                for (StudyRecord cacheRecord : cacheList) {
                    if (record.getStudentId().equals(cacheRecord.getStudentId())) {
                        cacheRecord.setId(record.getId());
                        cacheRecord.setStudyTime(record.getStudyTime() + cacheRecord.getStudyTime());
                        cacheRecord.setMeetCount(record.getMeetCount());
            List<Integer> studentIds = cacheList.stream().map(StudyRecord::getStudentId).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(studentIds)) {
                //数据库中已经存在的学生数据
                QueryWrapper<StudyRecord> wrapper = new QueryWrapper<>();
                wrapper.in("student_id", studentIds);
                List<StudyRecord> studyRecords = studyRecordMapper.selectList(wrapper);
                for (StudyRecord record : studyRecords) {
                    for (StudyRecord cacheRecord : cacheList) {
                        if (record.getStudentId().equals(cacheRecord.getStudentId())) {
                            cacheRecord.setId(record.getId());
                            cacheRecord.setStudyTime(record.getStudyTime() + cacheRecord.getStudyTime());
                            cacheRecord.setMeetCount(record.getMeetCount());
                        }
                    }
                }
                studyRecordService.saveOrUpdateBatch(cacheList);
            }
            studyRecordService.saveOrUpdateBatch(cacheList);
            caffeineCache.invalidate(CaffeineConstant.STUDY_RECORD);
        }
        caffeineCache.invalidate(CaffeineConstant.STUDY_RECORD);
        log.info("结束存学习时长");
    }
}