Browse Source

3.0.1-同步,修改异步前

xiaof 3 years ago
parent
commit
923b2ab5ea

+ 8 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamPaperStructureService.java

@@ -40,4 +40,12 @@ public interface ExamPaperStructureService extends IService<ExamPaperStructure>
      * @return 试卷结构
      * @return 试卷结构
      */
      */
     ExamPaperStructure submitExamPaperParams(EvaluationParameters evaluationParameters, SysUser requestUser);
     ExamPaperStructure submitExamPaperParams(EvaluationParameters evaluationParameters, SysUser requestUser);
+
+    /**
+     * 更新客观题答案
+     *
+     * @param id 试卷结构表Id
+     * @param objectiveStructure 客观题结构json
+     */
+    ExamPaperStructure updateObjectiveAnswer(Long id, String objectiveStructure);
 }
 }

+ 121 - 5
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/DataSyncServiceImpl.java

@@ -9,7 +9,6 @@ import com.qmth.distributed.print.business.bean.dto.ExamPaperObjectiveStructureD
 import com.qmth.distributed.print.business.bean.dto.ExamPaperSubjectiveStructureDto;
 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.SyncExamCardDto;
 import com.qmth.distributed.print.business.bean.dto.SyncExamStudentDto;
 import com.qmth.distributed.print.business.bean.dto.SyncExamStudentDto;
-import com.qmth.distributed.print.business.bean.marking.EvaluationParameters;
 import com.qmth.distributed.print.business.bean.params.SyncDataParam;
 import com.qmth.distributed.print.business.bean.params.SyncDataParam;
 import com.qmth.distributed.print.business.entity.*;
 import com.qmth.distributed.print.business.entity.*;
 import com.qmth.distributed.print.business.enums.ExamPaperStructureStatusEnum;
 import com.qmth.distributed.print.business.enums.ExamPaperStructureStatusEnum;
@@ -17,6 +16,7 @@ import com.qmth.distributed.print.business.enums.ExamPrintPlanSyncStatusEnum;
 import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
 import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
 import com.qmth.distributed.print.business.service.*;
 import com.qmth.distributed.print.business.service.*;
 import com.qmth.teachcloud.common.bean.dto.stmms.GroupDetailDTO;
 import com.qmth.teachcloud.common.bean.dto.stmms.GroupDetailDTO;
+import com.qmth.teachcloud.common.bean.dto.stmms.PicConfig;
 import com.qmth.teachcloud.common.bean.dto.stmms.QuestionBaseDTO;
 import com.qmth.teachcloud.common.bean.dto.stmms.QuestionBaseDTO;
 import com.qmth.teachcloud.common.bean.dto.stmms.QuestionDTO;
 import com.qmth.teachcloud.common.bean.dto.stmms.QuestionDTO;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.contant.SystemConstant;
@@ -389,9 +389,13 @@ public class DataSyncServiceImpl implements DataSyncService {
                 for (ExamPaperGroup examPaperGroup : examPaperGroups) {
                 for (ExamPaperGroup examPaperGroup : examPaperGroups) {
                     GroupDetailDTO groupDetailDTO = new GroupDetailDTO();
                     GroupDetailDTO groupDetailDTO = new GroupDetailDTO();
                     groupDetailDTO.setNumber(examPaperGroup.getGroupNumber());
                     groupDetailDTO.setNumber(examPaperGroup.getGroupNumber());
-                    groupDetailDTO.setPicList(null);
-//                    groupDetailDTO.setDoubleRate();
-//                    groupDetailDTO.setArbitrateThreshold(examPaperGroup.getArbitrateThreshold());
+                    String picListString = examPaperGroup.getPictureConfig();
+                    if (StringUtils.isNotBlank(picListString)) {
+                        List<PicConfig> picConfigs = JSONObject.parseArray(picListString, PicConfig.class);
+                        groupDetailDTO.setPicList(picConfigs);
+                    }
+                    groupDetailDTO.setDoubleRate(examPaperGroup.getDoubleRate());
+                    groupDetailDTO.setArbitrateThreshold(examPaperGroup.getArbitrateThreshold());
                     groupDetailDTO.setScorePolicy(examPaperGroup.getScorePolicy().getValue());
                     groupDetailDTO.setScorePolicy(examPaperGroup.getScorePolicy().getValue());
 //                    groupDetailDTO.setEnableAllZero();
 //                    groupDetailDTO.setEnableAllZero();
                     groupDetailDTO.setMarkMode("");
                     groupDetailDTO.setMarkMode("");
@@ -415,7 +419,7 @@ public class DataSyncServiceImpl implements DataSyncService {
             for (ExamPaperGroup examPaperGroup : examPaperGroups) {
             for (ExamPaperGroup examPaperGroup : examPaperGroups) {
                 List<ExamPaperGroupMarker> examPaperGroupMarkers = examPaperGroupMarkerService.listByGroupId(examPaperGroup.getId());
                 List<ExamPaperGroupMarker> examPaperGroupMarkers = examPaperGroupMarkerService.listByGroupId(examPaperGroup.getId());
                 for (ExamPaperGroupMarker examPaperGroupMarker : examPaperGroupMarkers) {
                 for (ExamPaperGroupMarker examPaperGroupMarker : examPaperGroupMarkers) {
-                    stmmsUtils.saveMarkerGroup(schoolId, examId, subjectCode, examPaperGroup.getGroupNumber(), examPaperGroupMarker.getLoginName());
+                    stmmsUtils.saveMarker(schoolId, examId, subjectCode, examPaperGroup.getGroupNumber(), examPaperGroupMarker.getLoginName());
                 }
                 }
             }
             }
 
 
@@ -427,6 +431,118 @@ public class DataSyncServiceImpl implements DataSyncService {
         }
         }
     }
     }
 
 
+    public void doSyncAnswerFile(ExamPaperStructure examPaperStructure) {
+        // 开始同步
+        examPaperStructureService.updateStatusById(examPaperStructure.getId(), ExamPaperStructureStatusEnum.START_SYNC);
+        ExamPaperStructureStatusEnum status = ExamPaperStructureStatusEnum.UPLOAD_FINISH;
+        try {
+            String paperTypes = examPaperStructure.getPaperType();
+            if (StringUtils.isBlank(paperTypes)) {
+                throw ExceptionResultEnum.ERROR.exception("没有可同步的试卷类型");
+            }
+
+            Long schoolId = examPaperStructure.getSchoolId();
+            // 云阅卷考试ID
+            String examId = String.valueOf(examPaperStructure.getThirdRelateId());
+            // 科目代码(课程代码+卷型+课程序号)
+            String subjectCode = examPaperStructure.getCourseCode().concat(examPaperStructure.getPaperType()).concat(examPaperStructure.getSequence());
+
+            // 同步试卷
+            String paperAnswer = examPaperStructure.getPaperAnswer();
+            if (StringUtils.isNotBlank(paperAnswer)) {
+                List<JSONObject> paperAnswerJsons = JSONObject.parseArray(paperAnswer, JSONObject.class);
+                for (JSONObject paperAnswerJson : paperAnswerJsons) {
+                    if (paperAnswerJson.containsKey("paperType") && paperAnswerJson.containsKey("paper")) {
+                        String paperType = paperAnswerJson.getString("paperType");
+                        String paper = paperAnswerJson.getString("paper");
+                        if (StringUtils.isAnyBlank(paperType, paper)) {
+                            continue;
+                        }
+
+                        // 同步试卷文件
+                        File paperFile = downFileFromFss(paper, paperType, SyncFileTypeEnum.PAPER);
+                        String syncPaperFileUrl = stmmsUtils.syncFile(schoolId, examId, subjectCode, SyncFileTypeEnum.PAPER, paperFile);
+                        // 试卷文件保存url
+                        paperAnswerJson.put("paperUrl", syncPaperFileUrl);
+                    }
+                }
+                status = ExamPaperStructureStatusEnum.PAPER_FINISH;
+                examPaperStructure.setPaperAnswer(JSONObject.toJSONString(paperAnswerJsons));
+            }
+
+            // 同步标答
+            if (StringUtils.isNotBlank(paperAnswer)) {
+                List<JSONObject> paperAnswerJsons = JSONObject.parseArray(paperAnswer, JSONObject.class);
+                for (JSONObject paperAnswerJson : paperAnswerJsons) {
+                    if (paperAnswerJson.containsKey("paperType") && paperAnswerJson.containsKey("answer")) {
+                        String paperType = paperAnswerJson.getString("paperType");
+                        String answer = paperAnswerJson.getString("answer");
+                        if (StringUtils.isAnyBlank(paperType, answer)) {
+                            continue;
+                        }
+                        // 同步标答文件
+                        File answerFile = downFileFromFss(answer, paperType, SyncFileTypeEnum.ANSWER);
+                        String syncAnswerFileUrl = stmmsUtils.syncFile(schoolId, examId, subjectCode, SyncFileTypeEnum.ANSWER, answerFile);
+                        // 标答文件保存url
+                        paperAnswerJson.put("answerUrl", syncAnswerFileUrl);
+                    }
+                }
+                examPaperStructure.setPaperAnswer(JSONObject.toJSONString(paperAnswerJsons));
+            }
+            status = ExamPaperStructureStatusEnum.ANSWER_FINISH;
+
+        } catch (ApiException e) {
+            throw ExceptionResultEnum.ERROR.exception("试卷结构同步失败:" + e.getMessage());
+        } finally {
+            examPaperStructure.setStatus(status);
+            examPaperStructureService.updateById(examPaperStructure);
+        }
+    }
+
+    public void doSyncObjectiveStructure(ExamPaperStructure examPaperStructure) {
+        // 开始同步
+        examPaperStructureService.updateStatusById(examPaperStructure.getId(), ExamPaperStructureStatusEnum.START_SYNC);
+        ExamPaperStructureStatusEnum status = ExamPaperStructureStatusEnum.UPLOAD_FINISH;
+        try {
+            String paperTypes = examPaperStructure.getPaperType();
+            if (StringUtils.isBlank(paperTypes)) {
+                throw ExceptionResultEnum.ERROR.exception("没有可同步的试卷类型");
+            }
+
+            // 同步客观题
+            String objectiveStructure = examPaperStructure.getObjectiveStructure();
+            if (StringUtils.isNotBlank(objectiveStructure)) {
+                List<JSONObject> objectiveJsons = JSONObject.parseArray(objectiveStructure, JSONObject.class);
+                for (JSONObject objectiveJson : objectiveJsons) {
+                    if (objectiveJson.containsKey("paperType") && objectiveJson.containsKey("content")) {
+                        String objectivePaperType = objectiveJson.getString("paperType");
+                        String objectiveContent = objectiveJson.getString("content");
+                        if (StringUtils.isAnyBlank(objectivePaperType, objectiveContent)) {
+                            continue;
+                        }
+                        List<ExamPaperObjectiveStructureDto> objectiveStructureDtos = JSONObject.parseArray(objectiveContent, ExamPaperObjectiveStructureDto.class);
+                        List<QuestionDTO> syncObjectiveStructureDatas = objectiveStructureDtos.stream().map(m -> {
+                            QuestionDTO syncStructureData = new QuestionDTO();
+                            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());
+                        stmmsUtils.syncPaperStructure(examPaperStructure.getSchoolId(), String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumberId() + objectivePaperType, true, null, syncObjectiveStructureDatas);
+                    }
+                }
+            }
+            status = ExamPaperStructureStatusEnum.OBJECTIVE_FINISH;
+        } catch (ApiException e) {
+            throw ExceptionResultEnum.ERROR.exception("试卷结构同步失败:" + e.getMessage());
+        } finally {
+            examPaperStructure.setStatus(status);
+            examPaperStructureService.updateById(examPaperStructure);
+        }
+    }
+
     /**
     /**
      * 同步核心方法
      * 同步核心方法
      *
      *

+ 12 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamPaperStructureServiceImpl.java

@@ -294,6 +294,18 @@ public class ExamPaperStructureServiceImpl extends ServiceImpl<ExamPaperStructur
         return examPaperStructure;
         return examPaperStructure;
     }
     }
 
 
+    @Override
+    public ExamPaperStructure updateObjectiveAnswer(Long id, String objectiveStructure) {
+        ExamPaperStructure examPaperStructure = this.getById(id);
+        if (examPaperStructure == null) {
+            throw ExceptionResultEnum.ERROR.exception("试卷结构数据不存在");
+        }
+        // todo xf 20220414 校验所有题卡都有答案
+        examPaperStructure.setObjectiveStructure(objectiveStructure);
+        this.updateById(examPaperStructure);
+        return examPaperStructure;
+    }
+
     /**
     /**
      * 保存试卷结构
      * 保存试卷结构
      *
      *

+ 35 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/execute/AsyncCloudMarkingTaskService.java

@@ -0,0 +1,35 @@
+package com.qmth.distributed.print.business.templete.execute;
+
+import com.qmth.distributed.print.business.entity.ExamPaperStructure;
+import com.qmth.distributed.print.business.service.DataSyncService;
+import com.qmth.teachcloud.common.entity.SysConfig;
+import com.qmth.teachcloud.common.service.SysConfigService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+
+/**
+ * 异步同步云阅卷
+ */
+@Service
+public class AsyncCloudMarkingTaskService {
+
+    private final static Logger log = LoggerFactory.getLogger(AsyncCloudMarkingTaskService.class);
+
+    @Resource
+    private SysConfigService sysConfigService;
+
+    @Resource
+    private DataSyncService dataSyncService;
+
+    private boolean isSync() {
+        SysConfig sysConfig = sysConfigService.getByKey("sys.sync.enable");
+        return sysConfig != null && "true".equals(sysConfig.getConfigValue());
+    }
+
+    public void syncPaperStructureAndGroup(ExamPaperStructure examPaperStructure){
+        dataSyncService.syncPaperStructureAndGroup(examPaperStructure);
+    }
+}

+ 15 - 2
distributed-print/src/main/java/com/qmth/distributed/print/api/ExamPaperStructureController.java

@@ -111,6 +111,21 @@ public class ExamPaperStructureController {
         return ResultUtil.ok(String.valueOf(examPaper.getId()), null);
         return ResultUtil.ok(String.valueOf(examPaper.getId()), null);
     }
     }
 
 
+    /**
+     * 保存客观题答案
+     * @param id 试卷结构表id
+     * @param objectiveStructure 客观题结构json
+     */
+    @ApiOperation(value = "保存客观题答案")
+    @RequestMapping(value = "/update_objective_answer", method = RequestMethod.POST)
+    public Result uploadAnswer(@RequestParam("id") Long id,
+                               @RequestParam("objectiveStructure") String objectiveStructure) {
+        ExamPaperStructure examPaper = examPaperStructureService.updateObjectiveAnswer(id, objectiveStructure);
+        // 推送云阅卷
+        dataSyncService.syncPaperStructure(examPaper);
+        return ResultUtil.ok(String.valueOf(examPaper.getId()), null);
+    }
+
     /**
     /**
      * 试卷结构预览
      * 试卷结构预览
      *
      *
@@ -123,7 +138,5 @@ public class ExamPaperStructureController {
         return ResultUtil.ok(list);
         return ResultUtil.ok(list);
     }
     }
 
 
-
-
 }
 }
 
 

+ 2 - 2
teachcloud-common/src/main/java/com/qmth/teachcloud/common/sync/StmmsUtils.java

@@ -392,7 +392,7 @@ public class StmmsUtils {
      * @param groupNumber 分组序号
      * @param groupNumber 分组序号
      * @param loginName   用户名
      * @param loginName   用户名
      */
      */
-    public boolean saveMarker(Long schoolId, String examId, String subjectCode, String groupNumber, String loginName) {
+    public boolean saveMarker(Long schoolId, String examId, String subjectCode, Integer groupNumber, String loginName) {
         String hostUrl = dictionaryConfig.syncDataDomain().getHostUrl();
         String hostUrl = dictionaryConfig.syncDataDomain().getHostUrl();
         String markerSaveUrl = dictionaryConfig.syncDataDomain().getMarkerSaveUrl();
         String markerSaveUrl = dictionaryConfig.syncDataDomain().getMarkerSaveUrl();
         validUrl(hostUrl, markerSaveUrl);
         validUrl(hostUrl, markerSaveUrl);
@@ -402,7 +402,7 @@ public class StmmsUtils {
             Map<String, Object> map = new HashMap<>();
             Map<String, Object> map = new HashMap<>();
             map.put("examId", validParam(examId, null, true, "考试ID"));
             map.put("examId", validParam(examId, null, true, "考试ID"));
             map.put("subjectCode", validParam(subjectCode, null, true, "科目代码"));
             map.put("subjectCode", validParam(subjectCode, null, true, "科目代码"));
-            map.put("groupNumber", validParam(groupNumber, null, true, "分组序号"));
+            map.put("groupNumber", validParam(String.valueOf(groupNumber), null, true, "分组序号"));
             map.put("loginName", validParam(loginName, null, true, "用户名"));
             map.put("loginName", validParam(loginName, null, true, "用户名"));
 
 
             String result = HttpKit.sendPost(postUrl, getHeaders(schoolId, markerSaveUrl), map, null, null, null);
             String result = HttpKit.sendPost(postUrl, getHeaders(schoolId, markerSaveUrl), map, null, null, null);