|
@@ -5,9 +5,12 @@ import java.io.FileOutputStream;
|
|
|
import java.io.OutputStream;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
@@ -25,6 +28,8 @@ import cn.com.qmth.examcloud.core.questions.dao.PaperDetailUnitRepo;
|
|
|
import cn.com.qmth.examcloud.core.questions.dao.PaperRepo;
|
|
|
import cn.com.qmth.examcloud.core.questions.dao.QuesTypeNameRepo;
|
|
|
import cn.com.qmth.examcloud.core.questions.dao.entity.Course;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.ExamPaper;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.ExtractConfig;
|
|
|
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.PaperDetailStruct;
|
|
@@ -38,6 +43,7 @@ import cn.com.qmth.examcloud.core.questions.service.PaperDetailUnitService;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.temp.vo.DdExcelDto;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.temp.vo.DdPaperDto;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.temp.vo.DdPaperStructDto;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.temp.vo.SubQuestionDto;
|
|
|
|
|
|
@Service("ddExcelService")
|
|
|
public class DdExcelService {
|
|
@@ -562,6 +568,88 @@ public class DdExcelService {
|
|
|
System.out.println("结束...");
|
|
|
}
|
|
|
|
|
|
+ @SuppressWarnings("resource")
|
|
|
+ public void exportSubQues(String orgId,Long examId,List<String> codes) throws Exception{
|
|
|
+ List<SubQuestionDto> dtos = new ArrayList<SubQuestionDto>();
|
|
|
+ int j = 1;
|
|
|
+ for(String code:codes){
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("orgId").is(orgId));
|
|
|
+ query.addCriteria(Criteria.where("examId").is(examId));
|
|
|
+ System.out.println("开始处理第"+j+"个调卷规则。。。。。。。");
|
|
|
+ query.addCriteria(Criteria.where("courseCode").is(code));
|
|
|
+ ExtractConfig tempConfig = this.mongoTemplate.findOne(query, ExtractConfig.class);
|
|
|
+ //定义试卷集合
|
|
|
+ Set<String> ids = new HashSet<String>();
|
|
|
+ //获取试卷
|
|
|
+ List<ExamPaper> examPaperList = tempConfig.getExamPaperList();
|
|
|
+ System.out.println("原试卷数量:"+examPaperList.size());
|
|
|
+ for(ExamPaper examPaper:examPaperList){
|
|
|
+ ids.add(examPaper.getPaper().getId());
|
|
|
+ }
|
|
|
+ System.out.println("去重后的试卷数量:"+ids.size());
|
|
|
+ //循环去重后的试卷
|
|
|
+ for(String id:ids){
|
|
|
+ Paper basePaper = paperRepo.findOne(id);
|
|
|
+ //根据试卷查询所有小题
|
|
|
+ List<PaperDetailUnit> allPaperDetailUnits = paperDetailUnitRepo.findByPaper(basePaper);
|
|
|
+ //循环所有小题,寻找主观题
|
|
|
+ for(PaperDetailUnit paperDetailUnit:allPaperDetailUnits){
|
|
|
+ Question question = paperDetailUnit.getQuestion();
|
|
|
+ //填空或问答
|
|
|
+ if(question.getQuestionType()==QuesStructType.FILL_BLANK_QUESTION
|
|
|
+ ||question.getQuestionType()==QuesStructType.TEXT_ANSWER_QUESTION){
|
|
|
+ String body = question.getQuesBody();
|
|
|
+ String clearBody = body.replace("<p>", "").replace("</p>", "").replace("<span>", "").replace("</span>", "").replace("###", "___");
|
|
|
+ String answer = question.getQuesAnswer();
|
|
|
+ String clearAnswer = answer.replace("<p>", "").replace("</p>", "").replace("<span>", "").replace("</span>", "");
|
|
|
+ SubQuestionDto dto = new SubQuestionDto();
|
|
|
+ dto.setAnswer(answer);
|
|
|
+ dto.setBody(body);
|
|
|
+ dto.setClearAnswer(clearAnswer);
|
|
|
+ dto.setClearBody(clearBody);
|
|
|
+ dto.setCourseCode(tempConfig.getCourseCode());
|
|
|
+ dto.setCourseName(tempConfig.getCourseName());
|
|
|
+ dto.setNumber(paperDetailUnit.getNumber());
|
|
|
+ dto.setPaperId(basePaper.getId());
|
|
|
+ dto.setPaperName(basePaper.getName());
|
|
|
+ dto.setScore(paperDetailUnit.getScore());
|
|
|
+ dtos.add(dto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成Excel对象
|
|
|
+ File ddExcelFile = new File("H:\\subQuesDto.xlsx");
|
|
|
+ Workbook workBook = new XSSFWorkbook(ddExcelFile);
|
|
|
+ //获取第一个工作页
|
|
|
+ Sheet sheet = workBook.getSheetAt(0);
|
|
|
+ //向Excle中写入数据,从第2行开始
|
|
|
+ for(int i = 0;i<dtos.size();i++){
|
|
|
+ //创建一行:从第1行开始,跳过表头
|
|
|
+ Row row = sheet.createRow(i+1);
|
|
|
+ SubQuestionDto dto = dtos.get(i);
|
|
|
+ //每列赋值
|
|
|
+ row.createCell(0).setCellValue(dto.getCourseCode());
|
|
|
+ row.createCell(1).setCellValue(dto.getCourseName());
|
|
|
+ row.createCell(2).setCellValue(dto.getPaperId());
|
|
|
+ row.createCell(3).setCellValue(dto.getPaperName());
|
|
|
+ row.createCell(4).setCellValue(dto.getNumber());
|
|
|
+ row.createCell(5).setCellValue(dto.getBody());
|
|
|
+ row.createCell(6).setCellValue(dto.getClearBody());
|
|
|
+ row.createCell(7).setCellValue(dto.getAnswer());
|
|
|
+ row.createCell(8).setCellValue(dto.getClearAnswer());
|
|
|
+ row.createCell(9).setCellValue(dto.getScore());
|
|
|
+ }
|
|
|
+ File file = new File("H:\\subQuesDtoNew.xlsx");
|
|
|
+ OutputStream out = new FileOutputStream(file);
|
|
|
+ workBook.write(out);
|
|
|
+ out.close();
|
|
|
+ System.out.println("结束...");
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public static void main(String[] args){
|
|
|
// File ddExcelFile = new File("H:\\ddExcelDto.xlsx");
|