wangliang 4 年之前
父節點
當前提交
3dcee9d2c5

+ 12 - 18
themis-admin/src/main/java/com/qmth/themis/admin/api/TEExamController.java

@@ -77,9 +77,9 @@ public class TEExamController {
 
     @Resource
     TOeExamRecordService tOeExamRecordService;
-    
+
     @Resource
-    private  TEExamPaperService examPaperService;
+    private TEExamPaperService examPaperService;
 
     @ApiOperation(value = "考试批次修改/新增接口")
     @RequestMapping(value = "/save", method = RequestMethod.POST)
@@ -98,29 +98,30 @@ public class TEExamController {
         if (Objects.isNull(teExamDto.getCode()) || Objects.equals(teExamDto.getCode(), "")) {
             throw new BusinessException("批次编码不能为空");
         }
-        TEExam teExam = new TEExam(teExamDto);
+        TEExam teExam = null;
         Long oldId = null;
         String activityCode = null;
         try {
             TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
             TBOrg tbOrg = (TBOrg) ServletUtil.getRequestOrg();
-            if (Objects.nonNull(tbOrg)) {
-                if (Objects.isNull(tbOrg.getId())) {
-                    throw new BusinessException("考试的机构id不允许为空");
-                }
-                teExamDto.setOrgId(tbOrg.getId());
+            if (Objects.nonNull(tbOrg) && Objects.isNull(tbOrg.getId())) {
+                throw new BusinessException("考试的机构id不允许为空");
             }
+            teExamDto.setOrgId(tbOrg.getId());
             oldId = teExamDto.getId();
             TEExam oldTeExam = null;
             if (Objects.nonNull(oldId)) {
                 teExamDto.setUpdateId(tbUser.getId());
                 oldTeExam = teExamService.getById(oldId);
+                if (Objects.equals(oldTeExam.getMonitorStatus(), InvigilateMonitorStatusEnum.FINISHED)) {
+                    throw new BusinessException("监考结束的考试批次不可以修改");
+                }
                 boolean recordUpdate = true;
                 if ((Objects.nonNull(oldTeExam.getRecordSelectStrategy()) && Objects.nonNull(teExamDto.getRecordSelectStrategy()) && !Objects.equals(oldTeExam.getRecordSelectStrategy(), teExamDto.getRecordSelectStrategy()))) {
                     recordUpdate = false;
                 }
                 boolean objectiveUpdate = true;
-                if ((Objects.nonNull(oldTeExam.getObjectiveScorePolicy()) && Objects.nonNull(teExam.getObjectiveScorePolicy()) && !Objects.equals(oldTeExam.getObjectiveScorePolicy(), teExamDto.getObjectiveScorePolicy()))) {
+                if ((Objects.nonNull(oldTeExam.getObjectiveScorePolicy()) && Objects.nonNull(teExamDto.getObjectiveScorePolicy()) && !Objects.equals(oldTeExam.getObjectiveScorePolicy(), teExamDto.getObjectiveScorePolicy()))) {
                     objectiveUpdate = false;
                 }
                 QueryWrapper<TOeExamRecord> tOeExamRecordQueryWrapper = new QueryWrapper<>();
@@ -138,15 +139,8 @@ public class TEExamController {
                 teExamDto.setId(uidUtil.getId());
                 teExamDto.setCreateId(tbUser.getId());
             }
-            if (oldTeExam != null) {
-                teExam.setMonitorStatus(oldTeExam.getMonitorStatus());
-            } else {
-                teExam.setMonitorStatus(InvigilateMonitorStatusEnum.NOT_START);
-            }
-            if (Objects.nonNull(teExam.getMonitorStatus()) && Objects
-                    .equals(teExam.getMonitorStatus(), InvigilateMonitorStatusEnum.FINISHED)) {
-                throw new BusinessException("监考结束的考试批次不可以修改");
-            }
+            teExamDto.setMonitorStatus(Objects.nonNull(oldTeExam) ? oldTeExam.getMonitorStatus() : InvigilateMonitorStatusEnum.NOT_START);
+            teExam = new TEExam(teExamDto);
             teExamService.saveOrUpdate(teExam);
             if (Objects.nonNull(oldTeExam) && !Objects
                     .equals(oldTeExam.getMode().name(), teExamDto.getMode().name())) {//如果模式改变,则删除之前模式的全部quartz

+ 1 - 0
themis-business/src/main/java/com/qmth/themis/business/entity/TEExam.java

@@ -258,6 +258,7 @@ public class TEExam extends BaseEntity {
         setUpdateId(teExamDto.getUpdateId());
         setUpdateTime(teExamDto.getUpdateTime());
         this.invigilateVerify = teExamDto.getInvigilateVerify();
+        this.monitorStatus = teExamDto.getMonitorStatus();
     }
 
     public Integer getInProcessRealnessVerify() {

+ 74 - 77
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamPaperServiceImpl.java

@@ -1,24 +1,5 @@
 package com.qmth.themis.business.service.impl;
 
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-
-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.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.aliyun.oss.common.utils.BinaryUtil;
@@ -35,6 +16,18 @@ import com.qmth.themis.business.service.TEExamPaperService;
 import com.qmth.themis.business.service.TEExamService;
 import com.qmth.themis.business.util.OssUtil;
 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 org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 /**
  * @Description: 考试试卷 服务实现类
@@ -45,20 +38,20 @@ import com.qmth.themis.common.exception.BusinessException;
  */
 @Service
 public class TEExamPaperServiceImpl extends ServiceImpl<TEExamPaperMapper, TEExamPaper> implements TEExamPaperService {
-	
-	private final static long objectiveAnswerCacheTimeOutHours=48L;
-	
-	@Resource
-	private TEExamService examService;
-	
+
+    private final static long objectiveAnswerCacheTimeOutHours = 48L;
+
+    @Resource
+    private TEExamService examService;
+
     @Resource
     OssUtil ossUtil;
 
     @Resource
     TEExamPaperMapper teExamPaperMapper;
-    
+
     @Resource
-    TEExamActivityMapper  examActivityMapper;
+    TEExamActivityMapper examActivityMapper;
 
     @Override
     public TEExamPaper findByExamIdAndCourseCodeAndPaperCode(Long examId, String courseCode, String paperCode) {
@@ -149,20 +142,20 @@ public class TEExamPaperServiceImpl extends ServiceImpl<TEExamPaperMapper, TEExa
         ret.setPaperViewPath(ep.getPaperViewPath());
         return ret;
     }
-    
+
     @Override
-    public void reloadObjectiveAnswerCacheBean(Long paperId,Long timeOutHours) {
+    public void reloadObjectiveAnswerCacheBean(Long paperId, Long timeOutHours) {
         ExamPaperCacheBean ep = getExamPaperCacheBean(paperId);
         if (ep == null) {
-            return ;
+            return;
         }
-        Long examId=ep.getExamId();
+        Long examId = ep.getExamId();
         if (StringUtils.isBlank(ep.getAnswerPath())) {//没有答案文件
-            return ;
+            return;
         }
         try {
             String answerjson = new String(ossUtil.download(false, ep.getAnswerPath()), StandardCharsets.UTF_8);
-            Map<String, ObjectiveAnswerCacheBean> map=buildObjectiveAnswerCache(answerjson);
+            Map<String, ObjectiveAnswerCacheBean> map = buildObjectiveAnswerCache(answerjson);
             ObjectiveAnswerCacheUtil.saveObjectiveAnswerCache(examId, paperId, map);
             ObjectiveAnswerCacheUtil.expireObjectiveAnswerCache(examId, timeOutHours);
         } catch (Exception e) {
@@ -177,17 +170,17 @@ public class TEExamPaperServiceImpl extends ServiceImpl<TEExamPaperMapper, TEExa
         if (ep == null) {
             return null;
         }
-        Long examId=ep.getExamId();
+        Long examId = ep.getExamId();
         if (StringUtils.isBlank(ep.getAnswerPath())) {//没有答案文件
             return null;
         }
-        Map<String, ObjectiveAnswerCacheBean> map=ObjectiveAnswerCacheUtil.getObjectiveAnswerCache(examId, paperId);
-        if(map!=null) {
-        	return map;
+        Map<String, ObjectiveAnswerCacheBean> map = ObjectiveAnswerCacheUtil.getObjectiveAnswerCache(examId, paperId);
+        if (map != null) {
+            return map;
         }
         try {
             String answerjson = new String(ossUtil.download(false, ep.getAnswerPath()), StandardCharsets.UTF_8);
-            map=buildObjectiveAnswerCache(answerjson);
+            map = buildObjectiveAnswerCache(answerjson);
             ObjectiveAnswerCacheUtil.saveObjectiveAnswerCache(examId, paperId, map);
             ObjectiveAnswerCacheUtil.expireObjectiveAnswerCache(examId, objectiveAnswerCacheTimeOutHours);
             return map;
@@ -196,7 +189,7 @@ public class TEExamPaperServiceImpl extends ServiceImpl<TEExamPaperMapper, TEExa
             throw new RuntimeException(e);
         }
     }
-    
+
     private Map<String, ObjectiveAnswerCacheBean> buildObjectiveAnswerCache(String answerStr) {
         Map<String, ObjectiveAnswerCacheBean> map = new HashMap<String, ObjectiveAnswerCacheBean>();
         JSONObject answerJson = JSONObject.parseObject(answerStr);
@@ -265,60 +258,64 @@ public class TEExamPaperServiceImpl extends ServiceImpl<TEExamPaperMapper, TEExa
             teExamPaperMapper.updateWeight(id, map.get(id));
         }
     }
-    
-    /**获取缓存过期时间,不满足条件的返回-1.条件:场次最小startTime在当天的,或者当前时间在场次最小startTime和最大finishTime之间的。
+
+    /**
+     * 获取缓存过期时间,不满足条件的返回-1.条件:场次最小startTime在当天的,或者当前时间在场次最小startTime和最大finishTime之间的。
+     *
      * @param examId
      * @return
      */
     private Long getObjectiveAnswerCacheTimeOut(Long examId) {
-    	Long objectiveAnswerCacheTimeOut=-1L;
-    	List<Map<String, Long>> list=examActivityMapper.findMinStartTimeAndMaxFinshTimeByExamId(examId);
-    	if(list!=null&&list.size()>0) {
-    		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
-    		Date now=new Date();
-    		Long startTime=list.get(0).get("startTime");
-    		Long finishTime=list.get(0).get("finishTime");
-    		Date start=new Date(startTime);
-    		if(sdf.format(now).equals(sdf.format(start))||(now.getTime()>=startTime&&now.getTime()<=finishTime)) {
-    			objectiveAnswerCacheTimeOut=(finishTime-now.getTime())/(1000*60*60)+24;
-        	}
-    	}
-    	return objectiveAnswerCacheTimeOut;
+        Long objectiveAnswerCacheTimeOut = -1L;
+        List<Map<String, Long>> list = examActivityMapper.findMinStartTimeAndMaxFinshTimeByExamId(examId);
+        if (list != null && list.size() > 0 && Objects.nonNull(list.get(0))) {
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            Date now = new Date();
+            Long startTime = list.get(0).get("startTime");
+            Long finishTime = list.get(0).get("finishTime");
+            Date start = new Date(startTime);
+            if (sdf.format(now).equals(sdf.format(start)) || (now.getTime() >= startTime && now.getTime() <= finishTime)) {
+                objectiveAnswerCacheTimeOut = (finishTime - now.getTime()) / (1000 * 60 * 60) + 24;
+            }
+        }
+        return objectiveAnswerCacheTimeOut;
     }
-    
-    /**处理考试批次下的客观题答案缓存
+
+    /**
+     * 处理考试批次下的客观题答案缓存
+     *
      * @param examId
      */
     @Override
     public void disposeObjectiveAnswer(Long examId) {
-    	Long objectiveAnswerCacheTimeOut=getObjectiveAnswerCacheTimeOut(examId);
-    	if(objectiveAnswerCacheTimeOut>0) {
-    		List<TEExamPaper> list=teExamPaperMapper.findByExamId(examId);
-    		if(list!=null&&list.size()>0) {
-    			for(TEExamPaper paper:list) {
-    				if(ObjectiveAnswerCacheUtil.getObjectiveAnswerCache(examId, paper.getId())==null) {
-    					reloadObjectiveAnswerCacheBean(paper.getId(), objectiveAnswerCacheTimeOut);
-    				}
-    			}
-    		}
-    		Long count=ObjectiveAnswerCacheUtil.getHashCacheSize(examId);
-    		if(count!=null&&count>0) {
-    			ObjectiveAnswerCacheUtil.expireObjectiveAnswerCache(examId, objectiveAnswerCacheTimeOut);
-    		}
-    	}
+        Long objectiveAnswerCacheTimeOut = getObjectiveAnswerCacheTimeOut(examId);
+        if (objectiveAnswerCacheTimeOut > 0) {
+            List<TEExamPaper> list = teExamPaperMapper.findByExamId(examId);
+            if (list != null && list.size() > 0) {
+                for (TEExamPaper paper : list) {
+                    if (ObjectiveAnswerCacheUtil.getObjectiveAnswerCache(examId, paper.getId()) == null) {
+                        reloadObjectiveAnswerCacheBean(paper.getId(), objectiveAnswerCacheTimeOut);
+                    }
+                }
+            }
+            Long count = ObjectiveAnswerCacheUtil.getHashCacheSize(examId);
+            if (count != null && count > 0) {
+                ObjectiveAnswerCacheUtil.expireObjectiveAnswerCache(examId, objectiveAnswerCacheTimeOut);
+            }
+        }
     }
-    
+
     /**
-     *导入试卷时处理缓存
+     * 导入试卷时处理缓存
      */
     @Override
-    public void disposePaperCacheOnPaperImport(Long examId,List<Long> paperIds) {
+    public void disposePaperCacheOnPaperImport(Long examId, List<Long> paperIds) {
         TEExamPaperService examPaperService = SpringContextHolder.getBean(TEExamPaperService.class);
         for (Long id : paperIds) {
             examPaperService.deleteExamPaperCacheBean(id);
-            Long objectiveAnswerCacheTimeOut=getObjectiveAnswerCacheTimeOut(examId);
-            if(objectiveAnswerCacheTimeOut>0) {
-            	examPaperService.reloadObjectiveAnswerCacheBean(id,objectiveAnswerCacheTimeOut);
+            Long objectiveAnswerCacheTimeOut = getObjectiveAnswerCacheTimeOut(examId);
+            if (objectiveAnswerCacheTimeOut > 0) {
+                examPaperService.reloadObjectiveAnswerCacheBean(id, objectiveAnswerCacheTimeOut);
             }
             examPaperService.deletePaperStructCacheBean(id);
         }