wangliang 4 роки тому
батько
коміт
a47e43bed6

+ 22 - 5
themis-business/src/main/java/com/qmth/themis/business/service/TEExamActivityService.java

@@ -81,9 +81,26 @@ public interface TEExamActivityService extends IService<TEExamActivity> {
      */
     public List<TEExamActivityDto> getWaitingExam(Long studentId, Long examId, Long examActivityId);
 
-	/**获取场次缓存
-	 * @param examActivityId
-	 * @return
-	 */
-	ExamActivityCacheBean getExamActivityCacheBean(Long examActivityId);
+    /**
+     * 获取场次缓存
+     *
+     * @param examActivityId
+     * @return
+     */
+    ExamActivityCacheBean getExamActivityCacheBean(Long examActivityId);
+
+    /**
+     * 更新场次缓存
+     *
+     * @param examActivityId
+     * @return
+     */
+    ExamActivityCacheBean updateExamActivityCacheBean(Long examActivityId);
+
+    /**
+     * 删除场次缓存
+     *
+     * @param examActivityId
+     */
+    void deleteExamActivityCacheBean(Long examActivityId);
 }

+ 19 - 2
themis-business/src/main/java/com/qmth/themis/business/service/TEExamCourseService.java

@@ -29,7 +29,24 @@ public interface TEExamCourseService extends IService<TEExamCourse> {
     public IPage<TEExamCourse> examCourseQuery(IPage<Map> iPage, Long examId, String courseCode, String courseName, Integer hasPaper);
 
 
-	ExamCourseCacheBean getExamCourseCacheBean(Long examId, String courseCode);
+    ExamCourseCacheBean getExamCourseCacheBean(Long examId, String courseCode);
 
-	TEExamCourse findByExamIdAndCourseCode(Long examId, String courseCode);
+    /**
+     * 更新科目缓存
+     *
+     * @param examId
+     * @param courseCode
+     * @return
+     */
+    ExamCourseCacheBean updateExamCourseCacheBean(Long examId, String courseCode);
+
+    /**
+     * 删除科目缓存
+     *
+     * @param examId
+     * @param courseCode
+     */
+    void deleteExamCourseCacheBean(Long examId, String courseCode);
+
+    TEExamCourse findByExamIdAndCourseCode(Long examId, String courseCode);
 }

+ 26 - 11
themis-business/src/main/java/com/qmth/themis/business/service/TEExamPaperService.java

@@ -1,30 +1,45 @@
 package com.qmth.themis.business.service;
 
-import java.util.List;
-import java.util.Map;
-
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.themis.business.cache.bean.ExamPaperCacheBean;
 import com.qmth.themis.business.cache.bean.ObjectiveAnswerCacheBean;
 import com.qmth.themis.business.entity.TEExamPaper;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * @Description: 考试试卷 服务类
  * @Param:
- * @returnß:
+ * @return:
  * @Author: wangliang
  * @Date: 2020/6/25
  */
 public interface TEExamPaperService extends IService<TEExamPaper> {
 
-	TEExamPaper findByExamIdAndCourseCodeAndPaperCode(Long examId, String courseCode, String paperCode);
-	
-	List<TEExamPaper> findByExamIdAndCourseCode(Long examId, String courseCode);
+    TEExamPaper findByExamIdAndCourseCodeAndPaperCode(Long examId, String courseCode, String paperCode);
+
+    List<TEExamPaper> findByExamIdAndCourseCode(Long examId, String courseCode);
+
+    ExamPaperCacheBean getExamPaperCacheBean(Long paperId);
+
+    /**
+     * 更新试卷缓存
+     *
+     * @param paperId
+     * @return
+     */
+    ExamPaperCacheBean updateExamPaperCacheBean(Long paperId);
+
+    /**
+     * 删除试卷缓存
+     *
+     * @param paperId
+     */
+    void deleteExamPaperCacheBean(Long paperId);
 
-	ExamPaperCacheBean getExamPaperCacheBean(Long paperId);
+    Map<String, ObjectiveAnswerCacheBean> getObjectiveAnswerCacheBean(Long paperId);
 
-	Map<String, ObjectiveAnswerCacheBean> getObjectiveAnswerCacheBean(Long paperId);
-	
-	void  savePaperWeight(Map<Long,Double> map);
+    void savePaperWeight(Map<Long, Double> map);
 
 }

+ 110 - 88
themis-business/src/main/java/com/qmth/themis/business/service/TEExamService.java

@@ -1,25 +1,16 @@
 package com.qmth.themis.business.service;
 
-import java.util.List;
-import java.util.Map;
-
-import com.qmth.themis.business.dto.response.TEExamQueryDto;
-import org.springframework.web.multipart.MultipartFile;
-
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
-import com.qmth.themis.business.bean.exam.AnswerSubmitBean;
-import com.qmth.themis.business.bean.exam.AudioLeftPlayCountSubmitBean;
-import com.qmth.themis.business.bean.exam.ExamFileUploadBean;
-import com.qmth.themis.business.bean.exam.ExamFinishBean;
-import com.qmth.themis.business.bean.exam.ExamPrepareBean;
-import com.qmth.themis.business.bean.exam.ExamResultBean;
-import com.qmth.themis.business.bean.exam.ExamResumeBean;
-import com.qmth.themis.business.bean.exam.ExamStartBean;
-import com.qmth.themis.business.bean.exam.StudentPaperStructBean;
+import com.qmth.themis.business.bean.exam.*;
 import com.qmth.themis.business.cache.bean.ExamCacheBean;
 import com.qmth.themis.business.dto.response.TEExamDto;
+import com.qmth.themis.business.dto.response.TEExamQueryDto;
 import com.qmth.themis.business.entity.TEExam;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.List;
+import java.util.Map;
 
 /**
  * @Description: 考试批次 服务类
@@ -68,79 +59,110 @@ public interface TEExamService extends IService<TEExam> {
      * @return
      */
     public ExamPrepareBean prepare(Long studentId, Long examStudentId);
-	
-	/**开始考试
-	 * @param id
-	 * @param recordId
-	 * @return
-	 */
-	public ExamStartBean start(Long studentId, Long recordId);
-
-	/**上传个人试卷结构
-	 * @param studentId
-	 * @param recordId
-	 * @param content
-	 * @return
-	 */
-	public StudentPaperStructBean studentPaperStruct(Long studentId, Long recordId,String content);
-	
-	/**提交作答结果
-	 * @param studentId
-	 * @param recordId
-	 * @param mainNumber
-	 * @param subNumber
-	 * @param subIndex
-	 * @param answer
-	 * @param version
-	 * @param durationSeconds
-	 * @return
-	 */
-	public AnswerSubmitBean answerSubmit(Long studentId, Long recordId, Integer mainNumber, Integer subNumber, Integer subIndex,
-			String answer, Long version, Integer durationSeconds);
-
-	/**更新音频剩余播放次数
-	 * @param id
-	 * @param recordId
-	 * @param key
-	 * @param count
-	 * @return
-	 */
-	public AudioLeftPlayCountSubmitBean audioLeftPlayCountSubmit(Long studentId, Long recordId, String key, Integer count);
-
-	
-	/**文件上传
-	 * @param studentId
-	 * @param recordId
-	 * @param file
-	 * @param suffix
-	 * @param md5
-	 * @return
-	 */
-	public ExamFileUploadBean fileUpload(Long studentId, Long recordId, MultipartFile file, String suffix, String md5);
-
-	/**断点恢复
-	 * @param studentId
-	 * @param recordId
-	 * @return
-	 */
-	public ExamResumeBean resume(Long studentId, Long recordId);
-
-	/**结束考试
-	 * @param studentId
-	 * @param recordId
-	 * @param type
-	 * @param durationSeconds
-	 * @return
-	 */
-	public ExamFinishBean finish(Long studentId, Long recordId, String type, Integer durationSeconds);
-
-	ExamCacheBean getExamCacheBean(Long examId);
-
-	/**查询交卷结果
-	 * @param recordId
-	 * @return
-	 */
-	public ExamResultBean result(Long recordId);
+
+    /**
+     * 开始考试
+     *
+     * @param id
+     * @param recordId
+     * @return
+     */
+    public ExamStartBean start(Long studentId, Long recordId);
+
+    /**
+     * 上传个人试卷结构
+     *
+     * @param studentId
+     * @param recordId
+     * @param content
+     * @return
+     */
+    public StudentPaperStructBean studentPaperStruct(Long studentId, Long recordId, String content);
+
+    /**
+     * 提交作答结果
+     *
+     * @param studentId
+     * @param recordId
+     * @param mainNumber
+     * @param subNumber
+     * @param subIndex
+     * @param answer
+     * @param version
+     * @param durationSeconds
+     * @return
+     */
+    public AnswerSubmitBean answerSubmit(Long studentId, Long recordId, Integer mainNumber, Integer subNumber, Integer subIndex,
+                                         String answer, Long version, Integer durationSeconds);
+
+    /**
+     * 更新音频剩余播放次数
+     *
+     * @param id
+     * @param recordId
+     * @param key
+     * @param count
+     * @return
+     */
+    public AudioLeftPlayCountSubmitBean audioLeftPlayCountSubmit(Long studentId, Long recordId, String key, Integer count);
+
+
+    /**
+     * 文件上传
+     *
+     * @param studentId
+     * @param recordId
+     * @param file
+     * @param suffix
+     * @param md5
+     * @return
+     */
+    public ExamFileUploadBean fileUpload(Long studentId, Long recordId, MultipartFile file, String suffix, String md5);
+
+    /**
+     * 断点恢复
+     *
+     * @param studentId
+     * @param recordId
+     * @return
+     */
+    public ExamResumeBean resume(Long studentId, Long recordId);
+
+    /**
+     * 结束考试
+     *
+     * @param studentId
+     * @param recordId
+     * @param type
+     * @param durationSeconds
+     * @return
+     */
+    public ExamFinishBean finish(Long studentId, Long recordId, String type, Integer durationSeconds);
+
+    ExamCacheBean getExamCacheBean(Long examId);
+
+    /**
+     * 更新批次缓存
+     *
+     * @param examId
+     * @return
+     */
+    ExamCacheBean updateExamCacheBean(Long examId);
+
+    /**
+     * 删除批次缓存
+     *
+     * @param examId
+     */
+    void deleteExamCacheBean(Long examId);
+
+    /**
+     * 查询交卷结果
+     *
+     * @param recordId
+     * @return
+     */
+    public ExamResultBean result(Long recordId);
 
 
 }

+ 16 - 1
themis-business/src/main/java/com/qmth/themis/business/service/TEExamStudentService.java

@@ -33,5 +33,20 @@ public interface TEExamStudentService extends IService<TEExamStudent> {
      */
     public IPage<TEExamStudentDto> examStudentQuery(IPage<Map> iPage, Long examId, Long activityId, String identity, String name, String roomCode, String courseCode, String grade, Integer enable);
 
-	ExamStudentCacheBean getExamStudnetCacheBean(Long examStudentId);
+    ExamStudentCacheBean getExamStudnetCacheBean(Long examStudentId);
+
+    /**
+     * 更新考生缓存
+     *
+     * @param examStudentId
+     * @return
+     */
+    ExamStudentCacheBean updateExamStudnetCacheBean(Long examStudentId);
+
+    /**
+     * 删除考生缓存
+     *
+     * @param examStudentId
+     */
+    void deleteExamStudnetCacheBean(Long examStudentId);
 }

+ 62 - 29
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamActivityServiceImpl.java

@@ -1,21 +1,21 @@
 package com.qmth.themis.business.service.impl;
 
-import java.util.List;
-import java.util.Map;
-
-import javax.annotation.Resource;
-
-import com.qmth.themis.business.dto.response.TEExamActivityDto;
-import com.qmth.themis.business.dto.response.TEExamActivityQueryDto;
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.stereotype.Service;
-
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.themis.business.cache.bean.ExamActivityCacheBean;
 import com.qmth.themis.business.dao.TEExamActivityMapper;
+import com.qmth.themis.business.dto.response.TEExamActivityDto;
+import com.qmth.themis.business.dto.response.TEExamActivityQueryDto;
 import com.qmth.themis.business.entity.TEExamActivity;
 import com.qmth.themis.business.service.TEExamActivityService;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.CachePut;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @Description: 考试场次 服务实现类
@@ -112,27 +112,60 @@ public class TEExamActivityServiceImpl extends ServiceImpl<TEExamActivityMapper,
     public List<TEExamActivityDto> getWaitingExam(Long studentId, Long examId, Long examActivityId) {
         return teExamActivityMapper.getWaitingExam(studentId, examId, examActivityId);
     }
-    
-    @Cacheable(value = "exam_activity", key = "#examActivityId",unless = "#result == null")
+
+    @Cacheable(value = "exam_activity", key = "#examActivityId", unless = "#result == null")
     @Override
     public ExamActivityCacheBean getExamActivityCacheBean(Long examActivityId) {
-    	ExamActivityCacheBean ret=null;
-    	TEExamActivity ac=getById(examActivityId);
-    	if(ac==null) {
-    		return ret;
-    	}
-    	if(ac.getEnable()!=null&&ac.getEnable().intValue()==0) {
-    		return ret;
-    	}
-    	ret=new ExamActivityCacheBean();
-    	ret.setId(ac.getId());
-    	ret.setCode(ac.getCode());
-    	ret.setExamId(ac.getExamId());
-    	ret.setPrepareSeconds(ac.getPrepareSeconds());
-    	ret.setMaxDurationSeconds(ac.getMaxDurationSeconds());
-    	ret.setOpeningSeconds(ac.getOpeningSeconds());
-    	ret.setStartTime(ac.getStartTime());
-    	ret.setFinishTime(ac.getFinishTime());
+        return cacheOperation(examActivityId);
+    }
+
+    /**
+     * 更新场次缓存
+     *
+     * @param examActivityId
+     * @return
+     */
+    @Override
+    @CachePut(value = "exam_activity", key = "#examActivityId", unless = "#result == null")
+    public ExamActivityCacheBean updateExamActivityCacheBean(Long examActivityId) {
+        return cacheOperation(examActivityId);
+    }
+
+    /**
+     * 删除场次缓存
+     *
+     * @param examActivityId
+     */
+    @Override
+    @CacheEvict(value = "exam_activity", key = "#examActivityId")
+    public void deleteExamActivityCacheBean(Long examActivityId) {
+
+    }
+
+    /**
+     * 缓存操作
+     *
+     * @param examActivityId
+     * @return
+     */
+    public ExamActivityCacheBean cacheOperation(Long examActivityId) {
+        ExamActivityCacheBean ret = null;
+        TEExamActivity ac = getById(examActivityId);
+        if (ac == null) {
+            return ret;
+        }
+        if (ac.getEnable() != null && ac.getEnable().intValue() == 0) {
+            return ret;
+        }
+        ret = new ExamActivityCacheBean();
+        ret.setId(ac.getId());
+        ret.setCode(ac.getCode());
+        ret.setExamId(ac.getExamId());
+        ret.setPrepareSeconds(ac.getPrepareSeconds());
+        ret.setMaxDurationSeconds(ac.getMaxDurationSeconds());
+        ret.setOpeningSeconds(ac.getOpeningSeconds());
+        ret.setStartTime(ac.getStartTime());
+        ret.setFinishTime(ac.getFinishTime());
         return ret;
     }
 }

+ 108 - 72
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamCourseServiceImpl.java

@@ -1,15 +1,5 @@
 package com.qmth.themis.business.service.impl;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import javax.annotation.Resource;
-
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.stereotype.Service;
-
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.themis.business.cache.bean.ExamCourseCacheBean;
@@ -19,6 +9,16 @@ import com.qmth.themis.business.entity.TEExamCourse;
 import com.qmth.themis.business.entity.TEExamPaper;
 import com.qmth.themis.business.service.TEExamCourseService;
 import com.qmth.themis.common.exception.BusinessException;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.CachePut;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @Description: 考试科目 服务实现类
@@ -29,71 +29,107 @@ import com.qmth.themis.common.exception.BusinessException;
  */
 @Service
 public class TEExamCourseServiceImpl extends ServiceImpl<TEExamCourseMapper, TEExamCourse>
-		implements TEExamCourseService {
+        implements TEExamCourseService {
+
+    @Resource
+    TEExamCourseMapper teExamCourseMapper;
+
+    @Resource
+    TEExamPaperMapper teExamPaperMapper;
+
+    /**
+     * 查询考试科目
+     *
+     * @param iPage
+     * @param examId
+     * @param courseCode
+     * @param courseName
+     * @param hasPaper
+     * @return
+     */
+    @Override
+    public IPage<TEExamCourse> examCourseQuery(IPage<Map> iPage, Long examId, String courseCode, String courseName,
+                                               Integer hasPaper) {
+        return teExamCourseMapper.examCourseQuery(iPage, examId, courseCode, courseName, hasPaper);
+    }
+
+    @Override
+    public TEExamCourse findByExamIdAndCourseCode(Long examId, String courseCode) {
+        if (examId == null) {
+            throw new BusinessException("examId is null");
+        }
+        if (StringUtils.isBlank(courseCode)) {
+            throw new BusinessException("courseCode is null");
+        }
+        return teExamCourseMapper.findByExamIdAndCourseCode(examId, courseCode);
+    }
 
-	@Resource
-	TEExamCourseMapper teExamCourseMapper;
+    @Cacheable(value = "exam_course", key = "#examId+'_'+#courseCode", unless = "#result == null")
+    @Override
+    public ExamCourseCacheBean getExamCourseCacheBean(Long examId, String courseCode) {
+        return cacheOperation(examId, courseCode);
+    }
 
-	@Resource
-	TEExamPaperMapper teExamPaperMapper;
+    /**
+     * 更新科目缓存
+     *
+     * @param examId
+     * @param courseCode
+     * @return
+     */
+    @Override
+    @CachePut(value = "exam_course", key = "#examId+'_'+#courseCode", unless = "#result == null")
+    public ExamCourseCacheBean updateExamCourseCacheBean(Long examId, String courseCode) {
+        return cacheOperation(examId, courseCode);
+    }
 
-	/**
-	 * 查询考试科目
-	 *
-	 * @param iPage
-	 * @param examId
-	 * @param courseCode
-	 * @param courseName
-	 * @param hasPaper
-	 * @return
-	 */
-	@Override
-	public IPage<TEExamCourse> examCourseQuery(IPage<Map> iPage, Long examId, String courseCode, String courseName,
-			Integer hasPaper) {
-		return teExamCourseMapper.examCourseQuery(iPage, examId, courseCode, courseName, hasPaper);
-	}
+    /**
+     * 删除科目缓存
+     *
+     * @param examId
+     * @param courseCode
+     */
+    @Override
+    @CacheEvict(value = "exam_course", key = "#examId+'_'+#courseCode")
+    public void deleteExamCourseCacheBean(Long examId, String courseCode) {
 
-	@Override
-	public TEExamCourse findByExamIdAndCourseCode(Long examId, String courseCode) {
-		if (examId == null) {
-			throw new BusinessException("examId is null");
-		}
-		if (StringUtils.isBlank(courseCode)) {
-			throw new BusinessException("courseCode is null");
-		}
-		return teExamCourseMapper.findByExamIdAndCourseCode(examId, courseCode);
-	}
+    }
 
-	@Cacheable(value = "exam_course", key = "#examId+'_'+#courseCode", unless = "#result == null")
-	@Override
-	public ExamCourseCacheBean getExamCourseCacheBean(Long examId, String courseCode) {
-		ExamCourseCacheBean ret = null;
-		TEExamCourse ec = teExamCourseMapper.findByExamIdAndCourseCode(examId, courseCode);
-		if (ec == null) {
-			return ret;
-		}
-		ret = new ExamCourseCacheBean();
-		ret.setId(ec.getId());
-		ret.setExamId(ec.getExamId());
-		ret.setCourseCode(ec.getCourseCode());
-		ret.setCourseName(ec.getCourseName());
-		ret.setObjectiveShuffle(ec.getObjectiveShuffle());
-		ret.setOptionShuffle(ec.getOptionShuffle());
-		ret.setPaperCount(ec.getPaperCount());
-		ret.setHasAnswer(ec.getHasAnswer());
-		ret.setAudioPlayCount(ec.getAudioPlayCount());
-		ret.setHasAudio(ec.getHasAudio());
-		List<TEExamPaper> papers = teExamPaperMapper.findListByExamIdAndCourseCode(examId, courseCode);
-		if (papers != null && papers.size() > 0) {
-			List<Long> paperIds=new ArrayList<Long>();
-			List<Double> weight=new ArrayList<Double>();
-			for(TEExamPaper paper:papers) {
-				paperIds.add(paper.getId());
-				weight.add(paper.getWeight());
-			}
-			ret.setPaperIds(paperIds);
-			ret.setPaperWeight(weight);
-		} 
-		return ret;
-	}
+    /**
+     * 缓存操作
+     *
+     * @param examId
+     * @param courseCode
+     * @return
+     */
+    public ExamCourseCacheBean cacheOperation(Long examId, String courseCode) {
+        ExamCourseCacheBean ret = null;
+        TEExamCourse ec = teExamCourseMapper.findByExamIdAndCourseCode(examId, courseCode);
+        if (ec == null) {
+            return ret;
+        }
+        ret = new ExamCourseCacheBean();
+        ret.setId(ec.getId());
+        ret.setExamId(ec.getExamId());
+        ret.setCourseCode(ec.getCourseCode());
+        ret.setCourseName(ec.getCourseName());
+        ret.setObjectiveShuffle(ec.getObjectiveShuffle());
+        ret.setOptionShuffle(ec.getOptionShuffle());
+        ret.setPaperCount(ec.getPaperCount());
+        ret.setHasAnswer(ec.getHasAnswer());
+        ret.setAudioPlayCount(ec.getAudioPlayCount());
+        ret.setHasAudio(ec.getHasAudio());
+        List<TEExamPaper> papers = teExamPaperMapper.findListByExamIdAndCourseCode(examId, courseCode);
+        if (papers != null && papers.size() > 0) {
+            List<Long> paperIds = new ArrayList<Long>();
+            List<Double> weight = new ArrayList<Double>();
+            for (TEExamPaper paper : papers) {
+                paperIds.add(paper.getId());
+                weight.add(paper.getWeight());
+            }
+            ret.setPaperIds(paperIds);
+            ret.setPaperWeight(weight);
+        }
+        return ret;
+    }
 }

+ 168 - 134
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamPaperServiceImpl.java

@@ -1,18 +1,5 @@
 package com.qmth.themis.business.service.impl;
 
-import java.io.File;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import javax.annotation.Resource;
-
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -26,6 +13,19 @@ import com.qmth.themis.business.service.TEExamPaperService;
 import com.qmth.themis.business.util.OssUtil;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.util.FileUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.CachePut;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.io.File;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
 
 /**
  * @Description: 考试试卷 服务实现类
@@ -36,165 +36,199 @@ import com.qmth.themis.common.util.FileUtil;
  */
 @Service
 public class TEExamPaperServiceImpl extends ServiceImpl<TEExamPaperMapper, TEExamPaper> implements TEExamPaperService {
-	private static String underLine = "_";
+    private static String underLine = "_";
     @Resource
     SystemConfig systemConfig;
-	@Resource
-	TEExamPaperMapper teExamPaperMapper;
-
-	@Override
-	public TEExamPaper findByExamIdAndCourseCodeAndPaperCode(Long examId, String courseCode, String paperCode) {
-		if (examId == null) {
-			throw new BusinessException("examId is null");
-		}
-		if (StringUtils.isBlank(courseCode)) {
-			throw new BusinessException("courseCode is null");
-		}
-		if (StringUtils.isBlank(paperCode)) {
-			throw new BusinessException("paperCode is null");
-		}
-		return teExamPaperMapper.findByExamIdAndCourseCodeAndPaperCode(examId, courseCode, paperCode);
-	}
-	
-	@Cacheable(value = "exam_paper", key = "#paperId", unless = "#result == null")
-	@Override
-	public ExamPaperCacheBean getExamPaperCacheBean(Long paperId) {
-		ExamPaperCacheBean ret = null;
-		TEExamPaper ep = getById(paperId);
-		if (ep == null) {
-			return ret;
-		}
-		ret = new ExamPaperCacheBean();
-		ret.setId(ep.getId());
-		ret.setExamId(ep.getExamId());
-		ret.setCourseCode(ep.getCourseCode());
-		ret.setCode(ep.getCode());
-		ret.setName(ep.getName());
-		ret.setTotalScore(ep.getTotalScore());
-		ret.setPaperPath(ep.getPaperPath());
-		ret.setStructPath(ep.getStructPath());
-		ret.setAnswerPath(ep.getAnswerPath());
-		ret.setDecryptSecret(ep.getDecryptSecret());
-		ret.setDecryptVector(ep.getDecryptVector());
-		ret.setEncryptMode(ep.getEncryptMode());
-		ret.setNeedVoiceAnswer(ep.getNeedVoiceAnswer());
-		ret.setHasAudio(ep.getHasAudio());
-		ret.setWeight(ep.getWeight());
-		ret.setAudioPlayCount(ep.getAudioPlayCount());
-		return ret;
-	}
-	
-	@Cacheable(value = "objective_answer", key = "#paperId", unless = "#result == null")
-	@Override
-	public Map<String,ObjectiveAnswerCacheBean> getObjectiveAnswerCacheBean(Long paperId) {
-		Map<String,ObjectiveAnswerCacheBean> ret = null;
-		ExamPaperCacheBean ep = getExamPaperCacheBean(paperId);
-		if (ep == null) {
-			return ret;
-		}
-		ret = new HashMap<String,ObjectiveAnswerCacheBean>();
-		String structUrl=OssUtil.getUrlForPrivateBucket(systemConfig.getOssEnv(3), ep.getStructPath());
-		String answerUrl=OssUtil.getUrlForPrivateBucket(systemConfig.getOssEnv(3), ep.getAnswerPath());
-		String tempDir = SystemConstant.TEMP_FILES_DIR;
+    @Resource
+    TEExamPaperMapper teExamPaperMapper;
+
+    @Override
+    public TEExamPaper findByExamIdAndCourseCodeAndPaperCode(Long examId, String courseCode, String paperCode) {
+        if (examId == null) {
+            throw new BusinessException("examId is null");
+        }
+        if (StringUtils.isBlank(courseCode)) {
+            throw new BusinessException("courseCode is null");
+        }
+        if (StringUtils.isBlank(paperCode)) {
+            throw new BusinessException("paperCode is null");
+        }
+        return teExamPaperMapper.findByExamIdAndCourseCodeAndPaperCode(examId, courseCode, paperCode);
+    }
+
+    @Cacheable(value = "exam_paper", key = "#paperId", unless = "#result == null")
+    @Override
+    public ExamPaperCacheBean getExamPaperCacheBean(Long paperId) {
+        return cacheOperation(paperId);
+    }
+
+    /**
+     * 更新试卷缓存
+     *
+     * @param paperId
+     * @return
+     */
+    @Override
+    @CachePut(value = "exam_paper", key = "#paperId", unless = "#result == null")
+    public ExamPaperCacheBean updateExamPaperCacheBean(Long paperId) {
+        return cacheOperation(paperId);
+    }
+
+    /**
+     * 删除试卷缓存
+     *
+     * @param paperId
+     */
+    @Override
+    @CacheEvict(value = "exam_paper", key = "#paperId")
+    public void deleteExamPaperCacheBean(Long paperId) {
+
+    }
+
+    /**
+     * 缓存操作
+     *
+     * @param paperId
+     * @return
+     */
+    public ExamPaperCacheBean cacheOperation(Long paperId) {
+        ExamPaperCacheBean ret = null;
+        TEExamPaper ep = getById(paperId);
+        if (ep == null) {
+            return ret;
+        }
+        ret = new ExamPaperCacheBean();
+        ret.setId(ep.getId());
+        ret.setExamId(ep.getExamId());
+        ret.setCourseCode(ep.getCourseCode());
+        ret.setCode(ep.getCode());
+        ret.setName(ep.getName());
+        ret.setTotalScore(ep.getTotalScore());
+        ret.setPaperPath(ep.getPaperPath());
+        ret.setStructPath(ep.getStructPath());
+        ret.setAnswerPath(ep.getAnswerPath());
+        ret.setDecryptSecret(ep.getDecryptSecret());
+        ret.setDecryptVector(ep.getDecryptVector());
+        ret.setEncryptMode(ep.getEncryptMode());
+        ret.setNeedVoiceAnswer(ep.getNeedVoiceAnswer());
+        ret.setHasAudio(ep.getHasAudio());
+        ret.setWeight(ep.getWeight());
+        ret.setAudioPlayCount(ep.getAudioPlayCount());
+        return ret;
+    }
+
+    @Cacheable(value = "objective_answer", key = "#paperId", unless = "#result == null")
+    @Override
+    public Map<String, ObjectiveAnswerCacheBean> getObjectiveAnswerCacheBean(Long paperId) {
+        Map<String, ObjectiveAnswerCacheBean> ret = null;
+        ExamPaperCacheBean ep = getExamPaperCacheBean(paperId);
+        if (ep == null) {
+            return ret;
+        }
+        ret = new HashMap<String, ObjectiveAnswerCacheBean>();
+        String structUrl = OssUtil.getUrlForPrivateBucket(systemConfig.getOssEnv(3), ep.getStructPath());
+        String answerUrl = OssUtil.getUrlForPrivateBucket(systemConfig.getOssEnv(3), ep.getAnswerPath());
+        String tempDir = SystemConstant.TEMP_FILES_DIR;
         String dir = tempDir + "/" + uuid() + "/";
         File dfile = new File(dir);
         try {
             dfile.mkdirs();
-            File structFile=new File(dir+"struct.json");
+            File structFile = new File(dir + "struct.json");
             FileUtil.saveUrlAsFile(structUrl, structFile);
-            File answerEncryptFile=new File(dir+"answer_encrypt_file.json");
+            File answerEncryptFile = new File(dir + "answer_encrypt_file.json");
             FileUtil.saveUrlAsFile(answerUrl, answerEncryptFile);
-            File answerFile=new File(dir+"answer_file.json");
+            File answerFile = new File(dir + "answer_file.json");
             FileUtil.decryptFile(answerEncryptFile, answerFile, ep.getDecryptSecret(), ep.getDecryptVector());
-            String structJson=FileUtil.readFileContent(structFile);
-            String answerjson=FileUtil.readFileContent(answerFile);
+            String structJson = FileUtil.readFileContent(structFile);
+            String answerjson = FileUtil.readFileContent(answerFile);
             return buildCache(structJson, answerjson);
         } finally {
             FileUtil.deleteFolder(dir);
         }
-	}
-	
-	
-	private Map<String,ObjectiveAnswerCacheBean> buildCache(String structStr,String answerStr){
-		Map<String,ObjectiveAnswerCacheBean> map=new HashMap<String,ObjectiveAnswerCacheBean>();
-		JSONObject answerJson = JSONObject.parseObject(answerStr);
+    }
+
+
+    private Map<String, ObjectiveAnswerCacheBean> buildCache(String structStr, String answerStr) {
+        Map<String, ObjectiveAnswerCacheBean> map = new HashMap<String, ObjectiveAnswerCacheBean>();
+        JSONObject answerJson = JSONObject.parseObject(answerStr);
         JSONArray answerdetails = answerJson.getJSONArray("details");
         JSONObject structJson = JSONObject.parseObject(structStr);
         JSONArray structdetails = structJson.getJSONArray("details");
         for (int i = 0; i < answerdetails.size(); i++) {
-        	Integer mainNum=answerdetails.getJSONObject(i).getInteger("number");
+            Integer mainNum = answerdetails.getJSONObject(i).getInteger("number");
             JSONArray answerdetailquestions = answerdetails.getJSONObject(i).getJSONArray("questions");
             JSONArray structdetailquestions = structdetails.getJSONObject(i).getJSONArray("questions");
             for (int j = 0; j < answerdetailquestions.size(); j++) {
                 JSONObject answerquestion = answerdetailquestions.getJSONObject(j);
                 JSONObject structquestion = structdetailquestions.getJSONObject(j);
-                Integer subNum=structquestion.getInteger("number");
-                Double score=structquestion.getDouble("score");
-                Integer structType=structquestion.getInteger("structType");
+                Integer subNum = structquestion.getInteger("number");
+                Double score = structquestion.getDouble("score");
+                Integer structType = structquestion.getInteger("structType");
                 if (structType.intValue() == 1
                         || structType.intValue() == 2
                         || structType.intValue() == 3) {
-                	ObjectiveAnswerCacheBean bean=new ObjectiveAnswerCacheBean();
-                	bean.setScore(score);
-                	bean.setStructType(structType);
-	                if (structType.intValue() == 1
-	                        || structType.intValue() == 2) {
-	                    JSONArray answer = answerquestion.getJSONArray("answer");
-	                    bean.setChoiceAnswer(answer);
-	                }
-	                if (structType.intValue() == 3) {
-	                    Boolean answer = answerquestion.getBoolean("answer");
-	                    bean.setBoolAnswer(answer);
-	                }
-	                map.put(mainNum + underLine + subNum, bean);
+                    ObjectiveAnswerCacheBean bean = new ObjectiveAnswerCacheBean();
+                    bean.setScore(score);
+                    bean.setStructType(structType);
+                    if (structType.intValue() == 1
+                            || structType.intValue() == 2) {
+                        JSONArray answer = answerquestion.getJSONArray("answer");
+                        bean.setChoiceAnswer(answer);
+                    }
+                    if (structType.intValue() == 3) {
+                        Boolean answer = answerquestion.getBoolean("answer");
+                        bean.setBoolAnswer(answer);
+                    }
+                    map.put(mainNum + underLine + subNum, bean);
                 }
-            	if (structType.intValue() == 6) {
-                        JSONArray answersubQuestions = answerquestion.getJSONArray("subQuestions");
-                        JSONArray structsubQuestions = structquestion.getJSONArray("subQuestions");
+                if (structType.intValue() == 6) {
+                    JSONArray answersubQuestions = answerquestion.getJSONArray("subQuestions");
+                    JSONArray structsubQuestions = structquestion.getJSONArray("subQuestions");
                     for (int k = 0; k < answersubQuestions.size(); k++) {
-                    	JSONObject answersubquestion = answersubQuestions.getJSONObject(k);
-                    	JSONObject structsubquestion = structsubQuestions.getJSONObject(k);
-                        Integer subIndex=structsubquestion.getInteger("number");
-                        Double subScore=structsubquestion.getDouble("score");
-                        Integer subStructType=structsubquestion.getInteger("structType");
+                        JSONObject answersubquestion = answersubQuestions.getJSONObject(k);
+                        JSONObject structsubquestion = structsubQuestions.getJSONObject(k);
+                        Integer subIndex = structsubquestion.getInteger("number");
+                        Double subScore = structsubquestion.getDouble("score");
+                        Integer subStructType = structsubquestion.getInteger("structType");
 
                         if (subStructType.intValue() == 1
                                 || subStructType.intValue() == 2
                                 || subStructType.intValue() == 3) {
-                        	ObjectiveAnswerCacheBean bean=new ObjectiveAnswerCacheBean();
-                        	bean.setScore(subScore);
-                        	bean.setStructType(subStructType);
-	                        if (subStructType.intValue() == 1
-	                                || subStructType.intValue() == 2) {
-	                            JSONArray answer = answersubquestion.getJSONArray("answer");
-	                            bean.setChoiceAnswer(answer);
-	                        }
-	                        if (subStructType.intValue() == 3) {
-	                            Boolean answer = answersubquestion.getBoolean("answer");
-	                            bean.setBoolAnswer(answer);
-	                        }
-	                        map.put(mainNum + underLine + subNum + underLine + subIndex, bean);
+                            ObjectiveAnswerCacheBean bean = new ObjectiveAnswerCacheBean();
+                            bean.setScore(subScore);
+                            bean.setStructType(subStructType);
+                            if (subStructType.intValue() == 1
+                                    || subStructType.intValue() == 2) {
+                                JSONArray answer = answersubquestion.getJSONArray("answer");
+                                bean.setChoiceAnswer(answer);
+                            }
+                            if (subStructType.intValue() == 3) {
+                                Boolean answer = answersubquestion.getBoolean("answer");
+                                bean.setBoolAnswer(answer);
+                            }
+                            map.put(mainNum + underLine + subNum + underLine + subIndex, bean);
                         }
                     }
                 }
             }
         }
-		return map;
-	}
+        return map;
+    }
+
     private String uuid() {
         return UUID.randomUUID().toString().replaceAll("-", "");
     }
 
-	@Override
-	public List<TEExamPaper> findByExamIdAndCourseCode(Long examId, String courseCode) {
-		return teExamPaperMapper.findListByExamIdAndCourseCode(examId, courseCode);
-	}
-
-	@Transactional
-	@Override
-	public void savePaperWeight(Map<Long, Double> map) {
-		for(Long id:map.keySet()) {
-			teExamPaperMapper.updateWeight(id, map.get(id));
-		}
-	}
+    @Override
+    public List<TEExamPaper> findByExamIdAndCourseCode(Long examId, String courseCode) {
+        return teExamPaperMapper.findListByExamIdAndCourseCode(examId, courseCode);
+    }
+
+    @Transactional
+    @Override
+    public void savePaperWeight(Map<Long, Double> map) {
+        for (Long id : map.keySet()) {
+            teExamPaperMapper.updateWeight(id, map.get(id));
+        }
+    }
 }

+ 96 - 62
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamServiceImpl.java

@@ -23,6 +23,8 @@ import com.qmth.themis.common.exception.BusinessException;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.CachePut;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -173,11 +175,11 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         }
         TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) redisUtil.getStudent(es.getStudentId());
         if (teStudentCacheDto.getUnFinishedRecordId() != null) {
-        	Long recordId=teStudentCacheDto.getUnFinishedRecordId();
-        	
-        	ExamPaperCacheBean ep = teExamPaperService.getExamPaperCacheBean(ExamRecordCacheUtil.getPaperId(recordId));
-        	ExamCourseCacheBean ec = teExamCourseService.getExamCourseCacheBean(es.getExamId(), es.getCourseCode());
-        	ExamPrepareBean prepare = new ExamPrepareBean();
+            Long recordId = teStudentCacheDto.getUnFinishedRecordId();
+
+            ExamPaperCacheBean ep = teExamPaperService.getExamPaperCacheBean(ExamRecordCacheUtil.getPaperId(recordId));
+            ExamCourseCacheBean ec = teExamCourseService.getExamCourseCacheBean(es.getExamId(), es.getCourseCode());
+            ExamPrepareBean prepare = new ExamPrepareBean();
             prepare.setRecordId(recordId);
             prepare.setAudioPlayCount(ep.getAudioPlayCount());
             prepare.setHasAudio((ep.getHasAudio() == null || ep.getHasAudio().intValue() == 0 ? false : true));
@@ -618,30 +620,30 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         ExamCacheBean exam = getExamCacheBean(es.getExamId());
         //页面结果
         if (exam.getShowObjectiveScore() != null && exam.getShowObjectiveScore().intValue() == 1) {//实时出分
-        	if(InvigilateVerifyEnum.NOW.equals(exam.getInvigilateVerify())) {//实时审核
-        		Integer warningCount=ExamRecordCacheUtil.getWarningCount(recordId);
-        		Integer breachStatus=ExamRecordCacheUtil.getBreachStatus(recordId);
-	            if(warningCount!=null&&warningCount.intValue()>0) {//有预警
-	            	if(breachStatus==null) {//无违纪结果
-		            	ret.setStatus(FinishExamResultEnum.AUDITING);
-	            	}else if(breachStatus.intValue()==0) {//违纪结果是false
-	            		ret.setReviewResult(ReviewResultEnum.PASS);
-		            	if (ret.getObjectiveScore() == null) {
-			                ret.setStatus(FinishExamResultEnum.SCORE_CALCULATE);
-			            } else {
-			                ret.setStatus(FinishExamResultEnum.SCORE_VIEW);
-			            }
-		            }else if(breachStatus.intValue()==1) {//违纪结果是true
-		            	ret.setReviewResult(ReviewResultEnum.UN_PASS);
-		            	ret.setStatus(FinishExamResultEnum.BREACH);
-		            }
-	            }
-        	}else {
-        		if (ret.getObjectiveScore() == null) {
-	                ret.setStatus(FinishExamResultEnum.SCORE_CALCULATE);
-	            } else {
-	                ret.setStatus(FinishExamResultEnum.SCORE_VIEW);
-	            }
+            if (InvigilateVerifyEnum.NOW.equals(exam.getInvigilateVerify())) {//实时审核
+                Integer warningCount = ExamRecordCacheUtil.getWarningCount(recordId);
+                Integer breachStatus = ExamRecordCacheUtil.getBreachStatus(recordId);
+                if (warningCount != null && warningCount.intValue() > 0) {//有预警
+                    if (breachStatus == null) {//无违纪结果
+                        ret.setStatus(FinishExamResultEnum.AUDITING);
+                    } else if (breachStatus.intValue() == 0) {//违纪结果是false
+                        ret.setReviewResult(ReviewResultEnum.PASS);
+                        if (ret.getObjectiveScore() == null) {
+                            ret.setStatus(FinishExamResultEnum.SCORE_CALCULATE);
+                        } else {
+                            ret.setStatus(FinishExamResultEnum.SCORE_VIEW);
+                        }
+                    } else if (breachStatus.intValue() == 1) {//违纪结果是true
+                        ret.setReviewResult(ReviewResultEnum.UN_PASS);
+                        ret.setStatus(FinishExamResultEnum.BREACH);
+                    }
+                }
+            } else {
+                if (ret.getObjectiveScore() == null) {
+                    ret.setStatus(FinishExamResultEnum.SCORE_CALCULATE);
+                } else {
+                    ret.setStatus(FinishExamResultEnum.SCORE_VIEW);
+                }
             }
         } else {//非实时出分
             ret.setStatus(FinishExamResultEnum.NORMAL);
@@ -662,14 +664,30 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
     @Cacheable(value = "exam", key = "#examId", unless = "#result == null")
     @Override
     public ExamCacheBean getExamCacheBean(Long examId) {
-        ExamCacheBean ret = null;
-        TEExam exam = getById(examId);
-        if (exam == null) {
-            return ret;
-        }
-        ret = new ExamCacheBean();
-        BeanUtils.copyProperties(exam, ret);
-        return ret;
+        return cacheOperation(examId);
+    }
+
+    /**
+     * 更新批次缓存
+     *
+     * @param examId
+     * @return
+     */
+    @Override
+    @CachePut(value = "exam", key = "#examId", unless = "#result == null")
+    public ExamCacheBean updateExamCacheBean(Long examId) {
+        return cacheOperation(examId);
+    }
+
+    /**
+     * 删除批次缓存
+     *
+     * @param examId
+     */
+    @Override
+    @CacheEvict(value = "exam", key = "#examId")
+    public void deleteExamCacheBean(Long examId) {
+
     }
 
     /**
@@ -697,33 +715,33 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
             ret.setObjectiveScore(ExamRecordCacheUtil.getObjectiveScore(recordId));
         }
 
-      //页面结果
+        //页面结果
         ExamCacheBean exam = getExamCacheBean(er.getExamId());
         if (exam.getShowObjectiveScore() != null && exam.getShowObjectiveScore().intValue() == 1) {//实时出分
-        	if(InvigilateVerifyEnum.NOW.equals(exam.getInvigilateVerify())) {//实时审核
-        		Integer warningCount=ExamRecordCacheUtil.getWarningCount(recordId);
-        		Integer breachStatus=ExamRecordCacheUtil.getBreachStatus(recordId);
-	            if(warningCount!=null&&warningCount.intValue()>0) {//有预警
-	            	if(breachStatus==null) {//无违纪结果
-		            	ret.setStatus(FinishExamResultEnum.AUDITING);
-	            	}else if(breachStatus.intValue()==0) {//违纪结果是false
-	            		ret.setReviewResult(ReviewResultEnum.PASS);
-		            	if (ret.getObjectiveScore() == null) {
-			                ret.setStatus(FinishExamResultEnum.SCORE_CALCULATE);
-			            } else {
-			                ret.setStatus(FinishExamResultEnum.SCORE_VIEW);
-			            }
-		            }else if(breachStatus.intValue()==1) {//违纪结果是true
-		            	ret.setReviewResult(ReviewResultEnum.UN_PASS);
-		            	ret.setStatus(FinishExamResultEnum.BREACH);
-		            }
-	            }
-        	}else {
-        		if (ret.getObjectiveScore() == null) {
-	                ret.setStatus(FinishExamResultEnum.SCORE_CALCULATE);
-	            } else {
-	                ret.setStatus(FinishExamResultEnum.SCORE_VIEW);
-	            }
+            if (InvigilateVerifyEnum.NOW.equals(exam.getInvigilateVerify())) {//实时审核
+                Integer warningCount = ExamRecordCacheUtil.getWarningCount(recordId);
+                Integer breachStatus = ExamRecordCacheUtil.getBreachStatus(recordId);
+                if (warningCount != null && warningCount.intValue() > 0) {//有预警
+                    if (breachStatus == null) {//无违纪结果
+                        ret.setStatus(FinishExamResultEnum.AUDITING);
+                    } else if (breachStatus.intValue() == 0) {//违纪结果是false
+                        ret.setReviewResult(ReviewResultEnum.PASS);
+                        if (ret.getObjectiveScore() == null) {
+                            ret.setStatus(FinishExamResultEnum.SCORE_CALCULATE);
+                        } else {
+                            ret.setStatus(FinishExamResultEnum.SCORE_VIEW);
+                        }
+                    } else if (breachStatus.intValue() == 1) {//违纪结果是true
+                        ret.setReviewResult(ReviewResultEnum.UN_PASS);
+                        ret.setStatus(FinishExamResultEnum.BREACH);
+                    }
+                }
+            } else {
+                if (ret.getObjectiveScore() == null) {
+                    ret.setStatus(FinishExamResultEnum.SCORE_CALCULATE);
+                } else {
+                    ret.setStatus(FinishExamResultEnum.SCORE_VIEW);
+                }
             }
         } else {//非实时出分
             ret.setStatus(FinishExamResultEnum.NORMAL);
@@ -731,4 +749,20 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         return ret;
     }
 
+    /**
+     * 缓存操作
+     *
+     * @param examId
+     * @return
+     */
+    public ExamCacheBean cacheOperation(Long examId) {
+        ExamCacheBean ret = null;
+        TEExam exam = getById(examId);
+        if (exam == null) {
+            return ret;
+        }
+        ret = new ExamCacheBean();
+        BeanUtils.copyProperties(exam, ret);
+        return ret;
+    }
 }

+ 62 - 30
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamStudentServiceImpl.java

@@ -1,20 +1,19 @@
 package com.qmth.themis.business.service.impl;
 
-import java.util.Map;
-
-import javax.annotation.Resource;
-
-import com.qmth.themis.business.dto.response.TEExamStudentDto;
-
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.stereotype.Service;
-
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.themis.business.cache.bean.ExamStudentCacheBean;
 import com.qmth.themis.business.dao.TEExamStudentMapper;
+import com.qmth.themis.business.dto.response.TEExamStudentDto;
 import com.qmth.themis.business.entity.TEExamStudent;
 import com.qmth.themis.business.service.TEExamStudentService;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.CachePut;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.Map;
 
 /**
  * @Description: 考生库 服务实现类
@@ -47,30 +46,63 @@ public class TEExamStudentServiceImpl extends ServiceImpl<TEExamStudentMapper, T
     public IPage<TEExamStudentDto> examStudentQuery(IPage<Map> iPage, Long examId, Long activityId, String identity, String name, String roomCode, String courseCode, String grade, Integer enable) {
         return teExamStudentMapper.examStudentQuery(iPage, examId, activityId, identity, name, roomCode, courseCode, grade, enable);
     }
-    
+
     @Cacheable(value = "exam_student", key = "#examStudentId", unless = "#result == null")
     @Override
     public ExamStudentCacheBean getExamStudnetCacheBean(Long examStudentId) {
-    	ExamStudentCacheBean ret=null;
-    	TEExamStudent es=getById(examStudentId);
-    	if(es==null) {
-    		return ret;
-    	}
-    	if(es.getEnable()!=null&&es.getEnable().intValue()==0) {
-    		return ret;
-    	}
-    	ret=new ExamStudentCacheBean();
-    	ret.setId(es.getId());
-    	ret.setExamId(es.getExamId());
-    	ret.setExamActivityId(es.getExamActivityId());
-    	ret.setStudentId(es.getStudentId());
-    	ret.setCourseCode(es.getCourseCode());
-    	ret.setCourseName(es.getCourseName());
-    	ret.setRoomCode(es.getRoomCode());
-    	ret.setRoomName(es.getRoomName());
-    	ret.setLeftExamCount(es.getLeftExamCount());
-    	ret.setCurrentRecordId(es.getCurrentRecordId());
-    	ret.setCurrentSerialNumber(null);
+        return cacheOperation(examStudentId);
+    }
+
+    /**
+     * 更新考生缓存
+     *
+     * @param examStudentId
+     * @return
+     */
+    @Override
+    @CachePut(value = "exam_student", key = "#examStudentId", unless = "#result == null")
+    public ExamStudentCacheBean updateExamStudnetCacheBean(Long examStudentId) {
+        return cacheOperation(examStudentId);
+    }
+
+    /**
+     * 删除考生缓存
+     *
+     * @param examStudentId
+     */
+    @Override
+    @CacheEvict(value = "exam_student", key = "#examStudentId")
+    public void deleteExamStudnetCacheBean(Long examStudentId) {
+
+    }
+
+    /**
+     * 缓存操作
+     *
+     * @param examStudentId
+     * @return
+     */
+    public ExamStudentCacheBean cacheOperation(Long examStudentId) {
+        ExamStudentCacheBean ret = null;
+        TEExamStudent es = getById(examStudentId);
+        if (es == null) {
+            return ret;
+        }
+        if (es.getEnable() != null && es.getEnable().intValue() == 0) {
+            return ret;
+        }
+        ret = new ExamStudentCacheBean();
+        ret.setId(es.getId());
+        ret.setExamId(es.getExamId());
+        ret.setExamActivityId(es.getExamActivityId());
+        ret.setStudentId(es.getStudentId());
+        ret.setCourseCode(es.getCourseCode());
+        ret.setCourseName(es.getCourseName());
+        ret.setRoomCode(es.getRoomCode());
+        ret.setRoomName(es.getRoomName());
+        ret.setLeftExamCount(es.getLeftExamCount());
+        ret.setCurrentRecordId(es.getCurrentRecordId());
+        ret.setCurrentSerialNumber(null);
         return ret;
     }
 }