|
@@ -1,6 +1,7 @@
|
|
package com.qmth.distributed.print.business.service.impl;
|
|
package com.qmth.distributed.print.business.service.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
@@ -41,6 +42,7 @@ import java.io.*;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.Executors;
|
|
import java.util.concurrent.Executors;
|
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -165,89 +167,152 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
throw ExceptionResultEnum.ERROR.exception("没有找到标答文件");
|
|
throw ExceptionResultEnum.ERROR.exception("没有找到标答文件");
|
|
}
|
|
}
|
|
|
|
|
|
- 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("没有找到标答文件");
|
|
|
|
|
|
+ String paperTypes = examPaperStructure.getPaperType();
|
|
|
|
+ if (StringUtils.isBlank(paperTypes)) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("没有找到试卷类型");
|
|
}
|
|
}
|
|
|
|
|
|
- // 同步试卷文件
|
|
|
|
- File paperFile = downFileFromFss(paper, paperType, SyncFileTypeEnum.PAPER);
|
|
|
|
- boolean syncPaperFile = stmmsUtils.syncFile(examPaperStructure.getSchoolId(), String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumber(), SyncFileTypeEnum.PAPER, paperFile);
|
|
|
|
- if (syncPaperFile) {
|
|
|
|
|
|
+ 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("试卷对应的类型有误");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 同步试卷文件
|
|
|
|
+ File paperFile = downFileFromFss(paper, paperType, SyncFileTypeEnum.PAPER);
|
|
|
|
+ String syncPaperFileUrl = stmmsUtils.syncFile(examPaperStructure.getSchoolId(), String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumber() + paperType, SyncFileTypeEnum.PAPER, paperFile);
|
|
|
|
+ if (StringUtils.isNotBlank(syncPaperFileUrl)) {
|
|
|
|
+ atomicInteger.getAndIncrement();
|
|
|
|
+ }
|
|
|
|
+ // 试卷文件保存url
|
|
|
|
+ paperAnswerJson.put("paperUrl", syncPaperFileUrl);
|
|
|
|
+ }
|
|
|
|
+ if (atomicInteger.intValue() - paperAnswerJsons.size() == 0) {
|
|
status = ExamPaperStructureStatusEnum.PAPER_FINISH;
|
|
status = ExamPaperStructureStatusEnum.PAPER_FINISH;
|
|
|
|
+ examPaperStructure.setPaperAnswer(JSONObject.toJSONString(paperAnswerJsons));
|
|
}
|
|
}
|
|
|
|
|
|
- // 同步标答文件
|
|
|
|
- File answerFile = downFileFromFss(paper, paperType, SyncFileTypeEnum.PAPER);
|
|
|
|
- boolean syncAnswerFile = stmmsUtils.syncFile(examPaperStructure.getSchoolId(), String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumber(), SyncFileTypeEnum.ANSWER, answerFile);
|
|
|
|
- if (syncAnswerFile) {
|
|
|
|
|
|
+ // 同步标答
|
|
|
|
+ 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.getPaperNumber() + paperType, SyncFileTypeEnum.ANSWER, answerFile);
|
|
|
|
+ if (StringUtils.isNotBlank(syncAnswerFileUrl)) {
|
|
|
|
+ atomicInteger.getAndIncrement();
|
|
|
|
+ }
|
|
|
|
+ // 标答文件保存url
|
|
|
|
+ paperAnswerJson.put("answerUrl", syncAnswerFileUrl);
|
|
|
|
+ }
|
|
|
|
+ if (atomicInteger.intValue() - paperAnswerJsons.size() == 0) {
|
|
status = ExamPaperStructureStatusEnum.ANSWER_FINISH;
|
|
status = ExamPaperStructureStatusEnum.ANSWER_FINISH;
|
|
|
|
+ examPaperStructure.setPaperAnswer(JSONObject.toJSONString(paperAnswerJsons));
|
|
}
|
|
}
|
|
|
|
+
|
|
// 同步客观题
|
|
// 同步客观题
|
|
|
|
+ atomicInteger.set(0);
|
|
String objectiveStructure = examPaperStructure.getObjectiveStructure();
|
|
String objectiveStructure = examPaperStructure.getObjectiveStructure();
|
|
if (StringUtils.isBlank(objectiveStructure)) {
|
|
if (StringUtils.isBlank(objectiveStructure)) {
|
|
throw ExceptionResultEnum.ERROR.exception("没有找到客观题数据");
|
|
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<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<SyncStructureData> syncObjectiveStructureDatas = objectiveStructureDtos.stream().map(m -> {
|
|
|
|
+ SyncStructureData syncStructureData = new SyncStructureData();
|
|
|
|
+ syncStructureData.setMainNumber(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.getPaperNumber() + objectivePaperType, true, objectivePaperType, syncObjectiveStructureDatas);
|
|
|
|
+ if (syncObjectiveStructure) {
|
|
|
|
+ atomicInteger.getAndIncrement();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- 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(examPaperStructure.getSchoolId(), String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumber() + objectivePaperType, true, objectivePaperType, syncObjectiveStructureDatas);
|
|
|
|
- if (syncObjectiveStructure) {
|
|
|
|
|
|
+ if (atomicInteger.intValue() - paperAnswerJsons.size() == 0) {
|
|
status = ExamPaperStructureStatusEnum.OBJECTIVE_FINISH;
|
|
status = ExamPaperStructureStatusEnum.OBJECTIVE_FINISH;
|
|
}
|
|
}
|
|
|
|
+
|
|
// 同步主观题
|
|
// 同步主观题
|
|
|
|
+ atomicInteger.set(0);
|
|
String subjectiveStructure = examPaperStructure.getSubjectiveStructure();
|
|
String subjectiveStructure = examPaperStructure.getSubjectiveStructure();
|
|
if (StringUtils.isBlank(subjectiveStructure)) {
|
|
if (StringUtils.isBlank(subjectiveStructure)) {
|
|
throw ExceptionResultEnum.ERROR.exception("没有找到主观题数据");
|
|
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 subjectiveContent = subjectiveJson.getString("content");
|
|
|
|
- if (StringUtils.isAnyBlank(subjectivePaperType, subjectiveContent)) {
|
|
|
|
- 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<SyncStructureData> syncSubjectiveStructureDatas = subjectiveStructureDtos.stream().map(m -> {
|
|
|
|
+ SyncStructureData syncStructureData = new SyncStructureData();
|
|
|
|
+ syncStructureData.setMainNumber(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.getPaperNumber() + subjectivePaperType, true, subjectivePaperType, syncSubjectiveStructureDatas);
|
|
|
|
+ if (syncSubjectiveStructure) {
|
|
|
|
+ atomicInteger.getAndIncrement();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- List<ExamPaperSubjectiveStructureDto> subjectiveStructureDtos = JSONObject.parseArray(subjectiveContent, 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(examPaperStructure.getSchoolId(), String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumber() + subjectivePaperType, true, subjectivePaperType, syncSubjectiveStructureDatas);
|
|
|
|
- if (syncSubjectiveStructure) {
|
|
|
|
- status = ExamPaperStructureStatusEnum.SUBJECTIVE_FINISH;
|
|
|
|
|
|
+ if (atomicInteger.intValue() - paperAnswerJsons.size() == 0) {
|
|
|
|
+ status = ExamPaperStructureStatusEnum.FINISH;
|
|
}
|
|
}
|
|
|
|
+
|
|
} catch (ApiException e) {
|
|
} catch (ApiException e) {
|
|
throw ExceptionResultEnum.ERROR.exception("试卷结构同步失败:" + e.getMessage());
|
|
throw ExceptionResultEnum.ERROR.exception("试卷结构同步失败:" + e.getMessage());
|
|
} finally {
|
|
} finally {
|
|
- examPaperStructureService.updateStatusById(examPaperStructure.getId(), status);
|
|
|
|
|
|
+ examPaperStructure.setStatus(status);
|
|
|
|
+ examPaperStructureService.updateById(examPaperStructure);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -384,31 +449,40 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ String paperType = examDetailCours.getPaperType();
|
|
|
|
+ if (StringUtils.isBlank(paperType)) {
|
|
|
|
+ log.info("数据异常,通过学校:{},课程代码:{},试卷编号:{}查出绑定试卷类型为空", examDetailCours.getSchoolId(), examDetailCours.getCourseCode(), examDetailCours.getPaperNumber());
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
SyncExamCardDto syncExamCardDto = syncExamCardDtos.get(0);
|
|
SyncExamCardDto syncExamCardDto = syncExamCardDtos.get(0);
|
|
if (StringUtils.isNotEmpty(syncExamCardDto.getContent())) {
|
|
if (StringUtils.isNotEmpty(syncExamCardDto.getContent())) {
|
|
- //生成json文件
|
|
|
|
- File file = null;
|
|
|
|
- try {
|
|
|
|
- // 文件临时目录
|
|
|
|
- String filePath = getTempDir(SyncFileTypeEnum.CARD);
|
|
|
|
- file = createJsonFile(filePath, syncExamCardDto.getContent());
|
|
|
|
- if (file.exists()) {
|
|
|
|
- boolean uploadCard = stmmsUtils.syncFile(schoolId, String.valueOf(thirdRelateId), syncExamCardDto.getPaperNumber(), SyncFileTypeEnum.CARD, file);
|
|
|
|
- if (uploadCard) {
|
|
|
|
- UpdateWrapper<ExamCard> updateWrapper = new UpdateWrapper<>();
|
|
|
|
- updateWrapper.lambda().set(ExamCard::getSyncStatus, true).eq(ExamCard::getId, syncExamCardDto.getId());
|
|
|
|
- examCardService.update(updateWrapper);
|
|
|
|
|
|
+ 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 = stmmsUtils.syncFile(schoolId, String.valueOf(thirdRelateId), syncExamCardDto.getPaperNumber() + s, 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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(e.getMessage());
|
|
|
|
+ } finally {
|
|
|
|
+ if (file != null && file.exists()) {
|
|
|
|
+ file.delete();
|
|
}
|
|
}
|
|
- }
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception(e.getMessage());
|
|
|
|
- } finally {
|
|
|
|
- if (file != null && file.exists()) {
|
|
|
|
- file.delete();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|