Эх сурвалжийг харах

试卷结构上传-客观题、主观题同步

xiaof 3 жил өмнө
parent
commit
dce917a3da

+ 93 - 29
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/DataSyncServiceImpl.java

@@ -4,7 +4,9 @@ import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
-import com.google.gson.JsonObject;
+import com.qmth.boot.api.exception.ApiException;
+import com.qmth.distributed.print.business.bean.dto.ExamPaperObjectiveStructureDto;
+import com.qmth.distributed.print.business.bean.dto.ExamPaperSubjectiveStructureDto;
 import com.qmth.distributed.print.business.bean.dto.SyncExamCardDto;
 import com.qmth.distributed.print.business.bean.dto.SyncExamStudentDto;
 import com.qmth.distributed.print.business.bean.params.SyncDataParam;
@@ -12,6 +14,7 @@ import com.qmth.distributed.print.business.entity.*;
 import com.qmth.distributed.print.business.enums.ExamPaperStructureStatusEnum;
 import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
 import com.qmth.distributed.print.business.service.*;
+import com.qmth.teachcloud.common.bean.dto.SyncStructureData;
 import com.qmth.teachcloud.common.config.DictionaryConfig;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicAttachment;
@@ -37,6 +40,7 @@ import java.io.*;
 import java.util.*;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.stream.Collectors;
 
 /**
  * @Date: 2021/5/20.
@@ -81,9 +85,7 @@ public class DataSyncServiceImpl implements DataSyncService {
 
     private ExecutorService executors = Executors.newFixedThreadPool(5);
 
-    private static final String SAVE_EXAM_TYPE = "SCAN_IMAGE";
     private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
-    private static final String POST_METHOD = "POST";
 
     /**
      * 定时任务批量同步
@@ -155,35 +157,97 @@ public class DataSyncServiceImpl implements DataSyncService {
     public void uploadStructure(ExamPaperStructure examPaperStructure) {
         // 开始同步
         examPaperStructureService.updateStatusById(examPaperStructure.getId(), ExamPaperStructureStatusEnum.START_SYNC);
+        ExamPaperStructureStatusEnum status = ExamPaperStructureStatusEnum.UPLOAD_FINISH;
+        try {
+            String paperAnswer = examPaperStructure.getPaperAnswer();
+            if (StringUtils.isBlank(paperAnswer)) {
+                throw ExceptionResultEnum.ERROR.exception("没有找到标答文件");
+            }
 
-        String paperAnswer = examPaperStructure.getPaperAnswer();
-        if (StringUtils.isBlank(paperAnswer)) {
-            throw ExceptionResultEnum.ERROR.exception("没有找到标答文件");
-        }
-
-        JSONObject jsonObject = JSONObject.parseObject(paperAnswer);
-        if (!jsonObject.containsKey("paperType") || !jsonObject.containsKey("paper") || !jsonObject.containsKey("answer")) {
-            throw ExceptionResultEnum.ERROR.exception("没有找到标答文件");
-        }
-        String paperType = jsonObject.getString("paperType");
-        String paper = jsonObject.getString("paper");
-        String answer = jsonObject.getString("answer");
-        if (StringUtils.isAnyBlank(paperType, paper, answer)) {
-            throw ExceptionResultEnum.ERROR.exception("没有找到标答文件");
-        }
-
-        // 同步试卷文件
-        File paperFile = downFileFromFss(paper, paperType, SyncFileTypeEnum.PAPER);
-        boolean synPaperFile = stmmsUtils.syncFile(String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumber(), SyncFileTypeEnum.PAPER, paperFile);
-
-        // 同步标答文件
-        File answerFile = downFileFromFss(paper, paperType, SyncFileTypeEnum.PAPER);
-        boolean synAnswerFile = stmmsUtils.syncFile(String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumber(), SyncFileTypeEnum.ANSWER, answerFile);
-
-        // 同步客观题 todo
+            JSONObject paperAnswerJson = JSONObject.parseObject(paperAnswer);
+            if (!paperAnswerJson.containsKey("paperType") || !paperAnswerJson.containsKey("paper") || !paperAnswerJson.containsKey("answer")) {
+                throw ExceptionResultEnum.ERROR.exception("没有找到标答文件");
+            }
+            String paperType = paperAnswerJson.getString("paperType");
+            String paper = paperAnswerJson.getString("paper");
+            String answer = paperAnswerJson.getString("answer");
+            if (StringUtils.isAnyBlank(paperType, paper, answer)) {
+                throw ExceptionResultEnum.ERROR.exception("没有找到标答文件");
+            }
 
-        // 同步主观题 todo
+            // 同步试卷文件
+            File paperFile = downFileFromFss(paper, paperType, SyncFileTypeEnum.PAPER);
+            boolean syncPaperFile = stmmsUtils.syncFile(String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumber(), SyncFileTypeEnum.PAPER, paperFile);
+            if (syncPaperFile) {
+                status = ExamPaperStructureStatusEnum.PAPER_FINISH;
+            }
 
+            // 同步标答文件
+            File answerFile = downFileFromFss(paper, paperType, SyncFileTypeEnum.PAPER);
+            boolean syncAnswerFile = stmmsUtils.syncFile(String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumber(), SyncFileTypeEnum.ANSWER, answerFile);
+            if (syncAnswerFile) {
+                status = ExamPaperStructureStatusEnum.ANSWER_FINISH;
+            }
+            // 同步客观题
+            String objectiveStructure = examPaperStructure.getObjectiveStructure();
+            if (StringUtils.isBlank(objectiveStructure)) {
+                throw ExceptionResultEnum.ERROR.exception("没有找到客观题数据");
+            }
+            JSONObject objectiveJson = JSONObject.parseObject(objectiveStructure);
+            if (!objectiveJson.containsKey("paperType") || !objectiveJson.containsKey("content")) {
+                throw ExceptionResultEnum.ERROR.exception("客观题文件未上传");
+            }
+            String objectivePaperType = objectiveJson.getString("paperType");
+            String objectiveContent = objectiveJson.getString("content");
+            if (StringUtils.isAnyBlank(objectivePaperType, objectiveContent)) {
+                throw ExceptionResultEnum.ERROR.exception("没有找到客观题数据");
+            }
+            List<ExamPaperObjectiveStructureDto> objectiveStructureDtos = JSONObject.parseArray(objectiveContent, ExamPaperObjectiveStructureDto.class);
+            List<SyncStructureData> syncObjectiveStructureDatas = objectiveStructureDtos.stream().map(m -> {
+                SyncStructureData syncStructureData = new SyncStructureData();
+                syncStructureData.setMainNumber(Integer.valueOf(m.getMainNumber()));
+                syncStructureData.setSubNumber(m.getSubNumber());
+                syncStructureData.setMainTitle(m.getMainName());
+                syncStructureData.setTotalScore(Double.valueOf(m.getScore()));
+                syncStructureData.setAnswer(m.getAnswer());
+                return syncStructureData;
+            }).collect(Collectors.toList());
+            boolean syncObjectiveStructure = stmmsUtils.syncPaperStructure(String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumber(), true, objectivePaperType, syncObjectiveStructureDatas);
+            if (syncObjectiveStructure) {
+                status = ExamPaperStructureStatusEnum.OBJECTIVE_FINISH;
+            }
+            // 同步主观题
+            String subjectiveStructure = examPaperStructure.getSubjectiveStructure();
+            if (StringUtils.isBlank(subjectiveStructure)) {
+                throw ExceptionResultEnum.ERROR.exception("没有找到主观题数据");
+            }
+            JSONObject subjectiveJson = JSONObject.parseObject(subjectiveStructure);
+            if (!subjectiveJson.containsKey("paperType") || !subjectiveJson.containsKey("content")) {
+                throw ExceptionResultEnum.ERROR.exception("主观题文件未上传");
+            }
+            String subjectivePaperType = subjectiveJson.getString("paperType");
+            String subjectieContent = subjectiveJson.getString("content");
+            if (StringUtils.isAnyBlank(subjectivePaperType, subjectieContent)) {
+                throw ExceptionResultEnum.ERROR.exception("没有找到主观题数据");
+            }
+            List<ExamPaperSubjectiveStructureDto> subjectiveStructureDtos = JSONObject.parseArray(subjectieContent, ExamPaperSubjectiveStructureDto.class);
+            List<SyncStructureData> syncSubjectiveStructureDatas = subjectiveStructureDtos.stream().map(m -> {
+                SyncStructureData syncStructureData = new SyncStructureData();
+                syncStructureData.setMainNumber(Integer.valueOf(m.getMainNumber()));
+                syncStructureData.setSubNumber(m.getSubNumber());
+                syncStructureData.setMainTitle(m.getMainName());
+                syncStructureData.setTotalScore(Double.valueOf(m.getScore()));
+                return syncStructureData;
+            }).collect(Collectors.toList());
+            boolean syncSubjectiveStructure = stmmsUtils.syncPaperStructure(String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumber(), true, subjectivePaperType, syncSubjectiveStructureDatas);
+            if (syncSubjectiveStructure) {
+                status = ExamPaperStructureStatusEnum.SUBJECTIVE_FINISH;
+            }
+        } catch (ApiException e) {
+            throw ExceptionResultEnum.ERROR.exception("试卷结构同步失败:" + e.getMessage());
+        } finally {
+            examPaperStructureService.updateStatusById(examPaperStructure.getId(), status);
+        }
     }
 
     @Override

+ 3 - 3
teachcloud-common/src/main/java/com/qmth/teachcloud/common/bean/dto/SyncStructureData.java

@@ -11,7 +11,7 @@ public class SyncStructureData {
 
     private String mainTitle;
 
-    private Integer totalScore;
+    private Double totalScore;
 
     private String answer;
 
@@ -39,11 +39,11 @@ public class SyncStructureData {
         this.mainTitle = mainTitle;
     }
 
-    public Integer getTotalScore() {
+    public Double getTotalScore() {
         return totalScore;
     }
 
-    public void setTotalScore(Integer totalScore) {
+    public void setTotalScore(Double totalScore) {
         this.totalScore = totalScore;
     }