Jelajahi Sumber

试卷结构上传、同步非必填

xiaof 3 tahun lalu
induk
melakukan
7d16df78bd

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

@@ -20,7 +20,7 @@ public interface ExamPaperStructureService extends IService<ExamPaperStructure>
 
     IPage<ExamPaperStructure> listByPropositionTeacherId(Integer pageNumber, Integer pageSize, String[] structureStatusEnums);
 
-    ExamPaperStructure upload(String examPaperStructure, String md5, MultipartFile[] files);
+    ExamPaperStructure upload(String examPaperStructure, String md5, String keys, MultipartFile[] files);
 
     void updateStatusById(Long id, ExamPaperStructureStatusEnum startSync);
 

+ 76 - 123
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/DataSyncServiceImpl.java

@@ -41,7 +41,6 @@ import java.io.*;
 import java.util.*;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
-import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
 /**
@@ -204,156 +203,110 @@ public class DataSyncServiceImpl implements DataSyncService {
         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 paperTypes = examPaperStructure.getPaperType();
             if (StringUtils.isBlank(paperTypes)) {
-                throw ExceptionResultEnum.ERROR.exception("没有找到试卷类型");
+                throw ExceptionResultEnum.ERROR.exception("没有可同步的试卷类型");
             }
 
-            List<String> paperTypeList = Arrays.asList(paperTypes.split(","));
-
-            AtomicInteger atomicInteger = new AtomicInteger(0);
             // 同步试卷
-            List<JSONObject> paperAnswerJsons = JSONObject.parseArray(paperAnswer, JSONObject.class);
-            for (JSONObject paperAnswerJson : paperAnswerJsons) {
-                if (!paperAnswerJson.containsKey("paperType") || !paperAnswerJson.containsKey("paper")) {
-                    throw ExceptionResultEnum.ERROR.exception("没有找到试卷文件");
-                }
-                String paperType = paperAnswerJson.getString("paperType");
-                String paper = paperAnswerJson.getString("paper");
-                if (StringUtils.isAnyBlank(paperType, paper)) {
-                    throw ExceptionResultEnum.ERROR.exception("没有找到试卷文件");
-                }
-
-                if (!paperTypeList.contains(paperType)) {
-                    throw ExceptionResultEnum.ERROR.exception("试卷对应的类型有误");
-                }
+            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(examPaperStructure.getSchoolId(), String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumberId() + paperType, SyncFileTypeEnum.PAPER, paperFile);
-                if (StringUtils.isNotBlank(syncPaperFileUrl)) {
-                    atomicInteger.getAndIncrement();
+                        // 同步试卷文件
+                        File paperFile = downFileFromFss(paper, paperType, SyncFileTypeEnum.PAPER);
+                        String syncPaperFileUrl = stmmsUtils.syncFile(examPaperStructure.getSchoolId(), String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumberId() + paperType, SyncFileTypeEnum.PAPER, paperFile);
+                        // 试卷文件保存url
+                        paperAnswerJson.put("paperUrl", syncPaperFileUrl);
+                    }
                 }
-                // 试卷文件保存url
-                paperAnswerJson.put("paperUrl", syncPaperFileUrl);
-            }
-            if (atomicInteger.intValue() - paperAnswerJsons.size() == 0) {
                 status = ExamPaperStructureStatusEnum.PAPER_FINISH;
                 examPaperStructure.setPaperAnswer(JSONObject.toJSONString(paperAnswerJsons));
             }
 
             // 同步标答
-            atomicInteger.set(0);
-            for (JSONObject paperAnswerJson : paperAnswerJsons) {
-                if (!paperAnswerJson.containsKey("paperType") || !paperAnswerJson.containsKey("answer")) {
-                    throw ExceptionResultEnum.ERROR.exception("没有找到标答文件");
-                }
-                String paperType = paperAnswerJson.getString("paperType");
-                String answer = paperAnswerJson.getString("answer");
-                if (StringUtils.isAnyBlank(paperType, answer)) {
-                    throw ExceptionResultEnum.ERROR.exception("没有找到标答文件");
-                }
-
-                if (!paperTypeList.contains(paperType)) {
-                    throw ExceptionResultEnum.ERROR.exception("标答对应的试卷类型有误");
-                }
-
-                // 同步标答文件
-                File answerFile = downFileFromFss(answer, paperType, SyncFileTypeEnum.ANSWER);
-                String syncAnswerFileUrl = stmmsUtils.syncFile(examPaperStructure.getSchoolId(), String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumberId() + paperType, SyncFileTypeEnum.ANSWER, answerFile);
-                if (StringUtils.isNotBlank(syncAnswerFileUrl)) {
-                    atomicInteger.getAndIncrement();
+            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(examPaperStructure.getSchoolId(), String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumberId() + paperType, SyncFileTypeEnum.ANSWER, answerFile);
+                        // 标答文件保存url
+                        paperAnswerJson.put("answerUrl", syncAnswerFileUrl);
+                    }
                 }
-                // 标答文件保存url
-                paperAnswerJson.put("answerUrl", syncAnswerFileUrl);
-            }
-            if (atomicInteger.intValue() - paperAnswerJsons.size() == 0) {
-                status = ExamPaperStructureStatusEnum.ANSWER_FINISH;
                 examPaperStructure.setPaperAnswer(JSONObject.toJSONString(paperAnswerJsons));
             }
+            status = ExamPaperStructureStatusEnum.ANSWER_FINISH;
 
             // 同步客观题
-            atomicInteger.set(0);
             String objectiveStructure = examPaperStructure.getObjectiveStructure();
-            if (StringUtils.isBlank(objectiveStructure)) {
-                throw ExceptionResultEnum.ERROR.exception("没有找到客观题数据");
-            }
-            List<JSONObject> objectiveJsons = JSONObject.parseArray(objectiveStructure, JSONObject.class);
-            for (JSONObject objectiveJson : objectiveJsons) {
-                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("没有找到客观题数据");
-                }
-                if (!paperTypeList.contains(objectivePaperType)) {
-                    throw ExceptionResultEnum.ERROR.exception("客观题对应的试卷类型有误");
-                }
-
-                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());
-                boolean syncObjectiveStructure = stmmsUtils.syncPaperStructure(examPaperStructure.getSchoolId(), String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumberId() + objectivePaperType, true, null, syncObjectiveStructureDatas);
-                if (syncObjectiveStructure) {
-                    atomicInteger.getAndIncrement();
+            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);
+                    }
                 }
             }
-            if (atomicInteger.intValue() - paperAnswerJsons.size() == 0) {
-                status = ExamPaperStructureStatusEnum.OBJECTIVE_FINISH;
-            }
+            status = ExamPaperStructureStatusEnum.OBJECTIVE_FINISH;
 
             // 同步主观题
-            atomicInteger.set(0);
             String subjectiveStructure = examPaperStructure.getSubjectiveStructure();
-            if (StringUtils.isBlank(subjectiveStructure)) {
-                throw ExceptionResultEnum.ERROR.exception("没有找到主观题数据");
-            }
-            List<JSONObject> subjectiveJsons = JSONObject.parseArray(subjectiveStructure, JSONObject.class);
-            for (JSONObject subjectiveJson : subjectiveJsons) {
-                if (!subjectiveJson.containsKey("paperType") || !subjectiveJson.containsKey("content")) {
-                    throw ExceptionResultEnum.ERROR.exception("主观题文件未上传");
-                }
-                String subjectivePaperType = subjectiveJson.getString("paperType");
-                String subjectiveContent = subjectiveJson.getString("content");
-                if (StringUtils.isAnyBlank(subjectivePaperType, subjectiveContent)) {
-                    throw ExceptionResultEnum.ERROR.exception("没有找到主观题数据");
-                }
-                List<ExamPaperSubjectiveStructureDto> subjectiveStructureDtos = JSONObject.parseArray(subjectiveContent, ExamPaperSubjectiveStructureDto.class);
-                List<QuestionDTO> syncSubjectiveStructureDatas = subjectiveStructureDtos.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()));
-                    return syncStructureData;
-                }).collect(Collectors.toList());
-                boolean syncSubjectiveStructure = stmmsUtils.syncPaperStructure(examPaperStructure.getSchoolId(), String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumberId() + subjectivePaperType, false, null, syncSubjectiveStructureDatas);
-                if (syncSubjectiveStructure) {
-                    atomicInteger.getAndIncrement();
+            if (StringUtils.isNotBlank(subjectiveStructure)) {
+                List<JSONObject> subjectiveJsons = JSONObject.parseArray(subjectiveStructure, JSONObject.class);
+                for (JSONObject subjectiveJson : subjectiveJsons) {
+                    if (subjectiveJson.containsKey("paperType") && subjectiveJson.containsKey("content")) {
+                        String subjectivePaperType = subjectiveJson.getString("paperType");
+                        String subjectiveContent = subjectiveJson.getString("content");
+                        if (StringUtils.isAnyBlank(subjectivePaperType, subjectiveContent)) {
+                            continue;
+                        }
+                        List<ExamPaperSubjectiveStructureDto> subjectiveStructureDtos = JSONObject.parseArray(subjectiveContent, ExamPaperSubjectiveStructureDto.class);
+                        List<QuestionDTO> syncSubjectiveStructureDatas = subjectiveStructureDtos.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()));
+                            return syncStructureData;
+                        }).collect(Collectors.toList());
+                        stmmsUtils.syncPaperStructure(examPaperStructure.getSchoolId(), String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumberId() + subjectivePaperType, false, null, syncSubjectiveStructureDatas);
+                    }
                 }
             }
-            if (atomicInteger.intValue() - paperAnswerJsons.size() == 0) {
-                status = ExamPaperStructureStatusEnum.FINISH;
-            }
-
+            status = ExamPaperStructureStatusEnum.FINISH;
         } catch (ApiException e) {
             throw ExceptionResultEnum.ERROR.exception("试卷结构同步失败:" + e.getMessage());
         } finally {
-//            examPaperStructure.setStatus(status);
             examPaperStructureService.updateStatusById(examPaperStructure.getId(), status);
         }
     }

+ 57 - 43
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamPaperStructureServiceImpl.java

@@ -81,7 +81,7 @@ public class ExamPaperStructureServiceImpl extends ServiceImpl<ExamPaperStructur
 
     @Transactional
     @Override
-    public ExamPaperStructure upload(String examPaperStructure, String md5, MultipartFile[] files) {
+    public ExamPaperStructure upload(String examPaperStructure, String md5, String keys, MultipartFile[] files) {
 
         ExamPaperStructure examPaperStructureTemp = JSONObject.parseObject(examPaperStructure, ExamPaperStructure.class);
         if (Objects.isNull(examPaperStructureTemp.getId())) {
@@ -93,7 +93,7 @@ public class ExamPaperStructureServiceImpl extends ServiceImpl<ExamPaperStructur
         }
 
         // 组装ExamPaperStructureDto
-        List<ExamPaperStructureDto> examPaperStructureDtos = createExamPaperStructure(md5, examPaperStructureTemp.getPaperType(), files);
+        List<ExamPaperStructureDto> examPaperStructureDtos = createExamPaperStructure(md5, keys, examPaperStructureTemp.getPaperType(), files);
         List<BasicAttachment> basicAttachmentList = new ArrayList<>();
 
         List<Map<String, Object>> paperAnswerList = new ArrayList<>();
@@ -112,31 +112,43 @@ public class ExamPaperStructureServiceImpl extends ServiceImpl<ExamPaperStructur
             Map<String, Object> objectiveStructureMap = new HashMap<>();
             objectiveStructureMap.put("paperType", examPaperStructureDto.getPaperType());
             try {
-                // 主观题附件
-                BasicAttachment subjectiveBasicAttachment = printCommonService.saveAttachment(examPaperStructureDto.getSubjectiveQuestionFile(), examPaperStructureDto.getSubjectiveQuestionMd5(), UploadFileEnum.UPLOAD);
-                if (Objects.isNull(subjectiveBasicAttachment)) {
-                    throw ExceptionResultEnum.ATTACHMENT_ERROR.exception();
-                }
-                // 解析试卷结构
-                List<Object> subjectiveStructrue = analyzPaperSubjectiveStructure(examPaperStructureDto.getSubjectiveQuestionFile());
-                subjectiveStructureMap.put("content", CollectionUtils.isEmpty(subjectiveStructrue) ? null : subjectiveStructrue);
                 // 客观题附件
-                basicAttachmentList.add(subjectiveBasicAttachment);
-                BasicAttachment objectiveBasicAttachment = printCommonService.saveAttachment(examPaperStructureDto.getObjectiveQuestionFile(), examPaperStructureDto.getObjectiveQuestionMd5(), UploadFileEnum.UPLOAD);
-                if (Objects.isNull(objectiveBasicAttachment)) {
-                    throw ExceptionResultEnum.ATTACHMENT_ERROR.exception();
+                List<Object> objectiveStructure = null;
+                if (examPaperStructureDto.getObjectiveQuestionFile() != null) {
+                    BasicAttachment objectiveBasicAttachment = printCommonService.saveAttachment(examPaperStructureDto.getObjectiveQuestionFile(), examPaperStructureDto.getObjectiveQuestionMd5(), UploadFileEnum.UPLOAD);
+                    if (Objects.isNull(objectiveBasicAttachment)) {
+                        throw ExceptionResultEnum.ATTACHMENT_ERROR.exception();
+                    }
+                    basicAttachmentList.add(objectiveBasicAttachment);
+                    // 解析试卷结构
+                    objectiveStructure = analyzPaperObjectiveStructure(examPaperStructureDto.getObjectiveQuestionFile());
                 }
-                // 解析试卷结构
-                List<Object> objectiveStructure = analyzPaperObjectiveStructure(examPaperStructureDto.getObjectiveQuestionFile());
                 objectiveStructureMap.put("content", CollectionUtils.isEmpty(objectiveStructure) ? null : objectiveStructure);
+
+                // 主观题附件
+                List<Object> subjectiveStructrue = null;
+                if (examPaperStructureDto.getSubjectiveQuestionFile() != null) {
+                    BasicAttachment subjectiveBasicAttachment = printCommonService.saveAttachment(examPaperStructureDto.getSubjectiveQuestionFile(), examPaperStructureDto.getSubjectiveQuestionMd5(), UploadFileEnum.UPLOAD);
+                    if (Objects.isNull(subjectiveBasicAttachment)) {
+                        throw ExceptionResultEnum.ATTACHMENT_ERROR.exception();
+                    }
+                    basicAttachmentList.add(subjectiveBasicAttachment);
+                    // 解析试卷结构
+                    subjectiveStructrue = analyzPaperSubjectiveStructure(examPaperStructureDto.getSubjectiveQuestionFile());
+                }
+                subjectiveStructureMap.put("content", CollectionUtils.isEmpty(subjectiveStructrue) ? null : subjectiveStructrue);
+
                 // 标答附件
-                basicAttachmentList.add(objectiveBasicAttachment);
-                BasicAttachment answerBasicAttachment = printCommonService.saveAttachment(examPaperStructureDto.getStandardAnswerFile(), examPaperStructureDto.getStandardAnswerMd5(), UploadFileEnum.UPLOAD);
-                if (Objects.isNull(answerBasicAttachment)) {
-                    throw ExceptionResultEnum.ATTACHMENT_ERROR.exception();
+                Long answerId = null;
+                if (examPaperStructureDto.getStandardAnswerFile() != null) {
+                    BasicAttachment answerBasicAttachment = printCommonService.saveAttachment(examPaperStructureDto.getStandardAnswerFile(), examPaperStructureDto.getStandardAnswerMd5(), UploadFileEnum.UPLOAD);
+                    if (Objects.isNull(answerBasicAttachment)) {
+                        throw ExceptionResultEnum.ATTACHMENT_ERROR.exception();
+                    }
+                    basicAttachmentList.add(answerBasicAttachment);
+                    answerId = answerBasicAttachment.getId();
                 }
-                paperAnswerMap.put("answer", answerBasicAttachment.getId());
-                basicAttachmentList.add(answerBasicAttachment);
+                paperAnswerMap.put("answer", answerId);
 
                 // 试卷原卷
                 paperAnswerMap.put("paper", paperMap.get(examPaperStructureDto.getPaperType()));
@@ -202,7 +214,7 @@ public class ExamPaperStructureServiceImpl extends ServiceImpl<ExamPaperStructur
         Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
         String[] structureStatusEnums = new String[]{ExamPaperStructureStatusEnum.FINISH.name()};
-        List<ExamPaperStructure> examPaperStructureList= this.baseMapper.listByPropositionTeacherId(schoolId, sysUser.getId(), ExamPrintPlanSyncStatusEnum.FINISH.name(), structureStatusEnums);
+        List<ExamPaperStructure> examPaperStructureList = this.baseMapper.listByPropositionTeacherId(schoolId, sysUser.getId(), ExamPrintPlanSyncStatusEnum.FINISH.name(), structureStatusEnums);
         return CollectionUtils.isEmpty(examPaperStructureList) ? 0 : examPaperStructureList.size();
     }
 
@@ -346,35 +358,37 @@ public class ExamPaperStructureServiceImpl extends ServiceImpl<ExamPaperStructur
      * @param files
      * @return
      */
-    private List<ExamPaperStructureDto> createExamPaperStructure(String md5, String paperType, MultipartFile[] files) {
-        int COUNT = 3;
-        if (files.length == 0) {
-            throw ExceptionResultEnum.ERROR.exception("请上传文件");
-        }
+    private List<ExamPaperStructureDto> createExamPaperStructure(String md5, String keys, String paperType, MultipartFile[] files) {
         if (StringUtils.isBlank(paperType)) {
-            throw ExceptionResultEnum.ERROR.exception("试卷卷型有误");
+            throw ExceptionResultEnum.ERROR.exception("没有可上传文件的试卷卷型");
         }
-        String[] paperTypes = paperType.split(",");
-        if (paperTypes.length * COUNT - files.length != 0) {
-            throw ExceptionResultEnum.ERROR.exception("上传文件有误");
+        if (files == null || files.length == 0) {
+            throw ExceptionResultEnum.ERROR.exception("请上传文件");
         }
-        if (StringUtils.isBlank(md5)) {
+        if (StringUtils.isBlank(keys)) {
             throw ExceptionResultEnum.ERROR.exception("上传文件有误");
         }
-        String[] md5s = md5.split(",");
-        if (md5s.length - files.length != 0) {
+        if (StringUtils.isBlank(md5)) {
             throw ExceptionResultEnum.ERROR.exception("上传文件有误");
         }
+        String[] paperTypesAttr = paperType.split(",");
+        String[] md5sAttr = md5.split(",");
+        String[] keysAttr = keys.split(",");
+        String[] fileTypeAttr = {"objectiveQuestion", "subjectiveQuestion", "standardAnswer"};
         List<ExamPaperStructureDto> list = new ArrayList<>();
-        for (int i = 0; i < paperTypes.length; i++) {
+
+        for (String pType : paperTypesAttr) {
             ExamPaperStructureDto examPaperStructureDto = new ExamPaperStructureDto();
-            examPaperStructureDto.setPaperType(paperTypes[i]);
-            examPaperStructureDto.setObjectiveQuestionFile(files[COUNT * i]);
-            examPaperStructureDto.setObjectiveQuestionMd5(md5s[COUNT * i]);
-            examPaperStructureDto.setSubjectiveQuestionFile(files[COUNT * i + 1]);
-            examPaperStructureDto.setSubjectiveQuestionMd5(md5s[COUNT * i + 1]);
-            examPaperStructureDto.setStandardAnswerFile(files[COUNT * i + 2]);
-            examPaperStructureDto.setStandardAnswerMd5(md5s[COUNT * i + 2]);
+            examPaperStructureDto.setPaperType(pType);
+            int oi = Arrays.asList(keysAttr).indexOf(pType + "-" + fileTypeAttr[0]);
+            examPaperStructureDto.setObjectiveQuestionFile(oi < 0 ? null : files[oi]);
+            examPaperStructureDto.setObjectiveQuestionMd5(oi < 0 ? null : md5sAttr[oi]);
+            int si = Arrays.asList(keysAttr).indexOf(pType + "-" + fileTypeAttr[1]);
+            examPaperStructureDto.setSubjectiveQuestionFile(si < 0 ? null : files[si]);
+            examPaperStructureDto.setSubjectiveQuestionMd5(si < 0 ? null : md5sAttr[si]);
+            int ai = Arrays.asList(keysAttr).indexOf(pType + "-" + fileTypeAttr[2]);
+            examPaperStructureDto.setStandardAnswerFile(ai < 0 ? null : files[ai]);
+            examPaperStructureDto.setStandardAnswerMd5(ai < 0 ? null : md5sAttr[ai]);
             list.add(examPaperStructureDto);
         }
         return list;

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

@@ -66,8 +66,9 @@ public class ExamPaperStructureController {
     @RequestMapping(value = "/upload", method = RequestMethod.POST)
     public Result upload(@RequestParam("examPaperStructure") String examPaperStructure,
                          @RequestParam("md5") String md5,
+                         @RequestParam("keys") String keys,
                          @RequestParam("files") MultipartFile[] files) {
-        ExamPaperStructure examPaper = examPaperStructureService.upload(examPaperStructure, md5, files);
+        ExamPaperStructure examPaper = examPaperStructureService.upload(examPaperStructure, md5, keys, files);
         // 推送云阅卷
         dataSyncService.syncPaperStructure(examPaper);
         return ResultUtil.ok(String.valueOf(examPaper.getId()), null);