|
@@ -1,11 +1,22 @@
|
|
|
package cn.com.qmth.examcloud.core.oe.admin.api.controller;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
import cn.com.qmth.examcloud.api.commons.enums.ExamType;
|
|
|
+import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.dao.ExamRecordDataRepo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.dao.entity.ExamRecordDataEntity;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.api.ExamRecordDataCloudService;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.api.request.GetExamRecordNumReq;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.api.response.GetExamRecordNumResp;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.ExamSettingsCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.helper.ExamCacheTransferHelper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Example;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
@@ -20,8 +31,12 @@ import io.swagger.annotations.ApiOperation;
|
|
|
@RequestMapping("${$rmp.ctr.oe}/examControl")
|
|
|
public class ExamControlController extends ControllerSupport {
|
|
|
|
|
|
- @Autowired
|
|
|
- private ExamStudentService examStudentService;
|
|
|
+ @Autowired
|
|
|
+ private ExamStudentService examStudentService;
|
|
|
+ @Autowired
|
|
|
+ private ExamRecordDataRepo examRecordDataRepo;
|
|
|
+ @Autowired
|
|
|
+ private ExamRecordDataCloudService examRecordDataCloudService;
|
|
|
|
|
|
/**
|
|
|
* 获取在线考试待考列表
|
|
@@ -35,15 +50,39 @@ public class ExamControlController extends ControllerSupport {
|
|
|
return examStudentService.queryOnlineExamList(user.getUserId(), ExamType.ONLINE);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 获取在线考试待考列表
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- @ApiOperation(value = "获取在线作业待考列表")
|
|
|
- @GetMapping("/queryHomeworkList")
|
|
|
- public List<OnHandExamInfo> queryHomeworkList() {
|
|
|
- User user = getAccessUser();
|
|
|
- return examStudentService.queryOnlineExamList(user.getUserId(),ExamType.ONLINE_HOMEWORK);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 获取考试同步完成百分比
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "获取在线考试待考列表")
|
|
|
+ @GetMapping("/queryExamList")
|
|
|
+ public long getExamSyncPercentage(@RequestParam("examId") Long examId) {
|
|
|
+ ExamSettingsCacheBean cachedExam =
|
|
|
+ ExamCacheTransferHelper.getCachedExam(examId, this.getAccessUser().getUserId());
|
|
|
+
|
|
|
+ Date now = new Date();
|
|
|
+ if (now.compareTo(cachedExam.getEndTime()) < 0) {
|
|
|
+ throw new StatusException("100001", "考试未结束,请考试结束后再试");
|
|
|
+ }
|
|
|
+
|
|
|
+ //已同步的考试记录数量
|
|
|
+ ExamRecordDataEntity query = new ExamRecordDataEntity();
|
|
|
+ query.setExamId(examId);
|
|
|
+ Example<ExamRecordDataEntity> queryExample = Example.of(query);
|
|
|
+ long syncedNum = examRecordDataRepo.count(queryExample);
|
|
|
+
|
|
|
+ //合计考试记录数量
|
|
|
+ GetExamRecordNumReq req = new GetExamRecordNumReq();
|
|
|
+ req.setExamId(examId);
|
|
|
+ GetExamRecordNumResp resp = examRecordDataCloudService.getExamRecordNum(req);
|
|
|
+ long totalNum = resp.getNum();
|
|
|
+
|
|
|
+ if (totalNum == 0) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ return (100 * syncedNum) / totalNum;
|
|
|
+ }
|
|
|
+
|
|
|
}
|