Explorar el Código

新增目标分变化提示和报错

wangliang hace 1 año
padre
commit
a0daca5d9f

+ 9 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/PrintCommonService.java

@@ -244,7 +244,6 @@ public interface PrintCommonService {
     /**
      * 根据学生集合创建考生考务数据
      *
-     * @param schoolId                       学校id
      * @param examTask                       命题任务
      * @param extendFields                   扩展字段
      * @param examTaskStudentObjectParamList 学生参数集合
@@ -330,4 +329,13 @@ public interface PrintCommonService {
      * @return
      */
     public IPage<ScoreResult> scoreList(IPage<Map> iPage, Long examId, String courseCode);
+
+    /**
+     * 获取成绩管理需要的锁
+     *
+     * @param examId
+     * @param courseCode
+     * @param paperNumber
+     */
+    public void getLock(Long examId, String courseCode, String paperNumber);
 }

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

@@ -115,4 +115,13 @@ public interface TCFinalScoreService extends IService<TCFinalScore> {
      * @param paperNumber
      */
     public void getFinalScoreSyncLock(Long examId, String courseCode, String paperNumber);
+
+    /**
+     * 获取期末考试导入锁
+     *
+     * @param examId
+     * @param courseCode
+     * @param paperNumber
+     */
+    public void getFinalScoreImportLock(Long examId, String courseCode, String paperNumber);
 }

+ 18 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/TCPaperStructService.java

@@ -59,4 +59,22 @@ public interface TCPaperStructService extends IService<TCPaperStruct> {
      * @return
      */
     public TCPaperStruct queryByExamIdAndCourseCodeAndPaperNumber(Long examId, String courseCode, String paperNumber);
+
+    /**
+     * 获取试卷结构同步锁
+     *
+     * @param examId
+     * @param courseCode
+     * @param paperNumber
+     */
+    public void getPaperStructSyncLock(Long examId, String courseCode, String paperNumber);
+
+    /**
+     * 获取试卷结构导入锁
+     *
+     * @param examId
+     * @param courseCode
+     * @param paperNumber
+     */
+    public void getPaperStructImportLock(Long examId, String courseCode, String paperNumber);
 }

+ 23 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/PrintCommonServiceImpl.java

@@ -164,6 +164,14 @@ public class PrintCommonServiceImpl implements PrintCommonService {
     @Resource
     BasicRoleDataPermissionService basicRoleDataPermissionService;
 
+    @Resource
+    @Lazy
+    TCFinalScoreService tcFinalScoreService;
+
+    @Resource
+    @Lazy
+    TCPaperStructService tcPaperStructService;
+
     /**
      * 保存附件
      *
@@ -527,6 +535,21 @@ public class PrintCommonServiceImpl implements PrintCommonService {
         return tcUsualScoreMapper.scoreList(iPage, examId, courseCode, dpr);
     }
 
+    /**
+     * 获取成绩管理需要的锁
+     *
+     * @param examId
+     * @param courseCode
+     * @param paperNumber
+     */
+    @Override
+    public void getLock(Long examId, String courseCode, String paperNumber) {
+        tcFinalScoreService.getFinalScoreSyncLock(examId, courseCode, paperNumber);
+        tcFinalScoreService.getFinalScoreImportLock(examId, courseCode, paperNumber);
+        tcPaperStructService.getPaperStructSyncLock(examId, courseCode, paperNumber);
+        tcPaperStructService.getPaperStructImportLock(examId, courseCode, paperNumber);
+    }
+
     /**
      * 保存html附件
      *

+ 16 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TCFinalScoreServiceImpl.java

@@ -351,4 +351,20 @@ public class TCFinalScoreServiceImpl extends ServiceImpl<TCFinalScoreMapper, TCF
             throw ExceptionResultEnum.ERROR.exception("正在同步数据,请稍候再试!");
         }
     }
+
+    /**
+     * 获取期末考试导入锁
+     *
+     * @param examId
+     * @param courseCode
+     * @param paperNumber
+     */
+    @Override
+    public void getFinalScoreImportLock(Long examId, String courseCode, String paperNumber) {
+        String lockKey = SystemConstant.REDIS_FINAL_SCORE_DATA_FLOW_PREFIX + SystemConstant.IMPORT + examId + "_" + courseCode + "_" + paperNumber;
+        Object o = redisUtil.get(lockKey);
+        if (Objects.nonNull(o)) {
+            throw ExceptionResultEnum.ERROR.exception("正在导入数据,请稍候再试!");
+        }
+    }
 }

+ 36 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TCPaperStructServiceImpl.java

@@ -17,6 +17,7 @@ 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.entity.MarkPaper;
@@ -56,6 +57,9 @@ public class TCPaperStructServiceImpl extends ServiceImpl<TCPaperStructMapper, T
     @Resource
     PrintCommonService printCommonService;
 
+    @Resource
+    RedisUtil redisUtil;
+
     /**
      * 根据考试id/课程编码/试卷编码查询数据库数据
      *
@@ -203,4 +207,36 @@ public class TCPaperStructServiceImpl extends ServiceImpl<TCPaperStructMapper, T
     public TCPaperStruct queryByExamIdAndCourseCodeAndPaperNumber(Long examId, String courseCode, String paperNumber) {
         return tcPaperStructService.getOne(new QueryWrapper<TCPaperStruct>().lambda().eq(TCPaperStruct::getExamId, examId).eq(TCPaperStruct::getCourseCode, courseCode).eq(TCPaperStruct::getPaperNumber, paperNumber));
     }
+
+    /**
+     * 获取试卷结构同步锁
+     *
+     * @param examId
+     * @param courseCode
+     * @param paperNumber
+     */
+    @Override
+    public void getPaperStructSyncLock(Long examId, String courseCode, String paperNumber) {
+        String lockKey = SystemConstant.REDIS_PAPER_STRUCT_FLOW_PREFIX + SystemConstant.SYNC + examId + "_" + courseCode + "_" + paperNumber;
+        Object o = redisUtil.get(lockKey);
+        if (Objects.nonNull(o)) {
+            throw ExceptionResultEnum.ERROR.exception("正在同步数据,请稍候再试!");
+        }
+    }
+
+    /**
+     * 获取试卷结构导入锁
+     *
+     * @param examId
+     * @param courseCode
+     * @param paperNumber
+     */
+    @Override
+    public void getPaperStructImportLock(Long examId, String courseCode, String paperNumber) {
+        String lockKey = SystemConstant.REDIS_PAPER_STRUCT_FLOW_PREFIX + SystemConstant.IMPORT + examId + "_" + courseCode + "_" + paperNumber;
+        Object o = redisUtil.get(lockKey);
+        if (Objects.nonNull(o)) {
+            throw ExceptionResultEnum.ERROR.exception("正在导入数据,请稍候再试!");
+        }
+    }
 }

+ 6 - 14
distributed-print/src/main/java/com/qmth/distributed/print/api/TCFinalScoreController.java

@@ -78,7 +78,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 {
-        tcFinalScoreService.getFinalScoreSyncLock(examId, courseCode, paperNumber);
+        printCommonService.getLock(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))));
@@ -113,12 +113,8 @@ 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 {
-        tcFinalScoreService.getFinalScoreSyncLock(examId, courseCode, paperNumber);
+        printCommonService.getLock(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) {
-            throw ExceptionResultEnum.ERROR.exception("正在同步数据,请稍候再试!");
-        }
         Map<String, String> map = null;
         try {
             map = tcFinalScoreService.finalScoreExcelImport(file, examId, courseCode, paperNumber);
@@ -142,11 +138,7 @@ public class TCFinalScoreController {
     public Result finalScoreSync(@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 lockImportKey = SystemConstant.REDIS_FINAL_SCORE_DATA_FLOW_PREFIX + SystemConstant.IMPORT + examId + "_" + courseCode + "_" + paperNumber;
-        Object o = redisUtil.get(lockImportKey);
-        if (Objects.nonNull(o)) {
-            throw ExceptionResultEnum.ERROR.exception("正在同步数据,请稍候再试!");
-        }
+        printCommonService.getLock(examId, courseCode, paperNumber);
         String lockKey = SystemConstant.REDIS_FINAL_SCORE_DATA_FLOW_PREFIX + SystemConstant.SYNC + examId + "_" + courseCode + "_" + paperNumber;
         Map<String, String> map = null;
         try {
@@ -198,6 +190,8 @@ public class TCFinalScoreController {
         TCFinalScore tcFinalScoreDb = tcFinalScoreService.getById(tcFinalScore.getId());
         Objects.requireNonNull(tcFinalScoreDb, "未找到期末成绩信息");
 
+        printCommonService.getLock(tcFinalScoreDb.getExamId(), tcFinalScoreDb.getCourseCode(), tcFinalScoreDb.getPaperNumber());
+
         List<TCFinalScoreDto> tcFinalScoreDtoList = GsonUtil.fromJson(tcFinalScore.getScoreDetail(), new TypeToken<List<TCFinalScoreDto>>() {
         }.getType());
         Double score = tcFinalScoreDtoList.stream().mapToDouble(e -> Double.valueOf(e.getScore())).sum();
@@ -205,8 +199,6 @@ public class TCFinalScoreController {
             throw ExceptionResultEnum.ERROR.exception("分数总分不能大于试卷总分");
         }
 
-        tcFinalScoreService.getFinalScoreSyncLock(tcFinalScoreDb.getExamId(), tcFinalScoreDb.getCourseCode(), tcFinalScoreDb.getPaperNumber());
-
         TCFinalScore tcFinalScoreSource = new TCFinalScore();
         BeanUtils.copyProperties(tcFinalScoreDb, tcFinalScoreSource);
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
@@ -229,7 +221,7 @@ public class TCFinalScoreController {
         TCFinalScore tcFinalScoreDb = tcFinalScoreService.getById(id);
         Objects.requireNonNull(tcFinalScoreDb, "未找到期末成绩信息");
 
-        tcFinalScoreService.getFinalScoreSyncLock(tcFinalScoreDb.getExamId(), tcFinalScoreDb.getCourseCode(), tcFinalScoreDb.getPaperNumber());
+        printCommonService.getLock(tcFinalScoreDb.getExamId(), tcFinalScoreDb.getCourseCode(), tcFinalScoreDb.getPaperNumber());
 
         TCFinalScore tcFinalScoreSource = new TCFinalScore();
         BeanUtils.copyProperties(tcFinalScoreDb, tcFinalScoreSource);

+ 39 - 9
distributed-print/src/main/java/com/qmth/distributed/print/api/TCPaperStructController.java

@@ -2,6 +2,7 @@ package com.qmth.distributed.print.api;
 
 import com.google.gson.reflect.TypeToken;
 import com.qmth.boot.api.constant.ApiConstant;
+import com.qmth.boot.api.exception.ApiException;
 import com.qmth.distributed.print.business.bean.dto.CourseWeightDto;
 import com.qmth.distributed.print.business.bean.excel.PaperStructDto;
 import com.qmth.distributed.print.business.bean.params.report.PaperStructParams;
@@ -38,6 +39,7 @@ import java.io.IOException;
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.Objects;
 import java.util.stream.Collectors;
 
@@ -55,9 +57,6 @@ import java.util.stream.Collectors;
 public class TCPaperStructController {
     private final static Logger log = LoggerFactory.getLogger(TCPaperStructController.class);
 
-    @Resource
-    TCFinalScoreService tcFinalScoreService;
-
     @Resource
     MarkQuestionService markQuestionService;
 
@@ -70,6 +69,9 @@ public class TCPaperStructController {
     @Resource
     PrintCommonService printCommonService;
 
+    @Resource
+    RedisUtil redisUtil;
+
     @ApiOperation(value = "导入试卷结构")
     @RequestMapping(value = "/final_score/paper_struct/import", method = RequestMethod.POST)
     @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.IMPORT)
@@ -78,8 +80,22 @@ 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 {
-        tcFinalScoreService.getFinalScoreSyncLock(examId, courseCode, paperNumber);
-        return ResultUtil.ok(tcPaperStructService.paperStructExcelImport(file, examId, courseCode, paperNumber));
+        printCommonService.getLock(examId, courseCode, paperNumber);
+        String lockKey = SystemConstant.REDIS_PAPER_STRUCT_FLOW_PREFIX + SystemConstant.IMPORT + examId + "_" + courseCode + "_" + paperNumber;
+        Map<String, String> map = null;
+        try {
+            map = tcPaperStructService.paperStructExcelImport(file, examId, courseCode, paperNumber);
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+            if (e instanceof ApiException) {
+                ResultUtil.error((ApiException) e, ((ApiException) e).getCode(), e.getMessage());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
+        } finally {
+            redisUtil.releaseLock(lockKey);
+        }
+        return ResultUtil.ok(map);
     }
 
     @ApiOperation(value = "同步试卷蓝图结构")
@@ -89,8 +105,22 @@ public class TCPaperStructController {
     public Result finalScorePaperStructDimensionSync(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
                                                      @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode,
                                                      @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber) throws IOException {
-        tcFinalScoreService.getFinalScoreSyncLock(examId, courseCode, paperNumber);
-        return ResultUtil.ok();
+        printCommonService.getLock(examId, courseCode, paperNumber);
+        String lockKey = SystemConstant.REDIS_PAPER_STRUCT_FLOW_PREFIX + SystemConstant.SYNC + examId + "_" + courseCode + "_" + paperNumber;
+        Map<String, String> map = null;
+        try {
+//            map = tcFinalScoreService.finalScoreExcelSync(examId, courseCode, paperNumber);
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+            if (e instanceof ApiException) {
+                ResultUtil.error((ApiException) e, ((ApiException) e).getCode(), e.getMessage());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
+        } finally {
+            redisUtil.releaseLock(lockKey);
+        }
+        return ResultUtil.ok(map);
     }
 
     @ApiOperation(value = "期末成绩试卷蓝图保存")
@@ -102,7 +132,7 @@ public class TCPaperStructController {
         if (bindingResult.hasErrors()) {
             return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
         }
-        tcFinalScoreService.getFinalScoreSyncLock(paperStructParams.getExamId(), paperStructParams.getCourseCode(), paperStructParams.getPaperNumber());
+        printCommonService.getLock(paperStructParams.getExamId(), paperStructParams.getCourseCode(), paperStructParams.getPaperNumber());
         CourseWeightResult courseWeightResult = trBasicInfoService.findCourseWeightResultRmi(paperStructParams.getExamId(), paperStructParams.getCourseCode());
         for (CourseWeightDto c : courseWeightResult.getSubmitForm()) {
             for (PaperStructDimensionResult paperStructDimensionResult : paperStructParams.getPaperStruct()) {
@@ -151,7 +181,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 {
-        tcFinalScoreService.getFinalScoreSyncLock(examId, courseCode, paperNumber);
+        printCommonService.getLock(examId, courseCode, paperNumber);
         List<PaperStructDimensionResult> paperStructDimensionResultList = null;
         TCPaperStruct tcPaperStruct = tcPaperStructService.queryByExamIdAndCourseCodeAndPaperNumber(examId, courseCode, paperNumber);
         if (Objects.isNull(tcPaperStruct) || Objects.isNull(tcPaperStruct.getPaperStruct())) {

+ 2 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/contant/SystemConstant.java

@@ -526,9 +526,11 @@ public class SystemConstant {
     public static final long REDIS_LOCK_CALCULATE_TIME_OUT = 60L * 60;
     public static final long REDIS_LOCK_PAPER_NUMBER_TIME_OUT = 60L * 2;
     public static final String REDIS_FINAL_SCORE_DATA_FLOW_PREFIX = "redis:lock:final:score:data";//期末考试数据锁
+    public static final String REDIS_PAPER_STRUCT_FLOW_PREFIX = "redis:lock:final:score:paper:struct";//期末考试试卷结构锁
 
     public static final String REDIS_LOCK_IMPORT_EXAM_DATA = "redis:lock:import:exam:data:";//导入考务数据锁
     public static final long REDIS_LOCK_IMPORT_EXAM_DATA_TIME_OUT = 60L * 10;
+    public static final long REDIS_PAPER_STRUCT_TIME_OUT = 60L * 10;
     /**
      * 机器心跳
      */