Browse Source

新增期末考试试卷结构导入

wangliang 1 năm trước cách đây
mục cha
commit
8da4b1be90

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/TCFinalScore.java

@@ -183,7 +183,7 @@ public class TCFinalScore extends BaseEntity implements Serializable {
             return false;
         }
         TCFinalScore that = (TCFinalScore) o;
-        return examId.equals(that.examId) && courseCode.equals(that.courseCode) && courseName.equals(that.courseName) && paperNumber.equals(that.paperNumber) && name.equals(that.name) && studentCode.equals(that.studentCode) && score.equals(that.score) && scoreDetail.equals(that.scoreDetail) && enable.equals(that.enable);
+        return examId.equals(that.examId) && courseCode.equals(that.courseCode) && Objects.equals(courseName, that.courseName) && paperNumber.equals(that.paperNumber) && name.equals(that.name) && studentCode.equals(that.studentCode) && score.equals(that.score) && scoreDetail.equals(that.scoreDetail) && enable.equals(that.enable);
     }
 
     @Override

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/TCUsualScore.java

@@ -143,7 +143,7 @@ public class TCUsualScore extends BaseEntity implements Serializable {
             return false;
         }
         TCUsualScore that = (TCUsualScore) o;
-        return examId.equals(that.examId) && courseCode.equals(that.courseCode) && courseName.equals(that.courseName) && paperNumber.equals(that.paperNumber) && name.equals(that.name) && studentCode.equals(that.studentCode) && score.equals(that.score) && enable.equals(that.enable);
+        return examId.equals(that.examId) && courseCode.equals(that.courseCode) && Objects.equals(courseName, that.courseName) && paperNumber.equals(that.paperNumber) && name.equals(that.name) && studentCode.equals(that.studentCode) && score.equals(that.score) && enable.equals(that.enable);
     }
 
     @Override

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

@@ -162,7 +162,7 @@ public class TCFinalScoreServiceImpl extends ServiceImpl<TCFinalScoreMapper, TCF
                     if (CollectionUtils.isEmpty(tcFinalScoreDbSourceList) || !CollectionUtils.isEqualCollection(tcFinalScoreDbSourceList, tcFinalScoreList)) {
                         tcFinalScoreService.removeByIds(tcFinalScoreDbSourceList.stream().map(s -> s.getId()).collect(Collectors.toList()));
                         tcFinalScoreService.saveBatch(tcFinalScoreList);
-                        trBasicInfoService.clearReportData(examId, courseCode, paperNumber, false);
+                        trBasicInfoService.clearReportData(examId, courseCode, paperNumber, true);
                     }
                 }
             }
@@ -280,7 +280,7 @@ public class TCFinalScoreServiceImpl extends ServiceImpl<TCFinalScoreMapper, TCF
                     if (CollectionUtils.isEmpty(tcFinalScoreDbSourceList) || !CollectionUtils.isEqualCollection(tcFinalScoreDbSourceList, tcFinalScoreList)) {
                         tcFinalScoreService.removeByIds(tcFinalScoreDbSourceList.stream().map(s -> s.getId()).collect(Collectors.toList()));
                         tcFinalScoreService.saveBatch(tcFinalScoreList);
-                        trBasicInfoService.clearReportData(examId, courseCode, paperNumber, false);
+                        trBasicInfoService.clearReportData(examId, courseCode, paperNumber, true);
                     }
                 }
             }

+ 4 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TRBasicInfoServiceImpl.java

@@ -836,8 +836,10 @@ public class TRBasicInfoServiceImpl extends ServiceImpl<TRBasicInfoMapper, TRBas
         trBasicInfoService.remove(examId, courseCode, paperNumber);
         if (clearDimension) {
             TCPaperStruct tcPaperStruct = tcPaperStructService.queryByExamIdAndCourseCodeAndPaperNumber(examId, courseCode, paperNumber);
-            tcPaperStruct.setPaperStructDimension(null);
-            tcPaperStructService.updateById(tcPaperStruct);
+            if (Objects.nonNull(tcPaperStruct)) {
+                tcPaperStruct.setPaperStructDimension(null);
+                tcPaperStructService.updateById(tcPaperStruct);
+            }
         }
     }
 

+ 51 - 18
distributed-print/src/main/java/com/qmth/distributed/print/api/TCFinalScoreController.java

@@ -1,11 +1,14 @@
 package com.qmth.distributed.print.api;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+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.excel.ExcelField;
+import com.qmth.distributed.print.business.bean.excel.PaperStructDto;
 import com.qmth.distributed.print.business.bean.result.EditResult;
 import com.qmth.distributed.print.business.entity.TCFinalScore;
+import com.qmth.distributed.print.business.entity.TCPaperStruct;
 import com.qmth.distributed.print.business.service.PrintCommonService;
 import com.qmth.distributed.print.business.service.TCFinalScoreService;
 import com.qmth.distributed.print.business.service.TCPaperStructService;
@@ -16,11 +19,7 @@ import com.qmth.teachcloud.common.entity.MarkQuestion;
 import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.log.CustomizedOperationTypeEnum;
-import com.qmth.teachcloud.common.util.RedisUtil;
-import com.qmth.teachcloud.common.util.Result;
-import com.qmth.teachcloud.common.util.ResultUtil;
-import com.qmth.teachcloud.common.util.ServletUtil;
-import com.qmth.teachcloud.mark.service.MarkPaperService;
+import com.qmth.teachcloud.common.util.*;
 import com.qmth.teachcloud.mark.service.MarkQuestionService;
 import io.swagger.annotations.*;
 import org.apache.commons.collections4.CollectionUtils;
@@ -68,6 +67,9 @@ public class TCFinalScoreController {
     @Resource
     TRBasicInfoService trBasicInfoService;
 
+    @Resource
+    TCPaperStructService tcPaperStructService;
+
     @ApiOperation(value = "导入期末成绩-模板下载")
     @RequestMapping(value = "/final_score/template_download", method = RequestMethod.POST)
     @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.EXPORT)
@@ -75,17 +77,30 @@ 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 {
-        List<MarkQuestion> markQuestionList = markQuestionService.listQuestionByExamIdAndPaperNumberAndPaperType(examId, paperNumber, null);
-        if (CollectionUtils.isEmpty(markQuestionList)) {
-            throw ExceptionResultEnum.ERROR.exception("未找到试卷结构");
+        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("正在同步数据,请稍候再试!");
         }
-
+        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))));
-
-        for (int i = 0; i < markQuestionList.size(); i++) {
-            MarkQuestion markQuestion = markQuestionList.get(i);
-            excelFieldList.add(new ExcelField("key" + (i + 1), markQuestion.getMainNumber() + "-" + markQuestion.getSubNumber(), true));
+        if (Objects.isNull(tcPaperStruct) && Objects.isNull(tcPaperStruct.getPaperStruct())) {
+            List<MarkQuestion> markQuestionList = markQuestionService.listQuestionByExamIdAndPaperNumberAndPaperType(examId, paperNumber, null);
+            if (CollectionUtils.isEmpty(markQuestionList)) {
+                throw ExceptionResultEnum.ERROR.exception("未找到试卷结构");
+            }
+            for (int i = 0; i < markQuestionList.size(); i++) {
+                MarkQuestion markQuestion = markQuestionList.get(i);
+                excelFieldList.add(new ExcelField("key" + (i + 1), markQuestion.getMainNumber() + "-" + markQuestion.getSubNumber(), true));
+            }
+        } else {
+            List<PaperStructDto> paperStructDtoList = GsonUtil.fromJson(tcPaperStruct.getPaperStruct(), new TypeToken<List<PaperStructDto>>() {
+            }.getType());
+            for (int i = 0; i < paperStructDtoList.size(); i++) {
+                PaperStructDto paperStructDto = paperStructDtoList.get(i);
+                excelFieldList.add(new ExcelField("key" + (i + 1), paperStructDto.getMainNumber() + "-" + paperStructDto.getSubNumber(), true));
+            }
         }
         printCommonService.scoreDownLoadExaminationTemplate("1、所有字段均为必填字段;\n" +
                 "2、期末成绩按总分,和小题分录入,题号按大题号-小题号方式录入,如下,1-1表示第一大题第一小题,2-1表示第二大题第一小题;\n" +
@@ -101,7 +116,12 @@ 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 lockKey = SystemConstant.REDIS_FINAL_SCORE_DATA_FLOW_PREFIX + examId + "_" + courseCode + "_" + paperNumber;
+        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("正在同步数据,请稍候再试!");
+        }
+        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("正在同步数据,请稍候再试!");
@@ -129,11 +149,12 @@ 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 lockKey = SystemConstant.REDIS_FINAL_SCORE_DATA_FLOW_PREFIX + examId + "_" + courseCode + "_" + paperNumber;
-        boolean lock = redisUtil.lock(lockKey, SystemConstant.REDIS_LOCK_IMPORT_EXAM_DATA_TIME_OUT);
-        if (!lock) {
-            throw ExceptionResultEnum.ERROR.exception("正在导入数据,请稍候再试!");
+        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("正在同步数据,请稍候再试!");
         }
+        String lockKey = SystemConstant.REDIS_FINAL_SCORE_DATA_FLOW_PREFIX + SystemConstant.SYNC + examId + "_" + courseCode + "_" + paperNumber;
         Map<String, String> map = null;
         try {
             map = tcFinalScoreService.finalScoreExcelSync(examId, courseCode, paperNumber);
@@ -184,6 +205,12 @@ 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("正在同步数据,请稍候再试!");
+        }
+
         TCFinalScore tcFinalScoreSource = new TCFinalScore();
         BeanUtils.copyProperties(tcFinalScoreDb, tcFinalScoreSource);
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
@@ -206,6 +233,12 @@ 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("正在同步数据,请稍候再试!");
+        }
+
         TCFinalScore tcFinalScoreSource = new TCFinalScore();
         BeanUtils.copyProperties(tcFinalScoreDb, tcFinalScoreSource);
         tcFinalScoreDb.setEnable(enable);

+ 16 - 1
distributed-print/src/main/java/com/qmth/distributed/print/api/TCPaperStructController.java

@@ -80,6 +80,11 @@ 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("正在同步数据,请稍候再试!");
+        }
         return ResultUtil.ok(tcPaperStructService.paperStructExcelImport(file, examId, courseCode, paperNumber));
     }
 
@@ -92,6 +97,11 @@ 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("正在同步数据,请稍候再试!");
+        }
         CourseWeightResult courseWeightResult = trBasicInfoService.findCourseWeightResultRmi(paperStructParams.getExamId(), paperStructParams.getCourseCode());
         for (CourseWeightDto c : courseWeightResult.getSubmitForm()) {
             for (PaperStructDimensionResult paperStructDimensionResult : paperStructParams.getPaperStruct()) {
@@ -136,6 +146,11 @@ 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("正在同步数据,请稍候再试!");
+        }
         List<PaperStructDimensionResult> paperStructDimensionResultList = null;
         TCPaperStruct tcPaperStruct = tcPaperStructService.queryByExamIdAndCourseCodeAndPaperNumber(examId, courseCode, paperNumber);
         if (Objects.isNull(tcPaperStruct)) {
@@ -150,7 +165,7 @@ public class TCPaperStructController {
         } else {
             CourseWeightResult courseWeightResult = trBasicInfoService.findCourseWeightResultRmi(examId, courseCode);
             if (Objects.nonNull(tcPaperStruct.getDimensionSign()) && tcPaperStruct.getDimensionSign().longValue() != courseWeightResult.getDimensionSign().longValue()) {
-                trBasicInfoService.clearReportData(examId, courseCode, paperNumber, true);
+                trBasicInfoService.clearReportData(examId, courseCode, paperNumber, false);
                 paperStructDimensionResultList = new ArrayList<>();
 
                 if (Objects.nonNull(tcPaperStruct.getPaperStruct())) {

+ 3 - 1
teachcloud-common/src/main/java/com/qmth/teachcloud/common/contant/SystemConstant.java

@@ -338,6 +338,8 @@ public class SystemConstant {
     public static final String LIMIT1 = "limit 1";
 
     public static final Integer DEFAULT_BACKUP_COUNT = 1;
+    public static final String IMPORT = ":import";
+    public static final String SYNC = ":sync";
 
     /**
      * oss url过期时间
@@ -528,7 +530,7 @@ public class SystemConstant {
     public static final String REDIS_FINAL_SCORE_DATA_FLOW_PREFIX = "redis:lock:final:score:data";//期末考试数据锁
 
     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 * 60;
+    public static final long REDIS_LOCK_IMPORT_EXAM_DATA_TIME_OUT = 60L * 10;
     /**
      * 机器心跳
      */