|
@@ -1,8 +1,26 @@
|
|
package com.qmth.cqb.paper.service;
|
|
package com.qmth.cqb.paper.service;
|
|
|
|
|
|
-import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
|
+import java.io.OutputStream;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.UUID;
|
|
|
|
+
|
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
|
|
|
+import org.docx4j.wml.P;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
|
+
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.Gson;
|
|
-import com.qmth.cqb.base.dao.CourseRepo;
|
|
|
|
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;
|
|
import com.qmth.cqb.paper.dao.PaperRepo;
|
|
import com.qmth.cqb.paper.dao.PaperRepo;
|
|
@@ -19,25 +37,15 @@ import com.qmth.cqb.utils.enums.PaperStatus;
|
|
import com.qmth.cqb.utils.enums.PaperType;
|
|
import com.qmth.cqb.utils.enums.PaperType;
|
|
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.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
|
|
|
-import org.docx4j.wml.P;
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
-import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
|
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.io.FileOutputStream;
|
|
|
|
-import java.io.OutputStream;
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.UUID;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
|
|
+import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class ImportPaperService {
|
|
public class ImportPaperService {
|
|
|
|
|
|
|
|
+ protected static final Logger log = LoggerFactory.getLogger(ImportPaperService.class);
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
PaperRepo paperRepo;
|
|
PaperRepo paperRepo;
|
|
|
|
|
|
@@ -59,9 +67,6 @@ public class ImportPaperService {
|
|
@Autowired
|
|
@Autowired
|
|
PaperService paperService;
|
|
PaperService paperService;
|
|
|
|
|
|
- @Autowired
|
|
|
|
- CourseRepo courseRepo;
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 获取上传文件
|
|
* 获取上传文件
|
|
*
|
|
*
|
|
@@ -77,6 +82,7 @@ public class ImportPaperService {
|
|
IOUtils.copyLarge(file.getInputStream(), os);
|
|
IOUtils.copyLarge(file.getInputStream(), os);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
|
+ log.error("上传文件异常:" + e.getMessage());
|
|
} finally {
|
|
} finally {
|
|
IOUtils.closeQuietly(os);
|
|
IOUtils.closeQuietly(os);
|
|
}
|
|
}
|
|
@@ -91,20 +97,20 @@ public class ImportPaperService {
|
|
* @param file
|
|
* @param file
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public String ImportPaper(String paperName, String courseNo, File file) {
|
|
|
|
- String errorInfo = paperService.checkPaperName(paperName);
|
|
|
|
|
|
+ public String ImportPaper(String paperName, String courseNo, String courseName, AccessUser user, File file) {
|
|
|
|
+ String errorInfo = paperService.checkPaperName(paperName, user.getOrgId().toString());
|
|
if (errorInfo == null) {
|
|
if (errorInfo == null) {
|
|
errorInfo = "";
|
|
errorInfo = "";
|
|
- errorInfo += processImportPaper(paperName, courseNo, file);
|
|
|
|
|
|
+ errorInfo += processImportPaper(paperName, courseNo, courseName, user, file);
|
|
if (StringUtils.isEmpty(errorInfo)) {
|
|
if (StringUtils.isEmpty(errorInfo)) {
|
|
return "success";
|
|
return "success";
|
|
} else {
|
|
} else {
|
|
|
|
+ log.error("导入异常:" + errorInfo);
|
|
return errorInfo;
|
|
return errorInfo;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
return errorInfo;
|
|
return errorInfo;
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -147,7 +153,7 @@ public class ImportPaperService {
|
|
*
|
|
*
|
|
* @param file
|
|
* @param file
|
|
*/
|
|
*/
|
|
- public String processImportPaper(String paperName, String courseNo, File file) {
|
|
|
|
|
|
+ public String processImportPaper(String paperName, String courseNo, String courseName, AccessUser user, File file) {
|
|
|
|
|
|
WordprocessingMLPackage wordMLPackage;
|
|
WordprocessingMLPackage wordMLPackage;
|
|
WordprocessingMLPackage tmpWordMlPackage;
|
|
WordprocessingMLPackage tmpWordMlPackage;
|
|
@@ -170,7 +176,11 @@ public class ImportPaperService {
|
|
|
|
|
|
paper.setCourseNo(courseNo);
|
|
paper.setCourseNo(courseNo);
|
|
|
|
|
|
- paper.setCourseName(courseRepo.findByCourseNo(courseNo).getCourseName());
|
|
|
|
|
|
+ paper.setCourseName(courseName);
|
|
|
|
+
|
|
|
|
+ paper.setOrgId(user.getOrgId().toString());
|
|
|
|
+
|
|
|
|
+ paper.setCreator(user.getLoginName());
|
|
|
|
|
|
// 设置试卷
|
|
// 设置试卷
|
|
initPaper(paper, paperName);
|
|
initPaper(paper, paperName);
|
|
@@ -214,8 +224,8 @@ public class ImportPaperService {
|
|
// 设置大题类
|
|
// 设置大题类
|
|
initQuesHeader(paper, paperDetail, paperDetails, ++mainQuesNum, importPaperCheck);
|
|
initQuesHeader(paper, paperDetail, paperDetails, ++mainQuesNum, importPaperCheck);
|
|
|
|
|
|
- } else if (pText.matches("^\\d{1,}\\.[\\s\\S]*") || (isNested(importPaperCheck) && !pText
|
|
|
|
- .startsWith("["))) {
|
|
|
|
|
|
+ } else if (pText.matches("^\\d{1,}\\.[\\s\\S]*")
|
|
|
|
+ || (isNested(importPaperCheck) && !pText.startsWith("["))) {
|
|
// 处理试题
|
|
// 处理试题
|
|
|
|
|
|
// 创建小题类和试题类
|
|
// 创建小题类和试题类
|
|
@@ -251,11 +261,10 @@ public class ImportPaperService {
|
|
}
|
|
}
|
|
// 设置WordMlPackage二进制数据
|
|
// 设置WordMlPackage二进制数据
|
|
setPkgByte(question, writePkg);
|
|
setPkgByte(question, writePkg);
|
|
- //Map<String, String> quesParams = new HashMap<String, String>();
|
|
|
|
- //quesParams.put("courseName", paper.getCourseName());
|
|
|
|
// 设置question与Unit集合数据
|
|
// 设置question与Unit集合数据
|
|
question.setCourseNo(paper.getCourseNo());
|
|
question.setCourseNo(paper.getCourseNo());
|
|
question.setCourseName(paper.getCourseName());
|
|
question.setCourseName(paper.getCourseName());
|
|
|
|
+ question.setOrgId(user.getOrgId().toString());
|
|
questions.add(question);
|
|
questions.add(question);
|
|
paperDetailUnits.add(paperDetailUnit);
|
|
paperDetailUnits.add(paperDetailUnit);
|
|
|
|
|
|
@@ -273,6 +282,7 @@ public class ImportPaperService {
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
importPaperCheck.setErrorInfo(e.getMessage());
|
|
importPaperCheck.setErrorInfo(e.getMessage());
|
|
|
|
+ log.error("导入处理异常:" + e.getMessage());
|
|
} finally {
|
|
} finally {
|
|
wordMLPackage = null;
|
|
wordMLPackage = null;
|
|
tmpWordMlPackage = null;
|
|
tmpWordMlPackage = null;
|
|
@@ -308,18 +318,11 @@ public class ImportPaperService {
|
|
ImportPaperCheck importPaperCheck) {
|
|
ImportPaperCheck importPaperCheck) {
|
|
|
|
|
|
paperDetail.setPaper(paper);
|
|
paperDetail.setPaper(paper);
|
|
-
|
|
|
|
- // 不从word中提取课程信息,统一从页面设置好
|
|
|
|
- // 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));
|
|
paperDetail.setNumber(mainQuesNum);
|
|
paperDetail.setNumber(mainQuesNum);
|
|
-
|
|
|
|
|
|
+ paperDetail.setCreator(paper.getCreator());
|
|
paperDetails.add(paperDetail);
|
|
paperDetails.add(paperDetail);
|
|
|
|
|
|
}
|
|
}
|
|
@@ -343,6 +346,7 @@ public class ImportPaperService {
|
|
paperDetailUnit.setPaperDetail(paperDetail);
|
|
paperDetailUnit.setPaperDetail(paperDetail);
|
|
paperDetailUnit.setQuestionType(getQuesStructType(importPaperCheck.quesType));
|
|
paperDetailUnit.setQuestionType(getQuesStructType(importPaperCheck.quesType));
|
|
paperDetailUnit.setScore(Double.parseDouble(importPaperCheck.quesScore));
|
|
paperDetailUnit.setScore(Double.parseDouble(importPaperCheck.quesScore));
|
|
|
|
+ paperDetailUnit.setCreator(paper.getCreator());
|
|
paperDetailUnit.setPaper(paper);
|
|
paperDetailUnit.setPaper(paper);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -813,23 +817,30 @@ public class ImportPaperService {
|
|
* @param paperName
|
|
* @param paperName
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public String saveBlankPaper(String courseNo, String paperName) {
|
|
|
|
|
|
+ public Map<String, Object> saveBlankPaper(String courseNo, String courseName, String paperName, AccessUser user) {
|
|
|
|
+ Map<String, Object> returnMap = new HashMap<String, Object>();
|
|
Paper paper = new Paper();
|
|
Paper paper = new Paper();
|
|
- String courseName = courseRepo.findByCourseNo(courseNo).getCourseName();
|
|
|
|
- String msg = paperService.checkPaperName(paperName);
|
|
|
|
|
|
+ String msg = paperService.checkPaperName(paperName, user.getOrgId().toString());
|
|
if (msg != null) {
|
|
if (msg != null) {
|
|
- return msg;
|
|
|
|
|
|
+ returnMap.put("msg", msg);
|
|
|
|
+ return returnMap;
|
|
}
|
|
}
|
|
initPaper(paper, paperName);
|
|
initPaper(paper, paperName);
|
|
paper.setCourseNo(courseNo);
|
|
paper.setCourseNo(courseNo);
|
|
paper.setCourseName(courseName);
|
|
paper.setCourseName(courseName);
|
|
|
|
+ paper.setOrgId(user.getOrgId().toString());
|
|
|
|
+ paper.setCreator(user.getLoginName());
|
|
|
|
+ paper.setCreateTime(CommonUtils.getCurDateTime());
|
|
PaperDetail pd = new PaperDetail();
|
|
PaperDetail pd = new PaperDetail();
|
|
pd.setId(UUID.randomUUID().toString());
|
|
pd.setId(UUID.randomUUID().toString());
|
|
pd.setNumber(1);
|
|
pd.setNumber(1);
|
|
pd.setPaper(paper);
|
|
pd.setPaper(paper);
|
|
- paperRepo.save(paper);
|
|
|
|
|
|
+ pd.setCreator(user.getLoginName());
|
|
|
|
+ pd.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
+ paper = paperRepo.save(paper);
|
|
paperDetailRepo.save(pd);
|
|
paperDetailRepo.save(pd);
|
|
- msg = "success";
|
|
|
|
- return msg;
|
|
|
|
|
|
+ returnMap.put("paper", paper);
|
|
|
|
+ returnMap.put("msg", "success");
|
|
|
|
+ return returnMap;
|
|
}
|
|
}
|
|
}
|
|
}
|