|
@@ -1,5 +1,7 @@
|
|
package com.qmth.jkserver.service.impl;
|
|
package com.qmth.jkserver.service.impl;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.qmth.jkserver.constant.SystemConstant;
|
|
import com.qmth.jkserver.constant.SystemConstant;
|
|
import com.qmth.jkserver.core.exception.JkServerException;
|
|
import com.qmth.jkserver.core.exception.JkServerException;
|
|
@@ -12,15 +14,23 @@ import com.qmth.jkserver.params.callApi.SaveSubjectParams;
|
|
import com.qmth.jkserver.params.callApi.fileUpload.JsonFileParams;
|
|
import com.qmth.jkserver.params.callApi.fileUpload.JsonFileParams;
|
|
import com.qmth.jkserver.params.callApi.fileUpload.PaperFileParams;
|
|
import com.qmth.jkserver.params.callApi.fileUpload.PaperFileParams;
|
|
import com.qmth.jkserver.service.*;
|
|
import com.qmth.jkserver.service.*;
|
|
|
|
+import com.qmth.jkserver.util.Base64Util;
|
|
|
|
+import com.qmth.jkserver.util.FileStoreUtil;
|
|
|
|
+import com.qmth.jkserver.util.JacksonUtil;
|
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.context.annotation.Scope;
|
|
import org.springframework.context.annotation.Scope;
|
|
import org.springframework.context.annotation.ScopedProxyMode;
|
|
import org.springframework.context.annotation.ScopedProxyMode;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
+import java.io.FileInputStream;
|
|
|
|
+import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
@@ -61,6 +71,9 @@ public class JointFlowSimulationServiceImpl implements JointFlowSimulationServic
|
|
@Resource
|
|
@Resource
|
|
CommonCacheService commonCacheService;
|
|
CommonCacheService commonCacheService;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ FileStoreUtil fileStoreUtil;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Map<String, Object> saveYunExam(Map<String, Object> map) throws IOException, IllegalAccessException {
|
|
public Map<String, Object> saveYunExam(Map<String, Object> map) throws IOException, IllegalAccessException {
|
|
ExamTask examTask = (ExamTask) map.get(SystemConstant.TASK);
|
|
ExamTask examTask = (ExamTask) map.get(SystemConstant.TASK);
|
|
@@ -151,6 +164,9 @@ public class JointFlowSimulationServiceImpl implements JointFlowSimulationServic
|
|
throw new JkServerException("没有找到试卷编号为[" + yunSubjectCode + "]的试卷文件");
|
|
throw new JkServerException("没有找到试卷编号为[" + yunSubjectCode + "]的试卷文件");
|
|
}
|
|
}
|
|
File paperFile = paperFileList.get(0);
|
|
File paperFile = paperFileList.get(0);
|
|
|
|
+ //解析试卷
|
|
|
|
+ Map<String, Object> jsonMap = this.disposeQuestionUrl(paperFile);
|
|
|
|
+ IOUtils.write(JacksonUtil.parseJson(jsonMap).getBytes(SystemConstant.CHARSET_NAME), new FileOutputStream(paperFile));
|
|
// 上传试卷结构和答案
|
|
// 上传试卷结构和答案
|
|
this.savePaperAndAnswer(map, yunExamId, yunSubjectCode, paperFile);
|
|
this.savePaperAndAnswer(map, yunExamId, yunSubjectCode, paperFile);
|
|
|
|
|
|
@@ -175,7 +191,7 @@ public class JointFlowSimulationServiceImpl implements JointFlowSimulationServic
|
|
!e.getIsAbsent() &&
|
|
!e.getIsAbsent() &&
|
|
paperId.equals(e.getPaperId()) &&
|
|
paperId.equals(e.getPaperId()) &&
|
|
Objects.equals(examStudent.getBatchId(), key)
|
|
Objects.equals(examStudent.getBatchId(), key)
|
|
-// && (e.getTaskSyncResult() == null || !e.getTaskSyncResult())
|
|
|
|
|
|
+ && (e.getTaskSyncResult() == null || !e.getTaskSyncResult())
|
|
) {
|
|
) {
|
|
return true;
|
|
return true;
|
|
} else {
|
|
} else {
|
|
@@ -269,12 +285,12 @@ public class JointFlowSimulationServiceImpl implements JointFlowSimulationServic
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
map = this.saveStudentJson(map, yunExamId, examNumber, thisJsonList.get(0));
|
|
map = this.saveStudentJson(map, yunExamId, examNumber, thisJsonList.get(0));
|
|
|
|
+ examStudentAnswer.setTaskSyncResult(true);
|
|
}
|
|
}
|
|
// 考生创建完毕同时有作答的也生成完毕了 考生上传成功 任务完成数++
|
|
// 考生创建完毕同时有作答的也生成完毕了 考生上传成功 任务完成数++
|
|
AtomicInteger completeProgress = new AtomicInteger(examTask.getCompleteProgress());
|
|
AtomicInteger completeProgress = new AtomicInteger(examTask.getCompleteProgress());
|
|
completeProgress.incrementAndGet();
|
|
completeProgress.incrementAndGet();
|
|
examTask.setCompleteProgress(completeProgress.get());
|
|
examTask.setCompleteProgress(completeProgress.get());
|
|
-
|
|
|
|
// examStudentAnswer.setTaskSyncResult(true);
|
|
// examStudentAnswer.setTaskSyncResult(true);
|
|
// examStudentAnswer.setExamTask(examTask);
|
|
// examStudentAnswer.setExamTask(examTask);
|
|
// mongoTemplate.save(examStudentAnswer);
|
|
// mongoTemplate.save(examStudentAnswer);
|
|
@@ -446,4 +462,89 @@ public class JointFlowSimulationServiceImpl implements JointFlowSimulationServic
|
|
return Arrays.asList(Objects.requireNonNull(tempList.get(0).listFiles()));
|
|
return Arrays.asList(Objects.requireNonNull(tempList.get(0).listFiles()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 解析试卷
|
|
|
|
+ *
|
|
|
|
+ * @param paperFile
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ public Map<String, Object> disposeQuestionUrl(File paperFile) throws Exception {
|
|
|
|
+ Map<String, Object> jsonMap = new LinkedHashMap<>();
|
|
|
|
+ byte[] bytes = IOUtils.toByteArray(new FileInputStream(paperFile));
|
|
|
|
+ jsonMap = JSONArray.parseObject(new String(bytes, SystemConstant.CHARSET_NAME), Map.class);
|
|
|
|
+ if (!CollectionUtils.isEmpty(jsonMap)) {
|
|
|
|
+ JSONArray structdetails = (JSONArray) jsonMap.get("details");
|
|
|
|
+ if (Objects.nonNull(structdetails) && structdetails.size() > 0) {
|
|
|
|
+ for (int i = 0; i < structdetails.size(); i++) {
|
|
|
|
+ JSONArray structdetailquestions = structdetails.getJSONObject(i).getJSONArray("questions");
|
|
|
|
+ if (Objects.nonNull(structdetailquestions) && structdetailquestions.size() > 0) {
|
|
|
|
+ for (int j = 0; j < structdetailquestions.size(); j++) {
|
|
|
|
+ JSONObject structquestion = structdetailquestions.getJSONObject(j);
|
|
|
|
+ JSONObject body = structquestion.getJSONObject(SystemConstant.BODY);
|
|
|
|
+ this.resolveImageAndAudio(paperFile, body);
|
|
|
|
+ JSONArray options = structquestion.getJSONArray("options");
|
|
|
|
+ if (Objects.nonNull(options) && options.size() > 0) {
|
|
|
|
+ for (int k = 0; k < options.size(); k++) {
|
|
|
|
+ JSONObject option = options.getJSONObject(k);
|
|
|
|
+ if (Objects.nonNull(option)) {
|
|
|
|
+ JSONObject optionBody = option.getJSONObject(SystemConstant.BODY);
|
|
|
|
+ this.resolveImageAndAudio(paperFile, optionBody);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return jsonMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * base64图片和音频
|
|
|
|
+ *
|
|
|
|
+ * @param paperFile
|
|
|
|
+ * @param body
|
|
|
|
+ */
|
|
|
|
+ public void resolveImageAndAudio(File paperFile, JSONObject body) {
|
|
|
|
+ if (Objects.nonNull(body)) {
|
|
|
|
+ JSONArray sections = body.getJSONArray("sections");
|
|
|
|
+ if (Objects.nonNull(sections) && sections.size() > 0) {
|
|
|
|
+ for (int k = 0; k < sections.size(); k++) {
|
|
|
|
+ JSONObject block = sections.getJSONObject(k);
|
|
|
|
+ if (block != null) {
|
|
|
|
+ JSONArray blocks = block.getJSONArray("blocks");
|
|
|
|
+ if (Objects.nonNull(blocks) && blocks.size() > 0) {
|
|
|
|
+ for (int m = 0; m < blocks.size(); m++) {
|
|
|
|
+ JSONObject blockInfo = blocks.getJSONObject(m);
|
|
|
|
+ String type = blockInfo.getString(SystemConstant.TYPE);
|
|
|
|
+ String value = blockInfo.getString("value");
|
|
|
|
+ File attachmentDir = new File(paperFile.getParentFile().getParentFile(), "attachment" + File.separator + value);
|
|
|
|
+ if (("image".equals(type) || "audio".equals(type)) && StringUtils.isNotBlank(value) && !value.toLowerCase()
|
|
|
|
+ .startsWith("https://") && !value.toLowerCase().startsWith("http://")) {
|
|
|
|
+ if ("image".equals(type)) {
|
|
|
|
+ if (value.contains("data:image")) {
|
|
|
|
+ blockInfo.put("value", value);
|
|
|
|
+ } else {
|
|
|
|
+ String base64Str = Base64Util.imageToBase64(attachmentDir);
|
|
|
|
+ blockInfo.put("value", base64Str);
|
|
|
|
+ }
|
|
|
|
+ } else if ("audio".equals(type)) {
|
|
|
|
+ if (value.contains("data:audio")) {
|
|
|
|
+ blockInfo.put("value", value);
|
|
|
|
+ } else {
|
|
|
|
+ String base64Str = Base64Util.audioToBase64(attachmentDir);
|
|
|
|
+ blockInfo.put("value", base64Str);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|