Browse Source

对外接口考试考生场次

xiatian 1 year ago
parent
commit
49a4201473

+ 136 - 26
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/provider/ExamCloudServiceProvider.java

@@ -1,14 +1,56 @@
 package cn.com.qmth.examcloud.core.examwork.api.provider;
 
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.criteria.Predicate;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.time.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
 import cn.com.qmth.examcloud.api.commons.enums.CURD;
 import cn.com.qmth.examcloud.api.commons.enums.CallType;
+import cn.com.qmth.examcloud.api.commons.enums.ExamSpecialSettingsType;
+import cn.com.qmth.examcloud.api.commons.enums.ExamStageStartExamStatus;
 import cn.com.qmth.examcloud.api.commons.enums.ExamType;
+import cn.com.qmth.examcloud.api.commons.enums.SubmitType;
 import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.commons.helpers.DynamicEnum;
 import cn.com.qmth.examcloud.commons.helpers.DynamicEnumManager;
 import cn.com.qmth.examcloud.core.examwork.base.enums.ExamProperty;
-import cn.com.qmth.examcloud.core.examwork.dao.*;
-import cn.com.qmth.examcloud.core.examwork.dao.entity.*;
+import cn.com.qmth.examcloud.core.examwork.dao.ExamCourseRelationRepo;
+import cn.com.qmth.examcloud.core.examwork.dao.ExamPaperTypeRelationRepo;
+import cn.com.qmth.examcloud.core.examwork.dao.ExamPropertyRepo;
+import cn.com.qmth.examcloud.core.examwork.dao.ExamRepo;
+import cn.com.qmth.examcloud.core.examwork.dao.ExamSpecialSettingsRepo;
+import cn.com.qmth.examcloud.core.examwork.dao.ExamStageRepo;
+import cn.com.qmth.examcloud.core.examwork.dao.ExamStudentRepo;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamCourseRelationEntity;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamEntity;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamPaperTypeRelationEntity;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamPropertyEntity;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamSpecialSettingsEntity;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStageEntity;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStudentEntity;
 import cn.com.qmth.examcloud.core.examwork.service.ExamCourseService;
 import cn.com.qmth.examcloud.core.examwork.service.ExamService;
 import cn.com.qmth.examcloud.core.examwork.service.OnGoingExamService;
@@ -19,31 +61,52 @@ import cn.com.qmth.examcloud.examwork.api.bean.ExamBean;
 import cn.com.qmth.examcloud.examwork.api.bean.ExamCourseRelationBean;
 import cn.com.qmth.examcloud.examwork.api.bean.ExamPaperTypeRelation;
 import cn.com.qmth.examcloud.examwork.api.bean.ExamSpecialSettingsBean;
-import cn.com.qmth.examcloud.examwork.api.request.*;
-import cn.com.qmth.examcloud.examwork.api.response.*;
+import cn.com.qmth.examcloud.examwork.api.request.CountExamStudentReq;
+import cn.com.qmth.examcloud.examwork.api.request.GetExamCourseIdsReq;
+import cn.com.qmth.examcloud.examwork.api.request.GetExamCourseListReq;
+import cn.com.qmth.examcloud.examwork.api.request.GetExamCoursePaperTypeListReq;
+import cn.com.qmth.examcloud.examwork.api.request.GetExamCourseReq;
+import cn.com.qmth.examcloud.examwork.api.request.GetExamListReq;
+import cn.com.qmth.examcloud.examwork.api.request.GetExamMapsReq;
+import cn.com.qmth.examcloud.examwork.api.request.GetExamOrgListReq;
+import cn.com.qmth.examcloud.examwork.api.request.GetExamPropertyListReq;
+import cn.com.qmth.examcloud.examwork.api.request.GetExamPropertyReq;
+import cn.com.qmth.examcloud.examwork.api.request.GetExamReq;
+import cn.com.qmth.examcloud.examwork.api.request.GetExamStudentPropertyValueListReq;
+import cn.com.qmth.examcloud.examwork.api.request.GetExamsByIdListReq;
+import cn.com.qmth.examcloud.examwork.api.request.GetExamsReq;
+import cn.com.qmth.examcloud.examwork.api.request.GetOngoingExamListReq;
+import cn.com.qmth.examcloud.examwork.api.request.LockExamStudentsReq;
+import cn.com.qmth.examcloud.examwork.api.request.SaveExamReq;
+import cn.com.qmth.examcloud.examwork.api.request.SaveStudentSpecialSettingsReq;
+import cn.com.qmth.examcloud.examwork.api.request.SetExamPropertyReq;
+import cn.com.qmth.examcloud.examwork.api.request.UnlockExamStudentsReq;
+import cn.com.qmth.examcloud.examwork.api.response.CountExamStudentResp;
+import cn.com.qmth.examcloud.examwork.api.response.GetExamCourseIdsResp;
+import cn.com.qmth.examcloud.examwork.api.response.GetExamCourseListResp;
+import cn.com.qmth.examcloud.examwork.api.response.GetExamCoursePaperTypeListResp;
+import cn.com.qmth.examcloud.examwork.api.response.GetExamCourseResp;
+import cn.com.qmth.examcloud.examwork.api.response.GetExamListResp;
+import cn.com.qmth.examcloud.examwork.api.response.GetExamMapsResp;
+import cn.com.qmth.examcloud.examwork.api.response.GetExamOrgListResp;
+import cn.com.qmth.examcloud.examwork.api.response.GetExamPropertyListResp;
+import cn.com.qmth.examcloud.examwork.api.response.GetExamPropertyResp;
+import cn.com.qmth.examcloud.examwork.api.response.GetExamResp;
+import cn.com.qmth.examcloud.examwork.api.response.GetExamStudentPropertyValueListResp;
+import cn.com.qmth.examcloud.examwork.api.response.GetExamsByIdListResp;
+import cn.com.qmth.examcloud.examwork.api.response.GetExamsResp;
+import cn.com.qmth.examcloud.examwork.api.response.GetOngoingExamListResp;
+import cn.com.qmth.examcloud.examwork.api.response.LockExamStudentsResp;
+import cn.com.qmth.examcloud.examwork.api.response.SaveExamResp;
+import cn.com.qmth.examcloud.examwork.api.response.SaveStudentSpecialSettingsResp;
+import cn.com.qmth.examcloud.examwork.api.response.SetExamPropertyResp;
+import cn.com.qmth.examcloud.examwork.api.response.UnlockExamStudentsResp;
+import cn.com.qmth.examcloud.support.enums.ExamProperties;
 import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 import cn.com.qmth.examcloud.web.redis.RedisClient;
 import cn.com.qmth.examcloud.web.support.ControllerSupport;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.domain.Sort;
-import org.springframework.data.jpa.domain.Specification;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import javax.persistence.criteria.Predicate;
-import java.util.*;
 
 /**
  * {@link StatusException} 状态码范围:012XXX<br>
@@ -59,10 +122,11 @@ import java.util.*;
 public class ExamCloudServiceProvider extends ControllerSupport implements ExamCloudService {
 
     private static final long serialVersionUID = 6850508158980856785L;
-
+    
     @Autowired
     RedisClient redisClient;
-
+    @Autowired
+    private ExamStageRepo examStageRepo;
     @Autowired
     private ExamService examService;
 
@@ -111,13 +175,24 @@ public class ExamCloudServiceProvider extends ControllerSupport implements ExamC
         examInfo.setExamLimit(req.getExamLimit());
 
         Map<String, String> properties = req.getProperties();
+        if(properties.get(ExamProperties.FREEZE_TIME.name())==null) {
+        	properties.put(ExamProperties.FREEZE_TIME.name(),"0");
+        }
+        if(properties.get(ExamProperties.EXAM_RECONNECT_TIME.name())==null) {
+        	properties.put(ExamProperties.EXAM_RECONNECT_TIME.name(),"30");
+        }
         examInfo.setProperties(properties);
-
+        if(req.getEnableExamStage()!=null&&req.getEnableExamStage()) {
+        	examInfo.setSpecialSettingsEnabled(true);
+        	examInfo.setSpecialSettingsType(ExamSpecialSettingsType.STAGE_BASED);
+        }else {
+        	examInfo.setSpecialSettingsEnabled(false);
+        }
         if(examInfo.getCallType() == null) {
             examInfo.setCallType(CallType.WHOLE_SET);
         }
         ExamEntity saved = examService.saveExam(examInfo, CURD.CREATION_OR_UPDATE);
-
+        disposeStage(req, saved);
         SaveExamResp resp = new SaveExamResp();
         resp.setExamId(saved.getId());
 
@@ -139,6 +214,41 @@ public class ExamCloudServiceProvider extends ControllerSupport implements ExamC
 
         return resp;
     }
+    
+    private void disposeStage(SaveExamReq req,ExamEntity exam) {
+    	if(req.getEnableExamStage()!=null&&!req.getEnableExamStage()) {
+    		return;
+    	}
+        Date examStartTime = req.getBeginTime();
+        Date examEndTime = req.getEndTime();
+
+        ExamStageEntity esEntity = examStageRepo.findByExamIdAndStageOrder(exam.getId(), 1);
+        if(esEntity==null) {
+        	esEntity=new ExamStageEntity();
+        }
+        esEntity.setStartTime(examStartTime);
+        if(req.getLateMinuteLimit()==null) {
+        	esEntity.setEndTime(examEndTime);
+        }else {
+        	Date temEnd=DateUtils.addMinutes(examStartTime, req.getLateMinuteLimit());
+        	if(temEnd.getTime()>examEndTime.getTime()) {
+        		esEntity.setEndTime(examEndTime);
+        	}else {
+        		esEntity.setEndTime(temEnd);
+        	}
+        }
+
+
+        esEntity.setRootOrgId(exam.getRootOrgId());
+        esEntity.setExamId(exam.getId());
+        esEntity.setStageOrder(1);
+        esEntity.setEnable(true);
+        esEntity.setSpecialSetting(false);
+        esEntity.setSubmitType(SubmitType.NORMAL);
+        esEntity.setSubmitDuration(null);
+        esEntity.setStartExamStatus(ExamStageStartExamStatus.NOT_START);
+        examStageRepo.save(esEntity);
+    }
 
     @ApiOperation(value = "查询考试")
     @PostMapping("getExam")

+ 11 - 1
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/provider/ExamStudentCloudServiceProvider.java

@@ -16,8 +16,10 @@ import cn.com.qmth.examcloud.core.basic.api.response.GetOrgResp;
 import cn.com.qmth.examcloud.core.basic.api.response.GetStudentResp;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamPaperTypeRelationRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamRepo;
+import cn.com.qmth.examcloud.core.examwork.dao.ExamStageRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamStudentRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamEntity;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStageEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStudentEntity;
 import cn.com.qmth.examcloud.core.examwork.service.ExamService;
 import cn.com.qmth.examcloud.core.examwork.service.ExamStudentService;
@@ -90,7 +92,8 @@ public class ExamStudentCloudServiceProvider extends ControllerSupport
 
     @Autowired
     CourseCloudService courseCloudService;
-
+    @Autowired
+    private ExamStageRepo examStageRepo;
     @Autowired
     ExamPaperTypeRelationRepo examPaperTypeRelationRepo;
 
@@ -131,6 +134,13 @@ public class ExamStudentCloudServiceProvider extends ControllerSupport
 
         info.setExamStageId(req.getExamStageId());
         info.setExamStageOrder(req.getExamStageOrder());
+        if(req.getExamStageOrder()!=null) {
+        	ExamStageEntity esEntity = examStageRepo.findByExamIdAndStageOrder(req.getExamId(), req.getExamStageOrder());
+            if(esEntity==null) {
+            	throw new StatusException("该场次号还未创建,场次号:"+req.getExamStageOrder());
+            }
+            info.setExamStageId(esEntity.getId());
+        }
 
         ExamStudentInfo saved = examStudentService.saveExamStudent(info);
 

+ 1 - 1
examcloud-core-examwork-starter/src/main/resources/exam-properties.xml

@@ -21,7 +21,7 @@
     <enum>
         <id>4</id>
         <name>EXAM_RECONNECT_TIME</name>
-        <desc>断点续考时间()</desc>
+        <desc>断点续考时间(分钟)</desc>
         <valueType>LONG</valueType>
     </enum>
     <enum>