|
@@ -1,5 +1,9 @@
|
|
package com.qmth.cqb.paper.service.export;
|
|
package com.qmth.cqb.paper.service.export;
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileNotFoundException;
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
|
+import java.io.IOException;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
@@ -8,11 +12,16 @@ import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
|
+import java.util.regex.Matcher;
|
|
|
|
+import java.util.regex.Pattern;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.xml.bind.JAXBElement;
|
|
import javax.xml.bind.JAXBElement;
|
|
|
|
|
|
|
|
+import main.java.com.UpYun;
|
|
|
|
+
|
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.docx4j.XmlUtils;
|
|
import org.docx4j.XmlUtils;
|
|
import org.docx4j.jaxb.Context;
|
|
import org.docx4j.jaxb.Context;
|
|
@@ -27,25 +36,42 @@ import org.springframework.beans.factory.annotation.Value;
|
|
import cn.com.qmth.examcloud.common.dto.core.enums.CourseLevel;
|
|
import cn.com.qmth.examcloud.common.dto.core.enums.CourseLevel;
|
|
import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
|
|
+import cn.com.qmth.examcloud.common.util.excel.ExcelWriter;
|
|
|
|
|
|
|
|
+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;
|
|
import com.qmth.cqb.paper.dao.PaperRepo;
|
|
import com.qmth.cqb.paper.dao.PaperRepo;
|
|
|
|
+import com.qmth.cqb.paper.dto.ObjectiveQuestionStructure;
|
|
import com.qmth.cqb.paper.dto.PaperDetailExp;
|
|
import com.qmth.cqb.paper.dto.PaperDetailExp;
|
|
import com.qmth.cqb.paper.dto.PaperDetailUnitExp;
|
|
import com.qmth.cqb.paper.dto.PaperDetailUnitExp;
|
|
import com.qmth.cqb.paper.dto.PaperExp;
|
|
import com.qmth.cqb.paper.dto.PaperExp;
|
|
|
|
+import com.qmth.cqb.paper.dto.SubjectiveQuestionStructure;
|
|
|
|
+import com.qmth.cqb.paper.model.ExamFile;
|
|
|
|
+import com.qmth.cqb.paper.model.ExamPaper;
|
|
import com.qmth.cqb.paper.model.ExportStructure;
|
|
import com.qmth.cqb.paper.model.ExportStructure;
|
|
import com.qmth.cqb.paper.model.ExtractConfig;
|
|
import com.qmth.cqb.paper.model.ExtractConfig;
|
|
import com.qmth.cqb.paper.model.Paper;
|
|
import com.qmth.cqb.paper.model.Paper;
|
|
import com.qmth.cqb.paper.model.PaperDetail;
|
|
import com.qmth.cqb.paper.model.PaperDetail;
|
|
import com.qmth.cqb.paper.model.PaperDetailUnit;
|
|
import com.qmth.cqb.paper.model.PaperDetailUnit;
|
|
|
|
+import com.qmth.cqb.paper.model.QuestionTypeNum;
|
|
|
|
+import com.qmth.cqb.paper.model.computerTestModel.Block;
|
|
|
|
+import com.qmth.cqb.paper.model.computerTestModel.ComputerTestOption;
|
|
|
|
+import com.qmth.cqb.paper.model.computerTestModel.ComputerTestPaper;
|
|
|
|
+import com.qmth.cqb.paper.model.computerTestModel.ComputerTestPaperDetail;
|
|
|
|
+import com.qmth.cqb.paper.model.computerTestModel.ComputerTestQuestion;
|
|
|
|
+import com.qmth.cqb.paper.model.computerTestModel.Section;
|
|
|
|
+import com.qmth.cqb.paper.model.computerTestModel.Sections;
|
|
import com.qmth.cqb.paper.service.ExamFileService;
|
|
import com.qmth.cqb.paper.service.ExamFileService;
|
|
|
|
+import com.qmth.cqb.paper.service.PaperDetailService;
|
|
import com.qmth.cqb.paper.service.PaperService;
|
|
import com.qmth.cqb.paper.service.PaperService;
|
|
import com.qmth.cqb.question.dao.QuesRepo;
|
|
import com.qmth.cqb.question.dao.QuesRepo;
|
|
import com.qmth.cqb.question.model.QuesOption;
|
|
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.utils.BeanCopierUtil;
|
|
import com.qmth.cqb.utils.BeanCopierUtil;
|
|
import com.qmth.cqb.utils.CommonUtils;
|
|
import com.qmth.cqb.utils.CommonUtils;
|
|
|
|
+import com.qmth.cqb.utils.FileDisposeUtil;
|
|
|
|
+import com.qmth.cqb.utils.enums.ExamFileType;
|
|
import com.qmth.cqb.utils.exception.PaperException;
|
|
import com.qmth.cqb.utils.exception.PaperException;
|
|
import com.qmth.cqb.utils.word.DocxProcessUtil;
|
|
import com.qmth.cqb.utils.word.DocxProcessUtil;
|
|
|
|
|
|
@@ -57,7 +83,7 @@ import freemarker.template.Template;
|
|
* @author chenken
|
|
* @author chenken
|
|
* @date 2017年7月15日 下午4:00:24
|
|
* @date 2017年7月15日 下午4:00:24
|
|
* @company QMTH
|
|
* @company QMTH
|
|
- * @description 上传下载文件父类
|
|
|
|
|
|
+ * @description 导出、上传文件service 父类
|
|
*/
|
|
*/
|
|
public abstract class ExportPaperAbstractService {
|
|
public abstract class ExportPaperAbstractService {
|
|
|
|
|
|
@@ -76,6 +102,9 @@ public abstract class ExportPaperAbstractService {
|
|
@Autowired
|
|
@Autowired
|
|
ExamFileService examFileService;
|
|
ExamFileService examFileService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private PaperDetailService paperDetailService;
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
QuesRepo quesRepo;
|
|
QuesRepo quesRepo;
|
|
|
|
|
|
@@ -120,7 +149,7 @@ public abstract class ExportPaperAbstractService {
|
|
protected static Template TJDX_TEMPLATE_ANSWER;
|
|
protected static Template TJDX_TEMPLATE_ANSWER;
|
|
|
|
|
|
//石油大学模板
|
|
//石油大学模板
|
|
- //protected static Template SYDX_TEMPLATE_NORMAL;
|
|
|
|
|
|
+ protected static Template SYDX_TEMPLATE_PAPER;
|
|
|
|
|
|
@Value("${upyun.bucketName}")
|
|
@Value("${upyun.bucketName}")
|
|
protected String bucketName;
|
|
protected String bucketName;
|
|
@@ -160,7 +189,7 @@ public abstract class ExportPaperAbstractService {
|
|
TJDX_TEMPLATE_PAPER = CONFIGURATION.getTemplate("tjdx_paper_template.ftl", ENCODING);
|
|
TJDX_TEMPLATE_PAPER = CONFIGURATION.getTemplate("tjdx_paper_template.ftl", ENCODING);
|
|
TJDX_TEMPLATE_ANSWER = CONFIGURATION.getTemplate("tjdx_answer_template.ftl", ENCODING);
|
|
TJDX_TEMPLATE_ANSWER = CONFIGURATION.getTemplate("tjdx_answer_template.ftl", ENCODING);
|
|
|
|
|
|
- //SYDX_TEMPLATE_NORMAL = CONFIGURATION.getTemplate("paper_template.ftl", ENCODING);
|
|
|
|
|
|
+ SYDX_TEMPLATE_PAPER = CONFIGURATION.getTemplate("sydx_paper_template.ftl", ENCODING);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
@@ -181,13 +210,11 @@ public abstract class ExportPaperAbstractService {
|
|
* @param paperId
|
|
* @param paperId
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
- public void uploadFile(ExtractConfig extractConfig,String paperId,ExportStructure exportStructure,AccessUser accessUser) throws Exception{
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ public abstract void uploadFile(ExtractConfig extractConfig,String paperId,ExportStructure exportStructure,AccessUser accessUser) throws Exception;
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * 公共方法
|
|
* 初始化导出试卷DTO
|
|
* 初始化导出试卷DTO
|
|
- *
|
|
|
|
* @param id
|
|
* @param id
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@@ -424,7 +451,7 @@ public abstract class ExportPaperAbstractService {
|
|
return pWordMl.toString();
|
|
return pWordMl.toString();
|
|
}
|
|
}
|
|
|
|
|
|
- public String getOptionNum(int number){
|
|
|
|
|
|
+ protected String getOptionNum(int number){
|
|
char optionNum = (char)(65 + number);
|
|
char optionNum = (char)(65 + number);
|
|
return String.valueOf(optionNum);
|
|
return String.valueOf(optionNum);
|
|
}
|
|
}
|
|
@@ -434,7 +461,7 @@ public abstract class ExportPaperAbstractService {
|
|
* @param id
|
|
* @param id
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public List<WordprocessingMLPackage> getPkgList(String id){
|
|
|
|
|
|
+ protected List<WordprocessingMLPackage> getPkgList(String id){
|
|
Paper paper = paperRepo.findOne(id);
|
|
Paper paper = paperRepo.findOne(id);
|
|
List<WordprocessingMLPackage> wordMLPackages = paperDetailUnitRepo.findByPaper(paper)
|
|
List<WordprocessingMLPackage> wordMLPackages = paperDetailUnitRepo.findByPaper(paper)
|
|
.stream().map(PaperDetailUnit::getQuestion).collect(Collectors.toList())
|
|
.stream().map(PaperDetailUnit::getQuestion).collect(Collectors.toList())
|
|
@@ -559,4 +586,355 @@ public abstract class ExportPaperAbstractService {
|
|
return pWordMl.toString();
|
|
return pWordMl.toString();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 创建机考文件,并打包上传至又拍云
|
|
|
|
+ * @param paperId
|
|
|
|
+ * @param currNum
|
|
|
|
+ * ObjectId("591ead1290994d57cd453464")
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ protected void uploadComputerTestFile(ExtractConfig extractConfig,AccessUser accessUser) throws IOException{
|
|
|
|
+ List<ComputerTestPaper> computerTestPaperList = buildComputerTestPapers(extractConfig);
|
|
|
|
+ for(ComputerTestPaper computerTestPaper:computerTestPaperList){
|
|
|
|
+ String jsonDirectoryName = extractConfig.getCourseCode()+"_"+computerTestPaper.getName();
|
|
|
|
+ String jsonDirectoryPath = TEMP_FILE_EXP + File.separator + jsonDirectoryName;
|
|
|
|
+ //新建文件夹
|
|
|
|
+ File dirFile = new File(jsonDirectoryPath);
|
|
|
|
+ if(!dirFile.exists()){
|
|
|
|
+ dirFile.mkdirs();
|
|
|
|
+ }
|
|
|
|
+ //创建新的JSON文件
|
|
|
|
+ File file = new File(jsonDirectoryPath+File.separator+extractConfig.getCourseCode()+".json");
|
|
|
|
+ //将对象转成 json对象
|
|
|
|
+ Gson gson = new Gson();
|
|
|
|
+ String strJSON = gson.toJson(computerTestPaper);
|
|
|
|
+ //生成文件流写入JSON文件
|
|
|
|
+ FileOutputStream outputStream = new FileOutputStream(file);
|
|
|
|
+ byte b[] = strJSON.getBytes();
|
|
|
|
+ outputStream.write(b);
|
|
|
|
+ outputStream.close();
|
|
|
|
+ FileDisposeUtil.fileToZip(jsonDirectoryPath,"docxExport",jsonDirectoryName);
|
|
|
|
+ //上传到又拍云
|
|
|
|
+ File zipFile = new File(TEMP_FILE_EXP+jsonDirectoryName+ZIP_SUFFIX);
|
|
|
|
+ String zipUpyunFilePath = uploadUrl+jsonDirectoryName+ZIP_SUFFIX;
|
|
|
|
+ UpYun upyun = new UpYun(bucketName,userName,password);
|
|
|
|
+ upyun.writeFile(zipUpyunFilePath,zipFile,true);
|
|
|
|
+ //保存数据库记录
|
|
|
|
+ examFileService.saveExamFile(new ExamFile(extractConfig,zipUpyunFilePath,ExamFileType.COMPUTERTEST_PACKAGE,computerTestPaper.getName(),ZIP_SUFFIX),accessUser);
|
|
|
|
+ //删除本地生成的文件
|
|
|
|
+ zipFile.delete();
|
|
|
|
+ FileUtils.deleteQuietly(dirFile);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 构建机考数据包实体类
|
|
|
|
+ * @param extractConfig
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private List<ComputerTestPaper> buildComputerTestPapers(ExtractConfig extractConfig){
|
|
|
|
+ List<ExamPaper> examPapers = extractConfig.getExamPaperList();
|
|
|
|
+ List<ComputerTestPaper> computerTestPapers = new ArrayList<ComputerTestPaper>();
|
|
|
|
+ //循环得到试卷
|
|
|
|
+ for(ExamPaper examPaper:examPapers){
|
|
|
|
+ Paper paper = examPaper.getPaper();
|
|
|
|
+ //得到所有旧对象的大题对象
|
|
|
|
+ List<PaperDetail> paperDetails = paperService.findPaperDetailsById(paper.getId());
|
|
|
|
+ //通过 paper 对象 ,生成新的 ComputerTestPaper 对象
|
|
|
|
+ ComputerTestPaper computerTestPaper = new ComputerTestPaper(paper);
|
|
|
|
+ List<ComputerTestPaperDetail> details = new ArrayList<ComputerTestPaperDetail>();
|
|
|
|
+ //遍历所有旧大题对象,得到小题对象的集合
|
|
|
|
+ for(PaperDetail paperDetail:paperDetails){
|
|
|
|
+ List<PaperDetailUnit> paperDetailUnits = paperDetailService.getUnitsByPaperDetailId(paperDetail.getId());
|
|
|
|
+ ComputerTestPaperDetail computerTestPaperDetail = new ComputerTestPaperDetail(paperDetail);
|
|
|
|
+ List<ComputerTestQuestion> questions = new ArrayList<ComputerTestQuestion>();
|
|
|
|
+ //遍历所有的小题对象
|
|
|
|
+ for(PaperDetailUnit paperDetailUnit:paperDetailUnits){
|
|
|
|
+ //根据旧的小题对象,生成新的小题对象
|
|
|
|
+ ComputerTestQuestion computerTestQuestion = new ComputerTestQuestion(paperDetailUnit);
|
|
|
|
+ //得到小题题干
|
|
|
|
+ computerTestQuestion.setBody(getBody(paperDetailUnit.getQuestion()));
|
|
|
|
+ //得到小题所有选项
|
|
|
|
+ computerTestQuestion.setOptions(getOption(paperDetailUnit.getQuestion()));
|
|
|
|
+ //查询小题中的 套题
|
|
|
|
+ List<Question> subQuestionsList = paperDetailUnit.getQuestion().getSubQuestions();
|
|
|
|
+ //判断这个小题中是否有套题
|
|
|
|
+ if(subQuestionsList!=null&&subQuestionsList.size()>0){
|
|
|
|
+ List<ComputerTestQuestion> subQuestions = new ArrayList<ComputerTestQuestion>();
|
|
|
|
+ //遍历每个套题
|
|
|
|
+ for(Question subQuestion:subQuestionsList){
|
|
|
|
+ ComputerTestQuestion subcomputerTestQuestion = new ComputerTestQuestion(subQuestion);
|
|
|
|
+ subcomputerTestQuestion.setBody(getBody(subQuestion));
|
|
|
|
+ subcomputerTestQuestion.setOptions(getOption(subQuestion));
|
|
|
|
+ subQuestions.add(subcomputerTestQuestion);
|
|
|
|
+ }
|
|
|
|
+ computerTestQuestion.setSubQuestions(subQuestions);
|
|
|
|
+ }
|
|
|
|
+ questions.add(computerTestQuestion);
|
|
|
|
+ }
|
|
|
|
+ computerTestPaperDetail.setQuestions(questions);
|
|
|
|
+ details.add(computerTestPaperDetail);
|
|
|
|
+ }
|
|
|
|
+ computerTestPaper.setDetails(details);
|
|
|
|
+ computerTestPapers.add(computerTestPaper);
|
|
|
|
+ }
|
|
|
|
+ return computerTestPapers;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Sections getBody(Question question){
|
|
|
|
+ Sections body = new Sections();
|
|
|
|
+ List<Section> sections = new ArrayList<Section>();
|
|
|
|
+ Section section = new Section();
|
|
|
|
+ //得到小题题干
|
|
|
|
+ String questionBodyString = question.getQuesBody();
|
|
|
|
+ //得到小题题干行数
|
|
|
|
+ String[] questionRowStrings = questionBodyString.split("</p>");
|
|
|
|
+ //将小题题干拆分为Block集合
|
|
|
|
+ section.setBlocks(disposeQuestionBodyOrOption(questionRowStrings));
|
|
|
|
+ sections.add(section);
|
|
|
|
+ body.setSections(sections);
|
|
|
|
+ return body;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<ComputerTestOption> getOption(Question question){
|
|
|
|
+ //得到小题选项
|
|
|
|
+ List<QuesOption> quesOptions = question.getQuesOptions();
|
|
|
|
+ List<ComputerTestOption> options = new ArrayList<ComputerTestOption>();
|
|
|
|
+ //遍历小题选项
|
|
|
|
+ if(quesOptions!=null&&quesOptions.size()>0){
|
|
|
|
+ for(QuesOption quesOption: quesOptions){
|
|
|
|
+ ComputerTestOption option = new ComputerTestOption();
|
|
|
|
+ option.setNumber(new Integer(quesOption.getNumber()));
|
|
|
|
+ option.setCorrect(quesOption.getIsCorrect()==1?true:false);
|
|
|
|
+ Sections body2 = new Sections();
|
|
|
|
+ Section section2 = new Section();
|
|
|
|
+ List<Section> sections2 = new ArrayList<Section>();
|
|
|
|
+ //得到小题选项
|
|
|
|
+ String optionString = quesOption.getOptionBody();
|
|
|
|
+ String[] optionStrings = optionString.split("</p>");
|
|
|
|
+ section2.setBlocks(disposeQuestionBodyOrOption(optionStrings));
|
|
|
|
+ sections2.add(section2);
|
|
|
|
+ body2.setSections(sections2);
|
|
|
|
+ option.setBody(body2);
|
|
|
|
+ options.add(option);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return options;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<Block> disposeQuestionBodyOrOption(String[] questionRowStrings) {
|
|
|
|
+ List<Block> blocks = new ArrayList<Block>();
|
|
|
|
+ for(int i=0;i<questionRowStrings.length;i++){
|
|
|
|
+ Block block = new Block();
|
|
|
|
+ //去掉每行里面的<p>,<span>,</span>标签
|
|
|
|
+ String questionRowString = questionRowStrings[i].replaceAll("<p>", "").replaceAll("<span>", "").replaceAll("</span>", "");
|
|
|
|
+ //判断是否有图片
|
|
|
|
+ if(questionRowString.contains("<img")){
|
|
|
|
+ Map<String, Object> param = new HashMap<String, Object>();
|
|
|
|
+ //需要继续做截取,取到Parma
|
|
|
|
+ block.setType("image");
|
|
|
|
+ //获取图片的路径
|
|
|
|
+ List<String> strSrcList = getImg(questionRowString, "src");
|
|
|
|
+ if(strSrcList.size()>0){
|
|
|
|
+ String strSrc = strSrcList.get(0).replaceAll("src=\"", "").replaceAll("\"", "");
|
|
|
|
+ block.setValue(strSrc);
|
|
|
|
+ }
|
|
|
|
+ //获取图片的高度
|
|
|
|
+ List<String> strHeightList = getImg(questionRowString, "height");
|
|
|
|
+ if(strHeightList.size()>0){
|
|
|
|
+ String strHeight = strHeightList.get(0).replaceAll("height=\"", "").replaceAll("\"", "");
|
|
|
|
+ param.put("height", strHeight);
|
|
|
|
+ }
|
|
|
|
+ //获取图片的宽度
|
|
|
|
+ List<String> strWidthList = getImg(questionRowString, "width");
|
|
|
|
+ if(strHeightList.size()>0){
|
|
|
|
+ String strWidth = strWidthList.get(0).replaceAll("width=\"", "").replaceAll("\"", "");
|
|
|
|
+ param.put("width", strWidth);
|
|
|
|
+ }
|
|
|
|
+ block.setParam(param);
|
|
|
|
+ blocks.add(block);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ block.setType("text");
|
|
|
|
+ block.setValue(questionRowString);
|
|
|
|
+ blocks.add(block);
|
|
|
|
+ }
|
|
|
|
+ return blocks;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取图片里面的路径,长度,宽度
|
|
|
|
+ * @param s
|
|
|
|
+ * @param str
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private List<String> getImg(String s,String str)
|
|
|
|
+ {
|
|
|
|
+ String regex;
|
|
|
|
+ List<String> list = new ArrayList<String>();
|
|
|
|
+ regex = str + "=\"(.*?)\"";
|
|
|
|
+ Pattern pa = Pattern.compile(regex, Pattern.DOTALL);
|
|
|
|
+ Matcher ma = pa.matcher(s);
|
|
|
|
+ while (ma.find())
|
|
|
|
+ {
|
|
|
|
+ list.add(ma.group());
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 生成试卷或答案Word,上传至又拍云
|
|
|
|
+ * @param orgName
|
|
|
|
+ * @param dataMap
|
|
|
|
+ * @param extractConfig
|
|
|
|
+ * @param paperId
|
|
|
|
+ * @param accessUser
|
|
|
|
+ */
|
|
|
|
+ protected void uploadPaperOrAnswerFile(PaperExp paperExp,ExtractConfig extractConfig,AccessUser accessUser,String currNum,Template template,ExamFileType examFileType){
|
|
|
|
+ String paperfileName = currNum+examFileType.name()+DOCX_SUFFIX;
|
|
|
|
+ try {
|
|
|
|
+ DocxProcessUtil.exportWord(paperExp,paperfileName,template);
|
|
|
|
+ DocxProcessUtil.processImage(paperfileName,getPkgList(paperExp.getId()));
|
|
|
|
+ File file = new File(TEMP_FILE_EXP+paperfileName);
|
|
|
|
+ String paperFilePath = uploadUrl+paperfileName;
|
|
|
|
+ UpYun upyun = new UpYun(bucketName,userName,password);
|
|
|
|
+ upyun.writeFile(paperFilePath,file,true);
|
|
|
|
+ examFileService.saveExamFile(new ExamFile(extractConfig,paperFilePath,examFileType,DOCX_SUFFIX),accessUser);
|
|
|
|
+ file.delete();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 生成试卷结构,上传至又拍云
|
|
|
|
+ */
|
|
|
|
+ protected void uploadPaperStructure(PaperExp paperExp,ExtractConfig extractConfig,AccessUser accessUser,String currNum,List<QuestionTypeNum> questionTypeNums) {
|
|
|
|
+ exportObjectiveQuestionStructures(paperExp,extractConfig,accessUser,currNum,questionTypeNums);
|
|
|
|
+ exportSubjectiveQuestionStructures(paperExp,extractConfig,accessUser,currNum);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获得客观题导出结构,并上传至又拍云
|
|
|
|
+ * @param paperExp
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ protected void exportObjectiveQuestionStructures(PaperExp paperExp,ExtractConfig extractConfig,AccessUser accessUser,String currNum,List<QuestionTypeNum> questionTypeNums){
|
|
|
|
+ String objectiveFilename = currNum+ExamFileType.PAPER_STRUCTURE_OBJECTIVE.name()+EXCEL_SUFFIX;
|
|
|
|
+ List<PaperDetailExp> objectiveDetails = paperExp.getObjectiveDetails();
|
|
|
|
+ //根据试卷结构导出设置中的数量补齐客观题
|
|
|
|
+ fillObjectiveQuestions(objectiveDetails,questionTypeNums);
|
|
|
|
+ List<ObjectiveQuestionStructure> objectiveQuestionStructureList = new ArrayList<ObjectiveQuestionStructure>();
|
|
|
|
+ for(PaperDetailExp paperDetailExp:objectiveDetails){
|
|
|
|
+ for(PaperDetailUnitExp unit:paperDetailExp.getPaperDetailUnits()){
|
|
|
|
+ objectiveQuestionStructureList.add(new ObjectiveQuestionStructure(paperExp,paperDetailExp,unit));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ExcelWriter objectiveExcelExporter = new ExcelWriter(ObjectiveQuestionStructure.class);
|
|
|
|
+ try {
|
|
|
|
+ File file = new File(TEMP_FILE_EXP+objectiveFilename);
|
|
|
|
+ FileOutputStream out = new FileOutputStream(file);
|
|
|
|
+ objectiveExcelExporter.write(objectiveFilename,objectiveQuestionStructureList,out);
|
|
|
|
+ String objectiveFilePath = uploadUrl+objectiveFilename;
|
|
|
|
+ UpYun upyun = new UpYun(bucketName,userName,password);
|
|
|
|
+ upyun.writeFile(objectiveFilePath,file,true);
|
|
|
|
+ examFileService.saveExamFile(new ExamFile(extractConfig,objectiveFilePath,ExamFileType.PAPER_STRUCTURE_OBJECTIVE,EXCEL_SUFFIX),accessUser);
|
|
|
|
+ file.delete();
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据试卷结构导出设置中的数量补齐客观题
|
|
|
|
+ * @param objectiveDetails
|
|
|
|
+ * @param questionTypeNums
|
|
|
|
+ */
|
|
|
|
+ public void fillObjectiveQuestions(List<PaperDetailExp> objectiveDetails,List<QuestionTypeNum> questionTypeNums) {
|
|
|
|
+ for(PaperDetailExp paperDetailExp:objectiveDetails){
|
|
|
|
+ List<PaperDetailUnitExp> paperDetailUnits = paperDetailExp.getPaperDetailUnits();
|
|
|
|
+ //1.将大题中的小题排序
|
|
|
|
+ Collections.sort(paperDetailUnits);
|
|
|
|
+ //2.将小题的number重新设置
|
|
|
|
+ for(int i = 0;i<paperDetailUnits.size();i++){
|
|
|
|
+ PaperDetailUnitExp paperDetailUnitExp = paperDetailUnits.get(i);
|
|
|
|
+ paperDetailUnitExp.setNumber(i+1);
|
|
|
|
+ }
|
|
|
|
+ //3.根据试卷结构导出设置中的数量补齐客观题
|
|
|
|
+ QuesStructType type = paperDetailUnits.get(0).getQuestionType();
|
|
|
|
+ int unitSize = paperDetailUnits.size();
|
|
|
|
+ for(QuestionTypeNum questionTypeNum:questionTypeNums){
|
|
|
|
+ if(type==questionTypeNum.getQuestionType()){
|
|
|
|
+ int length = questionTypeNum.getQuantity()-unitSize;
|
|
|
|
+ for(int i = 0;i<length;i++){
|
|
|
|
+ PaperDetailUnitExp paperDetailUnitExp = new PaperDetailUnitExp();
|
|
|
|
+ paperDetailUnitExp.setQuestionType(type);
|
|
|
|
+ paperDetailUnitExp.setScore((double) 0);
|
|
|
|
+ paperDetailUnitExp.setNumber(unitSize+(i+1));
|
|
|
|
+ Question question = new Question();
|
|
|
|
+ question.setQuesAnswer("#");
|
|
|
|
+ paperDetailUnitExp.setQuestion(question);
|
|
|
|
+ paperDetailUnits.add(paperDetailUnitExp);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 检查客观题数量是否小于试卷结构导出设置的数量
|
|
|
|
+ * @param paperExp
|
|
|
|
+ * @param objectiveDetails
|
|
|
|
+ * @param questionTypeNums
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ protected void checkObjectiveDetailsNum(PaperExp paperExp,List<PaperDetailExp> objectiveDetails,List<QuestionTypeNum> questionTypeNums) {
|
|
|
|
+ for(PaperDetailExp paperDetailExp:objectiveDetails){
|
|
|
|
+ for(QuestionTypeNum typeNum:questionTypeNums){
|
|
|
|
+ QuesStructType quesStructType = paperDetailExp.getPaperDetailUnits().get(0).getQuestionType();
|
|
|
|
+ if(typeNum.getQuestionType()==quesStructType){
|
|
|
|
+ if(paperDetailExp.getUnitCount()>typeNum.getQuantity()){
|
|
|
|
+ throw new RuntimeException("试卷:"+paperExp.getName()
|
|
|
|
+ +"中"+quesStructType.getName()+"的数量:"+paperDetailExp.getUnitCount()
|
|
|
|
+ + ",大于试卷结构导出设置的数量:"+typeNum.getQuantity()+",不符合试卷结构导出规则");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获得主观题导出结构,并上传至又拍云
|
|
|
|
+ * @param paperExp
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ protected void exportSubjectiveQuestionStructures(PaperExp paperExp,ExtractConfig extractConfig,AccessUser accessUser,String currNum){
|
|
|
|
+ String subjectiveFileName = currNum+ExamFileType.PAPER_STRUCTURE_SUBJECTIVE.name()+EXCEL_SUFFIX;
|
|
|
|
+ List<PaperDetailExp> subjectiveDetails = paperExp.getSubjectiveDetails();
|
|
|
|
+ List<SubjectiveQuestionStructure> subjectiveQuestionStructureList = new ArrayList<SubjectiveQuestionStructure>();
|
|
|
|
+ for(PaperDetailExp paperDetailExp:subjectiveDetails){
|
|
|
|
+ for(PaperDetailUnitExp unit:paperDetailExp.getPaperDetailUnits()){
|
|
|
|
+ subjectiveQuestionStructureList.add(new SubjectiveQuestionStructure(paperExp,paperDetailExp,unit));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ExcelWriter subjectiveExcelExporter = new ExcelWriter(SubjectiveQuestionStructure.class);
|
|
|
|
+ try {
|
|
|
|
+ File file = new File(TEMP_FILE_EXP+subjectiveFileName);
|
|
|
|
+ FileOutputStream out = new FileOutputStream(file);
|
|
|
|
+ subjectiveExcelExporter.write(subjectiveFileName,subjectiveQuestionStructureList,out);
|
|
|
|
+ String subjectiveFilePath = uploadUrl+subjectiveFileName;
|
|
|
|
+ UpYun upyun = new UpYun(bucketName,userName,password);
|
|
|
|
+ upyun.writeFile(subjectiveFilePath,file,true);
|
|
|
|
+ examFileService.saveExamFile(new ExamFile(extractConfig,subjectiveFilePath,ExamFileType.PAPER_STRUCTURE_SUBJECTIVE,EXCEL_SUFFIX),accessUser);
|
|
|
|
+ file.delete();
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|