소스 검색

fixbug并发导入考生时数据同步失败导致数据完整性错误

xiatian 1 개월 전
부모
커밋
01123011f3

+ 1 - 2
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/controller/ExamStudentController.java

@@ -415,7 +415,6 @@ public class ExamStudentController extends ControllerSupport {
      */
     @ApiOperation(value = "新增考试学生", notes = "新增")
     @PostMapping()
-    @Transactional
     public ExamStudentDomain addExamStudent(@RequestBody ExamStudentDomain examStudent) {
         trim(examStudent);
         Long rootOrgId = getRootOrgId();
@@ -437,7 +436,6 @@ public class ExamStudentController extends ControllerSupport {
      */
     @ApiOperation(value = "更新考试学生", notes = "更新")
     @PutMapping()
-    @Transactional
     public ExamStudentDomain updateExamStudent(@RequestBody ExamStudentDomain examStudent) {
         trim(examStudent);
         Long rootOrgId = getRootOrgId();
@@ -517,6 +515,7 @@ public class ExamStudentController extends ControllerSupport {
         }
 
         ExamStudentInfo savedExamStudent = examStudentService.saveExamStudent(info);
+        examStudentService.syncExamStudent(savedExamStudent);
 
         ExamStudentDomain ret = new ExamStudentDomain();
         ret.setId(savedExamStudent.getId());

+ 2 - 0
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/ExamStudentService.java

@@ -28,4 +28,6 @@ public interface ExamStudentService {
      */
     void unbindExamStudentExamStage(Long examId);
 
+    void syncExamStudent(ExamStudentInfo saved);
+
 }

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

@@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.dao.DataIntegrityViolationException;
 import org.springframework.data.domain.Example;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.commons.util.DateUtil;
@@ -251,6 +252,7 @@ public class ExamStudentServiceImpl implements ExamStudentService {
      * saveExamStudent(cn.com.qmth.examcloud.core.examwork.service.bean.
      * ExamStudentInfo)
      */
+    @Transactional
     @Override
     public ExamStudentInfo saveExamStudent(ExamStudentInfo examStudentInfo) {
         String paperType = examStudentInfo.getPaperType();
@@ -433,7 +435,7 @@ public class ExamStudentServiceImpl implements ExamStudentService {
                 relation.setWeixinAnswerEnabled(true);
                 relation.setPassScoreLine(Constants.OE_PASSS_CORE_LINE);
                 relation.setGoodScoreLine(Constants.OE_GOOD_SCORE_LINE);
-                examCourseRelationRepo.save(relation);
+                examCourseRelationRepo.saveAndFlush(relation);
             } else {
                 relation.setCourseLevel(saved.getCourseLevel());
                 relation.setCourseName(saved.getCourseName());
@@ -460,6 +462,49 @@ public class ExamStudentServiceImpl implements ExamStudentService {
             throw new StatusException("500500", "保存考生相关信息异常!", e);
         }
 
+        ExamStudentInfo ret = new ExamStudentInfo();
+        ret.setId(saved.getId());
+
+        ret.setEnable(saved.getEnable());
+
+        ret.setCourseId(courseBean.getId());
+        ret.setCourseCode(courseBean.getCode());
+        ret.setCourseLevel(courseBean.getLevel());
+        ret.setCourseName(courseBean.getName());
+
+        ret.setExamId(exam.getId());
+        ret.setExamName(exam.getName());
+
+        ret.setRootOrgId(saved.getRootOrgId());
+        ret.setStudentName(studentInfo.getName());
+        ret.setIdentityNumber(saved.getIdentityNumber());
+        ret.setStudentCode(saved.getStudentCode());
+        ret.setOrgId(studentInfo.getOrgId());
+        ret.setOrgName(studentInfo.getOrgName());
+        ret.setOrgCode(studentInfo.getOrgCode());
+        ret.setStudentId(studentInfo.getId());
+
+        ret.setPaperType(saved.getPaperType());
+        ret.setRemark(saved.getRemark());
+        ret.setInfoCollector(saved.getInfoCollector());
+        ret.setExamSite(saved.getExamSite());
+
+        ret.setGrade(saved.getGrade());
+        ret.setSpecialtyName(saved.getSpecialtyName());
+        ret.setExamStageId(saved.getExamStageId());
+        ret.setExamStageOrder(saved.getExamStageOrder());
+
+        ret.setExt1(saved.getExt1());
+        ret.setExt2(saved.getExt2());
+        ret.setExt3(saved.getExt3());
+        ret.setExt4(saved.getExt4());
+        ret.setExt5(saved.getExt5());
+
+        return ret;
+    }
+
+    @Override
+    public void syncExamStudent(ExamStudentInfo saved) {
         // 同步操作
         SyncExamStudentReq req = new SyncExamStudentReq();
         req.setSyncType("update");
@@ -467,22 +512,22 @@ public class ExamStudentServiceImpl implements ExamStudentService {
 
         req.setEnable(saved.getEnable());
 
-        req.setCourseId(courseBean.getId());
-        req.setCourseCode(courseBean.getCode());
-        req.setCourseLevel(courseBean.getLevel());
-        req.setCourseName(courseBean.getName());
+        req.setCourseId(saved.getCourseId());
+        req.setCourseCode(saved.getCourseCode());
+        req.setCourseLevel(saved.getCourseLevel());
+        req.setCourseName(saved.getCourseName());
 
-        req.setExamId(exam.getId());
-        req.setExamName(exam.getName());
+        req.setExamId(saved.getExamId());
+        req.setExamName(saved.getExamName());
 
         req.setRootOrgId(saved.getRootOrgId());
-        req.setStudentId(studentInfo.getId());
-        req.setStudentName(studentInfo.getName());
+        req.setStudentId(saved.getStudentId());
+        req.setStudentName(saved.getStudentName());
         req.setIdentityNumber(saved.getIdentityNumber());
         req.setStudentCode(saved.getStudentCode());
-        req.setOrgId(studentInfo.getOrgId());
-        req.setOrgName(studentInfo.getOrgName());
-        req.setOrgCode(studentInfo.getOrgCode());
+        req.setOrgId(saved.getOrgId());
+        req.setOrgName(saved.getOrgName());
+        req.setOrgCode(saved.getOrgCode());
 
         req.setGrade(saved.getGrade());
         req.setSpecialtyName(saved.getSpecialtyName());
@@ -504,33 +549,6 @@ public class ExamStudentServiceImpl implements ExamStudentService {
                 req.getExamId(), req.getCourseCode(), req.getStudentId(), req.getId(), req.getStudentCode(),
                 req.getIdentityNumber());
         dataSyncCloudService.syncExamStudent(req);
-
-        ExamStudentInfo ret = new ExamStudentInfo();
-        ret.setId(saved.getId());
-
-        ret.setCourseId(courseBean.getId());
-        ret.setCourseCode(courseBean.getCode());
-        ret.setCourseLevel(courseBean.getLevel());
-        ret.setCourseName(courseBean.getName());
-
-        ret.setExamId(exam.getId());
-        ret.setExamName(exam.getName());
-
-        ret.setRootOrgId(saved.getRootOrgId());
-        ret.setStudentName(studentInfo.getName());
-        ret.setIdentityNumber(saved.getIdentityNumber());
-        ret.setStudentCode(saved.getStudentCode());
-        ret.setOrgId(studentInfo.getOrgId());
-        ret.setOrgName(studentInfo.getOrgName());
-        ret.setOrgCode(studentInfo.getOrgCode());
-        ret.setStudentId(studentInfo.getId());
-
-        ret.setPaperType(saved.getPaperType());
-        ret.setRemark(saved.getRemark());
-        ret.setInfoCollector(saved.getInfoCollector());
-        ret.setExamSite(saved.getExamSite());
-
-        return ret;
     }
 
     @Override