瀏覽代碼

切屏次数限制

xiatian 3 年之前
父節點
當前提交
4a9f2d9757

+ 2 - 7
examcloud-core-oe-student-api-provider/src/main/java/cn/com/qmth/examcloud/core/oe/student/api/controller/ExamControlController.java

@@ -9,7 +9,6 @@ import cn.com.qmth.examcloud.core.oe.student.bean.client.CourseInfo;
 import cn.com.qmth.examcloud.core.oe.student.service.ExamControlService;
 import cn.com.qmth.examcloud.core.oe.student.service.ExamFileAnswerService;
 import cn.com.qmth.examcloud.core.oe.student.service.ExamRecordDataService;
-import cn.com.qmth.examcloud.core.oe.student.service.ExamingSessionService;
 import cn.com.qmth.examcloud.support.Constants;
 import cn.com.qmth.examcloud.support.enums.FileAnswerAcknowledgeStatus;
 import cn.com.qmth.examcloud.support.examing.ExamFileAnswer;
@@ -57,9 +56,6 @@ public class ExamControlController extends ControllerSupport {
     @Autowired
     private ExamControlService examControlService;
 
-    @Autowired
-    private ExamingSessionService examingSessionService;
-
     @Autowired
     private ExamFileAnswerService examFileAnswerService;
 
@@ -248,7 +244,6 @@ public class ExamControlController extends ControllerSupport {
         return fileAnswerId;
     }
 
-    //TODO 此方法有修改,微信需要修改代码
 
     /**
      * 查询客户端对上传的文件的响应状态(微信小程序调用)
@@ -402,14 +397,14 @@ public class ExamControlController extends ControllerSupport {
      */
     @ApiOperation(value = "记录切换屏幕次数")
     @PostMapping("/switchScreen")
-    public void switchScreen(@RequestParam @ApiParam(value = "考试记录id") Long examRecordDataId) {
+    public SwitchScreenCountInfo switchScreen(@RequestParam @ApiParam(value = "考试记录id") Long examRecordDataId) {
         User user = getAccessUser();
         String sequenceLockKey = Constants.EXAM_CONTROL_LOCK_PREFIX + user.getUserId();
         // 开始考试上锁,分布式锁,系统在请求结束后会,自动释放锁,无需手动解锁
         SequenceLockHelper.getLock(sequenceLockKey);
         Check.isNull(examRecordDataId, "examRecordDataId不能为空");
 
-        examControlService.switchScreen(examRecordDataId);
+        return examControlService.switchScreen(examRecordDataId);
     }
 
     @GetMapping("/courseName/{examRecordDataId}")

+ 37 - 0
examcloud-core-oe-student-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/bean/CheckExamInProgressInfo.java

@@ -9,6 +9,19 @@ public class CheckExamInProgressInfo implements JsonSerializable{
 	 * 
 	 */
 	private static final long serialVersionUID = 5411680698118472710L;
+	
+    /**
+     * 限制切屏次数
+     */
+    private Integer maxSwitchScreenCount;
+    
+    /**
+     * 已切屏次数
+     */
+    private Integer switchScreenCount;
+    
+    //是否达到切屏次数
+  	private Boolean exceedMaxSwitchScreenCount;
 
 	//已断点次数
 	private Integer interruptNum;
@@ -102,4 +115,28 @@ public class CheckExamInProgressInfo implements JsonSerializable{
         this.examType = examType;
     }
 
+	public Integer getMaxSwitchScreenCount() {
+		return maxSwitchScreenCount;
+	}
+
+	public void setMaxSwitchScreenCount(Integer maxSwitchScreenCount) {
+		this.maxSwitchScreenCount = maxSwitchScreenCount;
+	}
+
+	public Integer getSwitchScreenCount() {
+		return switchScreenCount;
+	}
+
+	public void setSwitchScreenCount(Integer switchScreenCount) {
+		this.switchScreenCount = switchScreenCount;
+	}
+
+	public Boolean getExceedMaxSwitchScreenCount() {
+		return exceedMaxSwitchScreenCount;
+	}
+
+	public void setExceedMaxSwitchScreenCount(Boolean exceedMaxSwitchScreenCount) {
+		this.exceedMaxSwitchScreenCount = exceedMaxSwitchScreenCount;
+	}
+
 }

+ 47 - 0
examcloud-core-oe-student-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/bean/SwitchScreenCountInfo.java

@@ -0,0 +1,47 @@
+package cn.com.qmth.examcloud.core.oe.student.bean;
+
+import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
+
+public class SwitchScreenCountInfo implements JsonSerializable{
+
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = -8650554167580096412L;
+
+	//已切屏次数
+	private Integer switchScreenCount;
+	
+	//最大切屏次数限制
+	private Integer maxSwitchScreenCount;
+
+	public Integer getSwitchScreenCount() {
+		return switchScreenCount;
+	}
+
+	public void setSwitchScreenCount(Integer switchScreenCount) {
+		this.switchScreenCount = switchScreenCount;
+	}
+
+	public Integer getMaxSwitchScreenCount() {
+		return maxSwitchScreenCount;
+	}
+
+	public void setMaxSwitchScreenCount(Integer maxSwitchScreenCount) {
+		this.maxSwitchScreenCount = maxSwitchScreenCount;
+	}
+
+	public SwitchScreenCountInfo(Integer switchScreenCount, Integer maxSwitchScreenCount) {
+		super();
+		this.switchScreenCount = switchScreenCount;
+		this.maxSwitchScreenCount = maxSwitchScreenCount;
+	}
+
+	public SwitchScreenCountInfo() {
+		super();
+	}
+
+	
+
+}

+ 1 - 1
examcloud-core-oe-student-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/service/ExamControlService.java

@@ -106,6 +106,6 @@ public interface ExamControlService {
      *
      * @param examRecordDataId
      */
-    void switchScreen(Long examRecordDataId);
+    SwitchScreenCountInfo switchScreen(Long examRecordDataId);
 
 }

+ 40 - 12
examcloud-core-oe-student-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/service/impl/ExamControlServiceImpl.java

@@ -30,9 +30,7 @@ import cn.com.qmth.examcloud.core.oe.student.base.utils.CommonUtil;
 import cn.com.qmth.examcloud.core.oe.student.base.utils.QuestionTypeUtil;
 import cn.com.qmth.examcloud.core.oe.student.bean.*;
 import cn.com.qmth.examcloud.core.oe.student.dao.ExamContinuedRecordRepo;
-import cn.com.qmth.examcloud.core.oe.student.dao.ExamRecordDataRepo;
 import cn.com.qmth.examcloud.core.oe.student.dao.entity.ExamContinuedRecordEntity;
-import cn.com.qmth.examcloud.core.oe.student.dao.entity.ExamRecordDataEntity;
 import cn.com.qmth.examcloud.core.oe.student.report.ExamProcessRecordReport;
 import cn.com.qmth.examcloud.core.oe.student.service.*;
 import cn.com.qmth.examcloud.core.oe.task.api.ExamCaptureCloudService;
@@ -58,7 +56,6 @@ import cn.com.qmth.examcloud.support.helper.FaceBiopsyHelper;
 import cn.com.qmth.examcloud.support.redis.RedisKeyHelper;
 import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
 import cn.com.qmth.examcloud.web.exception.SequenceLockException;
-import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 import cn.com.qmth.examcloud.web.helpers.SequenceLockHelper;
 import cn.com.qmth.examcloud.web.redis.RedisClient;
 import cn.com.qmth.examcloud.ws.api.WsCloudService;
@@ -143,9 +140,6 @@ public class ExamControlServiceImpl implements ExamControlService {
     @Autowired
     SyncExamDataCloudService syncExamDataCloudService;
 
-    @Autowired
-    private ExamRecordDataRepo examRecordDataRepo;
-
     @Autowired
     private ExamContinuedRecordRepo examContinuedRecordRepo;
 
@@ -1167,18 +1161,34 @@ public class ExamControlServiceImpl implements ExamControlService {
      * @param examRecordDataId
      */
     @Override
-    public void switchScreen(Long examRecordDataId) {
-        ExamRecordDataEntity examRecordDataEntity =
-                GlobalHelper.getEntity(examRecordDataRepo, examRecordDataId, ExamRecordDataEntity.class);
-        if (null == examRecordDataEntity) {
+    public SwitchScreenCountInfo switchScreen(Long examRecordDataId) {
+    	ExamRecordData examRecordData = examRecordDataService.getExamRecordDataCache(examRecordDataId);
+        if (null == examRecordData) {
             throw new StatusException("100001", "找不到相关考试记录");
         }
+        
+        ExamingSession examSessionInfo = examingSessionService.getExamingSession(examRecordData.getStudentId());
+        if (examSessionInfo == null
+                || examSessionInfo.getExamingStatus().equals(ExamingStatus.INFORMAL)) {
+            throw new StatusException("101001", "无效的会话,请离开考试");
+        }
+        
+        SwitchScreenCountInfo ret=new SwitchScreenCountInfo();
+        if(examSessionInfo.getRecordSwitchScreen()) {
+        	ret.setMaxSwitchScreenCount(examSessionInfo.getMaxSwitchScreenCount());
+        }else {
+        	ret.setMaxSwitchScreenCount(null);
+        }
 
         //更新考试记录缓存
-        ExamRecordData examRecordData = examRecordDataService.getExamRecordDataCache(examRecordDataId);
         int switchScreenCount = null == examRecordData.getSwitchScreenCount() ? 0 : examRecordData.getSwitchScreenCount();
         examRecordData.setSwitchScreenCount(++switchScreenCount);
+        ret.setSwitchScreenCount(examRecordData.getSwitchScreenCount());
+        if(ret.getMaxSwitchScreenCount()!=null&&ret.getSwitchScreenCount()>ret.getMaxSwitchScreenCount()) {
+        	examRecordData.setExceedMaxSwitchScreenCount(true);
+        }
         examRecordDataService.saveExamRecordDataCache(examRecordDataId, examRecordData);
+        return ret;
     }
 
     /**
@@ -1307,7 +1317,7 @@ public class ExamControlServiceImpl implements ExamControlService {
                 }
             }
 
-            //场次禁用,不允许考试 TODO 20200814 跟张莹确认一下,场次被禁用了是不能考试还是使用考试的设置???
+            //场次禁用,不允许考试
             if (examBean.getSpecialSettingsType() == ExamSpecialSettingsType.STAGE_BASED) {
                 if (null != examStageId) {
                     ExamStageCacheBean examStage = CacheHelper.getExamStage(examId, examStageId);
@@ -1530,6 +1540,20 @@ public class ExamControlServiceImpl implements ExamControlService {
      */
     public void initializeExamRecordSession(ExamingSession examSessionInfo, ExamRecordData examRecordData,
                                             final ExamSettingsCacheBean examBean) {
+    	//切屏设置
+    	Boolean isRecordSwitchScreenCount=false;
+    	Integer maxSwitchScreenCount=null;
+    	OrgPropertyCacheBean ss=CacheHelper.getOrgProperty(examRecordData.getRootOrgId(), "PREVENT_CHEATING_CONFIG");
+    	if(ss!=null&&ss.getHasValue()&&ss.getValue().contains("RECORD_SWITCH_SCREEN")) {
+    		isRecordSwitchScreenCount=true;
+    		ExamPropertyCacheBean sc=CacheHelper.getExamProperty(examBean.getId(), ExamProperties.MAX_SWITCH_SCREEN_COUNT.name());
+    		if(sc!=null&&StringUtils.isNotEmpty(sc.getValue())) {
+    			maxSwitchScreenCount=Integer.valueOf(sc.getValue());
+    		}
+    	}
+    	examSessionInfo.setMaxSwitchScreenCount(maxSwitchScreenCount);
+    	examSessionInfo.setRecordSwitchScreen(isRecordSwitchScreenCount);
+    	
         examSessionInfo.setExamRecordDataId(examRecordData.getId());
         //        examSessionInfo.setStartTime(examRecordData.getStartTime().getTime());//调整为在作答页面时赋值
         examSessionInfo.setExamType(examBean.getExamType());
@@ -1661,6 +1685,10 @@ public class ExamControlServiceImpl implements ExamControlService {
             ReportsUtil.report(new ExamProcessRecordReport(examRecordDataId, ExamProcess.CONTINUE, new Date()));
 
             setAndSaveActiveTime(examRecordDataId, ip);
+            
+            checkExamInProgressInfo.setExceedMaxSwitchScreenCount(examingRecord.getExceedMaxSwitchScreenCount());
+            checkExamInProgressInfo.setSwitchScreenCount(examingRecord.getSwitchScreenCount());
+            checkExamInProgressInfo.setMaxSwitchScreenCount(examSessionInfo.getMaxSwitchScreenCount());
 
             return checkExamInProgressInfo;
         }

+ 1 - 0
examcloud-core-oe-student-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/service/impl/ExamRecordDataServiceImpl.java

@@ -139,6 +139,7 @@ public class ExamRecordDataServiceImpl implements ExamRecordDataService {
         }
 
         ExamRecordData bean = of(examRecordData);
+        bean.setExceedMaxSwitchScreenCount(false);
         //存入redis
         saveExamRecordDataCache(examRecordData.getId(), bean);
         return bean;