deason 2 yıl önce
ebeveyn
işleme
cc7bde9c41

+ 52 - 56
examcloud-core-oe-admin-api-provider/src/main/java/cn/com/qmth/examcloud/core/oe/admin/api/provider/SyncExamDataCloudServiceProvider.java

@@ -23,7 +23,6 @@ import cn.com.qmth.examcloud.web.redis.RedisClient;
 import cn.com.qmth.examcloud.web.support.ControllerSupport;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
-
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.json.JSONArray;
@@ -122,11 +121,10 @@ public class SyncExamDataCloudServiceProvider extends ControllerSupport implemen
 
     @Autowired
     private RedisClient redisClient;
-    
+
     @Autowired
     private ExamCaptureCameraInfoRepo examCaptureCameraInfoRepo;
-    
-    
+
 
     /**
      * 同步考试记录数据
@@ -176,9 +174,9 @@ public class SyncExamDataCloudServiceProvider extends ControllerSupport implemen
         if (hasWarn != null && hasWarn) {
             examAuditService.saveHeaderWarnAudit(realExamRecordDataId);
         }
-        
+
         //切屏次数超限
-        if (transitionExamRecordData.getExceedMaxSwitchScreenCount()  != null && transitionExamRecordData.getExceedMaxSwitchScreenCount()) {
+        if (transitionExamRecordData.getExceedMaxSwitchScreenCount() != null && transitionExamRecordData.getExceedMaxSwitchScreenCount()) {
             examAuditService.saveExceedMaxSwitchScreenCount(realExamRecordDataId);
         }
 
@@ -368,8 +366,6 @@ public class SyncExamDataCloudServiceProvider extends ControllerSupport implemen
     }
 
     private Long syncExamRecordData(ExamRecordDataBean examRecordData) {
-
-
         ExamRecordDataEntity examRecordDataEntity = copyExamRecordDataEntityFrom(examRecordData);
 
         ExamRecordDataEntity result = examRecordDataRepo.saveAndFlush(examRecordDataEntity);
@@ -410,14 +406,13 @@ public class SyncExamDataCloudServiceProvider extends ControllerSupport implemen
         result.setRootOrgId(examRecordData.getRootOrgId());
         result.setBasePaperId(examRecordData.getBasePaperId());
 
-        //        result.setPaperStructId(examRecordData.getPaperStructId());
+        // result.setPaperStructId(examRecordData.getPaperStructId());
         result.setPaperType(examRecordData.getPaperType());
 
         CourseCacheBean course = CacheHelper.getCourse(examRecordData.getCourseId());
         result.setCourseLevel(course.getLevel());
 
-
-        result.setStartTime(examRecordData.getStartTime());
+        result.setStartTime(examRecordData.getStartTime() != null ? examRecordData.getStartTime() : examRecordData.getEnterExamTime());
         result.setEndTime(examRecordData.getEndTime());
         result.setCleanTime(examRecordData.getCleanTime());
         result.setIsWarn(examRecordData.getWarn());
@@ -448,8 +443,8 @@ public class SyncExamDataCloudServiceProvider extends ControllerSupport implemen
         result.setEnterExamTime(examRecordData.getEnterExamTime());
         result.setContinuedTime(examRecordData.getContinuedTime());
         result.setSwitchScreenCount(examRecordData.getSwitchScreenCount());
-        if(result.getSwitchScreenCount()==null) {
-        	result.setSwitchScreenCount(0);
+        if (result.getSwitchScreenCount() == null) {
+            result.setSwitchScreenCount(0);
         }
 
         return result;
@@ -741,55 +736,56 @@ public class SyncExamDataCloudServiceProvider extends ControllerSupport implemen
             examCaptureRepo.saveAndFlush(examCaptureEntity);
         }
     }
+
     private void saveExamCaptureCameraInfo(ExamCaptureEntity examCaptureEntity) {
-        if(StringUtils.isEmpty(examCaptureEntity.getCameraInfos())) {
-        	return;
+        if (StringUtils.isEmpty(examCaptureEntity.getCameraInfos())) {
+            return;
         }
         try {
-        	JSONArray jsonArray = new JSONArray(examCaptureEntity.getCameraInfos());
+            JSONArray jsonArray = new JSONArray(examCaptureEntity.getCameraInfos());
             for (int i = 0; i < jsonArray.length(); i++) {
-        		JSONObject jsonObject = (JSONObject) jsonArray.get(i);
-        		ExamCaptureCameraInfoEntity ci=new ExamCaptureCameraInfoEntity();
-        		ci.setExamRecordDataId(examCaptureEntity.getExamRecordDataId());
-        		ci.setDetail(getVal(jsonObject, "detail",500));
-        		ci.setName(getVal(jsonObject, "name",100));
-        		ci.setPid(getVal(jsonObject, "pid",100));
-        		ci.setVid(getVal(jsonObject, "vid",100));
-        		if (jsonObject.isNull("pid") || StringUtils.isBlank(jsonObject.getString("pid"))
-        				||jsonObject.isNull("vid") || StringUtils.isBlank(jsonObject.getString("vid"))) {
-        			ci.setVirtualCamera(true);
-        		}else {
-        			ci.setVirtualCamera(false);
-        		}
-        		List<ExamCaptureCameraInfoEntity> olds=examCaptureCameraInfoRepo.findByExamRecordDataIdAndPidAndVidAndName(examCaptureEntity.getExamRecordDataId(),ci.getPid(),ci.getVid(),ci.getName());
-        		if(CollectionUtils.isEmpty(olds)) {
-        			examCaptureCameraInfoRepo.saveAndFlush(ci);
-        		}else {
-        			ExamCaptureCameraInfoEntity old=olds.get(0);
-        			if(!StringUtils.equals(old.getDetail(), ci.getDetail())) {
-	        			old.setDetail(ci.getDetail());
-	        			examCaptureCameraInfoRepo.saveAndFlush(old);
-        			}
-        		}
+                JSONObject jsonObject = (JSONObject) jsonArray.get(i);
+                ExamCaptureCameraInfoEntity ci = new ExamCaptureCameraInfoEntity();
+                ci.setExamRecordDataId(examCaptureEntity.getExamRecordDataId());
+                ci.setDetail(getVal(jsonObject, "detail", 500));
+                ci.setName(getVal(jsonObject, "name", 100));
+                ci.setPid(getVal(jsonObject, "pid", 100));
+                ci.setVid(getVal(jsonObject, "vid", 100));
+                if (jsonObject.isNull("pid") || StringUtils.isBlank(jsonObject.getString("pid"))
+                        || jsonObject.isNull("vid") || StringUtils.isBlank(jsonObject.getString("vid"))) {
+                    ci.setVirtualCamera(true);
+                } else {
+                    ci.setVirtualCamera(false);
+                }
+                List<ExamCaptureCameraInfoEntity> olds = examCaptureCameraInfoRepo.findByExamRecordDataIdAndPidAndVidAndName(examCaptureEntity.getExamRecordDataId(), ci.getPid(), ci.getVid(), ci.getName());
+                if (CollectionUtils.isEmpty(olds)) {
+                    examCaptureCameraInfoRepo.saveAndFlush(ci);
+                } else {
+                    ExamCaptureCameraInfoEntity old = olds.get(0);
+                    if (!StringUtils.equals(old.getDetail(), ci.getDetail())) {
+                        old.setDetail(ci.getDetail());
+                        examCaptureCameraInfoRepo.saveAndFlush(old);
+                    }
+                }
             }
         } catch (Exception e) {
-        	LOG.error("保存摄像信息失败:"+examCaptureEntity.getExamRecordDataId()+" "+examCaptureEntity.getCameraInfos(), e);
-        }
-    }
-    
-    private String getVal(JSONObject jsonObject,String name,int length) throws JSONException {
-    	if (jsonObject.isNull(name) || StringUtils.isBlank(jsonObject.getString(name))) {
-    		return "";
-    	}else {
-    		String content=jsonObject.getString(name);
-    		if(content.length()>length) {
-    			return content.substring(0, length);
-    		}else {
-    			return content;
-    		}
-    	}
-    }
-    
+            LOG.error("保存摄像信息失败:" + examCaptureEntity.getExamRecordDataId() + " " + examCaptureEntity.getCameraInfos(), e);
+        }
+    }
+
+    private String getVal(JSONObject jsonObject, String name, int length) throws JSONException {
+        if (jsonObject.isNull(name) || StringUtils.isBlank(jsonObject.getString(name))) {
+            return "";
+        } else {
+            String content = jsonObject.getString(name);
+            if (content.length() > length) {
+                return content.substring(0, length);
+            } else {
+                return content;
+            }
+        }
+    }
+
     private ExamCaptureEntity copyExamCaptureFrom(ExamCaptureBean examCapture, Long examRecordDataId) {
         ExamCaptureEntity entity = new ExamCaptureEntity();
         entity.setExamRecordDataId(examRecordDataId);

+ 1 - 1
examcloud-core-oe-admin-base/pom.xml

@@ -55,7 +55,7 @@
         </dependency>
         <dependency>
             <groupId>cn.com.qmth.examcloud.rpc</groupId>
-            <artifactId>examcloud-core-oe-admin-api-client</artifactId>
+            <artifactId>examcloud-core-oe-admin-api</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>

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

@@ -177,6 +177,7 @@ public class ExamRecordQuestionsServiceImpl implements ExamRecordQuestionsServic
             examRecordQuestions = examRecordQuestionsRepo.findByExamRecordDataId(examRecordDataId);
 
             //将考试作答记录id保存至examRecordData表中,目的:纠正历史数据
+            examRecordData.setExamRecordQuestionsId(examRecordQuestions.getId());
             examRecordDataRepo.updateExamRecordDataQuestionIdById(examRecordQuestions.getId(), examRecordData.getId());
         }
 

+ 47 - 64
examcloud-core-oe-admin-service/src/main/java/cn/com/qmth/examcloud/core/oe/admin/service/impl/ExamStudentFinalScoreServiceImpl.java

@@ -1,6 +1,6 @@
 package cn.com.qmth.examcloud.core.oe.admin.service.impl;
 
-import cn.com.qmth.examcloud.commons.util.JsonUtil;
+import cn.com.qmth.examcloud.api.commons.enums.ExamType;
 import cn.com.qmth.examcloud.core.oe.admin.dao.ExamRecordDataRepo;
 import cn.com.qmth.examcloud.core.oe.admin.dao.ExamScoreRepo;
 import cn.com.qmth.examcloud.core.oe.admin.dao.ExamStudentFinalScoreRepo;
@@ -13,6 +13,7 @@ import cn.com.qmth.examcloud.core.oe.admin.dao.enums.MarkingType;
 import cn.com.qmth.examcloud.core.oe.admin.service.ExamStudentFinalScoreService;
 import cn.com.qmth.examcloud.support.enums.ExamProperties;
 import cn.com.qmth.examcloud.support.helper.ExamCacheTransferHelper;
+import org.apache.commons.collections4.CollectionUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -31,6 +32,8 @@ import java.util.stream.Collectors;
 @Service("examStudentFinalScoreService")
 public class ExamStudentFinalScoreServiceImpl implements ExamStudentFinalScoreService {
 
+    private static final Logger LOG = LoggerFactory.getLogger(ExamStudentFinalScoreServiceImpl.class);
+
     @Autowired
     private ExamRecordDataRepo examRecordDataRepo;
 
@@ -43,45 +46,35 @@ public class ExamStudentFinalScoreServiceImpl implements ExamStudentFinalScoreSe
     @Autowired
     private ExamStudentFinalScoreRepo examStudentFinalScoreRepo;
 
-    private static final Logger LOG = LoggerFactory.getLogger(ExamStudentFinalScoreServiceImpl.class);
-
     @Override
     public ExamStudentFinalScoreEntity calcAndSaveFinalScore(Long examStudentId) {
         ExamStudentEntity examStudent = examStudentRepo.findByExamStudentId(examStudentId);
-        String markingType = ExamCacheTransferHelper.
-                getDefaultCachedExamProperty(examStudent.getExamId(), ExamProperties.MARKING_TYPE.name()).getValue();
+
+        String markingType = ExamCacheTransferHelper.getDefaultCachedExamProperty(examStudent.getExamId(),
+                ExamProperties.MARKING_TYPE.name()).getValue();
         String examType = ExamCacheTransferHelper.getDefaultCachedExam(examStudent.getExamId()).getExamType();
-        List<ExamRecordDataEntity> effectiveExamRecordDataList = examRecordDataRepo.findEffectiveDataByExamStudentIdList(Arrays.asList(examStudentId));
 
-        if (LOG.isDebugEnabled()) {
-            if (null != effectiveExamRecordDataList) {
-                LOG.debug("[TEMP-DEBUG1]-effectiveExamRecordDataList: " + JsonUtil.toJson(effectiveExamRecordDataList));
-            } else {
-                LOG.debug("[TEMP-DEBUG1]-考生id:" + examStudentId + ",找不到任何考试记录");
-            }
+        List<ExamRecordDataEntity> effectiveExamRecordDataList = examRecordDataRepo.findEffectiveDataByExamStudentIdList(Arrays.asList(examStudentId));
+        if (CollectionUtils.isEmpty(effectiveExamRecordDataList)) {
+            LOG.warn("calcAndSaveFinalScore examRecordDataList is empty, examStudentId = {}", examStudentId);
+            return null;
         }
 
-
         //得到最终考试结果
         ExamScoreEntity finalEffectiveExamScore = getFinalEffectiveExamScore(effectiveExamRecordDataList, examType, markingType);
-
-        if (LOG.isDebugEnabled()) {
-            if (null != finalEffectiveExamScore) {
-                LOG.debug("[TEMP-DEBUG2]-finalEffectiveExamScore: " + JsonUtil.toJson(finalEffectiveExamScore));
-            } else {
-                LOG.debug("[TEMP-DEBUG2]-考生id:" + examStudentId + ",找不到最终考试记录");
-            }
+        if (finalEffectiveExamScore == null) {
+            LOG.warn("calcAndSaveFinalScore finalExamScore is null, examStudentId = {}", examStudentId);
+            return null;
         }
 
         //保存最终考试结果
-        return saveExamStudentFinalScore(examStudent.getExamStudentId(), finalEffectiveExamScore);
+        return saveExamStudentFinalScore(examStudentId, finalEffectiveExamScore);
     }
 
 
     @Override
     public ExamStudentFinalScoreEntity getFinalEffectiveExamScore(Long examStudentId) {
         ExamStudentFinalScoreEntity finalExamScore = examStudentFinalScoreRepo.findByExamStudentId(examStudentId);
-
         if (null != finalExamScore) {
             return finalExamScore;
         }
@@ -90,73 +83,63 @@ public class ExamStudentFinalScoreServiceImpl implements ExamStudentFinalScoreSe
         return this.calcAndSaveFinalScore(examStudentId);
     }
 
-    private ExamStudentFinalScoreEntity saveExamStudentFinalScore(Long examStudentId, final ExamScoreEntity finalEffectiveExamScore) {
-        ExamStudentFinalScoreEntity finalScoreEntity
-                = examStudentFinalScoreRepo.findByExamStudentId(examStudentId);
+    private ExamStudentFinalScoreEntity saveExamStudentFinalScore(Long examStudentId, ExamScoreEntity finalEffectiveExamScore) {
+        if (finalEffectiveExamScore == null) {
+            return null;
+        }
+
+        ExamStudentFinalScoreEntity finalScoreEntity = examStudentFinalScoreRepo.findByExamStudentId(examStudentId);
         if (finalScoreEntity == null) {
             finalScoreEntity = new ExamStudentFinalScoreEntity();
         }
 
-        if (null != finalEffectiveExamScore) {
-            finalScoreEntity.setExamRecordDataId(finalEffectiveExamScore.getExamRecordDataId());
-            finalScoreEntity.setExamStudentId(examStudentId);
-            finalScoreEntity.setObjectiveAccuracy(finalEffectiveExamScore.getObjectiveAccuracy());
-            finalScoreEntity.setObjectiveScore(finalEffectiveExamScore.getObjectiveScore());
-            finalScoreEntity.setSubjectiveScore(finalEffectiveExamScore.getSubjectiveScore());
-            finalScoreEntity.setSuccPercent(finalEffectiveExamScore.getSuccPercent());
-            finalScoreEntity.setTotalScore(finalEffectiveExamScore.getTotalScore());
-
-            return examStudentFinalScoreRepo.save(finalScoreEntity);
-        }
-
-        return null;
+        finalScoreEntity.setExamRecordDataId(finalEffectiveExamScore.getExamRecordDataId());
+        finalScoreEntity.setExamStudentId(examStudentId);
+        finalScoreEntity.setObjectiveAccuracy(finalEffectiveExamScore.getObjectiveAccuracy());
+        finalScoreEntity.setObjectiveScore(finalEffectiveExamScore.getObjectiveScore());
+        finalScoreEntity.setSubjectiveScore(finalEffectiveExamScore.getSubjectiveScore());
+        finalScoreEntity.setSuccPercent(finalEffectiveExamScore.getSuccPercent());
+        finalScoreEntity.setTotalScore(finalEffectiveExamScore.getTotalScore());
 
+        return examStudentFinalScoreRepo.save(finalScoreEntity);
     }
 
-
     /**
      * 计算得出最终有效成绩
      */
     private ExamScoreEntity getFinalEffectiveExamScore(List<ExamRecordDataEntity> effectiveExamRecordList, String examType, String markingType) {
         if (effectiveExamRecordList == null || effectiveExamRecordList.size() == 0) {
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("[TEMP-DEBUG1]-effectiveExamRecordList-考生找不到满足条件考试记录");
-            }
             return null;
         }
 
         //取出有效记录的id
-        List<Long> examRecordDataIds =
-                effectiveExamRecordList.stream().map(ExamRecordDataEntity::getId).collect(Collectors.toList());
+        List<Long> examRecordDataIds = effectiveExamRecordList.stream().map(ExamRecordDataEntity::getId).collect(Collectors.toList());
 
         List<ExamScoreEntity> effectiveExamScoreList = examScoreRepo.findByExamRecordDataIdIn(examRecordDataIds);
         if (effectiveExamScoreList == null || effectiveExamScoreList.size() == 0) {
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("[TEMP-DEBUG5]-effectiveExamScoreList-考生找不到满足条件考试分数记录");
-            }
+            LOG.warn("effectiveExamScoreList is empty, examRecordDataIds = {}", examRecordDataIds);
             return null;
         }
 
         //离线考试
-        if ("OFFLINE".equals(examType)) {
+        if (ExamType.OFFLINE.name().equals(examType)) {
             return effectiveExamScoreList.get(0);
-        } else {
-            if (markingType.equals(MarkingType.ALL.name()) || markingType.equals(MarkingType.OBJECT_SCORE_MAX.name())) {
-                //全部评阅规则或客观分最高规则:取总分最高
-                List<ExamScoreEntity> examScores = effectiveExamScoreList
-                        .stream()
-                        .sorted((o1, o2) -> o2.getTotalScore().compareTo(o1.getTotalScore()))
-                        .collect(Collectors.toList());
-                return examScores.get(0);
-            } else if (markingType.equals(MarkingType.LAST_SUBMIT.name())) {
-                //最后一次提交规则:取最后一次的成绩
-                List<ExamScoreEntity> examScores = effectiveExamScoreList
-                        .stream()
-                        .sorted((o1, o2) -> o2.getId().compareTo(o1.getId()))
-                        .collect(Collectors.toList());
-                return examScores.get(0);
-            }
         }
+
+        if (markingType.equals(MarkingType.ALL.name()) || markingType.equals(MarkingType.OBJECT_SCORE_MAX.name())) {
+            //全部评阅规则或客观分最高规则:取总分最高
+            List<ExamScoreEntity> examScores = effectiveExamScoreList.stream()
+                    .sorted((o1, o2) -> o2.getTotalScore().compareTo(o1.getTotalScore()))
+                    .collect(Collectors.toList());
+            return examScores.get(0);
+        } else if (markingType.equals(MarkingType.LAST_SUBMIT.name())) {
+            //最后一次提交规则:取最后一次的成绩
+            List<ExamScoreEntity> examScores = effectiveExamScoreList.stream()
+                    .sorted((o1, o2) -> o2.getId().compareTo(o1.getId()))
+                    .collect(Collectors.toList());
+            return examScores.get(0);
+        }
+
         return null;
     }