| | |
| | | .build(); |
| | | // 初始化认证缓存、学习时长缓存 |
| | | caffeineCache.put(CaffeineConstant.AUTH, new HashMap<>(128)); |
| | | caffeineCache.put(CaffeineConstant.AUTH, new HashMap<>(128)); |
| | | caffeineCache.put(CaffeineConstant.STUDY_RECORD, new HashMap<>(128)); |
| | | return caffeineCache; |
| | | } |
| | | } |
| | |
| | | */ |
| | | public final static String AUTH = "AUTH"; |
| | | |
| | | /** |
| | | * 记录学习时长 |
| | | * |
| | | */ |
| | | public final static String STUDY_RECORD ="STUDY_RECORD"; |
| | | } |
New file |
| | |
| | | package com.ycl.jxkg.controller.student; |
| | | |
| | | |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.ycl.jxkg.base.BaseApiController; |
| | | import com.ycl.jxkg.base.Result; |
| | | import com.ycl.jxkg.domain.entity.Subject; |
| | | import com.ycl.jxkg.domain.vo.admin.education.SubjectEditRequestVO; |
| | | import com.ycl.jxkg.domain.vo.admin.education.SubjectPageRequestVO; |
| | | import com.ycl.jxkg.domain.vo.admin.education.SubjectResponseVO; |
| | | import com.ycl.jxkg.service.SubjectService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.validation.Valid; |
| | | import java.util.List; |
| | | |
| | | @RequiredArgsConstructor |
| | | @RestController("StudentSubjectController") |
| | | @RequestMapping(value = "/api/student/subject") |
| | | public class SubjectController extends BaseApiController { |
| | | |
| | | private final SubjectService subjectService; |
| | | |
| | | @RequestMapping(value = "/list", method = RequestMethod.POST) |
| | | public Result<List<Subject>> list() { |
| | | List<Subject> subjects = subjectService.allSubject(); |
| | | return Result.ok(subjects); |
| | | } |
| | | } |
| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.github.benmanes.caffeine.cache.Cache; |
| | | import com.ycl.jxkg.constants.CaffeineConstant; |
| | | import com.ycl.jxkg.domain.entity.StudyRecord; |
| | | import com.ycl.jxkg.mapper.StudyRecordMapper; |
| | | import com.ycl.jxkg.service.StudyRecordService; |
| | |
| | | private void updateStudyRecord() { |
| | | log.info("开始存学习时长"); |
| | | List<StudyRecord> cacheList = new ArrayList<>(); |
| | | // 取出所有缓存项 |
| | | // 取出所有学习记录缓存项 |
| | | ConcurrentMap<String, Object> map = caffeineCache.asMap(); |
| | | for (Map.Entry<String, Object> entry : map.entrySet()) { |
| | | String key = entry.getKey(); |
| | | if (key.startsWith("STUDENT_")) { |
| | | StudyRecord studyRecord = (StudyRecord) entry.getValue(); |
| | | cacheList.add(studyRecord); |
| | | } |
| | | Map<String,StudyRecord> studyMap = (Map<String, StudyRecord>) map.get(CaffeineConstant.STUDY_RECORD); |
| | | 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)) { |
| | | //数据库中已经存在的学生数据 |
| | |
| | | } |
| | | studyRecordService.saveOrUpdateBatch(cacheList); |
| | | } |
| | | caffeineCache.invalidateAll(map.keySet()); |
| | | caffeineCache.invalidate(CaffeineConstant.STUDY_RECORD); |
| | | log.info("结束存学习时长"); |
| | | } |
| | | } |