瀏覽代碼

update api

deason 3 年之前
父節點
當前提交
d30a414e7b

+ 1 - 130
examcloud-core-oe-admin-api-provider/src/main/java/cn/com/qmth/examcloud/core/oe/admin/api/controller/ExamScoreController.java

@@ -1,14 +1,6 @@
-/*
- * *************************************************
- * Copyright (c) 2018 QMTH. All Rights Reserved.
- * Created by Deason on 2018-08-31 09:28:03.
- * *************************************************
- */
-
 package cn.com.qmth.examcloud.core.oe.admin.api.controller;
 
 import cn.com.qmth.examcloud.api.commons.security.bean.User;
-import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.commons.util.JsonMapper;
 import cn.com.qmth.examcloud.core.oe.admin.base.utils.Check;
 import cn.com.qmth.examcloud.core.oe.admin.base.utils.excel.ExportUtils;
@@ -20,14 +12,7 @@ import cn.com.qmth.examcloud.core.oe.admin.service.bean.examscore.ObjectiveScore
 import cn.com.qmth.examcloud.core.oe.admin.service.util.AsyncExportConcurrentUtil;
 import cn.com.qmth.examcloud.reports.commons.bean.AdminOperateReport;
 import cn.com.qmth.examcloud.reports.commons.util.ReportsUtil;
-import cn.com.qmth.examcloud.support.cache.bean.ExamSettingsCacheBean;
-import cn.com.qmth.examcloud.support.enums.ExamRecordStatus;
-import cn.com.qmth.examcloud.support.examing.ExamBoss;
-import cn.com.qmth.examcloud.support.examing.ExamRecordData;
-import cn.com.qmth.examcloud.support.helper.ExamCacheTransferHelper;
 import cn.com.qmth.examcloud.support.helper.IdentityNumberHelper;
-import cn.com.qmth.examcloud.support.redis.RedisKeyHelper;
-import cn.com.qmth.examcloud.web.redis.RedisClient;
 import cn.com.qmth.examcloud.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.web.support.Naked;
 import io.swagger.annotations.Api;
@@ -56,9 +41,6 @@ public class ExamScoreController extends ControllerSupport {
     @Autowired
     private ExamScoreService examScoreService;
 
-    @Autowired
-    private RedisClient redisClient;
-
     @PostMapping("/statistic/list")
     @ApiOperation(value = "查询“成绩统计”列表(分页)")
     public Page<ExamScoreInfo> getExamAuditList(@RequestBody ExamScoreQuery query) {
@@ -94,118 +76,7 @@ public class ExamScoreController extends ControllerSupport {
     @ApiOperation(value = "根据examStudentId获取客观分信息")
     @GetMapping("/queryObjectiveScoreList")
     public List<ObjectiveScoreInfo> queryObjectiveScoreList(@RequestParam Long examStudentId) {
-        Check.isNull(examStudentId, "examStudentId 不能为空");
-
-        List<ObjectiveScoreInfo> resultList = examScoreService.queryObjectiveScoreList(examStudentId);
-
-
-        //如果有未处理完成的考试记录,需要将未处理的考试记录数据添加到列表中
-        String examBossKey = RedisKeyHelper.getBuilder().examBossKey(examStudentId);
-        ExamBoss examBoss = redisClient.get(examBossKey, ExamBoss.class);
-        if (null != examBoss) {
-            //未完全同步的考试记录id
-            List<Long> unSyncedExamRecordDataIds = examBoss.getExamRecordDataIds();
-            if (null != unSyncedExamRecordDataIds && !unSyncedExamRecordDataIds.isEmpty()) {
-                //正序排列
-                unSyncedExamRecordDataIds.sort(Long::compareTo);
-
-                //已考次数
-                Integer examUsedNum = 0;
-
-                for (Long examRecordDataId : unSyncedExamRecordDataIds) {
-                    ExamRecordData examRecordData =
-                            redisClient.get(RedisKeyHelper.getBuilder().examRecordDataKey(examRecordDataId),
-                                    ExamRecordData.class);
-                    if (null == examRecordData) {
-                        throw new StatusException("100001", "考试记录的缓存数据有误");
-                    }
-
-                    //考试中的数据不展示
-                    if (ExamRecordStatus.EXAM_ING == examRecordData.getExamRecordStatus()) {
-                        continue;
-                    }
-
-                    if (!resultList.isEmpty()) {
-                        examUsedNum = resultList.get(resultList.size() - 1).getExamOrder();
-                    }
-
-                    ObjectiveScoreInfo cachedObjectiveScoreInfo = getCachedObjectiveScoreInfo(examRecordData);
-                    cachedObjectiveScoreInfo.setExamOrder(
-                            getExamOrder(examRecordData.getExamId(), examRecordData.getStudentId(), examUsedNum));
-
-                    resultList.add(cachedObjectiveScoreInfo);
-                }
-            }
-        }
-
-        return resultList;
-    }
-
-    private ObjectiveScoreInfo getCachedObjectiveScoreInfo(final ExamRecordData examRecordData) {
-
-
-        ObjectiveScoreInfo objectiveScoreInfo = new ObjectiveScoreInfo();
-        objectiveScoreInfo.setExamRecordDataId(examRecordData.getId());
-        objectiveScoreInfo.setStartTime(examRecordData.getStartTime());
-        objectiveScoreInfo.setEndTime(examRecordData.getEndTime());
-
-        //如果考试没有结束,则只能返回部分数据
-        if (!isExamRecordEnded(examRecordData)) {
-            objectiveScoreInfo.setIsExamEnded(false);
-            return objectiveScoreInfo;
-        } else {
-            objectiveScoreInfo.setIsExamEnded(true);
-        }
-
-        if (examRecordData.getIsIllegality() == null || !examRecordData.getIsIllegality()) {
-            if ((null != examRecordData.getIsWarn() && !examRecordData.getIsWarn())
-                    || (null != examRecordData.getIsWarn() && examRecordData.getIsWarn()
-                    && null != examRecordData.getIsAudit() && examRecordData.getIsAudit())) {
-                objectiveScoreInfo.setIsAuditing(true);
-
-                //缓存中的分数是存储在临时考试记录表中的,所以需要从考试记录缓存中取
-                objectiveScoreInfo.setObjectiveScore(examRecordData.getObjectiveScore());
-            } else {
-                objectiveScoreInfo.setIsAuditing(false);
-            }
-
-            objectiveScoreInfo.setIsIllegality(false);
-        } else {
-            objectiveScoreInfo.setIsIllegality(true);
-        }
-
-        return objectiveScoreInfo;
-    }
-
-    private boolean isExamRecordEnded(ExamRecordData examRecordData) {
-        //如果考试记录状态为已处理,则直接返回true.
-        if (examRecordData.getExamRecordStatus() == ExamRecordStatus.EXAM_END ||
-                examRecordData.getExamRecordStatus() == ExamRecordStatus.EXAM_OVERDUE ||
-                examRecordData.getExamRecordStatus() == ExamRecordStatus.EXAM_INVALID) {
-            return true;
-        }
-        return false;
-    }
-
-    /**
-     * 计算考试次数
-     *
-     * @param examId      考试id
-     * @param studentId   学生id
-     * @param usedExamNum 已考次数
-     * @return
-     */
-    private Integer getExamOrder(Long examId, Long studentId, Integer usedExamNum) {
-        ExamSettingsCacheBean cachedExam = ExamCacheTransferHelper.getDefaultCachedExam(examId);
-        Integer canExamTimes = cachedExam.getExamTimes() == null ? 0 : cachedExam.getExamTimes().intValue();//可考次数
-
-        //超过可考次数,始终为可考次数+1
-        if (usedExamNum > canExamTimes) {
-            return canExamTimes;
-        }
-
-        return usedExamNum;
-
+        return examScoreService.queryObjectiveScoreList(examStudentId);
     }
 
 }

+ 4 - 1
examcloud-core-oe-admin-api-provider/src/main/java/cn/com/qmth/examcloud/core/oe/admin/api/controller/client/ExamProcessController.java

@@ -49,6 +49,9 @@ public class ExamProcessController extends ControllerSupport {
     @Autowired
     private ExamRecordDataRepo examRecordDataRepo;
 
+    @Autowired
+    private ExamScoreService examScoreService;
+
     @ApiOperation(value = "获取在线考试待考列表")
     @PostMapping("/queryExamList")
     public List<OnHandExamInfo> queryExamList() {
@@ -137,7 +140,7 @@ public class ExamProcessController extends ControllerSupport {
     @ApiOperation(value = "根据examStudentId获取客观分信息")
     @PostMapping("/queryObjectiveScoreList")
     public List<ObjectiveScoreInfo> queryObjectiveScoreList(@RequestParam Long examStudentId) {
-        return null;
+        return examScoreService.queryObjectiveScoreList(examStudentId);
     }
 
     @ApiOperation(value = "获取离线考试列表")

+ 119 - 1
examcloud-core-oe-admin-service/src/main/java/cn/com/qmth/examcloud/core/oe/admin/service/impl/ExamScoreServiceImpl.java

@@ -7,6 +7,7 @@
 
 package cn.com.qmth.examcloud.core.oe.admin.service.impl;
 
+import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.core.oe.admin.base.jpa.SpecUtils;
 import cn.com.qmth.examcloud.core.oe.admin.base.utils.Check;
 import cn.com.qmth.examcloud.core.oe.admin.base.utils.CommonUtil;
@@ -28,7 +29,11 @@ import cn.com.qmth.examcloud.support.cache.bean.CourseCacheBean;
 import cn.com.qmth.examcloud.support.cache.bean.ExamSettingsCacheBean;
 import cn.com.qmth.examcloud.support.cache.bean.OrgCacheBean;
 import cn.com.qmth.examcloud.support.enums.ExamProperties;
+import cn.com.qmth.examcloud.support.examing.ExamBoss;
+import cn.com.qmth.examcloud.support.examing.ExamRecordData;
 import cn.com.qmth.examcloud.support.helper.ExamCacheTransferHelper;
+import cn.com.qmth.examcloud.support.redis.RedisKeyHelper;
+import cn.com.qmth.examcloud.web.redis.RedisClient;
 import com.google.common.collect.Lists;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -73,6 +78,9 @@ public class ExamScoreServiceImpl implements ExamScoreService {
     @Autowired
     private JdbcTemplate jdbcTemplate;
 
+    @Autowired
+    private RedisClient redisClient;
+
     @Autowired
     private ExamStudentFinalScoreService examStudentFinalScoreService;
 
@@ -486,6 +494,8 @@ public class ExamScoreServiceImpl implements ExamScoreService {
 
     @Override
     public List<ObjectiveScoreInfo> queryObjectiveScoreList(Long examStudentId) {
+        Check.isNull(examStudentId, "examStudentId 不能为空");
+
         List<ExamRecordDataEntity> examRecordDataList = examRecordDataRepo.findByExamStudentId(examStudentId);
         //过滤已完成的考试记录(包括违纪的)
         examRecordDataList = examRecordDataList.stream().filter((o -> {
@@ -495,7 +505,7 @@ public class ExamScoreServiceImpl implements ExamScoreService {
                     o.getExamRecordStatus() == ExamRecordStatus.EXAM_AUTO_HAND_IN;
         })).collect(Collectors.toList());
 
-        List<ObjectiveScoreInfo> objectiveScoreInfoList = new ArrayList<ObjectiveScoreInfo>();
+        List<ObjectiveScoreInfo> objectiveScoreInfoList = new ArrayList<>();
         for (ExamRecordDataEntity examRecordDataEntity : examRecordDataList) {
             ObjectiveScoreInfo objectiveScoreInfo = new ObjectiveScoreInfo();
             objectiveScoreInfo.setExamRecordDataId(examRecordDataEntity.getId());
@@ -526,9 +536,117 @@ public class ExamScoreServiceImpl implements ExamScoreService {
             }
             objectiveScoreInfoList.add(objectiveScoreInfo);
         }
+
+        processObjectiveScoreList(examStudentId, objectiveScoreInfoList);
+
         return objectiveScoreInfoList;
     }
 
+    private void processObjectiveScoreList(Long examStudentId, List<ObjectiveScoreInfo> resultList) {
+        //如果有未处理完成的考试记录,需要将未处理的考试记录数据添加到列表中
+        String examBossKey = RedisKeyHelper.getBuilder().examBossKey(examStudentId);
+        ExamBoss examBoss = redisClient.get(examBossKey, ExamBoss.class);
+        if (null != examBoss) {
+            //未完全同步的考试记录id
+            List<Long> unSyncedExamRecordDataIds = examBoss.getExamRecordDataIds();
+            if (null != unSyncedExamRecordDataIds && !unSyncedExamRecordDataIds.isEmpty()) {
+                //正序排列
+                unSyncedExamRecordDataIds.sort(Long::compareTo);
+
+                //已考次数
+                Integer examUsedNum = 0;
+
+                for (Long examRecordDataId : unSyncedExamRecordDataIds) {
+                    ExamRecordData examRecordData =
+                            redisClient.get(RedisKeyHelper.getBuilder().examRecordDataKey(examRecordDataId),
+                                    ExamRecordData.class);
+                    if (null == examRecordData) {
+                        throw new StatusException("100001", "考试记录的缓存数据有误");
+                    }
+
+                    //考试中的数据不展示
+                    if (cn.com.qmth.examcloud.support.enums.ExamRecordStatus.EXAM_ING == examRecordData.getExamRecordStatus()) {
+                        continue;
+                    }
+
+                    if (!resultList.isEmpty()) {
+                        examUsedNum = resultList.get(resultList.size() - 1).getExamOrder();
+                    }
+
+                    ObjectiveScoreInfo cachedObjectiveScoreInfo = getCachedObjectiveScoreInfo(examRecordData);
+                    cachedObjectiveScoreInfo.setExamOrder(
+                            getExamOrder(examRecordData.getExamId(), examRecordData.getStudentId(), examUsedNum));
+
+                    resultList.add(cachedObjectiveScoreInfo);
+                }
+            }
+        }
+    }
+
+    private ObjectiveScoreInfo getCachedObjectiveScoreInfo(final ExamRecordData examRecordData) {
+        ObjectiveScoreInfo objectiveScoreInfo = new ObjectiveScoreInfo();
+        objectiveScoreInfo.setExamRecordDataId(examRecordData.getId());
+        objectiveScoreInfo.setStartTime(examRecordData.getStartTime());
+        objectiveScoreInfo.setEndTime(examRecordData.getEndTime());
+
+        //如果考试没有结束,则只能返回部分数据
+        if (!isExamRecordEnded(examRecordData)) {
+            objectiveScoreInfo.setIsExamEnded(false);
+            return objectiveScoreInfo;
+        } else {
+            objectiveScoreInfo.setIsExamEnded(true);
+        }
+
+        if (examRecordData.getIsIllegality() == null || !examRecordData.getIsIllegality()) {
+            if ((null != examRecordData.getIsWarn() && !examRecordData.getIsWarn())
+                    || (null != examRecordData.getIsWarn() && examRecordData.getIsWarn()
+                    && null != examRecordData.getIsAudit() && examRecordData.getIsAudit())) {
+                objectiveScoreInfo.setIsAuditing(true);
+
+                //缓存中的分数是存储在临时考试记录表中的,所以需要从考试记录缓存中取
+                objectiveScoreInfo.setObjectiveScore(examRecordData.getObjectiveScore());
+            } else {
+                objectiveScoreInfo.setIsAuditing(false);
+            }
+
+            objectiveScoreInfo.setIsIllegality(false);
+        } else {
+            objectiveScoreInfo.setIsIllegality(true);
+        }
+
+        return objectiveScoreInfo;
+    }
+
+    /**
+     * 计算考试次数
+     *
+     * @param examId      考试id
+     * @param studentId   学生id
+     * @param usedExamNum 已考次数
+     * @return
+     */
+    private Integer getExamOrder(Long examId, Long studentId, Integer usedExamNum) {
+        ExamSettingsCacheBean cachedExam = ExamCacheTransferHelper.getDefaultCachedExam(examId);
+        Integer canExamTimes = cachedExam.getExamTimes() == null ? 0 : cachedExam.getExamTimes().intValue();//可考次数
+
+        //超过可考次数,始终为可考次数+1
+        if (usedExamNum > canExamTimes) {
+            return canExamTimes;
+        }
+
+        return usedExamNum;
+    }
+
+    private boolean isExamRecordEnded(ExamRecordData examRecordData) {
+        //如果考试记录状态为已处理,则直接返回true.
+        if (examRecordData.getExamRecordStatus() == cn.com.qmth.examcloud.support.enums.ExamRecordStatus.EXAM_END ||
+                examRecordData.getExamRecordStatus() == cn.com.qmth.examcloud.support.enums.ExamRecordStatus.EXAM_OVERDUE ||
+                examRecordData.getExamRecordStatus() == cn.com.qmth.examcloud.support.enums.ExamRecordStatus.EXAM_INVALID) {
+            return true;
+        }
+        return false;
+    }
+
     private boolean isExamRecordEnded(ExamRecordDataEntity examRecordData) {
         //如果考试记录状态为已处理,则直接返回true.
         if (examRecordData.getExamRecordStatus() == ExamRecordStatus.EXAM_END ||