|
@@ -1,25 +1,9 @@
|
|
package com.qmth.themis.business.templete.impl;
|
|
package com.qmth.themis.business.templete.impl;
|
|
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.io.IOException;
|
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.Objects;
|
|
|
|
-import java.util.UUID;
|
|
|
|
-
|
|
|
|
-import javax.annotation.Resource;
|
|
|
|
-
|
|
|
|
-import org.apache.commons.lang3.RandomStringUtils;
|
|
|
|
-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.qmth.themis.business.config.EnvConfig;
|
|
|
|
-import com.qmth.themis.business.config.SysConfig;
|
|
|
|
|
|
+import com.qmth.themis.business.config.SystemConfig;
|
|
import com.qmth.themis.business.constant.SpringContextHolder;
|
|
import com.qmth.themis.business.constant.SpringContextHolder;
|
|
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;
|
|
@@ -37,8 +21,15 @@ 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.lang3.RandomStringUtils;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Description: 试卷导入
|
|
* @Description: 试卷导入
|
|
@@ -47,352 +38,352 @@ import cn.hutool.core.date.DateUtil;
|
|
*/
|
|
*/
|
|
@Service("taskExamPaperImportTemplete")
|
|
@Service("taskExamPaperImportTemplete")
|
|
public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
- private SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
|
|
|
|
- @Resource
|
|
|
|
- TEExamService teExamService;
|
|
|
|
- @Resource
|
|
|
|
- SysConfig sysConfig;
|
|
|
|
- @Resource
|
|
|
|
- TEExamCourseService teExamCourseService;
|
|
|
|
- @Resource
|
|
|
|
- TEExamPaperService teExamPaperService;
|
|
|
|
|
|
+ private SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
|
|
|
|
+ @Resource
|
|
|
|
+ TEExamService teExamService;
|
|
|
|
+ @Resource
|
|
|
|
+ SystemConfig systemConfig;
|
|
|
|
+ @Resource
|
|
|
|
+ TEExamCourseService teExamCourseService;
|
|
|
|
+ @Resource
|
|
|
|
+ TEExamPaperService teExamPaperService;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional
|
|
|
|
+ public Result importTask(Map<String, Object> map) throws IOException {
|
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
|
+ TaskImportCommon taskImportCommon = new TaskImportCommon(map);
|
|
|
|
+ taskImportCommon.init();
|
|
|
|
+ StringBuilder result = new StringBuilder();
|
|
|
|
+ String timeFormat = taskImportCommon.getTimeFormat();
|
|
|
|
+ addResult(result, DateUtil.format(new Date(), timeFormat) + "处理开始");
|
|
|
|
+ File file = null;
|
|
|
|
+ try {
|
|
|
|
+ file = taskImportCommon.getUploadFile();
|
|
|
|
+ dispose(file, map, result);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ addResult(result, "处理出错 " + e.getMessage());
|
|
|
|
+ throw e;
|
|
|
|
+ } finally {
|
|
|
|
+ if (file != null) {
|
|
|
|
+ file.delete();
|
|
|
|
+ }
|
|
|
|
+ addResult(result, DateUtil.format(new Date(), timeFormat) + "处理结束");
|
|
|
|
+ long end = System.currentTimeMillis();
|
|
|
|
+ addResult(result, "耗时(秒):" + ((end - start) / 1000));
|
|
|
|
+ taskImportCommon.writeImportResultTxt(result.toString());
|
|
|
|
+ }
|
|
|
|
+ return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
|
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
|
- @Transactional
|
|
|
|
- public Result importTask(Map<String, Object> map) throws IOException {
|
|
|
|
- long start = System.currentTimeMillis();
|
|
|
|
- TaskImportCommon taskImportCommon = new TaskImportCommon(map);
|
|
|
|
- taskImportCommon.init();
|
|
|
|
- StringBuilder result = new StringBuilder();
|
|
|
|
- String timeFormat = taskImportCommon.getTimeFormat();
|
|
|
|
- addResult(result, DateUtil.format(new Date(), timeFormat) + "处理开始");
|
|
|
|
- File file = null;
|
|
|
|
- try {
|
|
|
|
- file = taskImportCommon.getUploadFile();
|
|
|
|
- dispose(file, map, result);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- addResult(result, "处理出错 " + e.getMessage());
|
|
|
|
- throw e;
|
|
|
|
- } finally {
|
|
|
|
- if (file != null) {
|
|
|
|
- file.delete();
|
|
|
|
- }
|
|
|
|
- addResult(result, DateUtil.format(new Date(), timeFormat) + "处理结束");
|
|
|
|
- long end = System.currentTimeMillis();
|
|
|
|
- addResult(result, "耗时(秒):" + ((end - start) / 1000));
|
|
|
|
- taskImportCommon.writeImportResultTxt(result.toString());
|
|
|
|
- }
|
|
|
|
- return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
|
|
|
|
- }
|
|
|
|
|
|
+ private void dispose(File file, Map<String, Object> map, StringBuilder result) throws IOException {
|
|
|
|
+ Long examId = (Long) map.get("examId");
|
|
|
|
|
|
- private void dispose(File file, Map<String, Object> map, StringBuilder result) throws IOException {
|
|
|
|
- Long examId = (Long) map.get("examId");
|
|
|
|
|
|
+ TEExam teExam = teExamService.getById(examId);
|
|
|
|
+ if (Objects.isNull(teExam)) {
|
|
|
|
+ throw new BusinessException(ExceptionResultEnum.EXAM_NO);
|
|
|
|
+ }
|
|
|
|
|
|
- TEExam teExam = teExamService.getById(examId);
|
|
|
|
- if (Objects.isNull(teExam)) {
|
|
|
|
- throw new BusinessException(ExceptionResultEnum.EXAM_NO);
|
|
|
|
- }
|
|
|
|
|
|
+ String tempDir = systemConfig.getProperty("sys.config.tempDataDir");
|
|
|
|
+ String dir = tempDir + "/" + uuid() + "/";
|
|
|
|
+ File dfile = new File(dir);
|
|
|
|
+ try {
|
|
|
|
+ dfile.mkdirs();
|
|
|
|
+ FileUtil.unZip(dfile, file);
|
|
|
|
+ if (!hasErr(dir, examId, dfile, result)) {
|
|
|
|
+ for (File courseDir : dfile.listFiles()) {
|
|
|
|
+ if (courseDir.isDirectory()) {
|
|
|
|
+ disposeCourseDir(dir, teExam, courseDir, map);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } finally {
|
|
|
|
+ FileUtil.deleteFolder(dir);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- String tempDir = sysConfig.getTempDir();
|
|
|
|
- String dir = tempDir + "/" + uuid() + "/";
|
|
|
|
- File dfile = new File(dir);
|
|
|
|
- try {
|
|
|
|
- dfile.mkdirs();
|
|
|
|
- FileUtil.unZip(dfile, file);
|
|
|
|
- if (!hasErr(dir, examId, dfile, result)) {
|
|
|
|
- for (File courseDir : dfile.listFiles()) {
|
|
|
|
- if (courseDir.isDirectory()) {
|
|
|
|
- disposeCourseDir(dir, teExam, courseDir, map);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } finally {
|
|
|
|
- FileUtil.deleteFolder(dir);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ private void disposeCourseDir(String rootDir, TEExam teExam, File courseDir, Map<String, Object> map) {
|
|
|
|
+ String courseCode = courseDir.getName();
|
|
|
|
+ TEExamCourse course = teExamCourseService.findByCode(courseCode);
|
|
|
|
+ if (course == null) {
|
|
|
|
+ throw new BusinessException("科目编码不存在 " + courseCode);
|
|
|
|
+ }
|
|
|
|
+ File[] childs = courseDir.listFiles();
|
|
|
|
+ for (File paperDir : childs) {
|
|
|
|
+ if (paperDir.isDirectory()) {
|
|
|
|
+ disposePaperDir(rootDir, teExam, course, paperDir, map);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Boolean objectiveShuffle = (Boolean) map.get("objectiveShuffle");
|
|
|
|
+ Boolean optionShuffle = (Boolean) map.get("optionShuffle");
|
|
|
|
+ Integer audioPlayTime = (Integer) map.get("audioPlayTime");
|
|
|
|
+ if (objectiveShuffle != null) {
|
|
|
|
+ course.setObjectiveShuffle(objectiveShuffle ? 1 : 0);
|
|
|
|
+ }
|
|
|
|
+ if (optionShuffle != null) {
|
|
|
|
+ course.setOptionShuffle(optionShuffle ? 1 : 0);
|
|
|
|
+ }
|
|
|
|
+ if (audioPlayTime != null) {
|
|
|
|
+ course.setAudioPlayTime(audioPlayTime);
|
|
|
|
+ }
|
|
|
|
+ if (objectiveShuffle != null || optionShuffle != null || audioPlayTime != null) {
|
|
|
|
+ teExamCourseService.save(course);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- private void disposeCourseDir(String rootDir, TEExam teExam, File courseDir, Map<String, Object> map) {
|
|
|
|
- String courseCode = courseDir.getName();
|
|
|
|
- TEExamCourse course = teExamCourseService.findByCode(courseCode);
|
|
|
|
- if (course == null) {
|
|
|
|
- throw new BusinessException("科目编码不存在 " + courseCode);
|
|
|
|
- }
|
|
|
|
- File[] childs = courseDir.listFiles();
|
|
|
|
- for (File paperDir : childs) {
|
|
|
|
- if (paperDir.isDirectory()) {
|
|
|
|
- disposePaperDir(rootDir, teExam, course, paperDir, map);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- Boolean objectiveShuffle = (Boolean) map.get("objectiveShuffle");
|
|
|
|
- Boolean optionShuffle = (Boolean) map.get("optionShuffle");
|
|
|
|
- Integer audioPlayTime = (Integer) map.get("audioPlayTime");
|
|
|
|
- if(objectiveShuffle!=null) {
|
|
|
|
- course.setObjectiveShuffle(objectiveShuffle?1:0);
|
|
|
|
- }
|
|
|
|
- if(optionShuffle!=null) {
|
|
|
|
- course.setOptionShuffle(optionShuffle?1:0);
|
|
|
|
- }
|
|
|
|
- if(audioPlayTime!=null) {
|
|
|
|
- course.setAudioPlayTime(audioPlayTime);
|
|
|
|
- }
|
|
|
|
- if(objectiveShuffle!=null||optionShuffle!=null||audioPlayTime!=null) {
|
|
|
|
- teExamCourseService.save(course);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ private void disposePaperDir(String rootDir, TEExam teExam, TEExamCourse course, File paperDir,
|
|
|
|
+ Map<String, Object> map) {
|
|
|
|
+ String paperCode = paperDir.getName();
|
|
|
|
+ File[] childs = paperDir.listFiles();
|
|
|
|
|
|
- private void disposePaperDir(String rootDir, TEExam teExam, TEExamCourse course, File paperDir,
|
|
|
|
- Map<String, Object> map) {
|
|
|
|
- String paperCode = paperDir.getName();
|
|
|
|
- File[] childs = paperDir.listFiles();
|
|
|
|
|
|
+ File paperFile = null;
|
|
|
|
+ File answerFile = null;
|
|
|
|
+ File attachmentDir = null;
|
|
|
|
+ for (File cfile : childs) {
|
|
|
|
+ if ("paper.json".equals(cfile.getName()) && cfile.isFile()) {
|
|
|
|
+ paperFile = cfile;
|
|
|
|
+ }
|
|
|
|
+ if ("answer.json".equals(cfile.getName()) && cfile.isFile()) {
|
|
|
|
+ answerFile = cfile;
|
|
|
|
+ }
|
|
|
|
+ if ("attachment".equals(cfile.getName()) && cfile.isDirectory()) {
|
|
|
|
+ if (cfile.listFiles() != null && cfile.listFiles().length != 0) {
|
|
|
|
+ attachmentDir = cfile;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ TEExamPaper paper = teExamPaperService.findByExamIdAndCourseCodeAndPaperCode(teExam.getId(),
|
|
|
|
+ course.getCourseCode(), paperCode);
|
|
|
|
+ if (paper == null) {
|
|
|
|
+ paper = new TEExamPaper();
|
|
|
|
+ Long createId = (Long) map.get("createId");
|
|
|
|
+ JSONObject paperJson = JSONObject.parseObject(FileUtil.readFileContent(paperFile));
|
|
|
|
+ paper.setName(paperJson.getString("name"));
|
|
|
|
+ paper.setTotalScore(paperJson.getDouble("totalScore"));
|
|
|
|
+ paper.setDecryptSecret(RandomStringUtils.randomAlphanumeric(16));
|
|
|
|
+ paper.setEncryptMode(0);
|
|
|
|
+ paper.setExamId(teExam.getId());
|
|
|
|
+ paper.setCode(paperCode);
|
|
|
|
+ paper.setHasAudio(paperJson.getInteger("hasAudio"));
|
|
|
|
+ paper.setCreateId(createId);
|
|
|
|
+ paper.setCourseCode(course.getCourseCode());
|
|
|
|
+ paper.setDecryptVector(RandomStringUtils.randomAlphanumeric(16));
|
|
|
|
+ }
|
|
|
|
+ disposePaper(rootDir, paper, paperFile, attachmentDir);
|
|
|
|
+ disposeStruct(rootDir, paper, paperFile);
|
|
|
|
+ disposeAnswer(rootDir, paper, answerFile);
|
|
|
|
|
|
- File paperFile = null;
|
|
|
|
- File answerFile = null;
|
|
|
|
- File attachmentDir = null;
|
|
|
|
- for (File cfile : childs) {
|
|
|
|
- if ("paper.json".equals(cfile.getName()) && cfile.isFile()) {
|
|
|
|
- paperFile = cfile;
|
|
|
|
- }
|
|
|
|
- if ("answer.json".equals(cfile.getName()) && cfile.isFile()) {
|
|
|
|
- answerFile = cfile;
|
|
|
|
- }
|
|
|
|
- if ("attachment".equals(cfile.getName()) && cfile.isDirectory()) {
|
|
|
|
- if (cfile.listFiles() != null && cfile.listFiles().length != 0) {
|
|
|
|
- attachmentDir = cfile;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- TEExamPaper paper = teExamPaperService.findByExamIdAndCourseCodeAndPaperCode(teExam.getId(),
|
|
|
|
- course.getCourseCode(), paperCode);
|
|
|
|
- if (paper == null) {
|
|
|
|
- paper = new TEExamPaper();
|
|
|
|
- Long createId = (Long) map.get("createId");
|
|
|
|
- JSONObject paperJson = JSONObject.parseObject(FileUtil.readFileContent(paperFile));
|
|
|
|
- paper.setName(paperJson.getString("name"));
|
|
|
|
- paper.setTotalScore(paperJson.getDouble("totalScore"));
|
|
|
|
- paper.setDecryptSecret(RandomStringUtils.randomAlphanumeric(16));
|
|
|
|
- paper.setEncryptMode(0);
|
|
|
|
- paper.setExamId(teExam.getId());
|
|
|
|
- paper.setCode(paperCode);
|
|
|
|
- paper.setHasAudio(paperJson.getInteger("hasAudio"));
|
|
|
|
- paper.setCreateId(createId);
|
|
|
|
- paper.setCourseCode(course.getCourseCode());
|
|
|
|
- paper.setDecryptVector(RandomStringUtils.randomAlphanumeric(16));
|
|
|
|
- }
|
|
|
|
- disposePaper(rootDir, paper, paperFile, attachmentDir);
|
|
|
|
- disposeStruct(rootDir, paper, paperFile);
|
|
|
|
- disposeAnswer(rootDir, paper, answerFile);
|
|
|
|
-
|
|
|
|
- teExamPaperService.save(paper);
|
|
|
|
- }
|
|
|
|
|
|
+ teExamPaperService.save(paper);
|
|
|
|
+ }
|
|
|
|
|
|
- private void disposePaper(String rootDir, TEExamPaper paper, File paperFile, File attachmentDir) {
|
|
|
|
- if (paperFile == null) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- File zip = new File(rootDir + uuid() + ".zip");
|
|
|
|
- List<File> files = new ArrayList<File>();
|
|
|
|
- files.add(paperFile);
|
|
|
|
- if (attachmentDir != null) {
|
|
|
|
- files.add(attachmentDir);
|
|
|
|
- }
|
|
|
|
- FileUtil.doZip(zip, files);
|
|
|
|
- File encryptZip = new File(rootDir + uuid() + ".zip");
|
|
|
|
- FileUtil.encryptFile(zip, encryptZip, paper.getDecryptSecret(), paper.getDecryptVector());
|
|
|
|
- String filePath = sdf.format(new Date()) + "/" + uuid() + ".zip";
|
|
|
|
- paper.setPaperPath(filePath);
|
|
|
|
- EnvConfig env = SpringContextHolder.getBean(EnvConfig.class);
|
|
|
|
- OssUtil.ossUpload(env.getOssEnv(3), filePath, encryptZip);
|
|
|
|
- }
|
|
|
|
|
|
+ private void disposePaper(String rootDir, TEExamPaper paper, File paperFile, File attachmentDir) {
|
|
|
|
+ if (paperFile == null) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ File zip = new File(rootDir + uuid() + ".zip");
|
|
|
|
+ List<File> files = new ArrayList<File>();
|
|
|
|
+ files.add(paperFile);
|
|
|
|
+ if (attachmentDir != null) {
|
|
|
|
+ files.add(attachmentDir);
|
|
|
|
+ }
|
|
|
|
+ FileUtil.doZip(zip, files);
|
|
|
|
+ File encryptZip = new File(rootDir + uuid() + ".zip");
|
|
|
|
+ FileUtil.encryptFile(zip, encryptZip, paper.getDecryptSecret(), paper.getDecryptVector());
|
|
|
|
+ String filePath = sdf.format(new Date()) + "/" + uuid() + ".zip";
|
|
|
|
+ paper.setPaperPath(filePath);
|
|
|
|
+ SystemConfig systemConfig = SpringContextHolder.getBean(SystemConfig.class);
|
|
|
|
+ OssUtil.ossUpload(systemConfig.getOssEnv(3), filePath, encryptZip);
|
|
|
|
+ }
|
|
|
|
|
|
- private void disposeStruct(String rootDir, TEExamPaper paper, File paperFile) {
|
|
|
|
- if (paperFile == null) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- JSONObject paperJson = JSONObject.parseObject(FileUtil.readFileContent(paperFile));
|
|
|
|
- JSONArray details = paperJson.getJSONArray("details");
|
|
|
|
- for (int i = 0; i < details.size(); i++) {
|
|
|
|
- JSONArray questions = details.getJSONObject(i).getJSONArray("questions");
|
|
|
|
- for (int j = 0; j < questions.size(); j++) {
|
|
|
|
- JSONObject question = questions.getJSONObject(j);
|
|
|
|
- question.remove("body");
|
|
|
|
- if (question.getInteger("structType").intValue() == 6) {
|
|
|
|
- JSONArray subQuestions = question.getJSONArray("subQuestions");
|
|
|
|
- for (int k = 0; k < subQuestions.size(); k++) {
|
|
|
|
- JSONObject subquestion = subQuestions.getJSONObject(k);
|
|
|
|
- subquestion.remove("body");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ private void disposeStruct(String rootDir, TEExamPaper paper, File paperFile) {
|
|
|
|
+ if (paperFile == null) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ JSONObject paperJson = JSONObject.parseObject(FileUtil.readFileContent(paperFile));
|
|
|
|
+ JSONArray details = paperJson.getJSONArray("details");
|
|
|
|
+ for (int i = 0; i < details.size(); i++) {
|
|
|
|
+ JSONArray questions = details.getJSONObject(i).getJSONArray("questions");
|
|
|
|
+ for (int j = 0; j < questions.size(); j++) {
|
|
|
|
+ JSONObject question = questions.getJSONObject(j);
|
|
|
|
+ question.remove("body");
|
|
|
|
+ if (question.getInteger("structType").intValue() == 6) {
|
|
|
|
+ JSONArray subQuestions = question.getJSONArray("subQuestions");
|
|
|
|
+ for (int k = 0; k < subQuestions.size(); k++) {
|
|
|
|
+ JSONObject subquestion = subQuestions.getJSONObject(k);
|
|
|
|
+ subquestion.remove("body");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- File file = new File(rootDir + uuid() + ".json");
|
|
|
|
- FileUtil.saveAsFile(file.getAbsolutePath(), paperJson.toJSONString());
|
|
|
|
- String filePath = sdf.format(new Date()) + "/" + uuid() + ".json";
|
|
|
|
- paper.setStructPath(filePath);
|
|
|
|
- EnvConfig env = SpringContextHolder.getBean(EnvConfig.class);
|
|
|
|
- OssUtil.ossUpload(env.getOssEnv(3), filePath, file);
|
|
|
|
- }
|
|
|
|
|
|
+ File file = new File(rootDir + uuid() + ".json");
|
|
|
|
+ FileUtil.saveAsFile(file.getAbsolutePath(), paperJson.toJSONString());
|
|
|
|
+ String filePath = sdf.format(new Date()) + "/" + uuid() + ".json";
|
|
|
|
+ paper.setStructPath(filePath);
|
|
|
|
+ SystemConfig systemConfig = SpringContextHolder.getBean(SystemConfig.class);
|
|
|
|
+ OssUtil.ossUpload(systemConfig.getOssEnv(3), filePath, file);
|
|
|
|
+ }
|
|
|
|
|
|
- private void disposeAnswer(String rootDir, TEExamPaper paper, File answerFile) {
|
|
|
|
- if (answerFile == null) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- File encryptFile = new File(rootDir + uuid() + ".json");
|
|
|
|
- FileUtil.encryptFile(answerFile, encryptFile, paper.getDecryptSecret(), paper.getDecryptVector());
|
|
|
|
- String filePath = sdf.format(new Date()) + "/" + uuid() + ".json";
|
|
|
|
- paper.setAnswerPath(filePath);
|
|
|
|
- EnvConfig env = SpringContextHolder.getBean(EnvConfig.class);
|
|
|
|
- OssUtil.ossUpload(env.getOssEnv(3), filePath, encryptFile);
|
|
|
|
- }
|
|
|
|
|
|
+ private void disposeAnswer(String rootDir, TEExamPaper paper, File answerFile) {
|
|
|
|
+ if (answerFile == null) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ File encryptFile = new File(rootDir + uuid() + ".json");
|
|
|
|
+ FileUtil.encryptFile(answerFile, encryptFile, paper.getDecryptSecret(), paper.getDecryptVector());
|
|
|
|
+ String filePath = sdf.format(new Date()) + "/" + uuid() + ".json";
|
|
|
|
+ paper.setAnswerPath(filePath);
|
|
|
|
+ SystemConfig systemConfig = SpringContextHolder.getBean(SystemConfig.class);
|
|
|
|
+ OssUtil.ossUpload(systemConfig.getOssEnv(3), filePath, encryptFile);
|
|
|
|
+ }
|
|
|
|
|
|
- private void addResult(StringBuilder result, String msg) {
|
|
|
|
- result.append(msg).append("\r\n");
|
|
|
|
- }
|
|
|
|
|
|
+ private void addResult(StringBuilder result, String msg) {
|
|
|
|
+ result.append(msg).append("\r\n");
|
|
|
|
+ }
|
|
|
|
|
|
- private boolean hasErr(String rootDir, Long examId, File dfile, StringBuilder result) {
|
|
|
|
- boolean hasErr = false;
|
|
|
|
- for (File courseDir : dfile.listFiles()) {// 校验每一个科目
|
|
|
|
- if (courseDir.isDirectory()) {
|
|
|
|
- String courseCode = courseDir.getName();
|
|
|
|
- TEExamCourse course = teExamCourseService.findByCode(courseCode);
|
|
|
|
- if (course == null) {
|
|
|
|
- addResult(result, "科目编码不存在 " + courseCode);
|
|
|
|
- hasErr = true;
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- File[] childs = courseDir.listFiles();
|
|
|
|
- if (childs == null || childs.length == 0) {
|
|
|
|
- addResult(result, "科目 " + courseCode + " 没有需要导入的文件");
|
|
|
|
- hasErr = true;
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- for (File paperDir : childs) {// 校验每一套试卷
|
|
|
|
- if (paperDir.isDirectory()) {
|
|
|
|
- String paperCode = paperDir.getName();
|
|
|
|
- File[] paperDirChilds = paperDir.listFiles();
|
|
|
|
- if (paperDirChilds == null || paperDirChilds.length == 0) {
|
|
|
|
- addResult(result, "科目 " + courseCode + " 试卷 " + paperCode + " 没有需要导入的文件");
|
|
|
|
- hasErr = true;
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- try {
|
|
|
|
- // 校验答案
|
|
|
|
- checkAnswerFile(rootDir, paperDirChilds, examId, courseCode, paperCode);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- addResult(result, e.getMessage());
|
|
|
|
- hasErr = true;
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return hasErr;
|
|
|
|
- }
|
|
|
|
|
|
+ private boolean hasErr(String rootDir, Long examId, File dfile, StringBuilder result) {
|
|
|
|
+ boolean hasErr = false;
|
|
|
|
+ for (File courseDir : dfile.listFiles()) {// 校验每一个科目
|
|
|
|
+ if (courseDir.isDirectory()) {
|
|
|
|
+ String courseCode = courseDir.getName();
|
|
|
|
+ TEExamCourse course = teExamCourseService.findByCode(courseCode);
|
|
|
|
+ if (course == null) {
|
|
|
|
+ addResult(result, "科目编码不存在 " + courseCode);
|
|
|
|
+ hasErr = true;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ File[] childs = courseDir.listFiles();
|
|
|
|
+ if (childs == null || childs.length == 0) {
|
|
|
|
+ addResult(result, "科目 " + courseCode + " 没有需要导入的文件");
|
|
|
|
+ hasErr = true;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ for (File paperDir : childs) {// 校验每一套试卷
|
|
|
|
+ if (paperDir.isDirectory()) {
|
|
|
|
+ String paperCode = paperDir.getName();
|
|
|
|
+ File[] paperDirChilds = paperDir.listFiles();
|
|
|
|
+ if (paperDirChilds == null || paperDirChilds.length == 0) {
|
|
|
|
+ addResult(result, "科目 " + courseCode + " 试卷 " + paperCode + " 没有需要导入的文件");
|
|
|
|
+ hasErr = true;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ // 校验答案
|
|
|
|
+ checkAnswerFile(rootDir, paperDirChilds, examId, courseCode, paperCode);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ addResult(result, e.getMessage());
|
|
|
|
+ hasErr = true;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return hasErr;
|
|
|
|
+ }
|
|
|
|
|
|
- private void checkAnswerFile(String rootDir, File[] paperDirChilds, Long examId, String courseCode,
|
|
|
|
- String paperCode) {
|
|
|
|
- File paperFile = null;
|
|
|
|
- File answerFile = null;
|
|
|
|
- for (File cfile : paperDirChilds) {// 校验试卷下的答案
|
|
|
|
- if ("paper.json".equals(cfile.getName()) && cfile.isFile()) {
|
|
|
|
- paperFile = cfile;
|
|
|
|
- }
|
|
|
|
- if ("answer.json".equals(cfile.getName()) && cfile.isFile()) {
|
|
|
|
- answerFile = cfile;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (answerFile != null) {
|
|
|
|
- if (paperFile == null) {// 没有试卷信息,不能先导入答案
|
|
|
|
- TEExamPaper paper = teExamPaperService.findByExamIdAndCourseCodeAndPaperCode(examId, courseCode,
|
|
|
|
- paperCode);
|
|
|
|
- if (paper == null) {
|
|
|
|
- throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 没有试卷信息,不能先导入答案");
|
|
|
|
- }
|
|
|
|
- String structPath = paper.getStructPath();
|
|
|
|
- EnvConfig env = SpringContextHolder.getBean(EnvConfig.class);
|
|
|
|
- String url = OssUtil.getUrlForPrivateBucket(env.getOssEnv(3), structPath);
|
|
|
|
- String name = structPath.substring(structPath.lastIndexOf("/") + 1);
|
|
|
|
- File structFile = new File(rootDir + name);
|
|
|
|
- try {
|
|
|
|
- FileUtil.saveUrlAsFile(url, structFile);
|
|
|
|
- compareAnswerAndPaper(courseCode, paperCode, answerFile, structFile);
|
|
|
|
- } finally {
|
|
|
|
- if (structFile.exists()) {
|
|
|
|
- structFile.delete();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- compareAnswerAndPaper(courseCode, paperCode, answerFile, paperFile);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ private void checkAnswerFile(String rootDir, File[] paperDirChilds, Long examId, String courseCode,
|
|
|
|
+ String paperCode) {
|
|
|
|
+ File paperFile = null;
|
|
|
|
+ File answerFile = null;
|
|
|
|
+ for (File cfile : paperDirChilds) {// 校验试卷下的答案
|
|
|
|
+ if ("paper.json".equals(cfile.getName()) && cfile.isFile()) {
|
|
|
|
+ paperFile = cfile;
|
|
|
|
+ }
|
|
|
|
+ if ("answer.json".equals(cfile.getName()) && cfile.isFile()) {
|
|
|
|
+ answerFile = cfile;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (answerFile != null) {
|
|
|
|
+ if (paperFile == null) {// 没有试卷信息,不能先导入答案
|
|
|
|
+ TEExamPaper paper = teExamPaperService.findByExamIdAndCourseCodeAndPaperCode(examId, courseCode,
|
|
|
|
+ paperCode);
|
|
|
|
+ if (paper == null) {
|
|
|
|
+ throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 没有试卷信息,不能先导入答案");
|
|
|
|
+ }
|
|
|
|
+ String structPath = paper.getStructPath();
|
|
|
|
+ SystemConfig systemConfig = SpringContextHolder.getBean(SystemConfig.class);
|
|
|
|
+ String url = OssUtil.getUrlForPrivateBucket(systemConfig.getOssEnv(3), structPath);
|
|
|
|
+ String name = structPath.substring(structPath.lastIndexOf("/") + 1);
|
|
|
|
+ File structFile = new File(rootDir + name);
|
|
|
|
+ try {
|
|
|
|
+ FileUtil.saveUrlAsFile(url, structFile);
|
|
|
|
+ compareAnswerAndPaper(courseCode, paperCode, answerFile, structFile);
|
|
|
|
+ } finally {
|
|
|
|
+ if (structFile.exists()) {
|
|
|
|
+ structFile.delete();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ compareAnswerAndPaper(courseCode, paperCode, answerFile, paperFile);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- private void compareAnswerAndPaper(String courseCode, String paperCode, File answerFile, File structFile) {
|
|
|
|
- JSONObject answerJson = JSONObject.parseObject(FileUtil.readFileContent(answerFile));
|
|
|
|
- JSONArray answerdetails = answerJson.getJSONArray("details");
|
|
|
|
- JSONObject structJson = JSONObject.parseObject(FileUtil.readFileContent(structFile));
|
|
|
|
- JSONArray structdetails = structJson.getJSONArray("details");
|
|
|
|
- if (answerdetails.size() != structdetails.size()) {
|
|
|
|
- throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷大题数量不一致");
|
|
|
|
- }
|
|
|
|
- for (int i = 0; i < answerdetails.size(); i++) {
|
|
|
|
- JSONArray answerdetailquestions = answerdetails.getJSONObject(i).getJSONArray("questions");
|
|
|
|
- JSONArray structdetailquestions = structdetails.getJSONObject(i).getJSONArray("questions");
|
|
|
|
- if (answerdetailquestions.size() != structdetailquestions.size()) {
|
|
|
|
- throw new BusinessException(
|
|
|
|
- "科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第" + (i + 1) + "大题的小题数量不一致");
|
|
|
|
- }
|
|
|
|
- for (int j = 0; j < answerdetailquestions.size(); j++) {
|
|
|
|
- JSONObject answerquestion = answerdetailquestions.getJSONObject(j);
|
|
|
|
- JSONObject structquestion = structdetailquestions.getJSONObject(j);
|
|
|
|
- if (structquestion.getInteger("structType").intValue() == 1
|
|
|
|
- || structquestion.getInteger("structType").intValue() == 2) {
|
|
|
|
- JSONArray answer = answerquestion.getJSONArray("answer");
|
|
|
|
- if (answer == null || answer.size() == 0) {
|
|
|
|
- throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第" + (i + 1)
|
|
|
|
- + "大题第" + (j + 1) + "小题没有答案");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (structquestion.getInteger("structType").intValue() == 3) {
|
|
|
|
- Boolean answer = answerquestion.getBoolean("answer");
|
|
|
|
- if (answer == null) {
|
|
|
|
- throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第" + (i + 1)
|
|
|
|
- + "大题第" + (j + 1) + "小题没有答案");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (structquestion.getInteger("structType").intValue() == 6) {
|
|
|
|
- JSONArray answersubQuestions = answerquestion.getJSONArray("subQuestions");
|
|
|
|
- JSONArray structsubQuestions = structquestion.getJSONArray("subQuestions");
|
|
|
|
- if (answersubQuestions.size() != structsubQuestions.size()) {
|
|
|
|
- throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第" + (i + 1)
|
|
|
|
- + "大题第" + (j + 1) + "小题子题数量不一致");
|
|
|
|
- }
|
|
|
|
- for (int k = 0; k < answersubQuestions.size(); k++) {
|
|
|
|
- JSONObject answersubquestion = answerdetailquestions.getJSONObject(k);
|
|
|
|
- JSONObject structsubquestion = structdetailquestions.getJSONObject(k);
|
|
|
|
- if (structsubquestion.getInteger("structType").intValue() == 1
|
|
|
|
- || structsubquestion.getInteger("structType").intValue() == 2) {
|
|
|
|
- JSONArray answer = answersubquestion.getJSONArray("answer");
|
|
|
|
- if (answer == null || answer.size() == 0) {
|
|
|
|
- throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第"
|
|
|
|
- + (i + 1) + "大题第" + (j + 1) + "小题第" + (k + 1) + "子题没有答案");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (structsubquestion.getInteger("structType").intValue() == 3) {
|
|
|
|
- Boolean answer = answersubquestion.getBoolean("answer");
|
|
|
|
- if (answer == null) {
|
|
|
|
- throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第"
|
|
|
|
- + (i + 1) + "大题第" + (j + 1) + "小题第" + (k + 1) + "子题没有答案");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ private void compareAnswerAndPaper(String courseCode, String paperCode, File answerFile, File structFile) {
|
|
|
|
+ JSONObject answerJson = JSONObject.parseObject(FileUtil.readFileContent(answerFile));
|
|
|
|
+ JSONArray answerdetails = answerJson.getJSONArray("details");
|
|
|
|
+ JSONObject structJson = JSONObject.parseObject(FileUtil.readFileContent(structFile));
|
|
|
|
+ JSONArray structdetails = structJson.getJSONArray("details");
|
|
|
|
+ if (answerdetails.size() != structdetails.size()) {
|
|
|
|
+ throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷大题数量不一致");
|
|
|
|
+ }
|
|
|
|
+ for (int i = 0; i < answerdetails.size(); i++) {
|
|
|
|
+ JSONArray answerdetailquestions = answerdetails.getJSONObject(i).getJSONArray("questions");
|
|
|
|
+ JSONArray structdetailquestions = structdetails.getJSONObject(i).getJSONArray("questions");
|
|
|
|
+ if (answerdetailquestions.size() != structdetailquestions.size()) {
|
|
|
|
+ throw new BusinessException(
|
|
|
|
+ "科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第" + (i + 1) + "大题的小题数量不一致");
|
|
|
|
+ }
|
|
|
|
+ for (int j = 0; j < answerdetailquestions.size(); j++) {
|
|
|
|
+ JSONObject answerquestion = answerdetailquestions.getJSONObject(j);
|
|
|
|
+ JSONObject structquestion = structdetailquestions.getJSONObject(j);
|
|
|
|
+ if (structquestion.getInteger("structType").intValue() == 1
|
|
|
|
+ || structquestion.getInteger("structType").intValue() == 2) {
|
|
|
|
+ JSONArray answer = answerquestion.getJSONArray("answer");
|
|
|
|
+ if (answer == null || answer.size() == 0) {
|
|
|
|
+ throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第" + (i + 1)
|
|
|
|
+ + "大题第" + (j + 1) + "小题没有答案");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (structquestion.getInteger("structType").intValue() == 3) {
|
|
|
|
+ Boolean answer = answerquestion.getBoolean("answer");
|
|
|
|
+ if (answer == null) {
|
|
|
|
+ throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第" + (i + 1)
|
|
|
|
+ + "大题第" + (j + 1) + "小题没有答案");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (structquestion.getInteger("structType").intValue() == 6) {
|
|
|
|
+ JSONArray answersubQuestions = answerquestion.getJSONArray("subQuestions");
|
|
|
|
+ JSONArray structsubQuestions = structquestion.getJSONArray("subQuestions");
|
|
|
|
+ if (answersubQuestions.size() != structsubQuestions.size()) {
|
|
|
|
+ throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第" + (i + 1)
|
|
|
|
+ + "大题第" + (j + 1) + "小题子题数量不一致");
|
|
|
|
+ }
|
|
|
|
+ for (int k = 0; k < answersubQuestions.size(); k++) {
|
|
|
|
+ JSONObject answersubquestion = answerdetailquestions.getJSONObject(k);
|
|
|
|
+ JSONObject structsubquestion = structdetailquestions.getJSONObject(k);
|
|
|
|
+ if (structsubquestion.getInteger("structType").intValue() == 1
|
|
|
|
+ || structsubquestion.getInteger("structType").intValue() == 2) {
|
|
|
|
+ JSONArray answer = answersubquestion.getJSONArray("answer");
|
|
|
|
+ if (answer == null || answer.size() == 0) {
|
|
|
|
+ throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第"
|
|
|
|
+ + (i + 1) + "大题第" + (j + 1) + "小题第" + (k + 1) + "子题没有答案");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (structsubquestion.getInteger("structType").intValue() == 3) {
|
|
|
|
+ Boolean answer = answersubquestion.getBoolean("answer");
|
|
|
|
+ if (answer == null) {
|
|
|
|
+ throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 答案和试卷第"
|
|
|
|
+ + (i + 1) + "大题第" + (j + 1) + "小题第" + (k + 1) + "子题没有答案");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- private String uuid() {
|
|
|
|
- return UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
|
- }
|
|
|
|
|
|
+ private String uuid() {
|
|
|
|
+ return UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
|
+ }
|
|
}
|
|
}
|