|
@@ -41,7 +41,6 @@ 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;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -204,156 +203,110 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
examPaperStructureService.updateStatusById(examPaperStructure.getId(), ExamPaperStructureStatusEnum.START_SYNC);
|
|
examPaperStructureService.updateStatusById(examPaperStructure.getId(), ExamPaperStructureStatusEnum.START_SYNC);
|
|
ExamPaperStructureStatusEnum status = ExamPaperStructureStatusEnum.UPLOAD_FINISH;
|
|
ExamPaperStructureStatusEnum status = ExamPaperStructureStatusEnum.UPLOAD_FINISH;
|
|
try {
|
|
try {
|
|
- String paperAnswer = examPaperStructure.getPaperAnswer();
|
|
|
|
- if (StringUtils.isBlank(paperAnswer)) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("没有找到标答文件");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
String paperTypes = examPaperStructure.getPaperType();
|
|
String paperTypes = examPaperStructure.getPaperType();
|
|
if (StringUtils.isBlank(paperTypes)) {
|
|
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;
|
|
status = ExamPaperStructureStatusEnum.PAPER_FINISH;
|
|
examPaperStructure.setPaperAnswer(JSONObject.toJSONString(paperAnswerJsons));
|
|
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));
|
|
examPaperStructure.setPaperAnswer(JSONObject.toJSONString(paperAnswerJsons));
|
|
}
|
|
}
|
|
|
|
+ status = ExamPaperStructureStatusEnum.ANSWER_FINISH;
|
|
|
|
|
|
// 同步客观题
|
|
// 同步客观题
|
|
- atomicInteger.set(0);
|
|
|
|
String objectiveStructure = examPaperStructure.getObjectiveStructure();
|
|
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();
|
|
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) {
|
|
} catch (ApiException e) {
|
|
throw ExceptionResultEnum.ERROR.exception("试卷结构同步失败:" + e.getMessage());
|
|
throw ExceptionResultEnum.ERROR.exception("试卷结构同步失败:" + e.getMessage());
|
|
} finally {
|
|
} finally {
|
|
-// examPaperStructure.setStatus(status);
|
|
|
|
examPaperStructureService.updateStatusById(examPaperStructure.getId(), status);
|
|
examPaperStructureService.updateStatusById(examPaperStructure.getId(), status);
|
|
}
|
|
}
|
|
}
|
|
}
|