|
@@ -28,7 +28,6 @@ import com.qmth.themis.common.exception.BusinessException;
|
|
|
import com.qmth.themis.common.util.FileUtil;
|
|
|
import com.qmth.themis.common.util.Result;
|
|
|
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;
|
|
@@ -37,7 +36,10 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.io.*;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FilenameFilter;
|
|
|
+import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
@@ -49,6 +51,7 @@ import java.util.*;
|
|
|
*/
|
|
|
@Service("taskExamPaperImportTemplete")
|
|
|
public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
+
|
|
|
private final static Logger log = LoggerFactory.getLogger(TaskExamPaperImportTemplete.class);
|
|
|
|
|
|
@Resource
|
|
@@ -233,7 +236,7 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
}
|
|
|
|
|
|
private void disposePaperDir(String rootDir, TEExam teExam, TEExamCourse course, File paperDir,
|
|
|
- Map<String, Object> map, List<Long> paperIds) throws IOException {
|
|
|
+ Map<String, Object> map, List<Long> paperIds) throws IOException {
|
|
|
String paperCode = paperDir.getName();
|
|
|
File[] childs = paperDir.listFiles();
|
|
|
|
|
@@ -253,8 +256,8 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- TEExamPaper paper = teExamPaperService
|
|
|
- .findByExamIdAndCourseCodeAndPaperCode(teExam.getId(), course.getCourseCode(), paperCode);
|
|
|
+ TEExamPaper paper = teExamPaperService.findByExamIdAndCourseCodeAndPaperCode(teExam.getId(),
|
|
|
+ course.getCourseCode(), paperCode);
|
|
|
if (paper == null) {
|
|
|
paper = new TEExamPaper();
|
|
|
String createId = map.get(SystemConstant.CREATE_ID).toString();
|
|
@@ -314,7 +317,8 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
disposeQuestionBodyUrl(rootDir, body, paper.getId(), attachmentDir);
|
|
|
JSONArray options = structquestion.getJSONArray(SystemConstant.OPTIONS);
|
|
|
disposeQuestionOptionsUrl(rootDir, options, paper.getId(), attachmentDir);
|
|
|
- if (structquestion.getInteger(SystemConstant.STRUCT_TYPE).intValue() == 6 || structquestion.getInteger(SystemConstant.STRUCT_TYPE).intValue() == 8) {
|
|
|
+ if (structquestion.getInteger(SystemConstant.STRUCT_TYPE).intValue() == 6
|
|
|
+ || structquestion.getInteger(SystemConstant.STRUCT_TYPE).intValue() == 8) {
|
|
|
JSONArray structsubQuestions = structquestion.getJSONArray(SystemConstant.SUB_QUESTIONS);
|
|
|
for (int k = 0; k < structsubQuestions.size(); k++) {
|
|
|
JSONObject structsubquestion = structsubQuestions.getJSONObject(k);
|
|
@@ -327,7 +331,8 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- String filePath = DateUtil.format(new Date(), Constants.DATE_PATTERN) + "/" + SystemConstant.getNanoId() + SystemConstant.JSON_PREFIX;
|
|
|
+ String filePath = DateUtil.format(new Date(), Constants.DATE_PATTERN) + "/" + SystemConstant.getNanoId()
|
|
|
+ + SystemConstant.JSON_PREFIX;
|
|
|
paper.setPaperViewPath(filePath);
|
|
|
ossUtil.upload(false, filePath, structJson.toJSONString());
|
|
|
}
|
|
@@ -399,7 +404,8 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
FileUtil.doZip(zip, files);
|
|
|
File encryptZip = new File(rootDir + SystemConstant.getNanoId() + ".zip");
|
|
|
FileUtil.encryptFile(zip, encryptZip, paper.getDecryptSecret(), paper.getDecryptVector());
|
|
|
- String filePath = DateUtil.format(new Date(), Constants.DATE_PATTERN) + "/" + SystemConstant.getNanoId() + ".zip";
|
|
|
+ String filePath =
|
|
|
+ DateUtil.format(new Date(), Constants.DATE_PATTERN) + "/" + SystemConstant.getNanoId() + ".zip";
|
|
|
paper.setPaperPath(filePath);
|
|
|
paper.setPaperMd5(BinaryUtil.encodeMD5(FileUtil.fileConvertToByteArray(encryptZip)));
|
|
|
ossUtil.upload(false, filePath, encryptZip);
|
|
@@ -424,6 +430,11 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
score = 0.0;
|
|
|
}
|
|
|
Integer structType = question.getInteger(SystemConstant.STRUCT_TYPE);
|
|
|
+ Integer type = question.getInteger(SystemConstant.TYPE);
|
|
|
+ if ((Objects.nonNull(structType) && structType.intValue() == 7) || (Objects.nonNull(type)
|
|
|
+ && type.intValue() == 110)) {
|
|
|
+ throw new BusinessException("当前暂不支持听力题型,请删除后重新导入");
|
|
|
+ }
|
|
|
if (structType.intValue() != 1 && structType.intValue() != 2 && structType.intValue() != 3
|
|
|
&& structType.intValue() != 6 && structType.intValue() != 8) {//主观题
|
|
|
subTotal = subTotal.add(BigDecimal.valueOf(score));
|
|
@@ -451,7 +462,8 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- String filePath = DateUtil.format(new Date(), Constants.DATE_PATTERN) + "/" + SystemConstant.getNanoId() + SystemConstant.JSON_PREFIX;
|
|
|
+ String filePath = DateUtil.format(new Date(), Constants.DATE_PATTERN) + "/" + SystemConstant.getNanoId()
|
|
|
+ + SystemConstant.JSON_PREFIX;
|
|
|
paper.setStructPath(filePath);
|
|
|
ByteArrayOutputStream out = null;
|
|
|
try {
|
|
@@ -494,7 +506,8 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
JSONArray answer = answerquestion.getJSONArray(SystemConstant.ANSWER);
|
|
|
disposeAnswerUrl(rootDir, answer, paper.getId(), attachmentDir);
|
|
|
}
|
|
|
- if (structquestion.getInteger(SystemConstant.STRUCT_TYPE).intValue() == 6 || structquestion.getInteger(SystemConstant.STRUCT_TYPE).intValue() == 8) {
|
|
|
+ if (structquestion.getInteger(SystemConstant.STRUCT_TYPE).intValue() == 6
|
|
|
+ || structquestion.getInteger(SystemConstant.STRUCT_TYPE).intValue() == 8) {
|
|
|
JSONArray answersubQuestions = answerquestion.getJSONArray(SystemConstant.SUB_QUESTIONS);
|
|
|
JSONArray structsubQuestions = structquestion.getJSONArray(SystemConstant.SUB_QUESTIONS);
|
|
|
for (int k = 0; k < answersubQuestions.size(); k++) {
|
|
@@ -511,7 +524,8 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- String filePath = DateUtil.format(new Date(), Constants.DATE_PATTERN) + "/" + SystemConstant.getNanoId() + SystemConstant.JSON_PREFIX;
|
|
|
+ String filePath = DateUtil.format(new Date(), Constants.DATE_PATTERN) + "/" + SystemConstant.getNanoId()
|
|
|
+ + SystemConstant.JSON_PREFIX;
|
|
|
paper.setAnswerPath(filePath);
|
|
|
ossUtil.upload(false, filePath, answerJson.toJSONString());
|
|
|
}
|
|
@@ -549,18 +563,19 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
if (("image".equals(type) || "audio".equals(type)) && StringUtils.isNotBlank(value) && !value.toLowerCase()
|
|
|
.startsWith("https://") && !value.toLowerCase().startsWith("http://")) {
|
|
|
if ("image".equals(type) && value.contains("data:image")) {
|
|
|
-// String suff = value.substring(11, value.indexOf(";"));
|
|
|
-// byte[] bytes = Base64.decodeBase64(value.substring(value.indexOf(",") + 1));
|
|
|
-// String filePath =
|
|
|
-// "upload" + File.separator + DateUtil.format(new Date(), Constants.DATE_PATTERN) + File.separator + SystemConstant.getNanoId() + "." + suff;
|
|
|
-// String md5 = BinaryUtil.toBase64String(BinaryUtil.calculateMd5(bytes));
|
|
|
-// ossUtil.upload(true, filePath, new ByteArrayInputStream(bytes), md5);
|
|
|
-// blockInfo.put("value", ossUtil.getAliYunOssPublicDomain().getPublicUrl() + "/" + filePath);
|
|
|
+ // String suff = value.substring(11, value.indexOf(";"));
|
|
|
+ // byte[] bytes = Base64.decodeBase64(value.substring(value.indexOf(",") + 1));
|
|
|
+ // String filePath =
|
|
|
+ // "upload" + File.separator + DateUtil.format(new Date(), Constants.DATE_PATTERN) + File.separator + SystemConstant.getNanoId() + "." + suff;
|
|
|
+ // String md5 = BinaryUtil.toBase64String(BinaryUtil.calculateMd5(bytes));
|
|
|
+ // ossUtil.upload(true, filePath, new ByteArrayInputStream(bytes), md5);
|
|
|
+ // blockInfo.put("value", ossUtil.getAliYunOssPublicDomain().getPublicUrl() + "/" + filePath);
|
|
|
blockInfo.put("value", value);
|
|
|
} else {
|
|
|
String suff = value.substring(value.indexOf("."));
|
|
|
String filePath =
|
|
|
- "upload" + File.separator + DateUtil.format(new Date(), Constants.DATE_PATTERN) + File.separator + SystemConstant.getNanoId() + "." + suff;
|
|
|
+ "upload" + File.separator + DateUtil.format(new Date(), Constants.DATE_PATTERN) + File.separator
|
|
|
+ + SystemConstant.getNanoId() + "." + suff;
|
|
|
File audioFile = new File(attachmentDir.getAbsolutePath() + "/" + value);
|
|
|
ossUtil.upload(true, filePath, audioFile);
|
|
|
blockInfo.put("value", ossUtil.getAliYunOssPublicDomain().getPublicUrl() + "/" + filePath);
|
|
@@ -661,7 +676,7 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
}
|
|
|
|
|
|
private void checkAnswerFile(String rootDir, File[] paperDirChilds, Long examId, String courseCode,
|
|
|
- String paperCode) {
|
|
|
+ String paperCode) {
|
|
|
File paperFile = null;
|
|
|
File answerFile = null;
|
|
|
for (File cfile : paperDirChilds) {// 校验试卷下的答案
|
|
@@ -674,8 +689,8 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
}
|
|
|
if (answerFile != null) {
|
|
|
if (paperFile == null) {// 没有试卷信息,不能先导入答案
|
|
|
- TEExamPaper paper = teExamPaperService
|
|
|
- .findByExamIdAndCourseCodeAndPaperCode(examId, courseCode, paperCode);
|
|
|
+ TEExamPaper paper = teExamPaperService.findByExamIdAndCourseCodeAndPaperCode(examId, courseCode,
|
|
|
+ paperCode);
|
|
|
if (paper == null) {
|
|
|
throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 没有试卷信息,不能先导入答案");
|
|
|
}
|