|
@@ -1,7 +1,5 @@
|
|
package com.qmth.cqb.paper.service;
|
|
package com.qmth.cqb.paper.service;
|
|
|
|
|
|
-import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.startsWith;
|
|
|
|
-
|
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.Gson;
|
|
import com.qmth.cqb.paper.dao.PaperDetailRepo;
|
|
import com.qmth.cqb.paper.dao.PaperDetailRepo;
|
|
import com.qmth.cqb.paper.dao.PaperDetailUnitRepo;
|
|
import com.qmth.cqb.paper.dao.PaperDetailUnitRepo;
|
|
@@ -15,19 +13,19 @@ import com.qmth.cqb.question.model.QuesOption;
|
|
import com.qmth.cqb.question.model.Question;
|
|
import com.qmth.cqb.question.model.Question;
|
|
import com.qmth.cqb.question.model.QuestionType;
|
|
import com.qmth.cqb.question.model.QuestionType;
|
|
import com.qmth.cqb.utils.CommonUtils;
|
|
import com.qmth.cqb.utils.CommonUtils;
|
|
|
|
+import com.qmth.cqb.utils.enums.PaperStatus;
|
|
|
|
+import com.qmth.cqb.utils.enums.PaperType;
|
|
import com.qmth.cqb.utils.enums.QuesStructType;
|
|
import com.qmth.cqb.utils.enums.QuesStructType;
|
|
import com.qmth.cqb.utils.enums.QuesUnit;
|
|
import com.qmth.cqb.utils.enums.QuesUnit;
|
|
import com.qmth.cqb.utils.word.DocxProcessUtil;
|
|
import com.qmth.cqb.utils.word.DocxProcessUtil;
|
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
|
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
|
import org.docx4j.wml.P;
|
|
import org.docx4j.wml.P;
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
-import org.springframework.data.domain.Example;
|
|
|
|
-import org.springframework.data.domain.ExampleMatcher;
|
|
|
|
-import org.springframework.data.domain.Page;
|
|
|
|
-import org.springframework.data.domain.PageRequest;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
|
|
|
import java.io.*;
|
|
import java.io.*;
|
|
|
|
|
|
@@ -55,57 +53,33 @@ public class ImportPaperService {
|
|
@Autowired
|
|
@Autowired
|
|
PaperService paperService;
|
|
PaperService paperService;
|
|
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 查询所有已导入试卷
|
|
|
|
- * @param searchCondition
|
|
|
|
- * @param curPage
|
|
|
|
- * @param pageSize
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public Page<Paper> findAll(ImportPaperSearchCondition searchCondition,
|
|
|
|
- int curPage,
|
|
|
|
- int pageSize){
|
|
|
|
- Paper importPaper = new Paper();
|
|
|
|
- BeanUtils.copyProperties(searchCondition,importPaper);
|
|
|
|
- ExampleMatcher matcher = ExampleMatcher.matching().withMatcher("paperName", startsWith());
|
|
|
|
- return paperRepo.findAll(Example.of(importPaper,matcher),
|
|
|
|
- new PageRequest(curPage - 1,pageSize));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 批量删除导入试卷
|
|
|
|
- * @param paperIds
|
|
|
|
- */
|
|
|
|
- public void deleteImportPaper(String[] paperIds) {
|
|
|
|
- paperService.deletePapers(paperIds);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
- * 查询所有已导入试卷
|
|
|
|
- * @param courseId
|
|
|
|
- * @param curPage
|
|
|
|
- * @param pageSize
|
|
|
|
|
|
+ * 获取上传文件
|
|
|
|
+ * @param file
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public Page<Paper> getImportPapersByCourseId(String courseId,int curPage,int pageSize){
|
|
|
|
- Paper importPaper = new Paper();
|
|
|
|
- if(!StringUtils.isEmpty(courseId)){
|
|
|
|
- Map<String,String> param = new HashMap<String,String>();
|
|
|
|
- param.put("courseId", courseId);
|
|
|
|
- importPaper.setParams(param);
|
|
|
|
- }
|
|
|
|
- return paperRepo.findAll(Example.of(importPaper),new PageRequest(curPage - 1,pageSize));
|
|
|
|
|
|
+ public File getUploadFile(CommonsMultipartFile file){
|
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
|
+ File tempFile = new File(DocxProcessUtil.TEMP_FILE_IMP+fileName);
|
|
|
|
+ OutputStream os = null;
|
|
|
|
+ try {
|
|
|
|
+ os = new FileOutputStream(tempFile);
|
|
|
|
+ IOUtils.copyLarge(file.getInputStream(),os);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }finally {
|
|
|
|
+ IOUtils.closeQuietly(os);
|
|
|
|
+ }
|
|
|
|
+ return tempFile;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 导入试卷
|
|
* 导入试卷
|
|
- * @param inputStream
|
|
|
|
|
|
+ * @param file
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public String ImportPaper(InputStream inputStream){
|
|
|
|
- String errorInfo = processImportPaper(inputStream);
|
|
|
|
|
|
+ public String ImportPaper(String paperName,File file){
|
|
|
|
+ String errorInfo = processImportPaper(paperName,file);
|
|
if(StringUtils.isEmpty(errorInfo)){
|
|
if(StringUtils.isEmpty(errorInfo)){
|
|
return "success";
|
|
return "success";
|
|
}else{
|
|
}else{
|
|
@@ -148,9 +122,9 @@ public class ImportPaperService {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 处理导入试卷
|
|
* 处理导入试卷
|
|
- * @param inputStream
|
|
|
|
|
|
+ * @param file
|
|
*/
|
|
*/
|
|
- public String processImportPaper(InputStream inputStream){
|
|
|
|
|
|
+ public String processImportPaper(String paperName,File file){
|
|
|
|
|
|
WordprocessingMLPackage wordMLPackage;
|
|
WordprocessingMLPackage wordMLPackage;
|
|
WordprocessingMLPackage tmpWordMlPackage;
|
|
WordprocessingMLPackage tmpWordMlPackage;
|
|
@@ -158,7 +132,7 @@ public class ImportPaperService {
|
|
ImportPaperCheck importPaperCheck = new ImportPaperCheck();
|
|
ImportPaperCheck importPaperCheck = new ImportPaperCheck();
|
|
|
|
|
|
try{
|
|
try{
|
|
- wordMLPackage = WordprocessingMLPackage.load(inputStream);
|
|
|
|
|
|
+ wordMLPackage = WordprocessingMLPackage.load(file);
|
|
//初始化图片路径
|
|
//初始化图片路径
|
|
DocxProcessUtil.initPkgImage(wordMLPackage);
|
|
DocxProcessUtil.initPkgImage(wordMLPackage);
|
|
//深拷贝临时pkg与最终写入数据库pkg
|
|
//深拷贝临时pkg与最终写入数据库pkg
|
|
@@ -172,6 +146,9 @@ public class ImportPaperService {
|
|
//创建试卷类
|
|
//创建试卷类
|
|
Paper paper = new Paper();
|
|
Paper paper = new Paper();
|
|
|
|
|
|
|
|
+ //设置试卷
|
|
|
|
+ initPaper(paper,paperName);
|
|
|
|
+
|
|
//创建空大题类
|
|
//创建空大题类
|
|
PaperDetail paperDetail = null;
|
|
PaperDetail paperDetail = null;
|
|
|
|
|
|
@@ -298,7 +275,8 @@ public class ImportPaperService {
|
|
return importPaperCheck.errorInfo;
|
|
return importPaperCheck.errorInfo;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ paper.setPaperDetailCount(mainQuesNum);
|
|
|
|
+ paper.setTotalScore((double)100);
|
|
//保存导入试卷信息
|
|
//保存导入试卷信息
|
|
savePaper(paper,
|
|
savePaper(paper,
|
|
paperDetails,
|
|
paperDetails,
|
|
@@ -309,13 +287,27 @@ public class ImportPaperService {
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
importPaperCheck.setErrorInfo(e.getMessage());
|
|
importPaperCheck.setErrorInfo(e.getMessage());
|
|
|
|
+ }finally {
|
|
|
|
+ wordMLPackage = null;
|
|
|
|
+ tmpWordMlPackage = null;
|
|
|
|
+ writePkg = null;
|
|
|
|
+ FileUtils.deleteQuietly(file);
|
|
}
|
|
}
|
|
- wordMLPackage = null;
|
|
|
|
- tmpWordMlPackage = null;
|
|
|
|
- writePkg = null;
|
|
|
|
return importPaperCheck.errorInfo;
|
|
return importPaperCheck.errorInfo;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 初始化试卷信息
|
|
|
|
+ * @param paper
|
|
|
|
+ * @param paperName
|
|
|
|
+ */
|
|
|
|
+ public void initPaper(Paper paper,String paperName){
|
|
|
|
+ paper.setName(paperName);
|
|
|
|
+ paper.setTitle(paperName);
|
|
|
|
+ paper.setPaperType(PaperType.IMPORT);
|
|
|
|
+ paper.setPaperStatus(PaperStatus.DRAFT);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 初始化大题头信息
|
|
* 初始化大题头信息
|
|
* @param paper
|
|
* @param paper
|
|
@@ -332,14 +324,12 @@ public class ImportPaperService {
|
|
|
|
|
|
paperDetail.setPaper(paper);
|
|
paperDetail.setPaper(paper);
|
|
|
|
|
|
- //设置试卷
|
|
|
|
- paper.setTitle(importPaperCheck.quesGroup);
|
|
|
|
- paper.setName(importPaperCheck.quesGroup);
|
|
|
|
- Map paramMap = new HashMap();
|
|
|
|
- paramMap.put("courseNo",getCourseNo(importPaperCheck));
|
|
|
|
- paramMap.put("courseName",getCourseName(importPaperCheck));
|
|
|
|
- paper.setParams(paramMap);
|
|
|
|
-
|
|
|
|
|
|
+ //设置课程
|
|
|
|
+ if(StringUtils.isEmpty(paper.getCourseNo())
|
|
|
|
+ || StringUtils.isEmpty(paper.getCourseName())){
|
|
|
|
+ paper.setCourseNo(getCourseNo(importPaperCheck));
|
|
|
|
+ paper.setCourseName(getCourseName(importPaperCheck));
|
|
|
|
+ }
|
|
//设置大题信息
|
|
//设置大题信息
|
|
paperDetail.setName(importPaperCheck.quesName);
|
|
paperDetail.setName(importPaperCheck.quesName);
|
|
paperDetail.setUnitCount(Integer.parseInt(importPaperCheck.quesCount));
|
|
paperDetail.setUnitCount(Integer.parseInt(importPaperCheck.quesCount));
|
|
@@ -382,24 +372,24 @@ public class ImportPaperService {
|
|
|
|
|
|
String tmpErrorInfo = "";
|
|
String tmpErrorInfo = "";
|
|
if(StringUtils.isEmpty(importPaperCheck.quesGroup)){
|
|
if(StringUtils.isEmpty(importPaperCheck.quesGroup)){
|
|
- tmpErrorInfo += "试题分类为空或格式不正确";
|
|
|
|
|
|
+ tmpErrorInfo += "试题分类为空或格式不正确\n";
|
|
|
|
|
|
}else if(StringUtils.isEmpty(importPaperCheck.quesType)){
|
|
}else if(StringUtils.isEmpty(importPaperCheck.quesType)){
|
|
- tmpErrorInfo += "题型为空或格式不正确";
|
|
|
|
|
|
+ tmpErrorInfo += "题型为空或格式不正确\n";
|
|
|
|
|
|
}else if(StringUtils.isEmpty(importPaperCheck.quesName)){
|
|
}else if(StringUtils.isEmpty(importPaperCheck.quesName)){
|
|
- tmpErrorInfo += "大题名称为空或格式不正确";
|
|
|
|
|
|
+ tmpErrorInfo += "大题名称为空或格式不正确\n";
|
|
|
|
|
|
}else if(StringUtils.isEmpty(importPaperCheck.quesCount)){
|
|
}else if(StringUtils.isEmpty(importPaperCheck.quesCount)){
|
|
- tmpErrorInfo += "题目数量为空或格式不正确";
|
|
|
|
|
|
+ tmpErrorInfo += "题目数量为空或格式不正确\n";
|
|
|
|
|
|
}else if(StringUtils.isEmpty(importPaperCheck.quesScore)){
|
|
}else if(StringUtils.isEmpty(importPaperCheck.quesScore)){
|
|
- tmpErrorInfo += "分数为空或格式不正确";
|
|
|
|
|
|
+ tmpErrorInfo += "分数为空或格式不正确\n";
|
|
|
|
|
|
}
|
|
}
|
|
if(!StringUtils.isEmpty(importPaperCheck.quesType)
|
|
if(!StringUtils.isEmpty(importPaperCheck.quesType)
|
|
&& !CommonUtils.checkQuesType(importPaperCheck.quesType)){
|
|
&& !CommonUtils.checkQuesType(importPaperCheck.quesType)){
|
|
- tmpErrorInfo += "题型必须是单选、多选、判断、填空、问答、套题中的一种";
|
|
|
|
|
|
+ tmpErrorInfo += "题型必须是单选、多选、判断、填空、问答、套题中的一种\n";
|
|
}
|
|
}
|
|
if(StringUtils.isEmpty(tmpErrorInfo)){
|
|
if(StringUtils.isEmpty(tmpErrorInfo)){
|
|
return true;
|
|
return true;
|
|
@@ -557,7 +547,7 @@ public class ImportPaperService {
|
|
importPaperCheck.setIndex(i);
|
|
importPaperCheck.setIndex(i);
|
|
if(optionCount < 2){
|
|
if(optionCount < 2){
|
|
importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName,
|
|
importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName,
|
|
- subQuesNum) +"中选项格式不正确或有缺失,如没有缺失可尝试换行处理");
|
|
|
|
|
|
+ subQuesNum) +"中选项格式不正确或有缺失,如没有缺失可尝试换行处理\n");
|
|
}else{
|
|
}else{
|
|
question.setQuesOptions(quesOptions);
|
|
question.setQuesOptions(quesOptions);
|
|
}
|
|
}
|
|
@@ -612,7 +602,7 @@ public class ImportPaperService {
|
|
DocxProcessUtil.formatPWordMl(quesAnwserWordMl));
|
|
DocxProcessUtil.formatPWordMl(quesAnwserWordMl));
|
|
}else{
|
|
}else{
|
|
importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName,
|
|
importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName,
|
|
- subQuesNum) +"答案为空或格式不正确");
|
|
|
|
|
|
+ subQuesNum) +"答案为空或格式不正确\n");
|
|
}
|
|
}
|
|
|
|
|
|
//设置小题分数
|
|
//设置小题分数
|
|
@@ -669,7 +659,7 @@ public class ImportPaperService {
|
|
|
|
|
|
if(StringUtils.isEmpty(nestedQuesType)){
|
|
if(StringUtils.isEmpty(nestedQuesType)){
|
|
importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName
|
|
importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName
|
|
- ,subQuesNum)+ "小题型为空或格式不正确");
|
|
|
|
|
|
+ ,subQuesNum)+ "小题型为空或格式不正确\n");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|