|
@@ -1,29 +1,29 @@
|
|
|
package cn.com.qmth.examcloud.core.questions.service.impl;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileInputStream;
|
|
|
-import java.io.FileNotFoundException;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
-import java.io.OutputStream;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.TreeMap;
|
|
|
-import java.util.regex.Matcher;
|
|
|
-import java.util.regex.Pattern;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-
|
|
|
+import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.CommonUtils;
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.FileDisposeUtil;
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.SpringContextUtils;
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.enums.ExamFileType;
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.word.DocxProcessUtil;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.CoursePropertyRepo;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.PaperRepo;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.QuestionAudioRepo;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.*;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.computerTestModel.*;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.ExportPaperService;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.PaperDetailService;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.PaperService;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.PropertyService;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.bean.dto.QuestionDistributeDto;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.converter.PrintExamPaperService;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.export.ExportPaperAbstractService;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.google.gson.Gson;
|
|
|
import main.java.com.UpYun;
|
|
|
-
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.apache.poi.ss.usermodel.Cell;
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
@@ -37,675 +37,662 @@ import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
import org.springframework.data.mongodb.core.query.Query;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
|
-
|
|
|
-import com.google.gson.Gson;
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.PaperRepo;
|
|
|
-import cn.com.qmth.examcloud.core.questions.service.bean.dto.QuestionDistributeDto;
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.Paper;
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.PaperDetail;
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.PaperDetailUnit;
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.computerTestModel.Block;
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.computerTestModel.ComputerTestOption;
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.computerTestModel.ComputerTestPaper;
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.computerTestModel.ComputerTestPaperDetail;
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.computerTestModel.ComputerTestQuestion;
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.computerTestModel.Section;
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.computerTestModel.Sections;
|
|
|
-import cn.com.qmth.examcloud.core.questions.service.ExportPaperService;
|
|
|
-import cn.com.qmth.examcloud.core.questions.service.PaperDetailService;
|
|
|
-import cn.com.qmth.examcloud.core.questions.service.PaperService;
|
|
|
-import cn.com.qmth.examcloud.core.questions.service.export.ExportPaperAbstractService;
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.CoursePropertyRepo;
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.QuestionAudioRepo;
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.CourseProperty;
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.Property;
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.QuesOption;
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.Question;
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.QuestionAudio;
|
|
|
-import cn.com.qmth.examcloud.core.questions.service.PropertyService;
|
|
|
-import cn.com.qmth.examcloud.core.questions.base.CommonUtils;
|
|
|
-import cn.com.qmth.examcloud.core.questions.base.FileDisposeUtil;
|
|
|
-import cn.com.qmth.examcloud.core.questions.base.SpringContextUtils;
|
|
|
-import cn.com.qmth.examcloud.core.questions.base.word.DocxProcessUtil;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.*;
|
|
|
+import java.util.*;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
@Service("exportPaperService")
|
|
|
-public class ExportPaperServiceImpl implements ExportPaperService{
|
|
|
-
|
|
|
- public static final String TEMP_FILE_EXP = "docxExport/";
|
|
|
-
|
|
|
- public static final String TEMP_FILE_NAME = "_考试说明.docx";
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private PaperRepo paperRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private PaperService paperService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private PaperDetailService paperDetailService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
+public class ExportPaperServiceImpl implements ExportPaperService {
|
|
|
+
|
|
|
+ public static final String TEMP_FILE_EXP = "docxExport/";
|
|
|
+
|
|
|
+ public static final String TEMP_FILE_NAME = "_考试说明.docx";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PaperRepo paperRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PaperService paperService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PaperDetailService paperDetailService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private MongoTemplate mongoTemplate;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CoursePropertyRepo coursePropertyRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private PropertyService propertyService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private QuestionAudioRepo questionAudioRepo;
|
|
|
-
|
|
|
- @Value("${upyun.bucketName}")
|
|
|
- protected String bucketName;
|
|
|
-
|
|
|
- @Value("${upyun.userName}")
|
|
|
- protected String userName;
|
|
|
-
|
|
|
- @Value("${upyun.password}")
|
|
|
- protected String password;
|
|
|
-
|
|
|
- @Override
|
|
|
- public void exportPaperFile(String paperId,String serviceName,String exportContentList,HttpServletResponse response,String loginName, String examType) throws Exception {
|
|
|
- ExportPaperAbstractService exportPaperAbstractService = (ExportPaperAbstractService) SpringContextUtils.getBeanById("tjdxExportPaperService");
|
|
|
- //根据试卷id查询试卷
|
|
|
- Paper paper = paperRepo.findOne(paperId);
|
|
|
- List<Paper> papers = new ArrayList<Paper>();
|
|
|
- papers.add(paper);
|
|
|
- String zipFileName = loginName + System.currentTimeMillis() + "";
|
|
|
- File directory = new File(TEMP_FILE_EXP + File.separator + zipFileName);
|
|
|
- if(!directory.exists()){
|
|
|
- directory.mkdirs();
|
|
|
- }
|
|
|
- if(exportContentList.indexOf("COMPUTERTEST_PACKAGE")>-1){
|
|
|
- downJson(paper,zipFileName);
|
|
|
- }
|
|
|
- if(exportContentList.indexOf("PAPER")>-1){
|
|
|
- exportPaperAbstractService.downloadPaper(paperId,zipFileName,examType);
|
|
|
- }
|
|
|
- if(exportContentList.indexOf("ANSWER")>-1){
|
|
|
- exportPaperAbstractService.downloadPaperAnswer(paperId,zipFileName);
|
|
|
- }
|
|
|
- //下载考试说明 2018-2-27 weiwehai
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CoursePropertyRepo coursePropertyRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PropertyService propertyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private QuestionAudioRepo questionAudioRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PrintExamPaperService printExamPaperService;
|
|
|
+
|
|
|
+ @Value("${upyun.bucketName}")
|
|
|
+ protected String bucketName;
|
|
|
+
|
|
|
+ @Value("${upyun.userName}")
|
|
|
+ protected String userName;
|
|
|
+
|
|
|
+ @Value("${upyun.password}")
|
|
|
+ protected String password;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void exportPaperFile(String paperId, String serviceName, String exportContentList, HttpServletResponse response, String loginName, String examType, String psw) throws Exception {
|
|
|
+ ExportPaperAbstractService exportPaperAbstractService = (ExportPaperAbstractService) SpringContextUtils.getBeanById("tjdxExportPaperService");
|
|
|
+ //根据试卷id查询试卷
|
|
|
+ Paper paper = paperRepo.findOne(paperId);
|
|
|
+
|
|
|
+ String zipFileName = loginName + System.currentTimeMillis() + "";
|
|
|
+ File directory = new File(TEMP_FILE_EXP + File.separator + zipFileName);
|
|
|
+ if (!directory.exists()) {
|
|
|
+ directory.mkdirs();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (exportContentList.indexOf(ExamFileType.PRINT_EXAM_PACKAGE.name()) > -1) {
|
|
|
+ printExamPaperService.downloadPaper(Lists.newArrayList(paper), directory.getAbsolutePath(), psw);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (exportContentList.indexOf(ExamFileType.COMPUTERTEST_PACKAGE.name()) > -1) {
|
|
|
+ downJson(paper, zipFileName);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (exportContentList.indexOf(ExamFileType.PAPER.name()) > -1) {
|
|
|
+ exportPaperAbstractService.downloadPaper(paperId, zipFileName, examType);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (exportContentList.indexOf(ExamFileType.ANSWER.name()) > -1) {
|
|
|
+ exportPaperAbstractService.downloadPaperAnswer(paperId, zipFileName);
|
|
|
+ }
|
|
|
+
|
|
|
+ //下载考试说明 2018-2-27 weiwehai
|
|
|
/*if(examType.equals("offLine") && StringUtils.isNotBlank(paper.getExamRemark())){
|
|
|
downExamRemark(paper,zipFileName);
|
|
|
}*/
|
|
|
- FileDisposeUtil.fileToZip(TEMP_FILE_EXP+File.separator+zipFileName,TEMP_FILE_EXP,zipFileName);
|
|
|
- FileDisposeUtil.downloadFile(paper.getName()+"_"+paper.getCourse().getCode()+".zip", TEMP_FILE_EXP+File.separator+zipFileName+".zip",response);
|
|
|
- deteleFolder(TEMP_FILE_EXP,zipFileName);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 下载考试说明
|
|
|
- * @param examRemark
|
|
|
- * @param zipFileName
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- private void downExamRemark(Paper paper,String zipFileName) throws Exception {
|
|
|
- //1.考试说明html转成word
|
|
|
- String title = "<p style=\"text-align:center\"><span style=\"font-size:26px\"><span style=\"font-family:宋体\">考 试 说 明</span></span></p>";
|
|
|
- WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
|
|
|
- DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(title+paper.getExamRemark()));
|
|
|
- //2.导出考试说明word
|
|
|
- File file = new File(TEMP_FILE_EXP+File.separator+zipFileName+File.separator+paper.getCourse().getCode()+TEMP_FILE_NAME);
|
|
|
- Docx4J.save(wordMLPackage, file);
|
|
|
- }
|
|
|
-
|
|
|
- private void deteleFolder(String sourceFilePath,String zipFileName) {
|
|
|
- File ComputerTestPaperfoler = new File(sourceFilePath + File.separator + "json");
|
|
|
- if(ComputerTestPaperfoler.exists()){
|
|
|
- FileUtils.deleteQuietly(ComputerTestPaperfoler);
|
|
|
- }
|
|
|
- File zipFolder = new File(sourceFilePath + File.separator + zipFileName);
|
|
|
- if(zipFolder.exists()){
|
|
|
- FileUtils.deleteQuietly(zipFolder);
|
|
|
- }
|
|
|
- File zipFile = new File(sourceFilePath + File.separator + zipFileName + ".zip");
|
|
|
- if(zipFile.exists()){
|
|
|
- FileUtils.deleteQuietly(zipFile);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void downJson(Paper paper,String zipFileName) {
|
|
|
- ComputerTestPaper computerTestPaper = buildComputerTestPapers(paper);
|
|
|
- String jsonDirectory = TEMP_FILE_EXP + File.separator + "json";
|
|
|
- //新建文件夹
|
|
|
- File dirFile = new File(jsonDirectory);
|
|
|
- if(!dirFile.exists()){
|
|
|
- dirFile.mkdirs();
|
|
|
- }
|
|
|
- makeComputerTestPaperToJsonFile(paper.getCourse().getCode(),computerTestPaper,jsonDirectory);
|
|
|
- downloadAudio(computerTestPaper,jsonDirectory);
|
|
|
- //将文件夹打包成zip压缩包放在docxExport下
|
|
|
- FileDisposeUtil.fileToZip(jsonDirectory,TEMP_FILE_EXP+File.separator+zipFileName,paper.getCourse().getCode()+"_"+paper.getName());
|
|
|
- }
|
|
|
-
|
|
|
- private void downloadAudio(ComputerTestPaper computerTestPaper,String jsonDirectory) {
|
|
|
- //取到所有大题
|
|
|
- List<ComputerTestPaperDetail> details = computerTestPaper.getDetails();
|
|
|
- if(details != null && details.size()>0){
|
|
|
- for(ComputerTestPaperDetail detail:details){
|
|
|
- //取到所有小题集合
|
|
|
- List<ComputerTestQuestion> questions = detail.getQuestions();
|
|
|
- if(questions != null && questions.size()>0){
|
|
|
- for(ComputerTestQuestion question:questions){
|
|
|
- int bodyNum = 1;
|
|
|
- //取到题干
|
|
|
- Sections body = question.getBody();
|
|
|
- List<Section> sections = body.getSections();
|
|
|
- for(Section section:sections){
|
|
|
- List<Block> blocks = section.getBlocks();
|
|
|
- if(blocks != null && blocks.size()>0){
|
|
|
- for(Block block:blocks){
|
|
|
- if(block.getType().equals("audio")){
|
|
|
- String id = block.getValue();
|
|
|
- QuestionAudio questionAudio = questionAudioRepo.findOne(id);
|
|
|
- String audioFileName = computerTestPaper.getCourseCode() + "_" +
|
|
|
- computerTestPaper.getName() + "_" +"_试卷_"+
|
|
|
- detail.getNumber()+"_"+question.getNumber()+
|
|
|
- "_1_"+bodyNum+"."+ questionAudio.getFileSuffixes();
|
|
|
- UpYun upyun = new UpYun(bucketName,userName,password);
|
|
|
- File file = new File(jsonDirectory+File.separator+audioFileName);
|
|
|
- upyun.readFile(questionAudio.getFileUrl(), file);
|
|
|
- bodyNum++;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //取到选项
|
|
|
- List<ComputerTestOption> options = question.getOptions();
|
|
|
- if(options != null && options.size()>0){
|
|
|
- for(ComputerTestOption computerTestOption:options){
|
|
|
- int optionNum = 1;
|
|
|
- //获取选项主体
|
|
|
- Sections optionBody = computerTestOption.getBody();
|
|
|
- List<Section> optionSections = optionBody.getSections();
|
|
|
- if(optionSections != null && optionSections.size()>0){
|
|
|
- for(Section optionSection:optionSections){
|
|
|
- List<Block> blocks = optionSection.getBlocks();
|
|
|
- if(blocks != null && blocks.size()>0){
|
|
|
- for(Block block:blocks){
|
|
|
- if(block.getType().equals("audio")){
|
|
|
- String id = block.getValue();
|
|
|
- QuestionAudio questionAudio = questionAudioRepo.findOne(id);
|
|
|
- String audioFileName = computerTestPaper.getCourseCode() + "_" +
|
|
|
- computerTestPaper.getName() + "_" +"_试卷_"+
|
|
|
- detail.getNumber()+"_"+question.getNumber()+
|
|
|
- "_2_"+computerTestOption.getNumber()+"_"+optionNum +"."+ questionAudio.getFileSuffixes();
|
|
|
- UpYun upyun = new UpYun(bucketName,userName,password);
|
|
|
- File file = new File(jsonDirectory+File.separator+audioFileName);
|
|
|
- upyun.readFile(questionAudio.getFileUrl(), file);
|
|
|
- optionNum++;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
+ FileDisposeUtil.fileToZip(TEMP_FILE_EXP + File.separator + zipFileName, TEMP_FILE_EXP, zipFileName);
|
|
|
+ FileDisposeUtil.downloadFile(paper.getName() + "_" + paper.getCourse().getCode() + ".zip", TEMP_FILE_EXP + File.separator + zipFileName + ".zip", response);
|
|
|
+ deteleFolder(TEMP_FILE_EXP, zipFileName);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载考试说明
|
|
|
+ *
|
|
|
+ * @param zipFileName
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ private void downExamRemark(Paper paper, String zipFileName) throws Exception {
|
|
|
+ //1.考试说明html转成word
|
|
|
+ String title = "<p style=\"text-align:center\"><span style=\"font-size:26px\"><span style=\"font-family:宋体\">考 试 说 明</span></span></p>";
|
|
|
+ WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
|
|
|
+ DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(title + paper.getExamRemark()));
|
|
|
+ //2.导出考试说明word
|
|
|
+ File file = new File(TEMP_FILE_EXP + File.separator + zipFileName + File.separator + paper.getCourse().getCode() + TEMP_FILE_NAME);
|
|
|
+ Docx4J.save(wordMLPackage, file);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void deteleFolder(String sourceFilePath, String zipFileName) {
|
|
|
+ File ComputerTestPaperfoler = new File(sourceFilePath + File.separator + "json");
|
|
|
+ if (ComputerTestPaperfoler.exists()) {
|
|
|
+ FileUtils.deleteQuietly(ComputerTestPaperfoler);
|
|
|
+ }
|
|
|
+ File zipFolder = new File(sourceFilePath + File.separator + zipFileName);
|
|
|
+ if (zipFolder.exists()) {
|
|
|
+ FileUtils.deleteQuietly(zipFolder);
|
|
|
+ }
|
|
|
+ File zipFile = new File(sourceFilePath + File.separator + zipFileName + ".zip");
|
|
|
+ if (zipFile.exists()) {
|
|
|
+ FileUtils.deleteQuietly(zipFile);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void downJson(Paper paper, String zipFileName) {
|
|
|
+ ComputerTestPaper computerTestPaper = buildComputerTestPapers(paper);
|
|
|
+ String jsonDirectory = TEMP_FILE_EXP + File.separator + "json";
|
|
|
+ //新建文件夹
|
|
|
+ File dirFile = new File(jsonDirectory);
|
|
|
+ if (!dirFile.exists()) {
|
|
|
+ dirFile.mkdirs();
|
|
|
+ }
|
|
|
+ makeComputerTestPaperToJsonFile(paper.getCourse().getCode(), computerTestPaper, jsonDirectory);
|
|
|
+ downloadAudio(computerTestPaper, jsonDirectory);
|
|
|
+ //将文件夹打包成zip压缩包放在docxExport下
|
|
|
+ FileDisposeUtil.fileToZip(jsonDirectory, TEMP_FILE_EXP + File.separator + zipFileName, paper.getCourse().getCode() + "_" + paper.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void downloadAudio(ComputerTestPaper computerTestPaper, String jsonDirectory) {
|
|
|
+ //取到所有大题
|
|
|
+ List<ComputerTestPaperDetail> details = computerTestPaper.getDetails();
|
|
|
+ if (details != null && details.size() > 0) {
|
|
|
+ for (ComputerTestPaperDetail detail : details) {
|
|
|
+ //取到所有小题集合
|
|
|
+ List<ComputerTestQuestion> questions = detail.getQuestions();
|
|
|
+ if (questions != null && questions.size() > 0) {
|
|
|
+ for (ComputerTestQuestion question : questions) {
|
|
|
+ int bodyNum = 1;
|
|
|
+ //取到题干
|
|
|
+ Sections body = question.getBody();
|
|
|
+ List<Section> sections = body.getSections();
|
|
|
+ for (Section section : sections) {
|
|
|
+ List<Block> blocks = section.getBlocks();
|
|
|
+ if (blocks != null && blocks.size() > 0) {
|
|
|
+ for (Block block : blocks) {
|
|
|
+ if (block.getType().equals("audio")) {
|
|
|
+ String id = block.getValue();
|
|
|
+ QuestionAudio questionAudio = questionAudioRepo.findOne(id);
|
|
|
+ String audioFileName = computerTestPaper.getCourseCode() + "_" +
|
|
|
+ computerTestPaper.getName() + "_" + "_试卷_" +
|
|
|
+ detail.getNumber() + "_" + question.getNumber() +
|
|
|
+ "_1_" + bodyNum + "." + questionAudio.getFileSuffixes();
|
|
|
+ UpYun upyun = new UpYun(bucketName, userName, password);
|
|
|
+ File file = new File(jsonDirectory + File.separator + audioFileName);
|
|
|
+ upyun.readFile(questionAudio.getFileUrl(), file);
|
|
|
+ bodyNum++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //取到选项
|
|
|
+ List<ComputerTestOption> options = question.getOptions();
|
|
|
+ if (options != null && options.size() > 0) {
|
|
|
+ for (ComputerTestOption computerTestOption : options) {
|
|
|
+ int optionNum = 1;
|
|
|
+ //获取选项主体
|
|
|
+ Sections optionBody = computerTestOption.getBody();
|
|
|
+ List<Section> optionSections = optionBody.getSections();
|
|
|
+ if (optionSections != null && optionSections.size() > 0) {
|
|
|
+ for (Section optionSection : optionSections) {
|
|
|
+ List<Block> blocks = optionSection.getBlocks();
|
|
|
+ if (blocks != null && blocks.size() > 0) {
|
|
|
+ for (Block block : blocks) {
|
|
|
+ if (block.getType().equals("audio")) {
|
|
|
+ String id = block.getValue();
|
|
|
+ QuestionAudio questionAudio = questionAudioRepo.findOne(id);
|
|
|
+ String audioFileName = computerTestPaper.getCourseCode() + "_" +
|
|
|
+ computerTestPaper.getName() + "_" + "_试卷_" +
|
|
|
+ detail.getNumber() + "_" + question.getNumber() +
|
|
|
+ "_2_" + computerTestOption.getNumber() + "_" + optionNum + "." + questionAudio.getFileSuffixes();
|
|
|
+ UpYun upyun = new UpYun(bucketName, userName, password);
|
|
|
+ File file = new File(jsonDirectory + File.separator + audioFileName);
|
|
|
+ upyun.readFile(questionAudio.getFileUrl(), file);
|
|
|
+ optionNum++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 构建机考数据包实体类
|
|
|
- * @param extractConfig
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
- private ComputerTestPaper buildComputerTestPapers(Paper paper){
|
|
|
- //得到所有旧对象的大题对象
|
|
|
- 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(int i = 0;i<paperDetailUnits.size();i++){
|
|
|
- PaperDetailUnit paperDetailUnit = paperDetailUnits.get(i);
|
|
|
- //根据旧的小题对象,生成新的小题对象
|
|
|
- ComputerTestQuestion computerTestQuestion = new ComputerTestQuestion(paperDetailUnit);
|
|
|
- //设置小题题号
|
|
|
- computerTestQuestion.setNumber(i+1);
|
|
|
- //得到小题题干
|
|
|
- computerTestQuestion.setBody(getBodyOrAnswer(paperDetailUnit.getQuestion().getQuesBody()));
|
|
|
- //得到小题所有选项
|
|
|
- computerTestQuestion.setOptions(getOption(paperDetailUnit.getQuestion()));
|
|
|
- //得到小题的答案
|
|
|
- computerTestQuestion.setAnswer(getBodyOrAnswer(paperDetailUnit.getQuestion().getQuesAnswer()));
|
|
|
- //查询小题中的 套题
|
|
|
- List<Question> subQuestionsList = paperDetailUnit.getQuestion().getSubQuestions();
|
|
|
- //判断这个小题中是否有套题
|
|
|
- if(subQuestionsList!=null&&subQuestionsList.size()>0){
|
|
|
- List<ComputerTestQuestion> subQuestions = new ArrayList<ComputerTestQuestion>();
|
|
|
- //遍历每个套题
|
|
|
- for(int j = 0;j<subQuestionsList.size();j++){
|
|
|
- Question subQuestion = subQuestionsList.get(j);
|
|
|
- ComputerTestQuestion subcomputerTestQuestion = new ComputerTestQuestion(subQuestion);
|
|
|
- //设置套题中小题题号
|
|
|
- subcomputerTestQuestion.setNumber(j+1);
|
|
|
- subcomputerTestQuestion.setBody(getBodyOrAnswer(subQuestion.getQuesBody()));
|
|
|
- subcomputerTestQuestion.setOptions(getOption(subQuestion));
|
|
|
- subcomputerTestQuestion.setAnswer(getBodyOrAnswer(subQuestion.getQuesAnswer()));
|
|
|
- subQuestions.add(subcomputerTestQuestion);
|
|
|
- }
|
|
|
- computerTestQuestion.setSubQuestions(subQuestions);
|
|
|
- }
|
|
|
- questions.add(computerTestQuestion);
|
|
|
- }
|
|
|
- computerTestPaperDetail.setQuestions(questions);
|
|
|
- //paperDetail中的题数(unitCount)可能不准确,这里以questions的实际size为准
|
|
|
- computerTestPaperDetail.setQuestionCount(questions.size());
|
|
|
- details.add(computerTestPaperDetail);
|
|
|
- }
|
|
|
- computerTestPaper.setDetails(details);
|
|
|
- return computerTestPaper;
|
|
|
+ public ComputerTestPaper buildComputerTestPapers(Paper paper) {
|
|
|
+ //得到所有旧对象的大题对象
|
|
|
+ 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 (int i = 0; i < paperDetailUnits.size(); i++) {
|
|
|
+ PaperDetailUnit paperDetailUnit = paperDetailUnits.get(i);
|
|
|
+ //根据旧的小题对象,生成新的小题对象
|
|
|
+ ComputerTestQuestion computerTestQuestion = new ComputerTestQuestion(paperDetailUnit);
|
|
|
+ //设置小题题号
|
|
|
+ computerTestQuestion.setNumber(i + 1);
|
|
|
+ //得到小题题干
|
|
|
+ computerTestQuestion.setBody(getBodyOrAnswer(paperDetailUnit.getQuestion().getQuesBody()));
|
|
|
+ //得到小题所有选项
|
|
|
+ computerTestQuestion.setOptions(getOption(paperDetailUnit.getQuestion()));
|
|
|
+ //得到小题的答案
|
|
|
+ computerTestQuestion.setAnswer(getBodyOrAnswer(paperDetailUnit.getQuestion().getQuesAnswer()));
|
|
|
+ //查询小题中的 套题
|
|
|
+ List<Question> subQuestionsList = paperDetailUnit.getQuestion().getSubQuestions();
|
|
|
+ //判断这个小题中是否有套题
|
|
|
+ if (subQuestionsList != null && subQuestionsList.size() > 0) {
|
|
|
+ List<ComputerTestQuestion> subQuestions = new ArrayList<ComputerTestQuestion>();
|
|
|
+ //遍历每个套题
|
|
|
+ for (int j = 0; j < subQuestionsList.size(); j++) {
|
|
|
+ Question subQuestion = subQuestionsList.get(j);
|
|
|
+ ComputerTestQuestion subcomputerTestQuestion = new ComputerTestQuestion(subQuestion);
|
|
|
+ //设置套题中小题题号
|
|
|
+ subcomputerTestQuestion.setNumber(j + 1);
|
|
|
+ subcomputerTestQuestion.setBody(getBodyOrAnswer(subQuestion.getQuesBody()));
|
|
|
+ subcomputerTestQuestion.setOptions(getOption(subQuestion));
|
|
|
+ subcomputerTestQuestion.setAnswer(getBodyOrAnswer(subQuestion.getQuesAnswer()));
|
|
|
+ subQuestions.add(subcomputerTestQuestion);
|
|
|
+ }
|
|
|
+ computerTestQuestion.setSubQuestions(subQuestions);
|
|
|
+ }
|
|
|
+ questions.add(computerTestQuestion);
|
|
|
+ }
|
|
|
+ computerTestPaperDetail.setQuestions(questions);
|
|
|
+ //paperDetail中的题数(unitCount)可能不准确,这里以questions的实际size为准
|
|
|
+ computerTestPaperDetail.setQuestionCount(questions.size());
|
|
|
+ details.add(computerTestPaperDetail);
|
|
|
+ }
|
|
|
+ computerTestPaper.setDetails(details);
|
|
|
+ return computerTestPaper;
|
|
|
}
|
|
|
-
|
|
|
- private Sections getBodyOrAnswer(String str){
|
|
|
- Sections body = new Sections();
|
|
|
- List<Section> sections = new ArrayList<Section>();
|
|
|
- //得到小题题干或者答案行数
|
|
|
- if(StringUtils.isBlank(str)){
|
|
|
- return body;
|
|
|
- }
|
|
|
- String[] questionRowStrings = str.split("</p>");
|
|
|
- for(int i = 0;i<questionRowStrings.length;i++){
|
|
|
- if(disposeQuestionBodyOrOption(questionRowStrings[i]) != null && disposeQuestionBodyOrOption(questionRowStrings[i]).size()>0){
|
|
|
- Section section = new Section();
|
|
|
- //将小题题干拆分为Block集合
|
|
|
- section.setBlocks(disposeQuestionBodyOrOption(questionRowStrings[i]));
|
|
|
- sections.add(section);
|
|
|
- }
|
|
|
- }
|
|
|
- body.setSections(sections);
|
|
|
- return body;
|
|
|
+
|
|
|
+ private Sections getBodyOrAnswer(String str) {
|
|
|
+ Sections body = new Sections();
|
|
|
+ List<Section> sections = new ArrayList<Section>();
|
|
|
+ //得到小题题干或者答案行数
|
|
|
+ if (StringUtils.isBlank(str)) {
|
|
|
+ return body;
|
|
|
+ }
|
|
|
+ String[] questionRowStrings = str.split("</p>");
|
|
|
+ for (int i = 0; i < questionRowStrings.length; i++) {
|
|
|
+ List<Block> blocks = disposeQuestionBodyOrOption(questionRowStrings[i]);
|
|
|
+ if (blocks != null && blocks.size() > 0) {
|
|
|
+ Section section = new Section();
|
|
|
+ //将小题题干拆分为Block集合
|
|
|
+ section.setBlocks(blocks);
|
|
|
+ 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 body = new Sections();
|
|
|
-
|
|
|
- List<Section> sections = new ArrayList<Section>();
|
|
|
- //得到小题选项
|
|
|
- String optionString = quesOption.getOptionBody();
|
|
|
- String[] optionStrings = optionString.split("</p>");
|
|
|
- for(int i = 0;i<optionStrings.length;i++){
|
|
|
- if(disposeQuestionBodyOrOption(optionStrings[i]) != null && disposeQuestionBodyOrOption(optionStrings[i]).size()>0){
|
|
|
- Section section = new Section();
|
|
|
- section.setBlocks(disposeQuestionBodyOrOption(optionStrings[i]));
|
|
|
- sections.add(section);
|
|
|
- }
|
|
|
- }
|
|
|
- body.setSections(sections);
|
|
|
- option.setBody(body);
|
|
|
- options.add(option);
|
|
|
- }
|
|
|
- }
|
|
|
- return options;
|
|
|
+
|
|
|
+ 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 body = new Sections();
|
|
|
+
|
|
|
+ List<Section> sections = new ArrayList<Section>();
|
|
|
+ //得到小题选项
|
|
|
+ String optionString = quesOption.getOptionBody();
|
|
|
+ String[] optionStrings = optionString.split("</p>");
|
|
|
+ for (int i = 0; i < optionStrings.length; i++) {
|
|
|
+ List<Block> blocks = disposeQuestionBodyOrOption(optionStrings[i]);
|
|
|
+ if (blocks != null && blocks.size() > 0) {
|
|
|
+ Section section = new Section();
|
|
|
+ section.setBlocks(blocks);
|
|
|
+ sections.add(section);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ body.setSections(sections);
|
|
|
+ option.setBody(body);
|
|
|
+ options.add(option);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return options;
|
|
|
}
|
|
|
|
|
|
private List<Block> disposeQuestionBodyOrOption(String questionRow) {
|
|
|
- List<Block> blocks = new ArrayList<Block>();
|
|
|
- //去掉每行里面的<p>,<span>,</span>标签
|
|
|
- questionRow = questionRow.replaceAll("<p>", "")
|
|
|
- .replaceAll("</p>", "")
|
|
|
- .replaceAll("<span>", "")
|
|
|
- .replaceAll("</span>", "")
|
|
|
- .replaceAll("</a>", "");
|
|
|
- String[] questionRowStrings = questionRow.split("<|/>|>");
|
|
|
- for(int i = 0;i<questionRowStrings.length;i++){
|
|
|
- Block block = new Block();
|
|
|
- //判断是否有图片
|
|
|
- if(questionRowStrings[i].startsWith("img")){
|
|
|
- questionRowStrings[i] = "<"+questionRowStrings[i]+">";
|
|
|
- Map<String, Object> param = new HashMap<String, Object>();
|
|
|
- //需要继续做截取,取到Parma
|
|
|
- block.setType("image");
|
|
|
- //获取图片的路径
|
|
|
- List<String> strSrcList = getImg(questionRowStrings[i], "src");
|
|
|
- if(strSrcList.size()>0){
|
|
|
- String strSrc = strSrcList.get(0).replaceAll("src=\"", "").replaceAll("\"", "");
|
|
|
- block.setValue(strSrc);
|
|
|
- }
|
|
|
- //获取图片的高度
|
|
|
- List<String> strHeightList = getImg(questionRowStrings[i], "height");
|
|
|
- if(strHeightList.size()>0){
|
|
|
- String strHeight = strHeightList.get(0).replaceAll("height=\"", "").replaceAll("\"", "");
|
|
|
- param.put("height", strHeight);
|
|
|
- }
|
|
|
- //获取图片的宽度
|
|
|
- List<String> strWidthList = getImg(questionRowStrings[i], "width");
|
|
|
- if(strHeightList.size()>0){
|
|
|
- String strWidth = strWidthList.get(0).replaceAll("width=\"", "").replaceAll("\"", "");
|
|
|
- param.put("width", strWidth);
|
|
|
- }
|
|
|
- block.setParam(param);
|
|
|
- blocks.add(block);
|
|
|
- }else if(questionRowStrings[i].startsWith("a")
|
|
|
- &&questionRowStrings[i].contains("id")
|
|
|
- &&questionRowStrings[i].contains("name")){ //处理音频
|
|
|
- questionRowStrings[i] = "<"+questionRowStrings[i]+">";
|
|
|
- block.setPlayTime(1);
|
|
|
- block.setType("audio");
|
|
|
- block.setValue(CommonUtils.getAttrValue(questionRowStrings[i],"id"));
|
|
|
- blocks.add(block);
|
|
|
- }else{
|
|
|
- block.setType("text");
|
|
|
- questionRowStrings[i] = questionRowStrings[i].replace(" ","");//消除空格
|
|
|
- questionRowStrings[i] = questionRowStrings[i].replace(""","\"");//将"转换成\"
|
|
|
- questionRowStrings[i] = questionRowStrings[i].replace("<","<");//将<转换成<
|
|
|
- questionRowStrings[i] = questionRowStrings[i].replace(">",">");//将>转换成>
|
|
|
- questionRowStrings[i] = questionRowStrings[i].replace("&","&");//将&转换成&
|
|
|
- if(StringUtils.isNotBlank(questionRowStrings[i])){
|
|
|
- block.setValue(questionRowStrings[i]);
|
|
|
- blocks.add(block);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return blocks;
|
|
|
- }
|
|
|
-
|
|
|
+ List<Block> blocks = new ArrayList<Block>();
|
|
|
+ //去掉每行里面的<p>,<span>,</span>标签
|
|
|
+ questionRow = questionRow.replaceAll("<p>", "")
|
|
|
+ .replaceAll("</p>", "")
|
|
|
+ .replaceAll("<span>", "")
|
|
|
+ .replaceAll("</span>", "")
|
|
|
+ .replaceAll("</a>", "");
|
|
|
+ String[] questionRowStrings = questionRow.split("<|/>|>");
|
|
|
+ for (int i = 0; i < questionRowStrings.length; i++) {
|
|
|
+ Block block = new Block();
|
|
|
+ String rowStr = questionRowStrings[i];
|
|
|
+ //判断是否有图片
|
|
|
+ if (rowStr.startsWith("img")) {
|
|
|
+ rowStr = "<" + rowStr + ">";
|
|
|
+ Map<String, Object> param = new HashMap<String, Object>();
|
|
|
+ //需要继续做截取,取到Parma
|
|
|
+ block.setType("image");
|
|
|
+ //获取图片的路径
|
|
|
+ List<String> strSrcList = getImg(rowStr, "src");
|
|
|
+ if (strSrcList.size() > 0) {
|
|
|
+ String strSrc = strSrcList.get(0).replaceAll("src=\"", "").replaceAll("\"", "");
|
|
|
+ block.setValue(strSrc);
|
|
|
+ }
|
|
|
+ //获取图片的高度
|
|
|
+ List<String> strHeightList = getImg(rowStr, "height");
|
|
|
+ if (strHeightList.size() > 0) {
|
|
|
+ String strHeight = strHeightList.get(0).replaceAll("height=\"", "").replaceAll("\"", "");
|
|
|
+ param.put("height", strHeight);
|
|
|
+ }
|
|
|
+ //获取图片的宽度
|
|
|
+ List<String> strWidthList = getImg(rowStr, "width");
|
|
|
+ if (strHeightList.size() > 0) {
|
|
|
+ String strWidth = strWidthList.get(0).replaceAll("width=\"", "").replaceAll("\"", "");
|
|
|
+ param.put("width", strWidth);
|
|
|
+ }
|
|
|
+ block.setParam(param);
|
|
|
+ blocks.add(block);
|
|
|
+ } else if (rowStr.startsWith("a")
|
|
|
+ && rowStr.contains("id")
|
|
|
+ && rowStr.contains("name")) { //处理音频
|
|
|
+ rowStr = "<" + rowStr + ">";
|
|
|
+ block.setPlayTime(1);
|
|
|
+ block.setType("audio");
|
|
|
+ block.setValue(CommonUtils.getAttrValue(rowStr, "id"));
|
|
|
+ blocks.add(block);
|
|
|
+ } else {
|
|
|
+ block.setType("text");
|
|
|
+ rowStr = rowStr.replace(" ", "");//消除空格
|
|
|
+ rowStr = rowStr.replace(""", "\"");//将"转换成\"
|
|
|
+ rowStr = rowStr.replace("<", "<");//将<转换成<
|
|
|
+ rowStr = rowStr.replace(">", ">");//将>转换成>
|
|
|
+ rowStr = rowStr.replace("&", "&");//将&转换成&
|
|
|
+ if (StringUtils.isNotBlank(rowStr)) {
|
|
|
+ block.setValue(rowStr);
|
|
|
+ blocks.add(block);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return blocks;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取图片里面的路径,长度,宽度
|
|
|
+ *
|
|
|
* @param s
|
|
|
* @param str
|
|
|
* @return
|
|
|
*/
|
|
|
- private List<String> getImg(String s,String str)
|
|
|
- {
|
|
|
+ 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())
|
|
|
- {
|
|
|
+ while (ma.find()) {
|
|
|
list.add(ma.group());
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 将computerTestPaper对象生成JSON文件存放在jsonDirectoryPath中
|
|
|
- * @param extractConfig
|
|
|
+ *
|
|
|
* @param computerTestPaper
|
|
|
* @param jsonDirectoryPath
|
|
|
*/
|
|
|
- private void makeComputerTestPaperToJsonFile(String courseCode,ComputerTestPaper computerTestPaper,String jsonDirectoryPath){
|
|
|
- //创建新的JSON文件
|
|
|
- File file = new File(jsonDirectoryPath + File.separator+courseCode+".json");
|
|
|
- //将对象转成 json对象
|
|
|
- Gson gson = new Gson();
|
|
|
- String strJSON = gson.toJson(computerTestPaper);
|
|
|
-
|
|
|
- strJSON = CommonUtils.replaceUnicodeStr(strJSON);
|
|
|
- //生成文件流写入JSON文件
|
|
|
- FileOutputStream outputStream = null;
|
|
|
- try {
|
|
|
- outputStream = new FileOutputStream(file);
|
|
|
- byte b[] = strJSON.getBytes();
|
|
|
- outputStream.write(b);
|
|
|
- outputStream.flush();
|
|
|
- } catch (FileNotFoundException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } finally{
|
|
|
- IOUtils.closeQuietly(outputStream);
|
|
|
- }
|
|
|
+ private void makeComputerTestPaperToJsonFile(String courseCode, ComputerTestPaper computerTestPaper, String jsonDirectoryPath) {
|
|
|
+ //创建新的JSON文件
|
|
|
+ File file = new File(jsonDirectoryPath + File.separator + courseCode + ".json");
|
|
|
+ //将对象转成 json对象
|
|
|
+ Gson gson = new Gson();
|
|
|
+ String strJSON = gson.toJson(computerTestPaper);
|
|
|
+
|
|
|
+ strJSON = CommonUtils.replaceUnicodeStr(strJSON);
|
|
|
+ //生成文件流写入JSON文件
|
|
|
+ FileOutputStream outputStream = null;
|
|
|
+ try {
|
|
|
+ outputStream = new FileOutputStream(file);
|
|
|
+ byte b[] = strJSON.getBytes();
|
|
|
+ outputStream.write(b);
|
|
|
+ outputStream.flush();
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ IOUtils.closeQuietly(outputStream);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void exportPaperFiles(List<String> paperIds, String serviceName, String exportContentList, HttpServletResponse response, String loginName, String examType) throws Exception {
|
|
|
+ ExportPaperAbstractService exportPaperAbstractService = (ExportPaperAbstractService) SpringContextUtils.getBeanById("tjdxExportPaperService");
|
|
|
+ //根据试卷id查询所有试卷
|
|
|
+ List<Paper> papers = CommonUtils.toList(paperRepo.findAll(paperIds));
|
|
|
+ String zipFileName = loginName;
|
|
|
+ //创建压缩文件夹
|
|
|
+ File directory = new File(TEMP_FILE_EXP + File.separator + zipFileName);
|
|
|
+ if (directory.exists()) {
|
|
|
+ deteleFolder(TEMP_FILE_EXP, zipFileName);
|
|
|
+ }
|
|
|
+ directory.mkdirs();
|
|
|
+ //下载试卷
|
|
|
+ if (exportContentList.indexOf(ExamFileType.PAPER.name()) > -1) {
|
|
|
+ for (Paper paper : papers) {
|
|
|
+ exportPaperAbstractService.downloadPaper(paper.getId(), zipFileName, examType);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //下载答案
|
|
|
+ if (exportContentList.indexOf(ExamFileType.ANSWER.name()) > -1) {
|
|
|
+ for (Paper paper : papers) {
|
|
|
+ exportPaperAbstractService.downloadPaperAnswer(paper.getId(), zipFileName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //下载机考数据包
|
|
|
+ if (exportContentList.indexOf(ExamFileType.COMPUTERTEST_PACKAGE.name()) > -1) {
|
|
|
+ int i = 1;
|
|
|
+ for (Paper paper : papers) {
|
|
|
+ //创建json文件夹
|
|
|
+ String jsonDir = TEMP_FILE_EXP + File.separator + zipFileName + File.separator + "json";
|
|
|
+ File jsonDirectory = new File(jsonDir);
|
|
|
+ if (!jsonDirectory.exists()) {
|
|
|
+ jsonDirectory.mkdirs();
|
|
|
+ }
|
|
|
+ ComputerTestPaper computerTestPaper = buildComputerTestPapers(paper);
|
|
|
+ makeComputerTestPaperToJsonFile(paper.getCourse().getCode(), computerTestPaper, jsonDir);
|
|
|
+ //将文件夹打包成zip压缩包放在docxExport下
|
|
|
+ FileDisposeUtil.fileToZip(jsonDir, TEMP_FILE_EXP + File.separator + zipFileName, paper.getCourse().getCode() + "_" + paper.getName());
|
|
|
+ //删除json文件夹
|
|
|
+ File ComputerTestPaperfoler = new File(jsonDir);
|
|
|
+ if (ComputerTestPaperfoler.exists()) {
|
|
|
+ FileUtils.deleteQuietly(ComputerTestPaperfoler);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String nameString = System.currentTimeMillis() + "";
|
|
|
+ FileDisposeUtil.fileToZip(TEMP_FILE_EXP + File.separator + zipFileName, TEMP_FILE_EXP, nameString);
|
|
|
+ FileDisposeUtil.downloadFile(nameString + ".zip", TEMP_FILE_EXP + File.separator + nameString + ".zip", response);
|
|
|
+ deteleFolder(TEMP_FILE_EXP, zipFileName);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void downQuestionDistribute(String courseNo, HttpServletResponse response) throws IOException {
|
|
|
+ //1.生成导出Excle的list集合
|
|
|
+ List<QuestionDistributeDto> questionDistributeDtos = new ArrayList<QuestionDistributeDto>();
|
|
|
+ //2.根据课程code查询课程属性集合
|
|
|
+ List<CourseProperty> courseProperties = coursePropertyRepo.findByCourseCodeAndEnable(courseNo, true);
|
|
|
+ //3.遍历课程属性集合,根据课程属性查询一级
|
|
|
+ if (courseProperties != null && courseProperties.size() > 0) {
|
|
|
+ for (CourseProperty courseProperty : courseProperties) {
|
|
|
+ List<Property> parentProperties = propertyService.findPropertyParents(courseProperty.getId(), courseProperty.getOrgId());
|
|
|
+ if (parentProperties != null && parentProperties.size() > 0) {
|
|
|
+ for (Property parentProperty : parentProperties) {
|
|
|
+ List<Property> sonProperties = propertyService.findPropertySons(parentProperty.getId());
|
|
|
+ if (sonProperties != null && sonProperties.size() > 0) {
|
|
|
+ for (Property sonProperty : sonProperties) {
|
|
|
+ //单选题集合
|
|
|
+ List<Question> sinList = questionList(courseNo, courseProperty, QuesStructType.SINGLE_ANSWER_QUESTION, parentProperty, sonProperty);
|
|
|
+ //多选题集合
|
|
|
+ List<Question> mulList = questionList(courseNo, courseProperty, QuesStructType.MULTIPLE_ANSWER_QUESTION, parentProperty, sonProperty);
|
|
|
+ //判断题集合
|
|
|
+ List<Question> bolList = questionList(courseNo, courseProperty, QuesStructType.BOOL_ANSWER_QUESTION, parentProperty, sonProperty);
|
|
|
+ //计算所有题型数量
|
|
|
+ Map<Long, Long> map = countQuesType(sinList, mulList, bolList);
|
|
|
+ QuestionDistributeDto questionDistributeDto = new QuestionDistributeDto(courseProperty.getName(), parentProperty.getName(), sonProperty.getName(), map);
|
|
|
+ questionDistributeDtos.add(questionDistributeDto);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //一级属性不为空,二级属性为空
|
|
|
+ //单选题集合
|
|
|
+ List<Question> sinList = questionList(courseNo, courseProperty, QuesStructType.SINGLE_ANSWER_QUESTION, parentProperty, null);
|
|
|
+ //多选题集合
|
|
|
+ List<Question> mulList = questionList(courseNo, courseProperty, QuesStructType.MULTIPLE_ANSWER_QUESTION, parentProperty, null);
|
|
|
+ //判断题集合
|
|
|
+ List<Question> bolList = questionList(courseNo, courseProperty, QuesStructType.BOOL_ANSWER_QUESTION, parentProperty, null);
|
|
|
+ //计算所有题型数量
|
|
|
+ Map<Long, Long> map = countQuesType(sinList, mulList, bolList);
|
|
|
+ QuestionDistributeDto questionDistributeDto = new QuestionDistributeDto(courseProperty.getName(), parentProperty.getName(), null, map);
|
|
|
+ questionDistributeDtos.add(questionDistributeDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //一级属性为空
|
|
|
+ QuestionDistributeDto questionDistributeDto = new QuestionDistributeDto(courseProperty.getName(), null, null, null);
|
|
|
+ questionDistributeDtos.add(questionDistributeDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //生成Excel导出
|
|
|
+ writeExcel(questionDistributeDtos, 21, courseNo, response);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据源 questionDistributeDtos
|
|
|
+ * Excel列数 cloumnCount
|
|
|
+ *
|
|
|
+ * @param questionDistributeDtos
|
|
|
+ * @param cloumnCount
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ private void writeExcel(List<QuestionDistributeDto> questionDistributeDtos, int cloumnCount, String courseNo, HttpServletResponse response) throws IOException {
|
|
|
+ //读取Excel模板
|
|
|
+ InputStream in = this.getClass().getResourceAsStream("/quesDistinct.xlsx");
|
|
|
+ Workbook workBook = new XSSFWorkbook(in);
|
|
|
+ //System.out.println(workBook.getAllNames());
|
|
|
+ //获取第一个工作页
|
|
|
+ Sheet sheet = workBook.getSheetAt(0);
|
|
|
+ System.out.println(sheet.getSheetName());
|
|
|
+ //往Excel中写入数据,从第5行开始
|
|
|
+ for (int i = 0; i < questionDistributeDtos.size(); i++) {
|
|
|
+ //创建一行:从第五行开始,跳过表头
|
|
|
+ Row row = sheet.createRow(i + 4);
|
|
|
+ //获取这行的记录
|
|
|
+ QuestionDistributeDto questionDistributeDto = questionDistributeDtos.get(i);
|
|
|
+ //每列赋值
|
|
|
+ row.createCell(0).setCellValue(questionDistributeDto.getCoursePropertyName());
|
|
|
+ row.createCell(1).setCellValue(questionDistributeDto.getFirstPropertyName());
|
|
|
+ row.createCell(2).setCellValue(questionDistributeDto.getSecondPropertyName());
|
|
|
+ Map<Long, Long> map = questionDistributeDto.getMap();
|
|
|
+ if (map == null) {
|
|
|
+ for (int j = 0; j < 18; j++) {
|
|
|
+ row.createCell(j + 3).setCellValue(0);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ int j = 3;
|
|
|
+ for (Long key : map.keySet()) {
|
|
|
+ row.createCell(j).setCellValue(map.get(key));
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ File file = new File(TEMP_FILE_EXP + File.separator + "试题分布.xlsx");
|
|
|
+ OutputStream out = new FileOutputStream(file);
|
|
|
+ workBook.write(out);
|
|
|
+ out.close();
|
|
|
+ FileDisposeUtil.downloadFile(courseNo + "试题分布.xlsx", TEMP_FILE_EXP + File.separator + "试题分布.xlsx", response);
|
|
|
+ FileUtils.deleteQuietly(file);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void exportPaperFiles(List<String> paperIds,String serviceName,String exportContentList, HttpServletResponse response,String loginName,String examType) throws Exception {
|
|
|
- ExportPaperAbstractService exportPaperAbstractService = (ExportPaperAbstractService) SpringContextUtils.getBeanById("tjdxExportPaperService");
|
|
|
- //根据试卷id查询所有试卷
|
|
|
- List<Paper> papers = CommonUtils.toList(paperRepo.findAll(paperIds));
|
|
|
- String zipFileName = loginName;
|
|
|
- //创建压缩文件夹
|
|
|
- File directory = new File(TEMP_FILE_EXP + File.separator + zipFileName);
|
|
|
- if(directory.exists()){
|
|
|
- deteleFolder(TEMP_FILE_EXP,zipFileName);
|
|
|
- }
|
|
|
- directory.mkdirs();
|
|
|
- //下载试卷
|
|
|
- if(exportContentList.indexOf("PAPER")>-1){
|
|
|
- for(Paper paper:papers){
|
|
|
- exportPaperAbstractService.downloadPaper(paper.getId(),zipFileName,examType);
|
|
|
- }
|
|
|
- }
|
|
|
- //下载答案
|
|
|
- if(exportContentList.indexOf("ANSWER")>-1){
|
|
|
- for(Paper paper:papers){
|
|
|
- exportPaperAbstractService.downloadPaperAnswer(paper.getId(),zipFileName);
|
|
|
- }
|
|
|
- }
|
|
|
- //下载机考数据包
|
|
|
- if(exportContentList.indexOf("COMPUTERTEST_PACKAGE")>-1){
|
|
|
- int i = 1;
|
|
|
- for(Paper paper:papers){
|
|
|
- //创建json文件夹
|
|
|
- String jsonDir = TEMP_FILE_EXP + File.separator + zipFileName + File.separator + "json";
|
|
|
- File jsonDirectory = new File(jsonDir);
|
|
|
- if(!jsonDirectory.exists()){
|
|
|
- jsonDirectory.mkdirs();
|
|
|
- }
|
|
|
- ComputerTestPaper computerTestPaper = buildComputerTestPapers(paper);
|
|
|
- makeComputerTestPaperToJsonFile(paper.getCourse().getCode(),computerTestPaper,jsonDir);
|
|
|
- //将文件夹打包成zip压缩包放在docxExport下
|
|
|
- FileDisposeUtil.fileToZip(jsonDir,TEMP_FILE_EXP+File.separator+zipFileName,paper.getCourse().getCode()+"_"+paper.getName());
|
|
|
- //删除json文件夹
|
|
|
- File ComputerTestPaperfoler = new File(jsonDir);
|
|
|
- if(ComputerTestPaperfoler.exists()){
|
|
|
- FileUtils.deleteQuietly(ComputerTestPaperfoler);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- String nameString = System.currentTimeMillis()+"";
|
|
|
- FileDisposeUtil.fileToZip(TEMP_FILE_EXP+File.separator+zipFileName,TEMP_FILE_EXP,nameString);
|
|
|
- FileDisposeUtil.downloadFile(nameString +".zip", TEMP_FILE_EXP+File.separator+nameString+".zip",response);
|
|
|
- deteleFolder(TEMP_FILE_EXP,zipFileName);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void downQuestionDistribute(String courseNo,HttpServletResponse response) throws IOException {
|
|
|
- //1.生成导出Excle的list集合
|
|
|
- List<QuestionDistributeDto> questionDistributeDtos = new ArrayList<QuestionDistributeDto>();
|
|
|
- //2.根据课程code查询课程属性集合
|
|
|
- List<CourseProperty> courseProperties = coursePropertyRepo.findByCourseCodeAndEnable(courseNo, true);
|
|
|
- //3.遍历课程属性集合,根据课程属性查询一级
|
|
|
- if(courseProperties != null && courseProperties.size()>0){
|
|
|
- for(CourseProperty courseProperty:courseProperties){
|
|
|
- List<Property> parentProperties = propertyService.findPropertyParents(courseProperty.getId(), courseProperty.getOrgId());
|
|
|
- if(parentProperties != null && parentProperties.size()>0){
|
|
|
- for(Property parentProperty:parentProperties){
|
|
|
- List<Property> sonProperties = propertyService.findPropertySons(parentProperty.getId());
|
|
|
- if(sonProperties != null && sonProperties.size()>0){
|
|
|
- for(Property sonProperty:sonProperties){
|
|
|
- //单选题集合
|
|
|
- List<Question> sinList = questionList(courseNo, courseProperty, QuesStructType.SINGLE_ANSWER_QUESTION, parentProperty, sonProperty);
|
|
|
- //多选题集合
|
|
|
- List<Question> mulList = questionList(courseNo, courseProperty, QuesStructType.MULTIPLE_ANSWER_QUESTION, parentProperty, sonProperty);
|
|
|
- //判断题集合
|
|
|
- List<Question> bolList = questionList(courseNo, courseProperty, QuesStructType.BOOL_ANSWER_QUESTION, parentProperty, sonProperty);
|
|
|
- //计算所有题型数量
|
|
|
- Map<Long,Long> map = countQuesType(sinList,mulList,bolList);
|
|
|
- QuestionDistributeDto questionDistributeDto = new QuestionDistributeDto(courseProperty.getName(),parentProperty.getName(),sonProperty.getName(),map);
|
|
|
- questionDistributeDtos.add(questionDistributeDto);
|
|
|
- }
|
|
|
- }else {
|
|
|
- //一级属性不为空,二级属性为空
|
|
|
- //单选题集合
|
|
|
- List<Question> sinList = questionList(courseNo, courseProperty, QuesStructType.SINGLE_ANSWER_QUESTION, parentProperty, null);
|
|
|
- //多选题集合
|
|
|
- List<Question> mulList = questionList(courseNo, courseProperty, QuesStructType.MULTIPLE_ANSWER_QUESTION, parentProperty, null);
|
|
|
- //判断题集合
|
|
|
- List<Question> bolList = questionList(courseNo, courseProperty, QuesStructType.BOOL_ANSWER_QUESTION, parentProperty, null);
|
|
|
- //计算所有题型数量
|
|
|
- Map<Long,Long> map = countQuesType(sinList,mulList,bolList);
|
|
|
- QuestionDistributeDto questionDistributeDto = new QuestionDistributeDto(courseProperty.getName(),parentProperty.getName(),null,map);
|
|
|
- questionDistributeDtos.add(questionDistributeDto);
|
|
|
- }
|
|
|
- }
|
|
|
- }else {
|
|
|
- //一级属性为空
|
|
|
- QuestionDistributeDto questionDistributeDto = new QuestionDistributeDto(courseProperty.getName(),null,null,null);
|
|
|
- questionDistributeDtos.add(questionDistributeDto);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //生成Excel导出
|
|
|
- writeExcel(questionDistributeDtos,21,courseNo,response);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 数据源 questionDistributeDtos
|
|
|
- * Excel列数 cloumnCount
|
|
|
- * @param questionDistributeDtos
|
|
|
- * @param cloumnCount
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- private void writeExcel(List<QuestionDistributeDto> questionDistributeDtos,int cloumnCount,String courseNo,HttpServletResponse response) throws IOException {
|
|
|
- //读取Excel模板
|
|
|
- InputStream in = this.getClass().getResourceAsStream("/quesDistinct.xlsx");
|
|
|
- Workbook workBook = new XSSFWorkbook(in);
|
|
|
- //System.out.println(workBook.getAllNames());
|
|
|
- //获取第一个工作页
|
|
|
- Sheet sheet = workBook.getSheetAt(0);
|
|
|
- System.out.println(sheet.getSheetName());
|
|
|
- //往Excel中写入数据,从第5行开始
|
|
|
- for(int i=0;i<questionDistributeDtos.size();i++){
|
|
|
- //创建一行:从第五行开始,跳过表头
|
|
|
- Row row = sheet.createRow(i+4);
|
|
|
- //获取这行的记录
|
|
|
- QuestionDistributeDto questionDistributeDto = questionDistributeDtos.get(i);
|
|
|
- //每列赋值
|
|
|
- row.createCell(0).setCellValue(questionDistributeDto.getCoursePropertyName());
|
|
|
- row.createCell(1).setCellValue(questionDistributeDto.getFirstPropertyName());
|
|
|
- row.createCell(2).setCellValue(questionDistributeDto.getSecondPropertyName());
|
|
|
- Map<Long,Long> map = questionDistributeDto.getMap();
|
|
|
- if(map == null){
|
|
|
- for(int j=0;j<18;j++){
|
|
|
- row.createCell(j+3).setCellValue(0);
|
|
|
- }
|
|
|
- }else {
|
|
|
- int j = 3;
|
|
|
- for(Long key:map.keySet()){
|
|
|
- row.createCell(j).setCellValue(map.get(key));
|
|
|
- j++;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- File file = new File(TEMP_FILE_EXP + File.separator + "试题分布.xlsx");
|
|
|
- OutputStream out = new FileOutputStream(file);
|
|
|
- workBook.write(out);
|
|
|
- out.close();
|
|
|
- FileDisposeUtil.downloadFile(courseNo+"试题分布.xlsx", TEMP_FILE_EXP + File.separator + "试题分布.xlsx",response);
|
|
|
- FileUtils.deleteQuietly(file);
|
|
|
- }
|
|
|
-
|
|
|
- private Map<Long, Long> countQuesType(List<Question> sinList,List<Question> mulList, List<Question> bolList) {
|
|
|
- Map<Long,Long> map = new TreeMap<Long, Long>();
|
|
|
- map = buildMap(sinList, map, 1);
|
|
|
- map = buildMap(mulList, map, 2);
|
|
|
- map = buildMap(bolList, map, 3);
|
|
|
- //给map的键排序
|
|
|
- Map<Long, Long> resultMap = sortMapByKey(map);
|
|
|
- return resultMap;
|
|
|
- }
|
|
|
-
|
|
|
- private Map<Long, Long> sortMapByKey(Map<Long, Long> map) {
|
|
|
- if (map == null || map.isEmpty()) {
|
|
|
+ private Map<Long, Long> countQuesType(List<Question> sinList, List<Question> mulList, List<Question> bolList) {
|
|
|
+ Map<Long, Long> map = new TreeMap<Long, Long>();
|
|
|
+ map = buildMap(sinList, map, 1);
|
|
|
+ map = buildMap(mulList, map, 2);
|
|
|
+ map = buildMap(bolList, map, 3);
|
|
|
+ //给map的键排序
|
|
|
+ Map<Long, Long> resultMap = sortMapByKey(map);
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<Long, Long> sortMapByKey(Map<Long, Long> map) {
|
|
|
+ if (map == null || map.isEmpty()) {
|
|
|
return null;
|
|
|
}
|
|
|
- Map<Long, Long> sortMap = new TreeMap<Long, Long>(new Comparator<Long>() {
|
|
|
- public int compare(Long l1,Long l2){
|
|
|
- return l1.compareTo(l2);
|
|
|
- }
|
|
|
- });
|
|
|
- sortMap.putAll(map);
|
|
|
- return sortMap;
|
|
|
- }
|
|
|
-
|
|
|
- private Map<Long, Long> buildMap(List<Question> quesList,Map<Long, Long> map,int questionType) {
|
|
|
- //初始化map
|
|
|
- for(int i=1;i<7;i++){
|
|
|
- if(i<4){
|
|
|
- map.put((long) (questionType*100+i), 0L);
|
|
|
- }else {
|
|
|
- map.put((long) (questionType*100+10+i-3), 0L);
|
|
|
- }
|
|
|
- }
|
|
|
- for(Question question:quesList){
|
|
|
- if(question.getPublicity()){
|
|
|
- //公开
|
|
|
- if(question.getDifficulty() !=null && question.getDifficulty().equals("难") || question.getDifficultyDegree()<0.4 && question.getDifficultyDegree()>0){
|
|
|
- map = buildMapSum(questionType*100+1,map);
|
|
|
- }else if(question.getDifficulty() !=null && question.getDifficulty().equals("中") || question.getDifficultyDegree()<0.8 && question.getDifficultyDegree()>0.3) {
|
|
|
- map = buildMapSum(questionType*100+2,map);
|
|
|
- }else{
|
|
|
- map = buildMapSum(questionType*100+3,map);
|
|
|
- }
|
|
|
- }else {
|
|
|
- //非公开
|
|
|
- if(question.getDifficulty() !=null && question.getDifficulty().equals("难") || question.getDifficultyDegree()<0.4 && question.getDifficultyDegree()>0){
|
|
|
- map = buildMapSum(questionType*100+11,map);
|
|
|
- }else if(question.getDifficulty() !=null && question.getDifficulty().equals("中") || question.getDifficultyDegree()<0.8 && question.getDifficultyDegree()>0.3){
|
|
|
- map = buildMapSum(questionType*100+12,map);
|
|
|
- }else{
|
|
|
- map = buildMapSum(questionType*100+13,map);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
- private Map<Long, Long> buildMapSum(long key, Map<Long, Long> map) {
|
|
|
- Long sum = map.get(key);
|
|
|
- map.put(key, sum+1);
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
- public List<Question> questionList(String courseNo,CourseProperty courseProperty,QuesStructType quesStructType,Property parentProperty,Property sonProperty){
|
|
|
- Query query = new Query();
|
|
|
- query.addCriteria(Criteria.where("orgId").is(courseProperty.getOrgId().toString()));
|
|
|
- query.addCriteria(Criteria.where("course.enable").is("true"));
|
|
|
- query.addCriteria(Criteria.where("course.code").is(courseNo));
|
|
|
- query.addCriteria(Criteria.where("questionType").is(quesStructType.name()));
|
|
|
- query.addCriteria(Criteria.where("quesProperties.coursePropertyName").is(courseProperty.getName()));
|
|
|
- //二级属性不为空,那么一级属性也不为空
|
|
|
- if(sonProperty != null && sonProperty.getId() != null){
|
|
|
- query.addCriteria(Criteria.where("quesProperties").elemMatch(Criteria.where("firstProperty.id").is(Long.valueOf(parentProperty.getId())).and("secondProperty.id").is(Long.valueOf(sonProperty.getId()))));
|
|
|
- }else {
|
|
|
- if(parentProperty != null && parentProperty.getId() != null){
|
|
|
- query.addCriteria(Criteria.where("quesProperties").elemMatch(Criteria.where("firstProperty.id").is(Long.valueOf(parentProperty.getId()))));
|
|
|
+ Map<Long, Long> sortMap = new TreeMap<Long, Long>(new Comparator<Long>() {
|
|
|
+ public int compare(Long l1, Long l2) {
|
|
|
+ return l1.compareTo(l2);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ sortMap.putAll(map);
|
|
|
+ return sortMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<Long, Long> buildMap(List<Question> quesList, Map<Long, Long> map, int questionType) {
|
|
|
+ //初始化map
|
|
|
+ for (int i = 1; i < 7; i++) {
|
|
|
+ if (i < 4) {
|
|
|
+ map.put((long) (questionType * 100 + i), 0L);
|
|
|
+ } else {
|
|
|
+ map.put((long) (questionType * 100 + 10 + i - 3), 0L);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (Question question : quesList) {
|
|
|
+ if (question.getPublicity()) {
|
|
|
+ //公开
|
|
|
+ if (question.getDifficulty() != null && question.getDifficulty().equals("难") || question.getDifficultyDegree() < 0.4 && question.getDifficultyDegree() > 0) {
|
|
|
+ map = buildMapSum(questionType * 100 + 1, map);
|
|
|
+ } else if (question.getDifficulty() != null && question.getDifficulty().equals("中") || question.getDifficultyDegree() < 0.8 && question.getDifficultyDegree() > 0.3) {
|
|
|
+ map = buildMapSum(questionType * 100 + 2, map);
|
|
|
+ } else {
|
|
|
+ map = buildMapSum(questionType * 100 + 3, map);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //非公开
|
|
|
+ if (question.getDifficulty() != null && question.getDifficulty().equals("难") || question.getDifficultyDegree() < 0.4 && question.getDifficultyDegree() > 0) {
|
|
|
+ map = buildMapSum(questionType * 100 + 11, map);
|
|
|
+ } else if (question.getDifficulty() != null && question.getDifficulty().equals("中") || question.getDifficultyDegree() < 0.8 && question.getDifficultyDegree() > 0.3) {
|
|
|
+ map = buildMapSum(questionType * 100 + 12, map);
|
|
|
+ } else {
|
|
|
+ map = buildMapSum(questionType * 100 + 13, map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<Long, Long> buildMapSum(long key, Map<Long, Long> map) {
|
|
|
+ Long sum = map.get(key);
|
|
|
+ map.put(key, sum + 1);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Question> questionList(String courseNo, CourseProperty courseProperty, QuesStructType quesStructType, Property parentProperty, Property sonProperty) {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("orgId").is(courseProperty.getOrgId().toString()));
|
|
|
+ query.addCriteria(Criteria.where("course.enable").is("true"));
|
|
|
+ query.addCriteria(Criteria.where("course.code").is(courseNo));
|
|
|
+ query.addCriteria(Criteria.where("questionType").is(quesStructType.name()));
|
|
|
+ query.addCriteria(Criteria.where("quesProperties.coursePropertyName").is(courseProperty.getName()));
|
|
|
+ //二级属性不为空,那么一级属性也不为空
|
|
|
+ if (sonProperty != null && sonProperty.getId() != null) {
|
|
|
+ query.addCriteria(Criteria.where("quesProperties").elemMatch(Criteria.where("firstProperty.id").is(Long.valueOf(parentProperty.getId())).and("secondProperty.id").is(Long.valueOf(sonProperty.getId()))));
|
|
|
+ } else {
|
|
|
+ if (parentProperty != null && parentProperty.getId() != null) {
|
|
|
+ query.addCriteria(Criteria.where("quesProperties").elemMatch(Criteria.where("firstProperty.id").is(Long.valueOf(parentProperty.getId()))));
|
|
|
}
|
|
|
}
|
|
|
List<Question> questionList = this.mongoTemplate.find(query, Question.class);
|
|
|
- return questionList;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public static void main(String[] args) {
|
|
|
- System.out.println("a");
|
|
|
- Map<Long, Long> map = new HashMap<Long, Long>();
|
|
|
- map.put(1l, 1l);
|
|
|
- map.put(1l, 2l);
|
|
|
- System.out.println(map.get(1l));
|
|
|
- }
|
|
|
+ return questionList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ System.out.println("a");
|
|
|
+ Map<Long, Long> map = new HashMap<Long, Long>();
|
|
|
+ map.put(1l, 1l);
|
|
|
+ map.put(1l, 2l);
|
|
|
+ System.out.println(map.get(1l));
|
|
|
+ }
|
|
|
}
|