Browse Source

Merge remote-tracking branch 'origin/dev_v3.3.1' into dev_v3.3.1

caozixuan 1 year ago
parent
commit
fa5fc3863e

+ 9 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/TCFinalScoreService.java

@@ -106,4 +106,13 @@ public interface TCFinalScoreService extends IService<TCFinalScore> {
      * @return
      */
     public List<TCFinalScore> queryDbSourceList(Long examId, String courseCode, String paperNumber);
+
+    /**
+     * 获取期末考试同步锁
+     *
+     * @param examId
+     * @param courseCode
+     * @param paperNumber
+     */
+    public void getFinalScoreSyncLock(Long examId, String courseCode, String paperNumber);
 }

+ 18 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TCFinalScoreServiceImpl.java

@@ -15,12 +15,12 @@ import com.qmth.distributed.print.business.mapper.TCFinalScoreMapper;
 import com.qmth.distributed.print.business.service.PrintCommonService;
 import com.qmth.distributed.print.business.service.TCFinalScoreService;
 import com.qmth.distributed.print.business.service.TRBasicInfoService;
-import com.qmth.distributed.print.business.service.TRExamStudentService;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.FieldUniqueEnum;
 import com.qmth.teachcloud.common.util.JacksonUtil;
+import com.qmth.teachcloud.common.util.RedisUtil;
 import com.qmth.teachcloud.common.util.ResultUtil;
 import com.qmth.teachcloud.common.util.ServletUtil;
 import com.qmth.teachcloud.mark.bean.archivescore.MarkStudentScoreVo;
@@ -70,7 +70,7 @@ public class TCFinalScoreServiceImpl extends ServiceImpl<TCFinalScoreMapper, TCF
     TRBasicInfoService trBasicInfoService;
 
     @Resource
-    TRExamStudentService trExamStudentService;
+    RedisUtil redisUtil;
 
     /**
      * 导入期末成绩excel
@@ -331,4 +331,20 @@ public class TCFinalScoreServiceImpl extends ServiceImpl<TCFinalScoreMapper, TCF
                 .eq(TCFinalScore::getCourseCode, courseCode)
                 .eq(TCFinalScore::getPaperNumber, paperNumber));
     }
+
+    /**
+     * 获取期末考试同步锁
+     *
+     * @param examId
+     * @param courseCode
+     * @param paperNumber
+     */
+    @Override
+    public void getFinalScoreSyncLock(Long examId, String courseCode, String paperNumber) {
+        String lockKey = SystemConstant.REDIS_FINAL_SCORE_DATA_FLOW_PREFIX + SystemConstant.SYNC + examId + "_" + courseCode + "_" + paperNumber;
+        Object o = redisUtil.get(lockKey);
+        if (Objects.nonNull(o)) {
+            throw ExceptionResultEnum.ERROR.exception("正在同步数据,请稍候再试!");
+        }
+    }
 }

+ 4 - 20
distributed-print/src/main/java/com/qmth/distributed/print/api/TCFinalScoreController.java

@@ -77,11 +77,7 @@ public class TCFinalScoreController {
     public void finalScoreTemplateDownload(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
                                            @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode,
                                            @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber) throws IOException {
-        String lockKey = SystemConstant.REDIS_FINAL_SCORE_DATA_FLOW_PREFIX + SystemConstant.SYNC + examId + "_" + courseCode + "_" + paperNumber;
-        Object o = redisUtil.get(lockKey);
-        if (Objects.nonNull(o)) {
-            throw ExceptionResultEnum.ERROR.exception("正在同步数据,请稍候再试!");
-        }
+        tcFinalScoreService.getFinalScoreSyncLock(examId, courseCode, paperNumber);
         TCPaperStruct tcPaperStruct = tcPaperStructService.queryByExamIdAndCourseCodeAndPaperNumber(examId, courseCode, paperNumber);
         List<ExcelField> excelFieldList = new ArrayList<>();
         excelFieldList.addAll(new ArrayList<>(Arrays.asList(new ExcelField("studentCode", "学号", true), new ExcelField("name", "姓名", true), new ExcelField("score", "成绩", true))));
@@ -116,11 +112,7 @@ public class TCFinalScoreController {
                                    @ApiParam(value = "考试id", required = true) @RequestParam Long examId,
                                    @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode,
                                    @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber) throws IOException {
-        String lockSyncKey = SystemConstant.REDIS_FINAL_SCORE_DATA_FLOW_PREFIX + SystemConstant.SYNC + examId + "_" + courseCode + "_" + paperNumber;
-        Object o = redisUtil.get(lockSyncKey);
-        if (Objects.nonNull(o)) {
-            throw ExceptionResultEnum.ERROR.exception("正在同步数据,请稍候再试!");
-        }
+        tcFinalScoreService.getFinalScoreSyncLock(examId, courseCode, paperNumber);
         String lockKey = SystemConstant.REDIS_FINAL_SCORE_DATA_FLOW_PREFIX + SystemConstant.IMPORT + examId + "_" + courseCode + "_" + paperNumber;
         boolean lock = redisUtil.lock(lockKey, SystemConstant.REDIS_LOCK_IMPORT_EXAM_DATA_TIME_OUT);
         if (!lock) {
@@ -205,11 +197,7 @@ public class TCFinalScoreController {
         TCFinalScore tcFinalScoreDb = tcFinalScoreService.getById(tcFinalScore.getId());
         Objects.requireNonNull(tcFinalScoreDb, "未找到期末成绩信息");
 
-        String lockKey = SystemConstant.REDIS_FINAL_SCORE_DATA_FLOW_PREFIX + SystemConstant.SYNC + tcFinalScoreDb.getExamId() + "_" + tcFinalScoreDb.getCourseCode() + "_" + tcFinalScoreDb.getPaperNumber();
-        Object o = redisUtil.get(lockKey);
-        if (Objects.nonNull(o)) {
-            throw ExceptionResultEnum.ERROR.exception("正在同步数据,请稍候再试!");
-        }
+        tcFinalScoreService.getFinalScoreSyncLock(tcFinalScoreDb.getExamId(), tcFinalScoreDb.getCourseCode(), tcFinalScoreDb.getPaperNumber());
 
         TCFinalScore tcFinalScoreSource = new TCFinalScore();
         BeanUtils.copyProperties(tcFinalScoreDb, tcFinalScoreSource);
@@ -233,11 +221,7 @@ public class TCFinalScoreController {
         TCFinalScore tcFinalScoreDb = tcFinalScoreService.getById(id);
         Objects.requireNonNull(tcFinalScoreDb, "未找到期末成绩信息");
 
-        String lockKey = SystemConstant.REDIS_FINAL_SCORE_DATA_FLOW_PREFIX + SystemConstant.SYNC + tcFinalScoreDb.getExamId() + "_" + tcFinalScoreDb.getCourseCode() + "_" + tcFinalScoreDb.getPaperNumber();
-        Object o = redisUtil.get(lockKey);
-        if (Objects.nonNull(o)) {
-            throw ExceptionResultEnum.ERROR.exception("正在同步数据,请稍候再试!");
-        }
+        tcFinalScoreService.getFinalScoreSyncLock(tcFinalScoreDb.getExamId(), tcFinalScoreDb.getCourseCode(), tcFinalScoreDb.getPaperNumber());
 
         TCFinalScore tcFinalScoreSource = new TCFinalScore();
         BeanUtils.copyProperties(tcFinalScoreDb, tcFinalScoreSource);

+ 3 - 15
distributed-print/src/main/java/com/qmth/distributed/print/api/TCPaperStructController.java

@@ -80,11 +80,7 @@ public class TCPaperStructController {
                                               @ApiParam(value = "考试id", required = true) @RequestParam Long examId,
                                               @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode,
                                               @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber) throws IOException {
-        String lockKey = SystemConstant.REDIS_FINAL_SCORE_DATA_FLOW_PREFIX + SystemConstant.SYNC + examId + "_" + courseCode + "_" + paperNumber;
-        Object o = redisUtil.get(lockKey);
-        if (Objects.nonNull(o)) {
-            throw ExceptionResultEnum.ERROR.exception("正在同步数据,请稍候再试!");
-        }
+        tcFinalScoreService.getFinalScoreSyncLock(examId, courseCode, paperNumber);
         return ResultUtil.ok(tcPaperStructService.paperStructExcelImport(file, examId, courseCode, paperNumber));
     }
 
@@ -97,11 +93,7 @@ public class TCPaperStructController {
         if (bindingResult.hasErrors()) {
             return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
         }
-        String lockKey = SystemConstant.REDIS_FINAL_SCORE_DATA_FLOW_PREFIX + SystemConstant.SYNC + paperStructParams.getExamId() + "_" + paperStructParams.getCourseCode() + "_" + paperStructParams.getPaperNumber();
-        Object o = redisUtil.get(lockKey);
-        if (Objects.nonNull(o)) {
-            throw ExceptionResultEnum.ERROR.exception("正在同步数据,请稍候再试!");
-        }
+        tcFinalScoreService.getFinalScoreSyncLock(paperStructParams.getExamId(), paperStructParams.getCourseCode(), paperStructParams.getPaperNumber());
         CourseWeightResult courseWeightResult = trBasicInfoService.findCourseWeightResultRmi(paperStructParams.getExamId(), paperStructParams.getCourseCode());
         for (CourseWeightDto c : courseWeightResult.getSubmitForm()) {
             for (PaperStructDimensionResult paperStructDimensionResult : paperStructParams.getPaperStruct()) {
@@ -146,11 +138,7 @@ public class TCPaperStructController {
     public Result finalScorePaperStructQuery(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
                                              @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode,
                                              @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber) throws IOException {
-        String lockKey = SystemConstant.REDIS_FINAL_SCORE_DATA_FLOW_PREFIX + SystemConstant.SYNC + examId + "_" + courseCode + "_" + paperNumber;
-        Object o = redisUtil.get(lockKey);
-        if (Objects.nonNull(o)) {
-            throw ExceptionResultEnum.ERROR.exception("正在同步数据,请稍候再试!");
-        }
+        tcFinalScoreService.getFinalScoreSyncLock(examId, courseCode, paperNumber);
         List<PaperStructDimensionResult> paperStructDimensionResultList = null;
         TCPaperStruct tcPaperStruct = tcPaperStructService.queryByExamIdAndCourseCodeAndPaperNumber(examId, courseCode, paperNumber);
         if (Objects.isNull(tcPaperStruct)) {