Pārlūkot izejas kodu

Merge branch 'dev'
1

wangliang 4 gadi atpakaļ
vecāks
revīzija
d98426004e

+ 108 - 47
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamServiceImpl.java

@@ -1,13 +1,65 @@
 package com.qmth.themis.business.service.impl;
 
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import javax.annotation.Resource;
+
+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;
+import org.springframework.web.multipart.MultipartFile;
+
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.qmth.themis.business.bean.exam.*;
+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.cache.ExamActivityRecordCacheUtil;
 import com.qmth.themis.business.cache.ExamRecordCacheUtil;
 import com.qmth.themis.business.cache.ExamingDataCacheUtil;
 import com.qmth.themis.business.cache.RedisKeyHelper;
-import com.qmth.themis.business.cache.bean.*;
+import com.qmth.themis.business.cache.bean.ExamActivityCacheBean;
+import com.qmth.themis.business.cache.bean.ExamActivityRecordCache;
+import com.qmth.themis.business.cache.bean.ExamCacheBean;
+import com.qmth.themis.business.cache.bean.ExamCourseCacheBean;
+import com.qmth.themis.business.cache.bean.ExamPaperCacheBean;
+import com.qmth.themis.business.cache.bean.ExamStudentAnswerCacheBean;
+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;
@@ -21,33 +73,37 @@ import com.qmth.themis.business.entity.TBSession;
 import com.qmth.themis.business.entity.TBTaskHistory;
 import com.qmth.themis.business.entity.TEExam;
 import com.qmth.themis.business.entity.TOeExamRecord;
-import com.qmth.themis.business.enums.*;
-import com.qmth.themis.business.service.*;
-import com.qmth.themis.business.util.*;
+import com.qmth.themis.business.enums.EntryAuthenticationPolicyEnum;
+import com.qmth.themis.business.enums.ExamModeEnum;
+import com.qmth.themis.business.enums.ExamRecordFieldEnum;
+import com.qmth.themis.business.enums.ExamRecordStatusEnum;
+import com.qmth.themis.business.enums.FinishExamResultEnum;
+import com.qmth.themis.business.enums.FinishTypeEnum;
+import com.qmth.themis.business.enums.HardwareTestEnum;
+import com.qmth.themis.business.enums.InvigilateVerifyEnum;
+import com.qmth.themis.business.enums.MonitorStatusSourceEnum;
+import com.qmth.themis.business.enums.MonitorVideoSourceEnum;
+import com.qmth.themis.business.enums.MqTagEnum;
+import com.qmth.themis.business.enums.MqTopicEnum;
+import com.qmth.themis.business.enums.ReviewResultEnum;
+import com.qmth.themis.business.enums.SystemOperationEnum;
+import com.qmth.themis.business.enums.TaskStatusEnum;
+import com.qmth.themis.business.enums.WebsocketStatusEnum;
+import com.qmth.themis.business.service.MqDtoService;
+import com.qmth.themis.business.service.TBTaskHistoryService;
+import com.qmth.themis.business.service.TEExamActivityService;
+import com.qmth.themis.business.service.TEExamCourseService;
+import com.qmth.themis.business.service.TEExamPaperService;
+import com.qmth.themis.business.service.TEExamService;
+import com.qmth.themis.business.service.TEExamStudentService;
+import com.qmth.themis.business.service.TOeExamRecordService;
+import com.qmth.themis.business.util.JacksonUtil;
+import com.qmth.themis.business.util.OssUtil;
+import com.qmth.themis.business.util.RedisUtil;
+import com.qmth.themis.business.util.ServletUtil;
+import com.qmth.themis.business.util.TencentYunUtil;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.util.IpUtil;
-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;
-import org.springframework.web.multipart.MultipartFile;
-
-import javax.annotation.Resource;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.math.BigDecimal;
-import java.text.SimpleDateFormat;
-import java.time.LocalDateTime;
-import java.time.ZoneOffset;
-import java.util.*;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
 
 /**
  * @Description: 考试批次 服务实现类
@@ -185,6 +241,26 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         return list;
     }
 
+    private void checkIp(ExamCacheBean examCache) {
+    	if (examCache.getEnableIpLimit() != null && examCache.getEnableIpLimit().intValue() == 1) {
+            String ipAllows = examCache.getIpAllow();
+            //ip限制判断
+            String ip = IpUtil.getRemoteIp(ServletUtil.getRequest());
+            boolean allow = false;
+            for (String ipAllow : ipAllows.split(",")) {
+                String reg = "^" + ipAllow.replaceAll("\\*", "[0-9]{1,3}").replaceAll("\\.", "\\\\.") + "$";
+                Pattern p = Pattern.compile(reg);
+                Matcher matcher = p.matcher(ip);
+                if (matcher.matches()) {
+                    allow = true;
+                    break;
+                }
+            }
+            if (!allow) {
+                throw new BusinessException("考生IP不被允许");
+            }
+        }
+    }
     /**
      * 开始候考
      */
@@ -203,24 +279,7 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         }
         ExamCacheBean examCache = getExamCacheBeanNative(es.getExamId());
 
-        if (examCache.getEnableIpLimit() != null && examCache.getEnableIpLimit().intValue() == 1) {
-            String ipAllows = examCache.getIpAllow();
-            //ip限制判断
-            String ip = IpUtil.getRemoteIp(ServletUtil.getRequest());
-            boolean allow = false;
-            for (String ipAllow : ipAllows.split(",")) {
-                String reg = "^" + ipAllow.replaceAll("\\*", "[0-9]{1,3}").replaceAll("\\.", "\\\\.") + "$";
-                Pattern p = Pattern.compile(reg);
-                Matcher matcher = p.matcher(ip);
-                if (matcher.matches()) {
-                    allow = true;
-                    break;
-                }
-            }
-            if (!allow) {
-                throw new BusinessException("考生IP不被允许");
-            }
-        }
+        checkIp(examCache);
 
         Long unFinishedRecordId = ExamingDataCacheUtil.getUnFinishedRecordId(studentId);
         if (unFinishedRecordId != null) {
@@ -729,6 +788,10 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         if (!studentId.equals(es.getStudentId())) {
             throw new BusinessException("考试记录的学生Id和当前登录用户不一致");
         }
+        Long examId = ExamRecordCacheUtil.getExamId(recordId);
+        ExamCacheBean ec = getExamCacheBeanNative(examId);//考试缓存
+        
+        checkIp(ec);
 
         Long paperId = ExamRecordCacheUtil.getPaperId(recordId);
         ExamPaperCacheBean ep = teExamPaperService.getExamPaperCacheBean(paperId);
@@ -739,8 +802,6 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         if (ExamRecordStatusEnum.FINISHED.equals(sta) || ExamRecordStatusEnum.PERSISTED.equals(sta)) {
             throw new BusinessException("该考试已结束");
         }
-        Long examId = ExamRecordCacheUtil.getExamId(recordId);
-        ExamCacheBean ec = getExamCacheBeanNative(examId);//考试缓存
         ExamStudentCacheBean examStudentCacheBean = teExamStudentService.getExamStudentCacheBean(examStudentId);
         Integer durationSeconds = Objects.isNull(ExamRecordCacheUtil.getDurationSeconds(recordId)) ? 0 : ExamRecordCacheUtil.getDurationSeconds(recordId);
         //获取断点时间