瀏覽代碼

3.2.0-同步题卡格式

xiaof 2 年之前
父節點
當前提交
3c12350051

+ 50 - 31
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/DataSyncServiceImpl.java

@@ -1,10 +1,11 @@
 package com.qmth.distributed.print.business.service.impl;
 
 import cn.hutool.core.date.DateUtil;
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.qmth.boot.api.exception.ApiException;
-import com.qmth.distributed.print.business.bean.dto.SyncExamCardDto;
+import com.qmth.distributed.print.business.bean.dto.CardDetailDto;
 import com.qmth.distributed.print.business.bean.dto.SyncExamStudentDto;
 import com.qmth.distributed.print.business.entity.*;
 import com.qmth.distributed.print.business.enums.ExamPaperStructureStatusEnum;
@@ -16,10 +17,8 @@ import com.qmth.teachcloud.common.bean.dto.stmms.QuestionBaseDTO;
 import com.qmth.teachcloud.common.bean.dto.stmms.QuestionDTO;
 import com.qmth.teachcloud.common.config.DictionaryConfig;
 import com.qmth.teachcloud.common.contant.SpringContextHolder;
-import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicAttachment;
 import com.qmth.teachcloud.common.entity.BasicCollege;
-import com.qmth.teachcloud.common.entity.SysOrg;
 import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.SyncFileTypeEnum;
@@ -78,6 +77,12 @@ public class DataSyncServiceImpl implements DataSyncService {
     @Resource
     private ExamPaperGroupMarkerService examPaperGroupMarkerService;
 
+    @Resource
+    ExamTaskService examTaskService;
+
+    @Resource
+    private ExamTaskDetailService examTaskDetailService;
+
     @Resource
     private CloudMarkingTaskUtils cloudMarkingTaskUtils;
 
@@ -497,46 +502,60 @@ public class DataSyncServiceImpl implements DataSyncService {
             return;
         }
         for (ExamDetailCourse examDetailCours : examDetailCourses) {
-            List<SyncExamCardDto> syncExamCardDtos = examCardService.listSyncCardByCourseCodeAndPaperNumber(examDetailCours.getSchoolId(), examDetailCours.getCourseCode(), examDetailCours.getPaperNumber());
-            if (CollectionUtils.isEmpty(syncExamCardDtos)) {
+            ExamTask examTask = examTaskService.getByCourseCodeAndPaperNumber(examDetailCours.getSchoolId(), examDetailCours.getCourseCode(), examDetailCours.getPaperNumber());
+            if (examTask == null) {
+                log.info("[上传题卡格式]数据异常,通过学校:{},课程代码:{},试卷编号:{}查出命题任务为空", examDetailCours.getSchoolId(), examDetailCours.getCourseCode(), examDetailCours.getPaperNumber());
                 return;
             }
-            if (syncExamCardDtos.size() > 1) {
-                log.info("数据异常,通过学校:{},课程代码:{},试卷编号:{}查出{}个题卡数据", examDetailCours.getSchoolId(), examDetailCours.getCourseCode(), examDetailCours.getPaperNumber(), syncExamCardDtos.size());
+            ExamTaskDetail examTaskDetail = examTaskDetailService.getByExamTaskId(examTask.getId());
+            List<JSONObject> paperAttachmentIds = JSON.parseArray(examTaskDetail.getPaperAttachmentIds(), JSONObject.class);
+            if (paperAttachmentIds.isEmpty()) {
+                log.info("[上传题卡格式]数据异常,通过命题任务ID:{}查询试卷信息为空", examTask.getId());
                 return;
             }
+
             String paperType = examDetailCours.getPaperType();
             if (StringUtils.isBlank(paperType)) {
-                log.info("数据异常,通过学校:{},课程代码:{},试卷编号:{}查出绑定型为空", examDetailCours.getSchoolId(), examDetailCours.getCourseCode(), examDetailCours.getPaperNumber());
+                log.info("[上传题卡格式]数据异常,通过学校:{},课程代码:{},试卷编号:{}查出考场科目信息中绑定卷型为空", examDetailCours.getSchoolId(), examDetailCours.getCourseCode(), examDetailCours.getPaperNumber());
                 return;
             }
-            SyncExamCardDto syncExamCardDto = syncExamCardDtos.get(0);
-            if (StringUtils.isNotEmpty(syncExamCardDto.getContent())) {
-                for (String s : paperType.split(",")) {
-                    //生成json文件
-                    File file = null;
-                    try {
-                        // 文件临时目录
-                        String filePath = getTempDir(SyncFileTypeEnum.CARD);
-                        file = createJsonFile(filePath, syncExamCardDto.getContent());
-                        if (file.exists()) {
-                            String uploadCardUrl = cloudMarkingTaskUtils.syncFile(schoolId, String.valueOf(thirdRelateId), syncExamCardDto.getCourseCode() + s + syncExamCardDto.getSequence(), SyncFileTypeEnum.CARD, file);
-                            if (StringUtils.isNotBlank(uploadCardUrl)) {
-                                UpdateWrapper<ExamCard> updateWrapper = new UpdateWrapper<>();
-                                updateWrapper.lambda().set(ExamCard::getSyncStatus, true).eq(ExamCard::getId, syncExamCardDto.getId());
-                                examCardService.update(updateWrapper);
-                            }
+            for (String s : examDetailCours.getPaperType().split(",")) {
+                Optional<JSONObject> optional = paperAttachmentIds.stream().filter(m -> m.getString("name").equals(s)).findFirst();
+                if (!optional.isPresent()) {
+                    log.info("[上传题卡格式]数据异常,未找到卷型{}绑定题卡ID", s);
+                    return;
+                }
+                Long cardId = optional.get().getLong("cardId");
+                CardDetailDto cardDetail = examCardService.getCardDetail(cardId);
+                if (cardDetail == null || StringUtils.isBlank(cardDetail.getContent())) {
+                    log.info("[上传题卡格式]数据异常,通过题卡ID:{}未查到题卡格式信息", cardId);
+                    return;
+                }
+
+                //生成json文件
+                File file = null;
+                try {
+                    // 文件临时目录
+                    String filePath = getTempDir(SyncFileTypeEnum.CARD);
+                    file = createJsonFile(filePath, cardDetail.getContent());
+                    if (file.exists()) {
+                        String uploadCardUrl = cloudMarkingTaskUtils.syncFile(schoolId, String.valueOf(thirdRelateId), examTask.getCourseCode() + s + examTask.getSequence(), SyncFileTypeEnum.CARD, file);
+                        if (StringUtils.isNotBlank(uploadCardUrl)) {
+                            UpdateWrapper<ExamCard> updateWrapper = new UpdateWrapper<>();
+                            updateWrapper.lambda().set(ExamCard::getSyncStatus, true).eq(ExamCard::getId, cardId);
+                            examCardService.update(updateWrapper);
                         }
-                    } catch (Exception e) {
-                        throw ExceptionResultEnum.ERROR.exception(e.getMessage());
-                    } finally {
-                        if (Objects.nonNull(dictionaryConfig.sysDomain()) && dictionaryConfig.sysDomain().isOss()) {
-                            if (file != null && file.exists()) {
-                                file.delete();
-                            }
+                    }
+                } catch (Exception e) {
+                    throw ExceptionResultEnum.ERROR.exception(e.getMessage());
+                } finally {
+                    if (Objects.nonNull(dictionaryConfig.sysDomain()) && dictionaryConfig.sysDomain().isOss()) {
+                        if (file != null && file.exists()) {
+                            file.delete();
                         }
                     }
                 }
+
             }
         }
     }