|
@@ -1,59 +1,20 @@
|
|
|
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.util.ArrayList;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.regex.Matcher;
|
|
|
-import java.util.regex.Pattern;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
-import main.java.com.UpYun;
|
|
|
-
|
|
|
-import org.apache.commons.io.FileUtils;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-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.util.excel.ExcelWriter;
|
|
|
|
|
|
-import com.google.gson.Gson;
|
|
|
-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.PaperDetailUnitExp;
|
|
|
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.ExtractConfig;
|
|
|
-import com.qmth.cqb.paper.model.Paper;
|
|
|
-import com.qmth.cqb.paper.model.PaperDetail;
|
|
|
-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.PaperDetailService;
|
|
|
-import com.qmth.cqb.paper.service.PaperService;
|
|
|
-import com.qmth.cqb.question.model.QuesOption;
|
|
|
-import com.qmth.cqb.question.model.Question;
|
|
|
import com.qmth.cqb.utils.CommonUtils;
|
|
|
-import com.qmth.cqb.utils.FileDisposeUtil;
|
|
|
import com.qmth.cqb.utils.enums.ExamFileType;
|
|
|
import com.qmth.cqb.utils.enums.ExportType;
|
|
|
import com.qmth.cqb.utils.word.DocxProcessUtil;
|
|
@@ -62,22 +23,11 @@ import com.qmth.cqb.utils.word.DocxProcessUtil;
|
|
|
* @author chenken
|
|
|
* @date 2017年7月7日 上午11:29:49
|
|
|
* @company QMTH
|
|
|
- * @description 陕西师范试卷导出service
|
|
|
+ * @description 陕西师范大学导出、上传文件service
|
|
|
*/
|
|
|
@Service("sxsfExportPaperService")
|
|
|
public class SxsfExportPaperService extends ExportPaperAbstractService {
|
|
|
|
|
|
- private static final Logger logger = LoggerFactory.getLogger(SxsfExportPaperService.class);
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private PaperService paperService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private PaperDetailService paperDetailService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- PaperRepo paperRepo;
|
|
|
-
|
|
|
@Override
|
|
|
public void downloadPaper(String paperId, HttpServletResponse response) throws Exception {
|
|
|
PaperExp paperExp = initExportPaper(paperId);
|
|
@@ -104,19 +54,19 @@ public class SxsfExportPaperService extends ExportPaperAbstractService {
|
|
|
//没有试卷结构导出设置
|
|
|
if(exportStructure==null){
|
|
|
//上传试卷
|
|
|
- uploadPaperWord(paperExp,extractConfig,paperId,accessUser,currNum);
|
|
|
+ uploadPaperOrAnswerFile(paperExp,extractConfig,accessUser,currNum,SXSF_TEMPLATE_PAPER,ExamFileType.PAPER);
|
|
|
//上传答案
|
|
|
- uploadAnswerWord(paperExp,extractConfig,paperId,accessUser,currNum);
|
|
|
+ uploadPaperOrAnswerFile(paperExp,extractConfig,accessUser,currNum,SXSF_TEMPLATE_ANSWER,ExamFileType.ANSWER);
|
|
|
}else if(exportStructure!=null&&exportStructure.getExportType()==ExportType.NORMAL){
|
|
|
List<QuestionTypeNum> questionTypeNums = exportStructure.getQuestionTypeNums();
|
|
|
//检查试卷中客观题的数量是否大于试卷导出设置中的设置的数量
|
|
|
checkObjectiveDetailsNum(paperExp,objectiveDetails,questionTypeNums);
|
|
|
//上传试卷
|
|
|
- uploadPaperWord(paperExp,extractConfig,paperId,accessUser,currNum);
|
|
|
+ uploadPaperOrAnswerFile(paperExp,extractConfig,accessUser,currNum,SXSF_TEMPLATE_PAPER,ExamFileType.PAPER);
|
|
|
//上传答案
|
|
|
- uploadAnswerWord(paperExp,extractConfig,paperId,accessUser,currNum);
|
|
|
+ uploadPaperOrAnswerFile(paperExp,extractConfig,accessUser,currNum,SXSF_TEMPLATE_ANSWER,ExamFileType.ANSWER);
|
|
|
//上传试卷结构 不能在上传试卷和答案之前
|
|
|
- uploadPaperStructure(paperExp,extractConfig,paperId,accessUser,currNum,questionTypeNums);
|
|
|
+ uploadPaperStructure(paperExp,extractConfig,accessUser,currNum,questionTypeNums);
|
|
|
}else if(exportStructure!=null&&exportStructure.getExportType()==ExportType.ONLINE){
|
|
|
//上传机考JSON文件
|
|
|
uploadComputerTestFile(extractConfig,accessUser);
|
|
@@ -124,375 +74,5 @@ public class SxsfExportPaperService extends ExportPaperAbstractService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 生成试卷Word,上传至又拍云
|
|
|
- * @param orgName
|
|
|
- * @param dataMap
|
|
|
- * @param extractConfig
|
|
|
- * @param paperId
|
|
|
- * @param accessUser
|
|
|
- */
|
|
|
- private void uploadPaperWord(PaperExp paperExp,ExtractConfig extractConfig,String paperId,AccessUser accessUser,String currNum){
|
|
|
- String paperfileName = currNum+ExamFileType.PAPER.name()+DOCX_SUFFIX;
|
|
|
- try {
|
|
|
- DocxProcessUtil.exportWord(paperExp,paperfileName,SXSF_TEMPLATE_PAPER);
|
|
|
- DocxProcessUtil.processImage(paperfileName,getPkgList(paperId));
|
|
|
- File paperFile = new File(TEMP_FILE_EXP+paperfileName);
|
|
|
- String paperFilePath = uploadUrl+paperfileName;
|
|
|
- UpYun upyun = new UpYun(bucketName,userName,password);
|
|
|
- upyun.writeFile(paperFilePath, paperFile,true);
|
|
|
- examFileService.saveExamFile(new ExamFile(extractConfig,paperFilePath,ExamFileType.PAPER,DOCX_SUFFIX),accessUser);
|
|
|
- paperFile.delete();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 生成答案Word,上传至又拍云
|
|
|
- * @param orgName
|
|
|
- * @param dataMap
|
|
|
- * @param extractConfig
|
|
|
- * @param paperId
|
|
|
- * @param accessUser
|
|
|
- */
|
|
|
- private void uploadAnswerWord(PaperExp paperExp,ExtractConfig extractConfig,String paperId,AccessUser accessUser,String currNum){
|
|
|
- String answerFileName = currNum+ExamFileType.ANSWER.name()+DOCX_SUFFIX;
|
|
|
- try {
|
|
|
- DocxProcessUtil.exportWord(paperExp,answerFileName,SXSF_TEMPLATE_ANSWER);
|
|
|
- DocxProcessUtil.processImage(answerFileName,getPkgList(paperId));
|
|
|
- File answerFile = new File(TEMP_FILE_EXP+answerFileName);
|
|
|
- String answerFilePath = uploadUrl+answerFileName;
|
|
|
- UpYun upyun = new UpYun(bucketName,userName,password);
|
|
|
- upyun.writeFile(answerFilePath, answerFile,true);
|
|
|
- examFileService.saveExamFile(new ExamFile(extractConfig,answerFilePath,ExamFileType.ANSWER,DOCX_SUFFIX),accessUser);
|
|
|
- answerFile.delete();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 生成试卷结构,上传至又拍云
|
|
|
- */
|
|
|
- private void uploadPaperStructure(PaperExp paperExp,ExtractConfig extractConfig,String paperId,AccessUser accessUser,String currNum,List<QuestionTypeNum> questionTypeNums) {
|
|
|
- exportObjectiveQuestionStructures(paperExp,extractConfig,accessUser,currNum,questionTypeNums);
|
|
|
- exportSubjectiveQuestionStructures(paperExp,extractConfig,accessUser,currNum);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获得客观题导出结构,并上传至又拍云
|
|
|
- * @param paperExp
|
|
|
- * @return
|
|
|
- */
|
|
|
- private 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
|
|
|
- */
|
|
|
- private 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
|
|
|
- */
|
|
|
- private 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();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 创建机考文件,并打包上传至又拍云
|
|
|
- * @param paperId
|
|
|
- * @param currNum
|
|
|
- * ObjectId("591ead1290994d57cd453464")
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- public 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");
|
|
|
- String zipUpyunFilePath = uploadUrl+jsonDirectoryName+".zip";
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public 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
|
|
|
- */
|
|
|
- public static 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;
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
|