浏览代码

3.4.4 update-20250515 数据同步bug修复

xiaofei 1 月之前
父节点
当前提交
135b824f8e

+ 15 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/BasicExamStudentServiceImpl.java

@@ -37,6 +37,8 @@ import com.qmth.teachcloud.mark.service.MarkStudentService;
 import com.qmth.teachcloud.mark.service.MarkTaskService;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -59,6 +61,8 @@ import java.util.stream.Collectors;
 @Service
 public class BasicExamStudentServiceImpl extends ServiceImpl<BasicExamStudentMapper, BasicExamStudent> implements BasicExamStudentService {
 
+    private static final Logger log = LoggerFactory.getLogger(BasicExamStudentServiceImpl.class);
+
     @Resource
     private BasicRoleDataPermissionService basicRoleDataPermissionService;
     @Resource
@@ -602,6 +606,7 @@ public class BasicExamStudentServiceImpl extends ServiceImpl<BasicExamStudentMap
                 .eq(BasicExamStudent::getSchoolId, schoolId).eq(BasicExamStudent::getExamId, examId));
         Map<String, BasicExamStudent> courseIdStudentCodeMap = basicExamStudentList.stream().collect(Collectors.toMap(k -> k.getCourseId() + SystemConstant.HYPHEN + k.getStudentCode(), Function.identity(), (v1, v2) -> v1));
 
+        log.info("考生同步:考生表已存在考生。数量:{}", basicExamStudentList.size());
         BasicSchool basicSchool = commonCacheService.schoolCache(schoolId);
         BasicExamRule basicExamRule = basicExamRuleService.getBySchoolId(schoolId);
         if (basicExamRule == null) {
@@ -621,8 +626,8 @@ public class BasicExamStudentServiceImpl extends ServiceImpl<BasicExamStudentMap
 
         List<BasicExamStudent> basicExamStudents = new ArrayList<>();
 
+        log.info("考生同步:校验考生数据开始");
         StringJoiner errorMsg = new StringJoiner("\n");
-        AtomicInteger i = new AtomicInteger(0);
         for (TSyncDataStudent tSyncDataStudent : examStudentDataVoList) {
             try {
                 if (StringUtils.isBlank(tSyncDataStudent.getCourseCode())) {
@@ -782,13 +787,22 @@ public class BasicExamStudentServiceImpl extends ServiceImpl<BasicExamStudentMap
                 errorMsg.add(e.getMessage());
             }
         }
+        log.info("考生同步:校验考生数据结束");
+        log.info("考生同步:更新(插入)考生数据开始");
 
         this.saveOrUpdateBatch(basicExamStudents);
+        log.info("考生同步:更新(插入)考生数据结束");
+        log.info("考生同步:更新启用状态开始");
         // 更新删除考生启用状态为false
         this.baseMapper.updateEnableFalse(examId);
+        log.info("考生同步:更新启用状态结束");
+        log.info("考生同步:扫描考生数据开始");
         this.updateMarkData(examId, basicExamStudentList, null);
+        log.info("考生同步:扫描考生数据结束");
+        log.info("考生同步:创建课程管理数据开始");
         // 自动创建课程管理数据
         teachCourseService.batchCreateTeachCourse(schoolId, examId, basicExamStudentList);
+        log.info("考生同步:创建课程管理数据结束");
         Map<String, Object> map = new HashMap<>();
         map.put("count", basicExamStudents.size());
         map.put("errMsg", errorMsg.toString());

+ 13 - 0
teachcloud-data/src/main/java/com/qmth/teachcloud/data/service/DataService.java

@@ -2,9 +2,22 @@ package com.qmth.teachcloud.data.service;
 
 
 import com.qmth.distributed.print.business.bean.params.SysAdminSetParam;
+import com.qmth.teachcloud.data.dto.SyncDataResult;
 import com.qmth.teachcloud.data.entity.TSyncData;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.transaction.annotation.Transactional;
 
 public interface DataService {
     boolean testConnect(SysAdminSetParam sysAdminSetParam);
     void syncData(Long schoolId, Long examId, TSyncData syncData);
+
+    SyncDataResult syncOrg(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType);
+
+    SyncDataResult syncUser(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType);
+
+    SyncDataResult syncCourse(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType);
+
+    SyncDataResult syncStudent(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType);
+
+    SyncDataResult syncExamTask(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType);
 }

+ 33 - 12
teachcloud-data/src/main/java/com/qmth/teachcloud/data/service/impl/DataServiceImpl.java

@@ -3,11 +3,9 @@ package com.qmth.teachcloud.data.service.impl;
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.qmth.distributed.print.business.bean.params.SysAdminSetParam;
-import com.qmth.distributed.print.business.enums.RequiredFieldsEnum;
 import com.qmth.distributed.print.business.service.BasicExamStudentService;
 import com.qmth.distributed.print.business.service.BasicMessageService;
 import com.qmth.distributed.print.business.service.ExamTaskService;
-import com.qmth.teachcloud.common.bean.examRule.CodeNameEnableDisabledValue;
 import com.qmth.teachcloud.common.bean.sync.*;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicSchool;
@@ -150,7 +148,9 @@ public class DataServiceImpl implements DataService {
         }
     }
 
-    private SyncDataResult syncOrg(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType) {
+    @Transactional
+    @Override
+    public SyncDataResult syncOrg(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType) {
         long startTime = System.currentTimeMillis();
         List<OrgDataVo> dataVoList = dataUtil.listOrg(jdbcTemplate, DataType.A, datasourceType);
         log.info("查询到待同步机构数量:" + dataVoList.size());
@@ -169,7 +169,9 @@ public class DataServiceImpl implements DataService {
         return new SyncDataResult(i.get(), errorMsg.toString());
     }
 
-    private SyncDataResult syncUser(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType) {
+    @Transactional
+    @Override
+    public SyncDataResult syncUser(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType) {
         long startTime = System.currentTimeMillis();
         List<UserDataVo> dataVoList = dataUtil.listUser(jdbcTemplate, DataType.B, datasourceType);
         log.info("查询到待同步用户数量:" + dataVoList.size());
@@ -188,7 +190,9 @@ public class DataServiceImpl implements DataService {
         return new SyncDataResult(i.get(), errorMsg.toString());
     }
 
-    private SyncDataResult syncCourse(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType) {
+    @Transactional
+    @Override
+    public SyncDataResult syncCourse(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType) {
         long startTime = System.currentTimeMillis();
         List<CourseDataVo> dataVoList = dataUtil.listCourse(jdbcTemplate, DataType.C, datasourceType);
         log.info("查询到待同步课程数量:" + dataVoList.size());
@@ -207,14 +211,18 @@ public class DataServiceImpl implements DataService {
         return new SyncDataResult(i.get(), errorMsg.toString());
     }
 
-    private SyncDataResult syncStudent(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType) {
+    @Transactional
+    @Override
+    public SyncDataResult syncStudent(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType) {
         long startTime = System.currentTimeMillis();
+        log.info("考生同步:查询待同步考生开始");
         List<TSyncDataStudent> dataVoList = dataUtil.listExamStudent(jdbcTemplate, DataType.D, datasourceType);
-        log.info("查询到待同步考生数量:" + dataVoList.size());
+        log.info("考生同步:查询待同步考生结束。数量:{}", dataVoList.size());
         Map<String, Object> map = new HashMap<>();
-        int successCount = 0;
+        int successCount;
         String errMsg = null;
         try {
+            log.info("考生同步:处理考试时间开始");
             for (TSyncDataStudent tSyncDataStudent : dataVoList) {
                 tSyncDataStudent.setId(SystemConstant.getDbUuid());
                 tSyncDataStudent.setSchoolId(schoolId);
@@ -230,21 +238,34 @@ public class DataServiceImpl implements DataService {
                     }
                 }
             }
-//            tSyncDataStudentService.remove(new UpdateWrapper<TSyncDataStudent>().lambda().eq(TSyncDataStudent::getSchoolId, schoolId).eq(TSyncDataStudent::getExamId, examId));
-//            tSyncDataStudentService.saveBatch(dataVoList);
+            log.info("考生同步:处理考试时间结束");
+            log.info("考生同步:删除临时表数据开始");
+            tSyncDataStudentService.remove(new UpdateWrapper<TSyncDataStudent>().lambda().eq(TSyncDataStudent::getSchoolId, schoolId).eq(TSyncDataStudent::getExamId, examId));
+            log.info("考生同步:删除临时表数据结束");
+            log.info("考生同步:插入临时表数据开始");
+            tSyncDataStudentService.saveOrUpdateBatch(dataVoList);
+            log.info("考生同步:插入临时表数据开始");
+            log.info("考生同步:处理考生考入开始");
             map = basicExamStudentService.saveBasicExamStudentFormSync(schoolId, examId, dataVoList);
+            log.info("考生同步:处理考生考入结束");
         } catch (Exception e) {
             errMsg = e.getMessage();
+            log.info("考生同步:过程中报错:{}",errMsg);
+            e.printStackTrace();
         } finally {
+            log.info("考生同步:保存日志数据开始");
             successCount = map.containsKey("count") ? Integer.parseInt(map.get("count").toString()) : 0;
-            errMsg = errMsg == null && map.containsKey("errMsg") ? map.get("errMsg").toString() : null;
+            errMsg = errMsg == null && map.containsKey("errMsg") ? map.get("errMsg").toString() : errMsg;
             long endTime = System.currentTimeMillis();
             tSyncDataLogService.saveLog(schoolId, examId, DataType.D.name(), startTime, endTime, dataVoList.size(), successCount, errMsg);
+            log.info("考生同步:保存日志数据结束");
         }
         return new SyncDataResult(successCount, errMsg);
     }
 
-    private SyncDataResult syncExamTask(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType) {
+    @Transactional
+    @Override
+    public SyncDataResult syncExamTask(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType) {
         long startTime = System.currentTimeMillis();
         List<ExamTaskDataVo> dataVoList = dataUtil.listExamTask(jdbcTemplate, DataType.E, datasourceType);
         log.info("查询到待同步命题任务数量:" + dataVoList.size());