|
@@ -1,6 +1,9 @@
|
|
package com.qmth.cqb.paper.service.export;
|
|
package com.qmth.cqb.paper.service.export;
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
+import java.io.FileNotFoundException;
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
|
+import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -12,9 +15,16 @@ import main.java.com.UpYun;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
|
|
+import cn.com.qmth.examcloud.common.util.excel.ExcelWriter;
|
|
|
|
|
|
|
|
+import com.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.ExamFile;
|
|
import com.qmth.cqb.paper.model.ExtractConfig;
|
|
import com.qmth.cqb.paper.model.ExtractConfig;
|
|
|
|
+import com.qmth.cqb.paper.model.PaperDetailUnit;
|
|
import com.qmth.cqb.utils.CommonUtils;
|
|
import com.qmth.cqb.utils.CommonUtils;
|
|
import com.qmth.cqb.utils.enums.ExamFileType;
|
|
import com.qmth.cqb.utils.enums.ExamFileType;
|
|
import com.qmth.cqb.utils.word.DocxProcessUtil;
|
|
import com.qmth.cqb.utils.word.DocxProcessUtil;
|
|
@@ -46,36 +56,140 @@ public class SxsfExportPaperService extends ExportPaperAbstractService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void uploadFile(String orgName,ExtractConfig extractConfig,String paperId,AccessUser accessUser) throws Exception{
|
|
|
|
|
|
+ public void uploadFile(ExtractConfig extractConfig,String paperId,AccessUser accessUser) throws Exception{
|
|
Map<String,Object> dataMap = initExportPaper(paperId);
|
|
Map<String,Object> dataMap = initExportPaper(paperId);
|
|
if (dataMap.get("fileName") != null) {
|
|
if (dataMap.get("fileName") != null) {
|
|
- String paperfileName = (String) dataMap.get("fileName")+"_"+CommonUtils.getCurNum();
|
|
|
|
- String answerFileName = paperfileName+"_答案";
|
|
|
|
- DocxProcessUtil.exportPaper(dataMap, paperfileName,SXSF_TEMPLATE_PAPER);
|
|
|
|
- DocxProcessUtil.exportAnswer(dataMap,answerFileName,SXSF_TEMPLATE_ANSWER);
|
|
|
|
- DocxProcessUtil.processImage(paperfileName,getPkgList(paperId));
|
|
|
|
- DocxProcessUtil.processImage(answerFileName,getPkgList(paperId));
|
|
|
|
- //得到本地文件和文件路径
|
|
|
|
- File paperFile = new File(TEMP_FILE_EXP+paperfileName+DOCX_SUFFIX);
|
|
|
|
- File answerFile = new File(TEMP_FILE_EXP+answerFileName+DOCX_SUFFIX);
|
|
|
|
- String paperFilePath = uploadUrl+paperfileName+DOCX_SUFFIX;
|
|
|
|
- String answerFilePath = uploadUrl+answerFileName+DOCX_SUFFIX;
|
|
|
|
- //上传至又拍云
|
|
|
|
|
|
+ String currNum = CommonUtils.getCurNum();
|
|
|
|
+ uploadPaperWord(dataMap,extractConfig,paperId,accessUser,currNum);
|
|
|
|
+ uploadAnswerWord(dataMap,extractConfig,paperId,accessUser,currNum);
|
|
|
|
+ uploadPaperStructure(dataMap,extractConfig,paperId,accessUser,currNum);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 生成试卷Word,上传至又拍云
|
|
|
|
+ * @param orgName
|
|
|
|
+ * @param dataMap
|
|
|
|
+ * @param extractConfig
|
|
|
|
+ * @param paperId
|
|
|
|
+ * @param accessUser
|
|
|
|
+ */
|
|
|
|
+ private void uploadPaperWord(Map<String,Object> dataMap,ExtractConfig extractConfig,String paperId,AccessUser accessUser,String currNum){
|
|
|
|
+ String paperfileName = extractConfig.getCourseName()+"_"+extractConfig.getCourseCode()+"_"+currNum+"_试卷";
|
|
|
|
+ try {
|
|
|
|
+ DocxProcessUtil.exportPaper(dataMap, paperfileName,SXSF_TEMPLATE_PAPER);
|
|
|
|
+ DocxProcessUtil.processImage(paperfileName,getPkgList(paperId));
|
|
|
|
+ File paperFile = new File(TEMP_FILE_EXP+paperfileName+DOCX_SUFFIX);
|
|
|
|
+ String paperFilePath = uploadUrl+paperfileName+DOCX_SUFFIX;
|
|
|
|
+ //上传至又拍云
|
|
UpYun upyun = new UpYun(bucketName,userName,password);
|
|
UpYun upyun = new UpYun(bucketName,userName,password);
|
|
upyun.writeFile(paperFilePath, paperFile,true);
|
|
upyun.writeFile(paperFilePath, paperFile,true);
|
|
- upyun.writeFile(answerFilePath, answerFile,true);
|
|
|
|
- //保存上传文件记录
|
|
|
|
- List<ExamFile> examFileList = new ArrayList<ExamFile>();
|
|
|
|
- //试卷
|
|
|
|
- examFileList.add(new ExamFile(extractConfig,orgName,paperfileName+DOCX_SUFFIX,paperFilePath,ExamFileType.PAPER));
|
|
|
|
- //答案
|
|
|
|
- examFileList.add(new ExamFile(extractConfig,orgName,answerFileName+DOCX_SUFFIX,answerFilePath,ExamFileType.ANSWER));
|
|
|
|
- examFileService.saveExamFiles(examFileList,accessUser);
|
|
|
|
- //删除本地文件
|
|
|
|
|
|
+ examFileService.saveExamFile(new ExamFile(extractConfig,paperfileName+DOCX_SUFFIX,paperFilePath,ExamFileType.PAPER),accessUser);
|
|
paperFile.delete();
|
|
paperFile.delete();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 生成答案Word,上传至又拍云
|
|
|
|
+ * @param orgName
|
|
|
|
+ * @param dataMap
|
|
|
|
+ * @param extractConfig
|
|
|
|
+ * @param paperId
|
|
|
|
+ * @param accessUser
|
|
|
|
+ */
|
|
|
|
+ private void uploadAnswerWord(Map<String,Object> dataMap,ExtractConfig extractConfig,String paperId,AccessUser accessUser,String currNum){
|
|
|
|
+ String answerFileName = extractConfig.getCourseName()+"_"+extractConfig.getCourseCode()+"_"+currNum+"_答案";
|
|
|
|
+ try {
|
|
|
|
+ DocxProcessUtil.exportAnswer(dataMap,answerFileName,SXSF_TEMPLATE_ANSWER);
|
|
|
|
+ DocxProcessUtil.processImage(answerFileName,getPkgList(paperId));
|
|
|
|
+ File answerFile = new File(TEMP_FILE_EXP+answerFileName+DOCX_SUFFIX);
|
|
|
|
+ String answerFilePath = uploadUrl+answerFileName+DOCX_SUFFIX;
|
|
|
|
+ //上传至又拍云
|
|
|
|
+ UpYun upyun = new UpYun(bucketName,userName,password);
|
|
|
|
+ upyun.writeFile(answerFilePath, answerFile,true);
|
|
|
|
+ examFileService.saveExamFile(new ExamFile(extractConfig,answerFileName+DOCX_SUFFIX,answerFilePath,ExamFileType.ANSWER),accessUser);
|
|
answerFile.delete();
|
|
answerFile.delete();
|
|
- }
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 生成试卷结构,上传至又拍云
|
|
|
|
+ */
|
|
|
|
+ private void uploadPaperStructure(Map<String,Object> dataMap,ExtractConfig extractConfig,String paperId,AccessUser accessUser,String currNum) {
|
|
|
|
+ exportObjectiveQuestionStructures(dataMap,extractConfig,accessUser,currNum);
|
|
|
|
+ exportSubjectiveQuestionStructures(dataMap,extractConfig,accessUser,currNum);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获得客观题导出结构,并上传至又拍云
|
|
|
|
+ * @param paperExp
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private void exportObjectiveQuestionStructures(Map<String,Object> dataMap,ExtractConfig extractConfig,AccessUser accessUser,String currNum){
|
|
|
|
+ PaperExp paperExp = (PaperExp) dataMap.get("paper");
|
|
|
|
+ List<PaperDetailExp> objectiveDetails = paperExp.getObjectiveDetails();
|
|
|
|
+ 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);
|
|
|
|
+ String objectiveFilename = extractConfig.getCourseName()+"_"+extractConfig.getCourseCode()+"_"+currNum+"_客观题";
|
|
|
|
+ try {
|
|
|
|
+ File file = new File(TEMP_FILE_EXP+objectiveFilename+".xlsx");
|
|
|
|
+ FileOutputStream out = new FileOutputStream(file);
|
|
|
|
+ objectiveExcelExporter.write(objectiveFilename,objectiveQuestionStructureList,out);
|
|
|
|
+ //上传至又拍云
|
|
|
|
+ String objectiveFilePath = uploadUrl+objectiveFilename+".xlsx";
|
|
|
|
+ UpYun upyun = new UpYun(bucketName,userName,password);
|
|
|
|
+ upyun.writeFile(objectiveFilePath,file,true);
|
|
|
|
+ //保存记录
|
|
|
|
+ examFileService.saveExamFile(new ExamFile(extractConfig,objectiveFilename+".xlsx",uploadUrl+objectiveFilename+".xlsx",ExamFileType.PAPER_STRUCTURE_OBJECTIVE),accessUser);
|
|
|
|
+ file.delete();
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 获得主观题导出结构,并上传至又拍云
|
|
|
|
+ * @param paperExp
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private void exportSubjectiveQuestionStructures(Map<String,Object> dataMap,ExtractConfig extractConfig,AccessUser accessUser,String currNum){
|
|
|
|
+ PaperExp paperExp = (PaperExp) dataMap.get("paper");
|
|
|
|
+ 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);
|
|
|
|
+ String subjectiveFileName = extractConfig.getCourseName()+"_"+extractConfig.getCourseCode()+"_"+currNum+"_主观题";
|
|
|
|
+ try {
|
|
|
|
+ File file = new File(TEMP_FILE_EXP+subjectiveFileName+".xlsx");
|
|
|
|
+ FileOutputStream out = new FileOutputStream(file);
|
|
|
|
+ subjectiveExcelExporter.write(subjectiveFileName,subjectiveQuestionStructureList,out);
|
|
|
|
+ //上传至又拍云
|
|
|
|
+ String subjectiveFilePath = uploadUrl+subjectiveFileName+".xlsx";
|
|
|
|
+ UpYun upyun = new UpYun(bucketName,userName,password);
|
|
|
|
+ upyun.writeFile(subjectiveFilePath,file,true);
|
|
|
|
+ //保存记录
|
|
|
|
+ examFileService.saveExamFile(new ExamFile(extractConfig,subjectiveFileName+".xlsx",uploadUrl+subjectiveFileName+".xlsx",ExamFileType.PAPER_STRUCTURE_SUBJECTIVE),accessUser);
|
|
|
|
+ file.delete();
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|