xiatian 4 năm trước cách đây
mục cha
commit
4a053af93e

+ 20 - 16
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamPaperServiceImpl.java

@@ -1,11 +1,28 @@
 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.CacheEvict;
+import org.springframework.cache.annotation.CachePut;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.scheduling.annotation.Async;
+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;
 import com.qmth.themis.business.cache.bean.ExamPaperCacheBean;
 import com.qmth.themis.business.cache.bean.ObjectiveAnswerCacheBean;
 import com.qmth.themis.business.config.SystemConfig;
+import com.qmth.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dao.TEExamPaperMapper;
 import com.qmth.themis.business.entity.TEExamPaper;
@@ -13,20 +30,6 @@ 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.scheduling.annotation.Async;
-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: 考试试卷 服务实现类
@@ -241,10 +244,11 @@ public class TEExamPaperServiceImpl extends ServiceImpl<TEExamPaperMapper, TEExa
     @Transactional
     @Override
     public void savePaperWeight(Map<Long, Double> map) {
+    	TEExamPaperService examPaperService = SpringContextHolder.getBean(TEExamPaperService.class);
         for (Long id : map.keySet()) {
             teExamPaperMapper.updateWeight(id, map.get(id));
-            deleteExamPaperCacheBean(id);
-            deleteObjectiveAnswerCacheBean(id);
+            examPaperService.deleteExamPaperCacheBean(id);
+            examPaperService.deleteObjectiveAnswerCacheBean(id);
         }
     }
 }

+ 19 - 18
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamServiceImpl.java

@@ -60,6 +60,7 @@ import com.qmth.themis.business.cache.bean.ExamStudentCacheBean;
 import com.qmth.themis.business.cache.bean.ExamStudentPaperStructCacheBean;
 import com.qmth.themis.business.cache.bean.ObjectiveAnswerCacheBean;
 import com.qmth.themis.business.config.SystemConfig;
+import com.qmth.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dao.TEExamMapper;
 import com.qmth.themis.business.dto.MqDto;
@@ -149,8 +150,6 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
     @Resource
     TEExamPaperService examPaperService;
 
-    @Resource
-    TEExamService teExamService;
 
     /**
      * 查询考试批次
@@ -194,7 +193,7 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
                 }
                 teExamActivityDtos.add(v);
                 map.put(v.getExamId(), teExamActivityDtos);
-                ExamCacheBean examCache = getExamCacheBean(v.getExamId());
+                ExamCacheBean examCache = getExamCacheBeanNative(v.getExamId());
                 ExamStudentCacheBean examStudentCacheBean = teExamStudentService.getExamStudentCacheBean(v.getExamStudentId());
                 v.setLeftExamCount(examCache.getExamCount() - examStudentCacheBean.getAlreadyExamCount());
                 if (Objects.nonNull(v.getInProcessLivenessFixedRangeStr())) {
@@ -257,7 +256,7 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         if (!studentId.equals(es.getStudentId())) {
             throw new BusinessException("考生Id和当前登录用户不一致");
         }
-        ExamCacheBean examCache = getExamCacheBean(es.getExamId());
+        ExamCacheBean examCache = getExamCacheBeanNative(es.getExamId());
         
         if(examCache.getEnableIpLimit()!=null&&examCache.getEnableIpLimit().intValue()==1) {
         	String ipAllows=examCache.getIpAllow();
@@ -305,14 +304,13 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         if (examCache.getExamCount().intValue() <= es.getAlreadyExamCount().intValue()) {
             throw new BusinessException("没有剩余考试次数");
         }
-        ExamCacheBean exam = getExamCacheBean(es.getExamId());
         Long activityId = es.getExamActivityId();
         ExamActivityCacheBean ac = teExamActivityService.getExamActivityCacheBean(activityId);
         if (ac == null) {
             throw new BusinessException("未找到场次");
         }
         Date now = new Date();
-        if (ExamModeEnum.ANYTIME.equals(exam.getMode())) {
+        if (ExamModeEnum.ANYTIME.equals(examCache.getMode())) {
             Long start = ac.getStartTime() - (ac.getPrepareSeconds() * 1000);
             Long end = ac.getFinishTime();
             if (now.getTime() < start) {
@@ -437,7 +435,7 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         if (!studentId.equals(es.getStudentId())) {
             throw new BusinessException("考试记录的学生Id和当前登录用户不一致");
         }
-        ExamCacheBean exam = getExamCacheBean(es.getExamId());
+        ExamCacheBean exam = getExamCacheBeanNative(es.getExamId());
         Long activityId = es.getExamActivityId();
         ExamActivityCacheBean ac = teExamActivityService.getExamActivityCacheBean(activityId);
         if (ac == null) {
@@ -498,23 +496,21 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
             throw new BusinessException("移动端第二机位离线");
         }
 
-        Long examId = ExamRecordCacheUtil.getExamId(recordId);
-        ExamCacheBean ec = teExamService.getExamCacheBean(examId);//考试缓存
         ExamStudentCacheBean examStudentCacheBean = teExamStudentService.getExamStudentCacheBean(examStudentId);
         Integer durationSeconds = Objects.isNull(ExamRecordCacheUtil.getDurationSeconds(recordId)) ? 0 : ExamRecordCacheUtil.getDurationSeconds(recordId);
         //获取断点时间
         Long lastBreakTime = ExamRecordCacheUtil.getLastBreakTime(recordId);
         //获取剩余断点次数
         Integer alreadyBreakCount = Objects.isNull(ExamRecordCacheUtil.getAlreadyBreakCount(recordId)) ? 0 : ExamRecordCacheUtil.getAlreadyBreakCount(recordId);
-        Integer leftBreakResumeCount = ec.getBreakResumeCount() - alreadyBreakCount;
-        Integer breakExpireSeconds = Objects.isNull(ec.getBreakExpireSeconds()) ? 0 : ec.getBreakExpireSeconds();
+        Integer leftBreakResumeCount = exam.getBreakResumeCount() - alreadyBreakCount;
+        Integer breakExpireSeconds = Objects.isNull(exam.getBreakExpireSeconds()) ? 0 : exam.getBreakExpireSeconds();
         //如果断点时间大于整体断点时间,则强制交卷
         if (Objects.nonNull(lastBreakTime) && (System.currentTimeMillis() - lastBreakTime) / 1000 > breakExpireSeconds) {
-            teExamService.finish(examStudentCacheBean.getStudentId(), recordId, FinishTypeEnum.AUTO.name(), durationSeconds);
+            finish(examStudentCacheBean.getStudentId(), recordId, FinishTypeEnum.AUTO.name(), durationSeconds);
         } else {
             //如果断点次数小于0,也强制交卷
             if (leftBreakResumeCount < 0) {
-                teExamService.finish(examStudentCacheBean.getStudentId(), recordId, FinishTypeEnum.AUTO.name(), durationSeconds);
+                finish(examStudentCacheBean.getStudentId(), recordId, FinishTypeEnum.AUTO.name(), durationSeconds);
             }
         }
         ret = new ExamStartBean();
@@ -799,7 +795,7 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
             throw new BusinessException("该考试已结束");
         }
         Long examId = ExamRecordCacheUtil.getExamId(recordId);
-        ExamCacheBean ec = teExamService.getExamCacheBean(examId);//考试缓存
+        ExamCacheBean ec = getExamCacheBeanNative(examId);//考试缓存
         ExamStudentCacheBean examStudentCacheBean = teExamStudentService.getExamStudentCacheBean(examStudentId);
         Integer durationSeconds = Objects.isNull(ExamRecordCacheUtil.getDurationSeconds(recordId)) ? 0 : ExamRecordCacheUtil.getDurationSeconds(recordId);
         //获取断点时间
@@ -810,11 +806,11 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         Integer breakExpireSeconds = Objects.isNull(ec.getBreakExpireSeconds()) ? 0 : ec.getBreakExpireSeconds();
         //如果断点时间大于整体断点时间,则强制交卷
         if (Objects.nonNull(lastBreakTime) && (System.currentTimeMillis() - lastBreakTime) / 1000 > breakExpireSeconds) {
-            teExamService.finish(examStudentCacheBean.getStudentId(), recordId, FinishTypeEnum.AUTO.name(), durationSeconds);
+            finish(examStudentCacheBean.getStudentId(), recordId, FinishTypeEnum.AUTO.name(), durationSeconds);
         } else {
             //如果断点次数小于0,也强制交卷
             if (leftBreakResumeCount < 0) {
-                teExamService.finish(examStudentCacheBean.getStudentId(), recordId, FinishTypeEnum.AUTO.name(), durationSeconds);
+                finish(examStudentCacheBean.getStudentId(), recordId, FinishTypeEnum.AUTO.name(), durationSeconds);
             }
         }
 
@@ -924,7 +920,7 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         ExamFinishBean ret = new ExamFinishBean();
         ret.setFinishTime(now.getTime());
         ret.setObjectiveScore(ExamRecordCacheUtil.getObjectiveScore(recordId));
-        ExamCacheBean exam = getExamCacheBean(es.getExamId());
+        ExamCacheBean exam = getExamCacheBeanNative(es.getExamId());
         //页面结果
         if (exam.getShowObjectiveScore() != null && exam.getShowObjectiveScore().intValue() == 1) {//实时出分
             if (InvigilateVerifyEnum.NOW.equals(exam.getInvigilateVerify())) {//实时审核
@@ -1015,6 +1011,11 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
     public ExamCacheBean getExamCacheBean(Long examId) {
         return cacheOperation(examId);
     }
+    
+    private ExamCacheBean getExamCacheBeanNative(Long examId) {
+    	TEExamService examService = SpringContextHolder.getBean(TEExamService.class);
+    	return examService.getExamCacheBean(examId);
+    }
 
     /**
      * 更新批次缓存
@@ -1063,7 +1064,7 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         }
 
         //页面结果
-        ExamCacheBean exam = getExamCacheBean(er.getExamId());
+        ExamCacheBean exam = getExamCacheBeanNative(er.getExamId());
         if (exam.getShowObjectiveScore() != null && exam.getShowObjectiveScore().intValue() == 1) {//实时出分
             if (InvigilateVerifyEnum.NOW.equals(exam.getInvigilateVerify())) {//实时审核
                 Integer warningCount = ExamRecordCacheUtil.getWarningCount(recordId);