|
@@ -1,31 +1,9 @@
|
|
package com.qmth.themis.business.templete.impl;
|
|
package com.qmth.themis.business.templete.impl;
|
|
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.io.FilenameFilter;
|
|
|
|
-import java.io.IOException;
|
|
|
|
-import java.math.BigDecimal;
|
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Collections;
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.Objects;
|
|
|
|
-import java.util.UUID;
|
|
|
|
-
|
|
|
|
-import javax.annotation.Resource;
|
|
|
|
-
|
|
|
|
-import org.apache.commons.io.FileUtils;
|
|
|
|
-import org.apache.commons.lang3.RandomStringUtils;
|
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
|
-import org.slf4j.Logger;
|
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
-
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.aliyun.oss.common.utils.BinaryUtil;
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
import com.qmth.themis.business.entity.TEExam;
|
|
import com.qmth.themis.business.entity.TEExam;
|
|
import com.qmth.themis.business.entity.TEExamCourse;
|
|
import com.qmth.themis.business.entity.TEExamCourse;
|
|
@@ -48,9 +26,22 @@ import com.qmth.themis.common.exception.BusinessException;
|
|
import com.qmth.themis.common.util.FileUtil;
|
|
import com.qmth.themis.common.util.FileUtil;
|
|
import com.qmth.themis.common.util.Result;
|
|
import com.qmth.themis.common.util.Result;
|
|
import com.qmth.themis.common.util.ResultUtil;
|
|
import com.qmth.themis.common.util.ResultUtil;
|
|
|
|
+import org.apache.commons.codec.binary.Base64;
|
|
|
|
+import org.apache.commons.lang3.RandomStringUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
|
-import sun.misc.BASE64Decoder;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FilenameFilter;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Description: 试卷导入
|
|
* @Description: 试卷导入
|
|
@@ -169,7 +160,8 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void disposeCourseDir(String rootDir, TEExam teExam, File courseDir, Map<String, Object> map) {
|
|
|
|
|
|
+ private void disposeCourseDir(String rootDir, TEExam teExam, File courseDir, Map<String, Object> map)
|
|
|
|
+ throws IOException {
|
|
String courseCode = courseDir.getName();
|
|
String courseCode = courseDir.getName();
|
|
TEExamCourse course = teExamCourseService.findByExamIdAndCourseCode(teExam.getId(), courseCode);
|
|
TEExamCourse course = teExamCourseService.findByExamIdAndCourseCode(teExam.getId(), courseCode);
|
|
if (course == null) {
|
|
if (course == null) {
|
|
@@ -237,7 +229,7 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
}
|
|
}
|
|
|
|
|
|
private void disposePaperDir(String rootDir, TEExam teExam, TEExamCourse course, File paperDir,
|
|
private void disposePaperDir(String rootDir, TEExam teExam, TEExamCourse course, File paperDir,
|
|
- Map<String, Object> map) {
|
|
|
|
|
|
+ Map<String, Object> map) throws IOException {
|
|
String paperCode = paperDir.getName();
|
|
String paperCode = paperDir.getName();
|
|
File[] childs = paperDir.listFiles();
|
|
File[] childs = paperDir.listFiles();
|
|
|
|
|
|
@@ -298,8 +290,8 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
teExamPaperService.saveOrUpdate(paper);
|
|
teExamPaperService.saveOrUpdate(paper);
|
|
}
|
|
}
|
|
|
|
|
|
- private void disposeViewPaper(String rootDir, TEExamPaper paper, File paperFile, File attachmentDir) {
|
|
|
|
- File urlPaperFile = new File(rootDir + uuid() + ".json");
|
|
|
|
|
|
+ private void disposeViewPaper(String rootDir, TEExamPaper paper, File paperFile, File attachmentDir)
|
|
|
|
+ throws IOException {
|
|
JSONObject structJson = JSONObject.parseObject(FileUtil.readFileContent(paperFile));
|
|
JSONObject structJson = JSONObject.parseObject(FileUtil.readFileContent(paperFile));
|
|
JSONArray structdetails = structJson.getJSONArray("details");
|
|
JSONArray structdetails = structJson.getJSONArray("details");
|
|
if (structdetails == null || structdetails.size() == 0) {
|
|
if (structdetails == null || structdetails.size() == 0) {
|
|
@@ -327,13 +319,13 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- FileUtil.saveAsFile(urlPaperFile.getAbsolutePath(), structJson.toJSONString());
|
|
|
|
String filePath = sdf.format(new Date()) + "/" + uuid() + ".json";
|
|
String filePath = sdf.format(new Date()) + "/" + uuid() + ".json";
|
|
paper.setPaperViewPath(filePath);
|
|
paper.setPaperViewPath(filePath);
|
|
- ossUtil.upload(false, filePath, urlPaperFile);
|
|
|
|
|
|
+ ossUtil.upload(false, filePath, structJson.toJSONString());
|
|
}
|
|
}
|
|
|
|
|
|
- private void disposeQuestionBodyUrl(String rootDir, JSONObject body, Long paperId, File attachmentDir) {
|
|
|
|
|
|
+ private void disposeQuestionBodyUrl(String rootDir, JSONObject body, Long paperId, File attachmentDir)
|
|
|
|
+ throws IOException {
|
|
if (body == null) {
|
|
if (body == null) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -355,7 +347,8 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void disposeQuestionOptionsUrl(String rootDir, JSONArray options, Long paperId, File attachmentDir) {
|
|
|
|
|
|
+ private void disposeQuestionOptionsUrl(String rootDir, JSONArray options, Long paperId, File attachmentDir)
|
|
|
|
+ throws IOException {
|
|
if (options == null || options.size() == 0) {
|
|
if (options == null || options.size() == 0) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -384,7 +377,8 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void disposePaper(String rootDir, TEExamPaper paper, File paperFile, File attachmentDir) {
|
|
|
|
|
|
+ private void disposePaper(String rootDir, TEExamPaper paper, File paperFile, File attachmentDir)
|
|
|
|
+ throws IOException {
|
|
if (paperFile == null) {
|
|
if (paperFile == null) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -449,21 +443,18 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- File file = new File(rootDir + uuid() + ".json");
|
|
|
|
- FileUtil.saveAsFile(file.getAbsolutePath(), paperJson.toJSONString());
|
|
|
|
String filePath = sdf.format(new Date()) + "/" + uuid() + ".json";
|
|
String filePath = sdf.format(new Date()) + "/" + uuid() + ".json";
|
|
paper.setStructPath(filePath);
|
|
paper.setStructPath(filePath);
|
|
paper.setTotalObjectiveScore(obTotal.doubleValue());
|
|
paper.setTotalObjectiveScore(obTotal.doubleValue());
|
|
paper.setTotalSubjectiveScore(subTotal.doubleValue());
|
|
paper.setTotalSubjectiveScore(subTotal.doubleValue());
|
|
- ossUtil.upload(false, filePath, file);
|
|
|
|
|
|
+ ossUtil.upload(false, filePath, paperJson.toJSONString());
|
|
}
|
|
}
|
|
|
|
|
|
- private void disposeAnswer(String rootDir, TEExamPaper paper, File answerFile, File structFile,
|
|
|
|
- File attachmentDir) {
|
|
|
|
|
|
+ private void disposeAnswer(String rootDir, TEExamPaper paper, File answerFile, File structFile, File attachmentDir)
|
|
|
|
+ throws IOException {
|
|
if (answerFile == null) {
|
|
if (answerFile == null) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- File urlAnswerFile = new File(rootDir + uuid() + ".json");
|
|
|
|
JSONObject answerJson = JSONObject.parseObject(FileUtil.readFileContent(answerFile));
|
|
JSONObject answerJson = JSONObject.parseObject(FileUtil.readFileContent(answerFile));
|
|
JSONArray answerdetails = answerJson.getJSONArray("details");
|
|
JSONArray answerdetails = answerJson.getJSONArray("details");
|
|
JSONObject structJson = JSONObject.parseObject(FileUtil.readFileContent(structFile));
|
|
JSONObject structJson = JSONObject.parseObject(FileUtil.readFileContent(structFile));
|
|
@@ -497,13 +488,13 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- FileUtil.saveAsFile(urlAnswerFile.getAbsolutePath(), answerJson.toJSONString());
|
|
|
|
String filePath = sdf.format(new Date()) + "/" + uuid() + ".json";
|
|
String filePath = sdf.format(new Date()) + "/" + uuid() + ".json";
|
|
paper.setAnswerPath(filePath);
|
|
paper.setAnswerPath(filePath);
|
|
- ossUtil.upload(false, filePath, urlAnswerFile);
|
|
|
|
|
|
+ ossUtil.upload(false, filePath, answerJson.toJSONString());
|
|
}
|
|
}
|
|
|
|
|
|
- private void disposeAnswerUrl(String rootDir, JSONArray answer, Long paperId, File attachmentDir) {
|
|
|
|
|
|
+ private void disposeAnswerUrl(String rootDir, JSONArray answer, Long paperId, File attachmentDir)
|
|
|
|
+ throws IOException {
|
|
if (answer != null && answer.size() > 0) {
|
|
if (answer != null && answer.size() > 0) {
|
|
for (int i = 0; i < answer.size(); i++) {
|
|
for (int i = 0; i < answer.size(); i++) {
|
|
JSONObject section = answer.getJSONObject(i);
|
|
JSONObject section = answer.getJSONObject(i);
|
|
@@ -528,30 +519,27 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void uploadImageAndAudio(String rootDir, JSONObject blockInfo, Long paperId, File attachmentDir) {
|
|
|
|
|
|
+ private void uploadImageAndAudio(String rootDir, JSONObject blockInfo, Long paperId, File attachmentDir)
|
|
|
|
+ throws IOException {
|
|
String type = blockInfo.getString("type");
|
|
String type = blockInfo.getString("type");
|
|
String value = blockInfo.getString("value");
|
|
String value = blockInfo.getString("value");
|
|
if (("image".equals(type) || "audio".equals(type)) && StringUtils.isNotBlank(value) && !value.toLowerCase()
|
|
if (("image".equals(type) || "audio".equals(type)) && StringUtils.isNotBlank(value) && !value.toLowerCase()
|
|
.startsWith("https://") && !value.toLowerCase().startsWith("http://")) {
|
|
.startsWith("https://") && !value.toLowerCase().startsWith("http://")) {
|
|
if ("image".equals(type) && value.contains("data:image")) {
|
|
if ("image".equals(type) && value.contains("data:image")) {
|
|
String suff = value.substring(11, value.indexOf(";"));
|
|
String suff = value.substring(11, value.indexOf(";"));
|
|
- File iamgeFile = new File(rootDir + uuid() + "." + suff);
|
|
|
|
- BASE64Decoder decoder = new BASE64Decoder();
|
|
|
|
- try {
|
|
|
|
- byte[] bytes = decoder.decodeBuffer(value.substring(value.indexOf(",") + 1));
|
|
|
|
- FileUtils.writeByteArrayToFile(iamgeFile, bytes);
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- throw new BusinessException("媒体文件上传处理出错:" + blockInfo.toJSONString() + " errmsg:" + e.getMessage());
|
|
|
|
- }
|
|
|
|
- String filePath = "upload/paper_file/" + paperId + "/" + uuid() + "." + suff;
|
|
|
|
- ossUtil.upload(false, filePath, iamgeFile);
|
|
|
|
- blockInfo.put("value", ossUtil.getAliYunOssPrivateDomain().getPrivateUrl() + "/" + filePath);
|
|
|
|
|
|
+ byte[] bytes = Base64.decodeBase64(value.substring(value.indexOf(",") + 1));
|
|
|
|
+ String filePath =
|
|
|
|
+ "upload" + File.separator + sdf.format(new Date()) + File.separator + uuid() + "." + suff;
|
|
|
|
+ String md5 = BinaryUtil.toBase64String(BinaryUtil.calculateMd5(bytes));
|
|
|
|
+ ossUtil.upload(true, filePath, new ByteArrayInputStream(bytes), md5);
|
|
|
|
+ blockInfo.put("value", ossUtil.getAliYunOssPublicDomain().getPublicUrl() + "/" + filePath);
|
|
} else {
|
|
} else {
|
|
String suff = value.substring(value.indexOf("."));
|
|
String suff = value.substring(value.indexOf("."));
|
|
- String filePath = "upload/paper_file/" + paperId + "/" + uuid() + suff;
|
|
|
|
|
|
+ String filePath =
|
|
|
|
+ "upload" + File.separator + sdf.format(new Date()) + File.separator + uuid() + "." + suff;
|
|
File audioFile = new File(attachmentDir.getAbsolutePath() + "/" + value);
|
|
File audioFile = new File(attachmentDir.getAbsolutePath() + "/" + value);
|
|
- ossUtil.upload(false, filePath, audioFile);
|
|
|
|
- blockInfo.put("value", ossUtil.getAliYunOssPrivateDomain().getPrivateUrl() + "/" + filePath);
|
|
|
|
|
|
+ ossUtil.upload(true, filePath, audioFile);
|
|
|
|
+ blockInfo.put("value", ossUtil.getAliYunOssPublicDomain().getPublicUrl() + "/" + filePath);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -649,7 +637,7 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
}
|
|
}
|
|
|
|
|
|
private void checkAnswerFile(String rootDir, File[] paperDirChilds, Long examId, String courseCode,
|
|
private void checkAnswerFile(String rootDir, File[] paperDirChilds, Long examId, String courseCode,
|
|
- String paperCode) {
|
|
|
|
|
|
+ String paperCode) {
|
|
File paperFile = null;
|
|
File paperFile = null;
|
|
File answerFile = null;
|
|
File answerFile = null;
|
|
for (File cfile : paperDirChilds) {// 校验试卷下的答案
|
|
for (File cfile : paperDirChilds) {// 校验试卷下的答案
|