|
@@ -1,21 +1,6 @@
|
|
|
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.*;
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
-
|
|
|
-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.JSONObject;
|
|
|
import com.qmth.themis.business.config.SystemConfig;
|
|
@@ -30,7 +15,6 @@ import com.qmth.themis.business.service.TEExamPaperService;
|
|
|
import com.qmth.themis.business.service.TEExamService;
|
|
|
import com.qmth.themis.business.templete.TaskImportCommon;
|
|
|
import com.qmth.themis.business.templete.TaskImportTemplete;
|
|
|
-import com.qmth.themis.business.util.JacksonUtil;
|
|
|
import com.qmth.themis.business.util.OssUtil;
|
|
|
import com.qmth.themis.common.contanst.Constants;
|
|
|
import com.qmth.themis.common.enums.ExceptionResultEnum;
|
|
@@ -38,8 +22,20 @@ 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.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 javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FilenameFilter;
|
|
|
+import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @Description: 试卷导入
|
|
@@ -48,7 +44,7 @@ import cn.hutool.core.date.DateUtil;
|
|
|
*/
|
|
|
@Service("taskExamPaperImportTemplete")
|
|
|
public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
- private final static Logger log = LoggerFactory.getLogger(TaskExamPaperImportTemplete.class);
|
|
|
+ private final static Logger log = LoggerFactory.getLogger(TaskExamPaperImportTemplete.class);
|
|
|
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
|
|
|
@Resource
|
|
|
TEExamService teExamService;
|
|
@@ -73,8 +69,8 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
file = taskImportCommon.getUploadFile();
|
|
|
dispose(file, map, result);
|
|
|
} catch (Exception e) {
|
|
|
- taskImportCommon.setException(true);
|
|
|
- log.error("处理出错 ",e);
|
|
|
+ taskImportCommon.setException(true);
|
|
|
+ log.error("处理出错 ", e);
|
|
|
addResult(result, "处理出错 " + e.getMessage());
|
|
|
} finally {
|
|
|
if (file != null) {
|
|
@@ -83,7 +79,7 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
addResult(result, DateUtil.format(new Date(), timeFormat) + "处理结束");
|
|
|
long end = System.currentTimeMillis();
|
|
|
addResult(result, "耗时(秒):" + ((end - start) / 1000));
|
|
|
- taskImportCommon.writeImportResultTxt(result.toString());
|
|
|
+ taskImportCommon.writeImportResultTxt(result.toString(), file);
|
|
|
}
|
|
|
return ResultUtil.ok(Collections.singletonMap("success", true));
|
|
|
}
|
|
@@ -102,14 +98,14 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
try {
|
|
|
dfile.mkdirs();
|
|
|
FileUtil.unZip(dfile, file);
|
|
|
- if (!hasErr(map,dir, examId, dfile, result)) {
|
|
|
+ if (!hasErr(map, dir, examId, dfile, result)) {
|
|
|
for (File courseDir : dfile.listFiles()) {
|
|
|
if (courseDir.isDirectory()) {
|
|
|
disposeCourseDir(dir, teExam, courseDir, map);
|
|
|
}
|
|
|
}
|
|
|
- }else {
|
|
|
- throw new BusinessException("校验失败");
|
|
|
+ } else {
|
|
|
+ throw new BusinessException("校验失败");
|
|
|
}
|
|
|
} finally {
|
|
|
FileUtil.deleteFolder(dir);
|
|
@@ -118,7 +114,7 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
|
|
|
private void disposeCourseDir(String rootDir, TEExam teExam, File courseDir, Map<String, Object> map) {
|
|
|
String courseCode = courseDir.getName();
|
|
|
- TEExamCourse course = teExamCourseService.findByExamIdAndCourseCode(teExam.getId(),courseCode);
|
|
|
+ TEExamCourse course = teExamCourseService.findByExamIdAndCourseCode(teExam.getId(), courseCode);
|
|
|
if (course == null) {
|
|
|
throw new BusinessException("科目编码不存在 " + courseCode);
|
|
|
}
|
|
@@ -140,46 +136,46 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
if (audioPlayCount != null) {
|
|
|
course.setAudioPlayCount(audioPlayCount);
|
|
|
}
|
|
|
- List<TEExamPaper> list=teExamPaperService.findByExamIdAndCourseCode(teExam.getId(), courseCode);
|
|
|
- int hasAnswer=1;
|
|
|
- for(TEExamPaper p:list) {
|
|
|
- if(StringUtils.isBlank(p.getAnswerPath())) {
|
|
|
- hasAnswer=0;
|
|
|
- break;
|
|
|
- }
|
|
|
+ List<TEExamPaper> list = teExamPaperService.findByExamIdAndCourseCode(teExam.getId(), courseCode);
|
|
|
+ int hasAnswer = 1;
|
|
|
+ for (TEExamPaper p : list) {
|
|
|
+ if (StringUtils.isBlank(p.getAnswerPath())) {
|
|
|
+ hasAnswer = 0;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
course.setPaperCount(list.size());
|
|
|
course.setHasAnswer(hasAnswer);
|
|
|
- int hasAudio=0;
|
|
|
- for(TEExamPaper p:list) {
|
|
|
- if(p.getHasAudio()!=null&&p.getHasAudio().intValue()==1) {
|
|
|
- hasAudio=1;
|
|
|
- break;
|
|
|
- }
|
|
|
+ int hasAudio = 0;
|
|
|
+ for (TEExamPaper p : list) {
|
|
|
+ if (p.getHasAudio() != null && p.getHasAudio().intValue() == 1) {
|
|
|
+ hasAudio = 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
course.setHasAudio(hasAudio);
|
|
|
teExamCourseService.saveOrUpdate(course);
|
|
|
//设置调卷比例
|
|
|
teExamPaperService.savePaperWeight(paperWeight(list));
|
|
|
}
|
|
|
-
|
|
|
- private Map<Long,Double> paperWeight(List<TEExamPaper> list){
|
|
|
- BigDecimal b1 = new BigDecimal(1.0);//基数总数
|
|
|
- BigDecimal b2 = new BigDecimal(list.size());//份数
|
|
|
- BigDecimal b3=b1.divide(b2,2, BigDecimal.ROUND_FLOOR );//平均数
|
|
|
- BigDecimal b4=b1.subtract(b3.multiply(b2).setScale(2, BigDecimal.ROUND_FLOOR ));//余数
|
|
|
- Map<Long,Double> map=new HashMap<Long,Double>();
|
|
|
- for(int i=0;i<list.size();i++) {
|
|
|
- TEExamPaper p=list.get(i);
|
|
|
- if(i==list.size()-1) {
|
|
|
- map.put(p.getId(), b3.add(b4).doubleValue());
|
|
|
- }else {
|
|
|
- map.put(p.getId(), b3.doubleValue());
|
|
|
- }
|
|
|
- }
|
|
|
- return map;
|
|
|
+
|
|
|
+ private Map<Long, Double> paperWeight(List<TEExamPaper> list) {
|
|
|
+ BigDecimal b1 = new BigDecimal(1.0);//基数总数
|
|
|
+ BigDecimal b2 = new BigDecimal(list.size());//份数
|
|
|
+ BigDecimal b3 = b1.divide(b2, 2, BigDecimal.ROUND_FLOOR);//平均数
|
|
|
+ BigDecimal b4 = b1.subtract(b3.multiply(b2).setScale(2, BigDecimal.ROUND_FLOOR));//余数
|
|
|
+ Map<Long, Double> map = new HashMap<Long, Double>();
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ TEExamPaper p = list.get(i);
|
|
|
+ if (i == list.size() - 1) {
|
|
|
+ map.put(p.getId(), b3.add(b4).doubleValue());
|
|
|
+ } else {
|
|
|
+ map.put(p.getId(), b3.doubleValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private void disposePaperDir(String rootDir, TEExam teExam, TEExamCourse course, File paperDir,
|
|
|
Map<String, Object> map) {
|
|
|
String paperCode = paperDir.getName();
|
|
@@ -221,12 +217,12 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
}
|
|
|
Boolean processPaper = (Boolean) map.get("processPaper");
|
|
|
Boolean processAnswer = (Boolean) map.get("processAnswer");
|
|
|
- if(processPaper) {
|
|
|
- disposePaper(rootDir, paper, paperFile, attachmentDir);
|
|
|
- disposeStruct(rootDir, paper, paperFile);
|
|
|
+ if (processPaper) {
|
|
|
+ disposePaper(rootDir, paper, paperFile, attachmentDir);
|
|
|
+ disposeStruct(rootDir, paper, paperFile);
|
|
|
}
|
|
|
- if(processAnswer) {
|
|
|
- disposeAnswer(rootDir, paper, answerFile);
|
|
|
+ if (processAnswer) {
|
|
|
+ disposeAnswer(rootDir, paper, answerFile);
|
|
|
}
|
|
|
Integer audioPlayCount = (Integer) map.get("audioPlayCount");
|
|
|
paper.setAudioPlayCount(audioPlayCount);
|
|
@@ -299,14 +295,14 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
result.append(msg).append("\r\n");
|
|
|
}
|
|
|
|
|
|
- private boolean hasErr(Map<String, Object> map,String rootDir, Long examId, File dfile, StringBuilder result) {
|
|
|
- Boolean processPaper = (Boolean) map.get("processPaper");
|
|
|
+ private boolean hasErr(Map<String, Object> map, String rootDir, Long examId, File dfile, StringBuilder result) {
|
|
|
+ Boolean processPaper = (Boolean) map.get("processPaper");
|
|
|
Boolean processAnswer = (Boolean) map.get("processAnswer");
|
|
|
boolean hasErr = false;
|
|
|
for (File courseDir : dfile.listFiles()) {// 校验每一个科目
|
|
|
if (courseDir.isDirectory()) {
|
|
|
String courseCode = courseDir.getName();
|
|
|
- TEExamCourse course = teExamCourseService.findByExamIdAndCourseCode(examId,courseCode);
|
|
|
+ TEExamCourse course = teExamCourseService.findByExamIdAndCourseCode(examId, courseCode);
|
|
|
if (course == null) {
|
|
|
addResult(result, "科目编码不存在 " + courseCode);
|
|
|
hasErr = true;
|
|
@@ -327,33 +323,33 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
hasErr = true;
|
|
|
continue;
|
|
|
}
|
|
|
- if(processPaper) {
|
|
|
- String[] ps=paperDir.list(new FilenameFilter() {
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean accept(File dir, String name) {
|
|
|
- return name.equals("paper.json");
|
|
|
- }
|
|
|
- });
|
|
|
- if(ps==null||ps.length==0) {
|
|
|
- addResult(result, "科目 " + courseCode + " 试卷 " + paperCode + " 没有试卷文件");
|
|
|
+ if (processPaper) {
|
|
|
+ String[] ps = paperDir.list(new FilenameFilter() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean accept(File dir, String name) {
|
|
|
+ return name.equals("paper.json");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (ps == null || ps.length == 0) {
|
|
|
+ addResult(result, "科目 " + courseCode + " 试卷 " + paperCode + " 没有试卷文件");
|
|
|
hasErr = true;
|
|
|
continue;
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
- if(processAnswer) {
|
|
|
- String[] ps=paperDir.list(new FilenameFilter() {
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean accept(File dir, String name) {
|
|
|
- return name.equals("answer.json");
|
|
|
- }
|
|
|
- });
|
|
|
- if(ps==null||ps.length==0) {
|
|
|
- addResult(result, "科目 " + courseCode + " 试卷 " + paperCode + " 没有答案文件");
|
|
|
+ if (processAnswer) {
|
|
|
+ String[] ps = paperDir.list(new FilenameFilter() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean accept(File dir, String name) {
|
|
|
+ return name.equals("answer.json");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (ps == null || ps.length == 0) {
|
|
|
+ addResult(result, "科目 " + courseCode + " 试卷 " + paperCode + " 没有答案文件");
|
|
|
hasErr = true;
|
|
|
continue;
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
try {
|
|
|
// 校验答案
|
|
@@ -369,7 +365,7 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
|
}
|
|
|
return hasErr;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private void checkAnswerFile(String rootDir, File[] paperDirChilds, Long examId, String courseCode,
|
|
|
String paperCode) {
|
|
|
File paperFile = null;
|