|
@@ -11,7 +11,6 @@ import java.util.UUID;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
-import com.qmth.cqb.utils.exception.PaperException;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
@@ -40,6 +39,7 @@ 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.QuesUnit;
|
|
|
+import com.qmth.cqb.utils.exception.PaperException;
|
|
|
import com.qmth.cqb.utils.word.DocxProcessUtil;
|
|
|
|
|
|
import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
@@ -77,7 +77,7 @@ public class ImportPaperService {
|
|
|
* @param file
|
|
|
* @return
|
|
|
*/
|
|
|
- public File getUploadFile(CommonsMultipartFile file) throws Exception{
|
|
|
+ public File getUploadFile(CommonsMultipartFile file) throws Exception {
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
File tempFile = new File(DocxProcessUtil.TEMP_FILE_IMP + fileName);
|
|
|
OutputStream os = null;
|
|
@@ -95,23 +95,22 @@ public class ImportPaperService {
|
|
|
* @param file
|
|
|
* @return
|
|
|
*/
|
|
|
- public String ImportPaper(String paperName,
|
|
|
- String courseNo,
|
|
|
- String courseName,
|
|
|
- AccessUser user,
|
|
|
- File file) throws Exception{
|
|
|
+ public Map<String, Object> ImportPaper(String paperName, String courseNo, String courseName, AccessUser user,
|
|
|
+ File file) throws Exception {
|
|
|
+ Map<String, Object> msgMap = new HashMap<String, Object>();
|
|
|
String errorInfo = paperService.checkPaperName(paperName, user.getOrgId().toString());
|
|
|
if (errorInfo == null) {
|
|
|
- errorInfo = "";
|
|
|
- errorInfo += processImportPaper(paperName, courseNo, courseName, user, file);
|
|
|
- if (StringUtils.isEmpty(errorInfo)) {
|
|
|
- return "success";
|
|
|
+ msgMap = processImportPaper(paperName, courseNo, courseName, user, file);
|
|
|
+ if (StringUtils.isEmpty((String) msgMap.get("msg"))) {
|
|
|
+ msgMap.put("msg", "success");
|
|
|
+ return msgMap;
|
|
|
} else {
|
|
|
- log.error("导入异常:" + errorInfo);
|
|
|
- return errorInfo;
|
|
|
+ log.error("导入异常:" + (String) msgMap.get("msg"));
|
|
|
+ return msgMap;
|
|
|
}
|
|
|
} else {
|
|
|
- return errorInfo;
|
|
|
+ msgMap.put("msg", errorInfo);
|
|
|
+ return msgMap;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -123,13 +122,13 @@ public class ImportPaperService {
|
|
|
* @param paperDetailUnits
|
|
|
* @param importPaperCheck
|
|
|
*/
|
|
|
- public void savePaper(Paper paper, List paperDetails, List paperDetailUnits, List questions,
|
|
|
+ public Paper savePaper(Paper paper, List paperDetails, List paperDetailUnits, List questions,
|
|
|
ImportPaperCheck importPaperCheck) {
|
|
|
|
|
|
Paper tempPaper = null;
|
|
|
|
|
|
if (!StringUtils.isEmpty(importPaperCheck.errorInfo))
|
|
|
- return;
|
|
|
+ return null;
|
|
|
|
|
|
if (paper != null) {
|
|
|
tempPaper = paperRepo.save(paper);
|
|
@@ -148,6 +147,8 @@ public class ImportPaperService {
|
|
|
}
|
|
|
|
|
|
paperService.formatPaper(tempPaper, null);
|
|
|
+
|
|
|
+ return tempPaper;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -160,8 +161,9 @@ public class ImportPaperService {
|
|
|
* @param file
|
|
|
* @return
|
|
|
*/
|
|
|
- public String processImportPaper(String paperName, String courseNo, String courseName, AccessUser user, File file) throws Exception {
|
|
|
-
|
|
|
+ public Map<String, Object> processImportPaper(String paperName, String courseNo, String courseName, AccessUser user,
|
|
|
+ File file) throws Exception {
|
|
|
+ Map<String, Object> msgMap = new HashMap<String, Object>();
|
|
|
WordprocessingMLPackage wordMLPackage;
|
|
|
WordprocessingMLPackage tmpWordMlPackage;
|
|
|
WordprocessingMLPackage writePkg;
|
|
@@ -213,7 +215,6 @@ public class ImportPaperService {
|
|
|
P p = (P) pList.get(i);
|
|
|
String pText = DocxProcessUtil.getPText(p);
|
|
|
|
|
|
-
|
|
|
if (StringUtils.isEmpty(pText)) {
|
|
|
// 跳过空白段落
|
|
|
continue;
|
|
@@ -289,12 +290,14 @@ public class ImportPaperService {
|
|
|
}
|
|
|
paper.setPaperDetailCount(mainQuesNum);
|
|
|
// 保存导入试卷信息
|
|
|
- savePaper(paper, paperDetails, paperDetailUnits, questions, importPaperCheck);
|
|
|
+ paper = savePaper(paper, paperDetails, paperDetailUnits, questions, importPaperCheck);
|
|
|
wordMLPackage = null;
|
|
|
tmpWordMlPackage = null;
|
|
|
writePkg = null;
|
|
|
FileUtils.deleteQuietly(file);
|
|
|
- return importPaperCheck.errorInfo;
|
|
|
+ msgMap.put("msg", importPaperCheck.errorInfo);
|
|
|
+ msgMap.put("paper", paper);
|
|
|
+ return msgMap;
|
|
|
}
|
|
|
|
|
|
/**
|