瀏覽代碼

update saveExamStudent logs

deason 1 年之前
父節點
當前提交
2741b84169

+ 46 - 26
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/impl/ExamStudentServiceImpl.java

@@ -30,7 +30,10 @@ import cn.com.qmth.examcloud.task.api.request.SyncExamStudentReq;
 import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DataIntegrityViolationException;
 import org.springframework.data.domain.Example;
 import org.springframework.stereotype.Service;
 
@@ -44,6 +47,8 @@ import java.util.stream.Collectors;
 @Service
 public class ExamStudentServiceImpl implements ExamStudentService {
 
+    private static final Logger log = LoggerFactory.getLogger(ExamStudentServiceImpl.class);
+
     @Autowired
     ExamStudentRepo examStudentRepo;
 
@@ -378,33 +383,46 @@ public class ExamStudentServiceImpl implements ExamStudentService {
             examStudent.setEnable(enable);
         }
 
-        ExamStudentEntity saved = examStudentRepo.save(examStudent);
-
-        ExamCourseRelationEntity relation = examCourseRelationRepo.findByExamIdAndCourseCode(saved.getExamId(), courseBean.getCode());
-        if (relation == null) {
-            relation = new ExamCourseRelationEntity();
-            relation.setExamId(saved.getExamId());
-            relation.setCourseId(saved.getCourseId());
-            relation.setCourseLevel(saved.getCourseLevel());
-            relation.setCourseCode(courseBean.getCode());
-            relation.setCourseName(saved.getCourseName());
-            relation.setCourseEnable(courseBean.getEnable());
-            relation.setWeixinAnswerEnabled(true);
-            relation.setPassScoreLine(Constants.OE_PASSS_CORE_LINE);
-            relation.setGoodScoreLine(Constants.OE_GOOD_SCORE_LINE);
-            examCourseRelationRepo.save(relation);
-        } else {
-            relation.setCourseLevel(saved.getCourseLevel());
-            relation.setCourseName(saved.getCourseName());
-            relation.setCourseEnable(courseBean.getEnable());
-            examCourseRelationRepo.save(relation);
-        }
+        ExamStudentEntity saved;
+        try {
+            saved = examStudentRepo.save(examStudent);
+
+            ExamCourseRelationEntity relation = examCourseRelationRepo.findByExamIdAndCourseCode(saved.getExamId(), courseBean.getCode());
+            if (relation == null) {
+                relation = new ExamCourseRelationEntity();
+                relation.setExamId(saved.getExamId());
+                relation.setCourseId(saved.getCourseId());
+                relation.setCourseLevel(saved.getCourseLevel());
+                relation.setCourseCode(courseBean.getCode());
+                relation.setCourseName(saved.getCourseName());
+                relation.setCourseEnable(courseBean.getEnable());
+                relation.setWeixinAnswerEnabled(true);
+                relation.setPassScoreLine(Constants.OE_PASSS_CORE_LINE);
+                relation.setGoodScoreLine(Constants.OE_GOOD_SCORE_LINE);
+                examCourseRelationRepo.save(relation);
+            } else {
+                relation.setCourseLevel(saved.getCourseLevel());
+                relation.setCourseName(saved.getCourseName());
+                relation.setCourseEnable(courseBean.getEnable());
+                examCourseRelationRepo.save(relation);
+            }
 
-        ExamPaperTypeRelationEntity pt = new ExamPaperTypeRelationEntity();
-        pt.setCourseId(saved.getCourseId());
-        pt.setExamId(saved.getExamId());
-        pt.setPaperType(saved.getPaperType());
-        examPaperTypeRelationRepo.save(pt);
+            ExamPaperTypeRelationEntity pt = new ExamPaperTypeRelationEntity();
+            pt.setCourseId(saved.getCourseId());
+            pt.setExamId(saved.getExamId());
+            pt.setPaperType(saved.getPaperType());
+            examPaperTypeRelationRepo.save(pt);
+        } catch (DataIntegrityViolationException ee) {
+            // 存在数据库唯一约束等异常
+            log.error("[saveExamStudent] examId:{} courseCode:{} studentId:{} examStudentId:{} studentCode:{} identityNumber:{} err:{}",
+                    examStudent.getExamId(), examStudent.getCourseCode(), examStudent.getStudentId(), examStudent.getId(),
+                    examStudent.getStudentCode(), examStudent.getIdentityNumber(), ee.getMessage());
+            throw new StatusException("5005XX", "保存考生相关信息异常,数据唯一性错误!");
+        } catch (Exception e) {
+            log.error("[saveExamStudent] studentCode:{} identityNumber:{} err:{}",
+                    examStudent.getStudentCode(), examStudent.getIdentityNumber(), e.getMessage());
+            throw new StatusException("500500", "保存考生相关信息异常!", e);
+        }
 
         // 同步操作
         SyncExamStudentReq req = new SyncExamStudentReq();
@@ -445,6 +463,8 @@ public class ExamStudentServiceImpl implements ExamStudentService {
         req.setExt4(saved.getExt4());
         req.setExt5(saved.getExt5());
 
+        log.warn("[syncExamStudent] examId:{} courseCode:{} studentId:{} examStudentId:{} studentCode:{} identityNumber:{}",
+                req.getExamId(), req.getCourseCode(), req.getStudentId(), req.getId(), req.getStudentCode(), req.getIdentityNumber());
         dataSyncCloudService.syncExamStudent(req);
 
         ExamStudentInfo ret = new ExamStudentInfo();