|
@@ -1,6 +1,7 @@
|
|
|
package com.qmth.cqb.paper.service.impl;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
@@ -27,6 +28,7 @@ import org.springframework.data.mongodb.core.query.Query;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.common.dto.core.ExamCourseDto;
|
|
|
import cn.com.qmth.examcloud.common.dto.em.enums.ExamType;
|
|
|
import cn.com.qmth.examcloud.common.dto.question.PaperDetailDto;
|
|
|
import cn.com.qmth.examcloud.common.dto.question.PaperDetailUnitDto;
|
|
@@ -36,6 +38,7 @@ import cn.com.qmth.examcloud.common.dto.question.QuestionDto;
|
|
|
import cn.com.qmth.examcloud.common.dto.question.SubQuestionDto;
|
|
|
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.qmth.cqb.paper.dao.ExportServiceManageRepo;
|
|
|
import com.qmth.cqb.paper.dao.ExtractConfigRepo;
|
|
@@ -43,6 +46,11 @@ import com.qmth.cqb.paper.dao.PaperDetailRepo;
|
|
|
import com.qmth.cqb.paper.dao.PaperDetailUnitRepo;
|
|
|
import com.qmth.cqb.paper.dao.PaperRepo;
|
|
|
import com.qmth.cqb.paper.dto.ExportPaperInfoModel;
|
|
|
+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.ExportServiceManage;
|
|
@@ -52,12 +60,14 @@ 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.rpc.ExamCourseClient;
|
|
|
import com.qmth.cqb.paper.service.ExamFileService;
|
|
|
import com.qmth.cqb.paper.service.ExportStructureService;
|
|
|
import com.qmth.cqb.paper.service.ExtractConfigService;
|
|
|
import com.qmth.cqb.paper.service.PaperDetailUnitService;
|
|
|
import com.qmth.cqb.paper.service.PaperService;
|
|
|
import com.qmth.cqb.paper.service.export.ExportPaperAbstractService;
|
|
|
+import com.qmth.cqb.paper.service.export.SxsfExportPaperService;
|
|
|
import com.qmth.cqb.question.dao.QuesRepo;
|
|
|
import com.qmth.cqb.question.model.QuesOption;
|
|
|
import com.qmth.cqb.question.model.Question;
|
|
@@ -65,7 +75,7 @@ import com.qmth.cqb.utils.BeanCopierUtil;
|
|
|
import com.qmth.cqb.utils.CommonUtils;
|
|
|
import com.qmth.cqb.utils.FileDisposeUtil;
|
|
|
import com.qmth.cqb.utils.SpringContextUtils;
|
|
|
-import com.qmth.cqb.utils.enums.ExportType;
|
|
|
+import com.qmth.cqb.utils.enums.ExportWay;
|
|
|
import com.qmth.cqb.utils.enums.PaperType;
|
|
|
|
|
|
/**
|
|
@@ -113,6 +123,12 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
|
|
|
@Autowired
|
|
|
private ExportStructureService exportStructureService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ExamCourseClient examCourseClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SxsfExportPaperService sxsfExportPaperService;
|
|
|
+
|
|
|
@Value("${upyun.bucketName}")
|
|
|
private String bucketName;
|
|
|
|
|
@@ -661,58 +677,70 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void exportExamPaperInfo(ExportPaperInfoModel exportModel,HttpServletResponse response) {
|
|
|
+ public void exportExamPaperInfo(ExportPaperInfoModel exportModel,HttpServletResponse response) throws Exception {
|
|
|
+ //如果是批量导出,首先检查该考试下的所有课程是否都制定了调卷规则
|
|
|
+ List<String> paperIds = new ArrayList<String>();
|
|
|
+ if(exportModel.getExportWay()==ExportWay.BATCH&&
|
|
|
+ exportModel.getExportContentList().contains("PAPER_STRUCTURE_OBJECTIVE")){
|
|
|
+ paperIds = checkAllCourseByExamId(exportModel.getExamId());
|
|
|
+ }
|
|
|
List<ExamFile> examFiles = examFileService.findExamFileListByExportPaperInfoModel(exportModel);
|
|
|
- if(examFiles.size()>0){
|
|
|
- //创建试卷和压缩文件 文件夹
|
|
|
- createDirectory(downloadDirectory);
|
|
|
- createDirectory(zipDirectory);
|
|
|
- //下载文件到服务器
|
|
|
+ //创建试卷和压缩文件 文件夹
|
|
|
+ createDirectory(downloadDirectory);
|
|
|
+ createDirectory(zipDirectory);
|
|
|
+ //下载文件到服务器
|
|
|
+ if(examFiles!=null&&examFiles.size()>0){
|
|
|
for(ExamFile examFile:examFiles){
|
|
|
FileDisposeUtil.saveUrlAs(downloadUrl+examFile.getFilePath(),downloadDirectory+"\\"+examFile.getFileName());
|
|
|
}
|
|
|
- //创建压缩文件名称
|
|
|
- String zipFileName = examFiles.get(0).getExamName()+"_"+
|
|
|
- examFiles.get(0).getExamType().name()+"_"+
|
|
|
- CommonUtils.getCurNum();
|
|
|
- //将文件夹压缩成zip文件
|
|
|
- FileDisposeUtil.fileToZip(downloadDirectory,zipDirectory,zipFileName);
|
|
|
- //下载zip文件到客户端
|
|
|
- FileDisposeUtil.downloadFile(zipFileName+".zip",zipDirectory+"\\"+zipFileName+".zip",response);
|
|
|
}
|
|
|
+ //生成试卷结构到downloadDirectory目录
|
|
|
+ Map<String, Object> exportStructureMap = exportStructureService.findStructureByExamIdAndExamType(exportModel.getExamId()+"",exportModel.getExamType());
|
|
|
+ ExportStructure exportStructure = (ExportStructure) exportStructureMap.get("exportStructure");
|
|
|
+ if(exportStructure==null){
|
|
|
+ throw new RuntimeException("该考试下的试卷结构导出设置未制定,不能导出");
|
|
|
+ }
|
|
|
+ if(paperIds.size()>0){
|
|
|
+ //创建试卷结构Excel文件
|
|
|
+ makePaperStructure(exportStructure.getExamName(),paperIds,exportStructure);
|
|
|
+ }
|
|
|
+ //创建压缩文件名称
|
|
|
+ String zipFileName = exportStructure.getExamName()+"_"+
|
|
|
+ exportStructure.getExamType().name()+"_"+
|
|
|
+ CommonUtils.getCurNum();
|
|
|
+ //将downloadDirectory文件夹压缩成zip文件,存放到zipDirectory文件夹中
|
|
|
+ FileDisposeUtil.fileToZip(downloadDirectory,zipDirectory,zipFileName);
|
|
|
+ //下载zip文件到客户端
|
|
|
+ FileDisposeUtil.downloadFile(zipFileName+".zip",zipDirectory+"\\"+zipFileName+".zip",response);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 导出加密数据包
|
|
|
- */
|
|
|
- private void exportEncryptPackage(HttpServletResponse response) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 查询该考试下是否所有课程都制定了调卷规则
|
|
|
* @param examId
|
|
|
*/
|
|
|
- @Override
|
|
|
- public boolean checkAllCourseByExamId(String examId) {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 创建文件夹
|
|
|
- * 如果已经存在,删除再新建
|
|
|
- * @param directoryName
|
|
|
- */
|
|
|
- private static void createDirectory(String directoryName){
|
|
|
- File directory = new File(directoryName);
|
|
|
- if(directory.exists()){
|
|
|
- FileUtils.deleteQuietly(directory);
|
|
|
+ private List<String> checkAllCourseByExamId(String examId) {
|
|
|
+ List<String> paperIdList = new ArrayList<String>();
|
|
|
+ List<ExamCourseDto> examCourseDtoList = examCourseClient.findExamCourseByExamId(examId);
|
|
|
+ for(ExamCourseDto examCourseDto:examCourseDtoList){
|
|
|
+ ExtractConfig extractConfig = new ExtractConfig();
|
|
|
+ extractConfig.setExamId(examCourseDto.getExamId());
|
|
|
+ extractConfig.setExamType(examCourseDto.getExamType().name());
|
|
|
+ extractConfig.setCourseCode(examCourseDto.getCourseCode());
|
|
|
+ extractConfig = findConfig(extractConfig);
|
|
|
+ Map<String,String> finishedPaperIdMap = extractConfig.getFinishedPaperIdMap();
|
|
|
+ if(extractConfig==null||finishedPaperIdMap==null){
|
|
|
+ throw new RuntimeException("该考试下的课程没有全部制定调卷规则或考试文件没有生成,不能批量导出");
|
|
|
+ }
|
|
|
+ Set<Entry<String,String>> entry = finishedPaperIdMap.entrySet();
|
|
|
+ Iterator<Entry<String,String>> iterator = entry.iterator();
|
|
|
+ while(iterator.hasNext()){
|
|
|
+ String paperId = iterator.next().getValue();
|
|
|
+ paperIdList.add(paperId);
|
|
|
+ }
|
|
|
}
|
|
|
- directory.mkdirs();
|
|
|
+ return paperIdList;
|
|
|
}
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public List<ExamFile> findPaperStructure(String examId, String courseId) {
|
|
@@ -721,4 +749,54 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
|
|
|
examFile.setCourseId(courseId);
|
|
|
return examFileService.findExamFileListByExamFile(examFile);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ private void makePaperStructure(String examName,List<String> paperIds,ExportStructure exportStructure) throws Exception{
|
|
|
+ List<QuestionTypeNum> questionTypeNums = exportStructure.getQuestionTypeNums();
|
|
|
+
|
|
|
+ List<ObjectiveQuestionStructure> objectiveQuestionStructureList = new ArrayList<ObjectiveQuestionStructure>();
|
|
|
+
|
|
|
+ List<SubjectiveQuestionStructure> subjectiveQuestionStructureList = new ArrayList<SubjectiveQuestionStructure>();
|
|
|
+
|
|
|
+ for(String paperId:paperIds){
|
|
|
+ Map<String,Object> dataMap = sxsfExportPaperService.initExportPaper(paperId);
|
|
|
+ PaperExp paperExp = (PaperExp) dataMap.get("paper");
|
|
|
+ List<PaperDetailExp> objectiveDetails = paperExp.getObjectiveDetails();
|
|
|
+ //根据设置补齐客观题
|
|
|
+ sxsfExportPaperService.fillObjectiveDetails(objectiveDetails, questionTypeNums);
|
|
|
+ List<ObjectiveQuestionStructure> objectiveList = new ArrayList<ObjectiveQuestionStructure>();
|
|
|
+ for(PaperDetailExp paperDetailExp:objectiveDetails){
|
|
|
+ for(PaperDetailUnitExp unit:paperDetailExp.getPaperDetailUnits()){
|
|
|
+ objectiveList.add(new ObjectiveQuestionStructure(paperExp,paperDetailExp,unit));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ objectiveQuestionStructureList.addAll(objectiveList);
|
|
|
+
|
|
|
+ List<PaperDetailExp> subjectiveDetails = paperExp.getSubjectiveDetails();
|
|
|
+ List<SubjectiveQuestionStructure> subjectiveList = new ArrayList<SubjectiveQuestionStructure>();
|
|
|
+ for(PaperDetailExp paperDetailExp:subjectiveDetails){
|
|
|
+ for(PaperDetailUnitExp unit:paperDetailExp.getPaperDetailUnits()){
|
|
|
+ subjectiveList.add(new SubjectiveQuestionStructure(paperExp,paperDetailExp,unit));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ subjectiveQuestionStructureList.addAll(subjectiveList);
|
|
|
+ }
|
|
|
+
|
|
|
+ ExcelWriter objectiveExcelExporter = new ExcelWriter(ObjectiveQuestionStructure.class);
|
|
|
+ FileOutputStream out1 = new FileOutputStream(downloadDirectory+"\\"+examName+"_客观题.xlsx");
|
|
|
+ objectiveExcelExporter.write(examName+"_客观题.xlsx",objectiveQuestionStructureList,out1);
|
|
|
+
|
|
|
+ ExcelWriter subjectiveExcelExporter = new ExcelWriter(SubjectiveQuestionStructure.class);
|
|
|
+ FileOutputStream out2 = new FileOutputStream(downloadDirectory+"\\"+examName+"_主观题.xlsx");
|
|
|
+ subjectiveExcelExporter.write(examName+"_主观题.xlsx",subjectiveQuestionStructureList,out2);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createDirectory(String downloadDirectory) {
|
|
|
+ File directory = new File(downloadDirectory);
|
|
|
+ if(directory.exists()){
|
|
|
+ FileUtils.deleteQuietly(directory);
|
|
|
+ }
|
|
|
+ directory.mkdir();
|
|
|
+ }
|
|
|
+
|
|
|
}
|