Просмотр исходного кода

Merge remote-tracking branch 'origin/dev0410' into dev0410

宋悦 8 лет назад
Родитель
Сommit
47663330bd

+ 52 - 0
cqb-comm-utils/src/main/java/com/qmth/cqb/utils/ZipUtils.java

@@ -0,0 +1,52 @@
+package com.qmth.cqb.utils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+public class ZipUtils {
+	public static void doCompress(String srcFile, String zipFile) throws Exception {
+        doCompress(new File(srcFile), new File(zipFile));
+    }
+    
+    /**
+     * 文件压缩
+     * @param srcFile  目录或者单个文件
+     * @param destFile 压缩后的ZIP文件
+     */
+    public static void doCompress(File srcFile, File destFile) throws Exception {
+        ZipOutputStream out = new ZipOutputStream(new FileOutputStream(destFile));
+        if(srcFile.isDirectory()){
+            File[] files = srcFile.listFiles();
+            for(File file : files){
+                doCompress(file, out);
+            }
+        }else {
+            doCompress(srcFile, out);
+        }
+    }
+    
+    public static void doCompress(String pathname, ZipOutputStream out) throws IOException{
+        doCompress(new File(pathname), out);
+    }
+    
+    public static void doCompress(File file, ZipOutputStream out) throws IOException{
+        if( file.exists() ){
+            byte[] buffer = new byte[1024];
+            FileInputStream fis = new FileInputStream(file);
+            out.putNextEntry(new ZipEntry(file.getName()));
+            int len = 0 ;
+            // 读取文件的内容,打包到zip文件    
+            while ((len = fis.read(buffer)) > 0) {
+                out.write(buffer, 0, len);
+            }
+            out.flush();
+            out.closeEntry();
+            fis.close();
+        }
+    }
+
+}

+ 18 - 14
cqb-comm-utils/src/main/java/com/qmth/cqb/utils/word/DocxProcessUtil.java

@@ -1,6 +1,7 @@
 package com.qmth.cqb.utils.word;
 
 import com.qmth.cqb.utils.CommonUtils;
+import com.qmth.cqb.utils.ZipUtils;
 import com.qmth.cqb.utils.enums.QuesUnit;
 import freemarker.template.Configuration;
 import freemarker.template.Template;
@@ -58,6 +59,7 @@ import java.io.*;
 import java.util.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import java.util.zip.ZipOutputStream;
 
 /**
  * docx处理工具类 Created by songyue on 17/3/10.
@@ -656,8 +658,8 @@ public final class DocxProcessUtil {
      * @param dataMap
      * @param fileName
      */
-    public static void exportPaper(Map dataMap, String fileName) throws Exception {
-        exportWord(dataMap, fileName, PAPER_TEMPLATE);
+    public static void exportPaper(Map dataMap, String fileName,String paperTemplate) throws Exception {
+        exportWord(dataMap, fileName, paperTemplate);
     }
 
     /**
@@ -666,8 +668,8 @@ public final class DocxProcessUtil {
      * @param dataMap
      * @param fileName
      */
-    public static void exportAnswer(Map dataMap, String fileName) throws Exception {
-        exportWord(dataMap, fileName, ANSWER_TEMPLATE);
+    public static void exportAnswer(Map dataMap, String fileName,String answerTemplate) throws Exception {
+        exportWord(dataMap, fileName, answerTemplate);
     }
 
     /**
@@ -812,16 +814,18 @@ public final class DocxProcessUtil {
      * @param response
      * @throws Exception
      */
-    public static void processDownload(String fileName, HttpServletResponse response) throws Exception {
-        String filePath = TEMP_FILE_EXP + fileName + DOCX_SUFFIX;
-        InputStream inputStream = new FileInputStream(filePath);
-        OutputStream outputStream = response.getOutputStream();
-        // 设置强制下载不打开
-        response.setContentType("application/octet-stream;charset=utf-8");
-        // 设置文件名
-        response.addHeader("Content-Disposition",
-                "attachment;fileName=" + new String(fileName.getBytes("UTF-8"), "iso-8859-1") + DOCX_SUFFIX);
-        IOUtils.copyLarge(inputStream, outputStream);
+    public static void processDownload(List<String> fileNames, HttpServletResponse response) throws Exception {	
+    	 String zipFileName = fileNames.get(0);
+         response.setHeader("Content-Disposition","attachment; filename="+new String(zipFileName.getBytes("UTF-8"), "iso-8859-1")+".zip");
+         // 设置强制下载不打开
+         response.setContentType("application/octet-stream;charset=utf-8");
+         ZipOutputStream out = new ZipOutputStream(response.getOutputStream());
+        for(String fileName:fileNames){
+            ZipUtils.doCompress(TEMP_FILE_EXP+fileName+DOCX_SUFFIX, out);
+            response.flushBuffer();
+        }
+        out.close();
+   
     }
 
     /**

Разница между файлами не показана из-за своего большого размера
+ 4100 - 0
cqb-comm-utils/src/main/resources/dzkd_answer_template.ftl


Разница между файлами не показана из-за своего большого размера
+ 293 - 0
cqb-comm-utils/src/main/resources/dzkd_paper_template.ftl


+ 13 - 0
cqb-gen-paper/src/main/java/com/qmth/cqb/genpaper/model/GenPaperDto.java

@@ -7,6 +7,8 @@ import java.util.Map;
 import com.qmth.cqb.genpaper.condition.Condition;
 import com.qmth.cqb.utils.enums.RandomGenPaperPolicy;
 
+import cn.com.qmth.examcloud.common.dto.core.enums.CourseLevel;
+
 /**
  * Created by songyue on 17/3/24.
  */
@@ -17,6 +19,8 @@ public class GenPaperDto implements Serializable {
     private String courseNo;// 课程代码
 
     private String courseName;// 课程名称
+    
+    private CourseLevel level;// 层次
 
     private String paperName;// 试卷名称
 
@@ -132,4 +136,13 @@ public class GenPaperDto implements Serializable {
         this.orgId = orgId;
     }
 
+	public CourseLevel getLevel() {
+		return level;
+	}
+
+	public void setLevel(CourseLevel level) {
+		this.level = level;
+	}
+
+    
 }

+ 2 - 0
cqb-gen-paper/src/main/java/com/qmth/cqb/genpaper/service/GenPaperService.java

@@ -115,6 +115,7 @@ public class GenPaperService {
             paper.setCourseName(genPaperDto.getCourseName());
             paper.setCreator(genPaperDto.getCreator());
             paper.setOrgId(genPaperDto.getOrgId());
+            paper.setLevel(genPaperDto.getLevel());
             paper.setCreateTime(CommonUtils.getCurDateTime());
             paper.setUnitCount(this.getTotalQuesNum(paperDetailunits));
             paper.setPaperType(PaperType.GENERATE);
@@ -277,6 +278,7 @@ public class GenPaperService {
             paper.setTotalScore(score);
             paper.setPaperType(PaperType.GENERATE);
             paper.setOrgId(genPaperDto.getOrgId());
+            paper.setLevel(genPaperDto.getLevel());
         }
         return paper;
 

+ 10 - 0
cqb-paper/src/main/java/com/qmth/cqb/paper/dao/ExportServiceManageRepo.java

@@ -0,0 +1,10 @@
+package com.qmth.cqb.paper.dao;
+
+import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.data.repository.query.QueryByExampleExecutor;
+
+import com.qmth.cqb.paper.model.ExportServiceManage;
+
+public interface ExportServiceManageRepo extends MongoRepository<ExportServiceManage, Long>,QueryByExampleExecutor<ExportServiceManage> {
+	ExportServiceManage findByOrgName(String orgName);
+}

+ 57 - 1
cqb-paper/src/main/java/com/qmth/cqb/paper/dto/PaperExp.java

@@ -3,6 +3,8 @@ package com.qmth.cqb.paper.dto;
 import com.qmth.cqb.utils.enums.PaperStatus;
 import com.qmth.cqb.utils.enums.PaperType;
 
+import cn.com.qmth.examcloud.common.dto.core.enums.CourseLevel;
+
 import java.io.Serializable;
 import java.util.Map;
 import java.util.*;
@@ -35,7 +37,18 @@ public class PaperExp implements Serializable{
     private List<PaperDetailExp> paperDetails;
 
     private Map<String,String> params;//导入试卷属性
-
+    
+    private List<PaperDetailExp> objectiveDetails;//客观题
+    
+    private List<PaperDetailExp> subjectiveDetails;//主观题
+    
+    private Double objectiveScore;
+    
+    private Double subjectiveScore;
+
+    private String courseLevel;
+
+    
     public static long getSerialVersionUID() {
         return serialVersionUID;
     }
@@ -127,4 +140,47 @@ public class PaperExp implements Serializable{
     public void setSubTitle(String subTitle) {
         this.subTitle = subTitle;
     }
+
+	public List<PaperDetailExp> getObjectiveDetails() {
+		return objectiveDetails;
+	}
+
+	public void setObjectiveDetails(List<PaperDetailExp> objectiveDetails) {
+		this.objectiveDetails = objectiveDetails;
+	}
+
+	public List<PaperDetailExp> getSubjectiveDetails() {
+		return subjectiveDetails;
+	}
+
+	public void setSubjectiveDetails(List<PaperDetailExp> subjectiveDetails) {
+		this.subjectiveDetails = subjectiveDetails;
+	}
+
+	public Double getObjectiveScore() {
+		return objectiveScore;
+	}
+
+	public void setObjectiveScore(Double objectiveScore) {
+		this.objectiveScore = objectiveScore;
+	}
+
+	public Double getSubjectiveScore() {
+		return subjectiveScore;
+	}
+
+	public void setSubjectiveScore(Double subjectiveScore) {
+		this.subjectiveScore = subjectiveScore;
+	}
+
+	public String getCourseLevel() {
+		return courseLevel;
+	}
+
+	public void setCourseLevel(String courseLevel) {
+		this.courseLevel = courseLevel;
+	}
+
+	
+    
 }

+ 43 - 0
cqb-paper/src/main/java/com/qmth/cqb/paper/model/ExportServiceManage.java

@@ -0,0 +1,43 @@
+package com.qmth.cqb.paper.model;
+
+import java.io.Serializable;
+
+import org.springframework.data.annotation.Id;
+
+public class ExportServiceManage  implements Serializable {
+
+	private static final long serialVersionUID = 561933232237607796L;
+
+	@Id
+	 private String id;
+	 
+	 private String orgName;
+	 
+	 private String exportServiceName;
+
+	public String getId() {
+		return id;
+	}
+
+	public void setId(String id) {
+		this.id = id;
+	}
+
+	public String getOrgName() {
+		return orgName;
+	}
+
+	public void setOrgName(String orgName) {
+		this.orgName = orgName;
+	}
+
+	public String getExportServiceName() {
+		return exportServiceName;
+	}
+
+	public void setExportServiceName(String exportServiceName) {
+		this.exportServiceName = exportServiceName;
+	}
+	  
+	 
+}

+ 13 - 0
cqb-paper/src/main/java/com/qmth/cqb/paper/model/Paper.java

@@ -10,6 +10,8 @@ import com.qmth.cqb.utils.CommonUtils;
 import com.qmth.cqb.utils.enums.PaperStatus;
 import com.qmth.cqb.utils.enums.PaperType;
 
+import cn.com.qmth.examcloud.common.dto.core.enums.CourseLevel;
+
 /**
  * @author songyue
  *
@@ -49,6 +51,8 @@ public class Paper implements Serializable {
     private String courseNo;
 
     private String courseName;
+    
+    private CourseLevel level;
 
     private String orgId;
 
@@ -198,4 +202,13 @@ public class Paper implements Serializable {
         this.createTime = CommonUtils.getCurDateTime();
     }
 
+	public CourseLevel getLevel() {
+		return level;
+	}
+
+	public void setLevel(CourseLevel level) {
+		this.level = level;
+	}
+    
+    
 }

+ 1 - 1
cqb-paper/src/main/java/com/qmth/cqb/paper/service/ImportPaperService.java

@@ -94,7 +94,7 @@ public class ImportPaperService {
      * @param file
      * @return
      */
-    public Paper ImportPaper(Paper paper, AccessUser user,
+    public Paper importPaper(Paper paper, AccessUser user,
             File file) throws Exception {
         paperService.checkPaperNameNew(paper.getName(), user.getRootOrgId().toString());
         return processImportPaper(paper,user,file);

+ 234 - 0
cqb-paper/src/main/java/com/qmth/cqb/paper/service/export/DzkdExportPaperService.java

@@ -0,0 +1,234 @@
+package com.qmth.cqb.paper.service.export;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+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.PaperDetailExp;
+import com.qmth.cqb.paper.dto.PaperDetailUnitExp;
+import com.qmth.cqb.paper.dto.PaperExp;
+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.service.PaperService;
+import com.qmth.cqb.question.dao.QuesRepo;
+import com.qmth.cqb.question.model.QuesOption;
+import com.qmth.cqb.question.model.Question;
+import com.qmth.cqb.utils.BeanCopierUtil;
+import com.qmth.cqb.utils.CommonUtils;
+import com.qmth.cqb.utils.exception.PaperException;
+import com.qmth.cqb.utils.word.DocxProcessUtil;
+
+import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
+
+@Service("zkdExportPaperService")
+public class DzkdExportPaperService extends ExportPaperAbstractService {
+	
+    @Autowired
+    PaperRepo paperRepo;
+	
+    @Autowired
+    PaperService paperService;
+
+    @Autowired
+    PaperDetailRepo paperDetailRepo;
+
+    @Autowired
+    PaperDetailUnitRepo paperDetailUnitRepo;
+
+    @Autowired
+    QuesRepo quesRepo;
+	
+    @Autowired
+    ExportPaperService exportPaperService;
+	
+    /**
+     * 初始化导出试卷DTO
+     * @param id
+     * @return
+     */
+    public Map initExportPaper(String id) throws Exception{
+        //创建返回Map
+        Map returnMap = new HashMap();
+        //获取paper
+        Paper paper = paperRepo.findOne(id);
+
+        paperService.formatPaper(paper,null);
+
+        if(paper == null){
+            throw new PaperException("该试卷不存在");
+        }
+
+        //创建paperDto
+        PaperExp paperExp = BeanCopierUtil.copyProperties(paper,PaperExp.class);
+        paperExp.setCourseLevel(paper.getLevel().getName());
+        List<PaperDetailExp> objectiveDetails = new ArrayList<PaperDetailExp>();//客观题
+        List<PaperDetailExp> subjectiveDetails = new ArrayList<PaperDetailExp>();//主观题
+        double objectiveScore = 0;
+        double subjectiveScore = 0;
+        paperExp.setTitle(CommonUtils.PAPER_TITLE);
+        paperExp.setSubTitle(CommonUtils.PAPER_SUB_TITLE);
+        //获取大题
+        List<PaperDetail> paperDetails = paperDetailRepo.findByPaper(paper);
+
+        int objectNumber = 1;//客观题大题序号
+        int objetcUnitSum = 0;
+        for(int i = 0; i < paperDetails.size(); i++){
+            PaperDetailExp paperDetailExp = BeanCopierUtil.copyProperties(paperDetails.get(i), PaperDetailExp.class);
+            List<PaperDetailUnit> paperDetailUnits =
+                    paperDetailUnitRepo.findByPaperDetail(paperDetails.get(i));
+            //把大题分类 :客观题和主观题 
+            List<PaperDetailUnitExp> paperDetailUnitExps =
+                    BeanCopierUtil.copyPropertiesOfList(paperDetailUnits,PaperDetailUnitExp.class);
+            //选择题,套题下选择题  选项顺序重新排列
+            paperService.reorderChoicequestionOption(paperDetailUnitExps);
+            paperDetailExp.setPaperDetailUnits(paperDetailUnitExps);
+            boolean hasTextAnswer = false;//判断主观题
+            if(paperDetailUnits.get(0).getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION){
+            	for(Question ques :paperDetailUnits.get(0).getQuestion().getSubQuestions()){
+            		if(ques.getQuestionType() ==  QuesStructType.TEXT_ANSWER_QUESTION){
+            			hasTextAnswer = true;
+            			break;
+            		}
+            	}
+            } else if(paperDetailUnits.get(0).getQuestionType() == QuesStructType.TEXT_ANSWER_QUESTION) {
+            	hasTextAnswer = true;
+            }
+            if(hasTextAnswer){
+            	subjectiveDetails.add(paperDetailExp);
+            	subjectiveScore += paperDetailExp.getScore();
+            } else {
+            	objectiveDetails.add(paperDetailExp);
+            	paperDetailExp.setNumber(objectNumber);
+            	paperDetailExp.setCnNum(CommonUtils.toCHNum(objectNumber));
+            	objectiveScore += paperDetailExp.getScore();
+            	objetcUnitSum += paperDetailExp.getUnitCount();
+            	objectNumber++;
+            }
+            setExpTitle(paperDetailExp);
+        }
+        
+        paperExp.setObjectiveDetails(objectiveDetails);
+        paperExp.setSubjectiveDetails(subjectiveDetails);
+        paperExp.setObjectiveScore(objectiveScore);
+        paperExp.setSubjectiveScore(subjectiveScore);
+        if(objectiveDetails.size()>0){
+        	 setUnitExpNumber(objectiveDetails, 0);
+        }
+        if(subjectiveDetails.size()>0){
+        	for(PaperDetailExp subDetail:subjectiveDetails){
+        		subDetail.setNumber(objectNumber);
+        		subDetail.setCnNum(CommonUtils.toCHNum(objectNumber));
+        		objectNumber++;
+        	}
+        	setUnitExpNumber(subjectiveDetails,objetcUnitSum);
+        }
+        returnMap.put("paper", paperExp);
+        returnMap.put("fileName", paperExp.getName());
+
+        return returnMap;
+    }
+    
+    
+    /**
+     * 下载试卷
+     * @param id
+     */
+    public void dzkdDownloadPaper(String id, HttpServletResponse response) throws Exception {
+        Map dataMap = initExportPaper(id);
+        List<String> fileList = new ArrayList<String>();
+        if (dataMap.get("fileName") != null) {
+            String paperfileName = (String) dataMap.get("fileName");
+            String answerFileName = paperfileName+"__答案";
+            DocxProcessUtil.exportPaper(dataMap, paperfileName,"dzkd_paper_template.ftl");
+            DocxProcessUtil.exportAnswer(dataMap,answerFileName,"dzkd_answer_template.ftl");
+            DocxProcessUtil.processImage(paperfileName, exportPaperService.getPkgList(id));
+            DocxProcessUtil.processImage(answerFileName, exportPaperService.getPkgList(id));
+            fileList.add(paperfileName);
+            fileList.add(answerFileName);
+            DocxProcessUtil.processDownload(fileList, response);
+        }
+    }
+    
+    private void setExpTitle(PaperDetailExp paperDetailExp){
+    	String title =""; 
+    	String totalScore = BigDecimal.valueOf(paperDetailExp.getScore()).stripTrailingZeros().toPlainString();
+    	String unitScore = BigDecimal.valueOf(paperDetailExp.getPaperDetailUnits().get(0).getScore()).stripTrailingZeros().toPlainString();
+    	QuesStructType type = paperDetailExp.getPaperDetailUnits().get(0).getQuestionType();
+    	if(type == QuesStructType.SINGLE_ANSWER_QUESTION){
+    		paperDetailExp.setName("单项选择题");
+    		title = "(本大题共"+paperDetailExp.getUnitCount()+"小题,每小题"+unitScore+"分共"+totalScore+"分)。"
+    				+ "在每小题列出的四个备选中只有一个符合题目要求的,请将其选出并将“答题卡”的相应代码涂黑,错涂、多涂或未涂均无分";
+    	} else if (type == QuesStructType.BOOL_ANSWER_QUESTION){
+    		paperDetailExp.setName("判断题");
+    		title = "(本大题共"+paperDetailExp.getUnitCount()+"小题,每小题"+unitScore+"分共"+totalScore+"分。正确的填涂A、错误填涂B。错涂、多涂或未涂均无分)";
+    	} else if(type == QuesStructType.FILL_BLANK_QUESTION){
+    		paperDetailExp.setName("填空题");
+    		int blankNum = 0;
+    		for(PaperDetailUnitExp unit:paperDetailExp.getPaperDetailUnits()){
+    			String tempStr = unit.getQuestion().getQuesBody().replaceAll("###", "");
+    			int lenTimes = (unit.getQuestion().getQuesBody().length()-tempStr.length())/"###".length();//出现的次数
+    			blankNum +=lenTimes;			
+    		}
+    		title = "(本大题共"+blankNum+"个空格,将每空答在答题卡 “1—"+blankNum+"”相应的序号上。每空"+unitScore+"分共"+totalScore+"分)";
+    	} else {
+    		title = "(本大题共"+paperDetailExp.getUnitCount()+"小题,每小题"+unitScore+"分共"+totalScore+"分)";
+    	}
+    	paperDetailExp.setTitle(title);
+    }
+    
+    public void setUnitExpNumber(List<PaperDetailExp> paperDetails,int startIndxt) throws Exception {
+        int subNum = startIndxt;
+	    for(PaperDetailExp paperDetail: paperDetails){
+	        for(PaperDetailUnitExp paperDetailUnit:paperDetail.getPaperDetailUnits()){
+	            List<QuesOption> optionList = paperDetailUnit.getQuestion().getQuesOptions();
+	            if(optionList != null && optionList.size() > 0){
+	                int index = 0;
+	                for(QuesOption quesOption:optionList){
+	                    quesOption.setOptionBodyWord(exportPaperService.setOptionNum(quesOption.getOptionBodyWord(),exportPaperService.getOptionNum(index)));
+	                    index++;
+	                }
+	            }
+	            List<Question> subQuesList = paperDetailUnit.getQuestion().getSubQuestions();
+	            Question question = paperDetailUnit.getQuestion();
+	            //套题序号
+	            if(subQuesList != null && subQuesList.size() > 0){
+	
+	                question.setQuesBodyWord(exportPaperService.replaceQuesBlank(question.getQuesBodyWord(),subNum + 1));
+	
+	                for(Question subQues:subQuesList){
+	                    int curSubNum = ++subNum;
+	                    subQues.setQuesBodyWord(exportPaperService.setSubQuesNum(subQues.getQuesBodyWord(),curSubNum));
+	                    subQues.setQuesAnswerWord(exportPaperService.setSubQuesNum(subQues.getQuesAnswerWord(),curSubNum));
+	                    subQues.setQuesBodyWord(exportPaperService.replaceQuesBlank(subQues.getQuesBodyWord(),curSubNum));
+	                    List<QuesOption> subOptionList = subQues.getQuesOptions();
+	                    if(subOptionList != null && subOptionList.size() > 0){
+	                        int sub_index = 0;
+	                        for(QuesOption quesOption:subOptionList){
+	                            quesOption.setOptionBodyWord(exportPaperService.setOptionNum(quesOption.getOptionBodyWord(),exportPaperService.getOptionNum(sub_index)));
+	                            sub_index++;
+	                        }
+	                    }
+	                }
+	            }else{
+	                int curSubNum = ++subNum;
+	                question.setQuesBodyWord(exportPaperService.setSubQuesNum(question.getQuesBodyWord(),curSubNum));
+	                question.setQuesAnswerWord(exportPaperService.setSubQuesNum(question.getQuesAnswerWord(),curSubNum));
+	                question.setQuesBodyWord(exportPaperService.replaceQuesBlank(question.getQuesBodyWord(),curSubNum));
+	            }
+	        }
+	     }
+	 }
+}

+ 12 - 0
cqb-paper/src/main/java/com/qmth/cqb/paper/service/export/ExportPaperAbstractService.java

@@ -0,0 +1,12 @@
+package com.qmth.cqb.paper.service.export;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.stereotype.Service;
+
+@Service("exportPaperService")
+public abstract class ExportPaperAbstractService {
+	
+	 public abstract void dzkdDownloadPaper(String id, HttpServletResponse response) throws Exception;
+	 
+}

+ 16 - 10
cqb-paper/src/main/java/com/qmth/cqb/paper/service/ExportPaperService.java → cqb-paper/src/main/java/com/qmth/cqb/paper/service/export/ExportPaperService.java

@@ -1,4 +1,4 @@
-package com.qmth.cqb.paper.service;
+package com.qmth.cqb.paper.service.export;
 
 import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
 import com.google.gson.Gson;
@@ -11,6 +11,8 @@ import com.qmth.cqb.paper.dto.PaperExp;
 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.service.PaperDetailUnitService;
+import com.qmth.cqb.paper.service.PaperService;
 import com.qmth.cqb.question.dao.QuesRepo;
 import com.qmth.cqb.question.model.QuesOption;
 import com.qmth.cqb.question.model.Question;
@@ -28,6 +30,8 @@ import org.springframework.stereotype.Service;
 
 import javax.servlet.http.HttpServletResponse;
 import javax.xml.bind.JAXBElement;
+
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -254,12 +258,12 @@ public class ExportPaperService {
      * @param id
      */
     public void exportPaper(String id) throws Exception {
-        Map dataMap = initExportPaper(id);
-        if(dataMap.get("fileName") != null){
-            String fileName = (String)dataMap.get("fileName");
-            DocxProcessUtil.exportPaper(dataMap,fileName);
-            DocxProcessUtil.processImage(fileName,getPkgList(id));
-        }
+//        Map dataMap = initExportPaper(id);
+//        if(dataMap.get("fileName") != null){
+//            String fileName = (String)dataMap.get("fileName");
+//            DocxProcessUtil.exportPaper(dataMap,fileName);
+//            DocxProcessUtil.processImage(fileName,getPkgList(id));
+//        }
     }
 
     /**
@@ -267,12 +271,14 @@ public class ExportPaperService {
      * @param id
      */
     public void downloadPaper(String id, HttpServletResponse response) throws Exception {
-        Map dataMap = initExportPaper(id);
+    	List<String> fileNames = new ArrayList<String>();
+         Map dataMap = initExportPaper(id);
+        
         if (dataMap.get("fileName") != null) {
             String fileName = (String) dataMap.get("fileName");
-            DocxProcessUtil.exportPaper(dataMap, fileName);
+            DocxProcessUtil.exportPaper(dataMap, fileName,"paper_template.ftl");
             DocxProcessUtil.processImage(fileName, getPkgList(id));
-            DocxProcessUtil.processDownload(fileName, response);
+            DocxProcessUtil.processDownload(fileNames, response);
         }
     }
 

+ 30 - 7
cqb-paper/src/main/java/com/qmth/cqb/paper/web/ExportPaperController.java

@@ -1,21 +1,31 @@
 package com.qmth.cqb.paper.web;
 
 import cn.com.qmth.examcloud.common.uac.annotation.Uac;
+import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
 import cn.com.qmth.examcloud.common.uac.enums.RoleMeta;
 import cn.com.qmth.examcloud.common.uac.enums.UacPolicy;
-
-import com.qmth.cqb.paper.service.ExportPaperService;
-
 import io.swagger.annotations.ApiOperation;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 
+import com.qmth.cqb.paper.dao.ExportServiceManageRepo;
+import com.qmth.cqb.paper.model.ExportServiceManage;
+import com.qmth.cqb.paper.service.export.DzkdExportPaperService;
+import com.qmth.cqb.paper.service.export.ExportPaperAbstractService;
+import com.qmth.cqb.paper.service.export.ExportPaperService;
+
+import java.lang.reflect.Method;
+
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 /**
@@ -26,9 +36,13 @@ import javax.servlet.http.HttpServletResponse;
 public class ExportPaperController {
 
     protected static final Logger log = LoggerFactory.getLogger(ExportPaperController.class);
-
+    
+    
+    @Autowired
+    ExportServiceManageRepo exportServiceManageRepo; 
+    
     @Autowired
-    ExportPaperService exportPaperService;
+    ExportPaperAbstractService exportPaperService;
 
     /**
      * 导出试卷
@@ -38,10 +52,17 @@ public class ExportPaperController {
     @ApiOperation(value="导出试卷",notes="导出试卷")
     @Uac(roles={RoleMeta.QUESTION_ADMIN,RoleMeta.SUPER_ADMIN},policy=UacPolicy.IN)
     @GetMapping(value = "/paper/export/{id}")
-    public void getPaperById(@PathVariable String id, HttpServletResponse response){
+    public void getPaperById(@PathVariable String id, HttpServletResponse response,HttpServletRequest request){
         log.info("导出开始");
         try {
-            exportPaperService.downloadPaper(id,response);
+            //AccessUser user = (AccessUser) request.getAttribute("accessUser");
+            ExportServiceManage esm = exportServiceManageRepo.findByOrgName("电子科技大学");        
+            Method mds[] = ExportPaperAbstractService.class.getDeclaredMethods(); 
+            for(Method met:mds){ 
+	            if(met.getName().equals(esm.getExportServiceName())){ 
+		            met.invoke(exportPaperService, id,response); 
+	            } 
+            } 
         } catch (Exception e) {
             e.printStackTrace();
             log.error("导出异常:"+e.getMessage());
@@ -49,4 +70,6 @@ public class ExportPaperController {
             log.info("导出结束");
         }
     }
+
+
 }

+ 1 - 1
cqb-paper/src/main/java/com/qmth/cqb/paper/web/ImportPaperController.java

@@ -71,7 +71,7 @@ public class ImportPaperController {
         File tempFile = null;
         try {
             tempFile = importPaperService.getUploadFile(file);
-            Paper newPaper = importPaperService.ImportPaper(paper, user, tempFile);
+            Paper newPaper = importPaperService.importPaper(paper, user, tempFile);
             return new ResponseEntity(newPaper, HttpStatus.OK);
         } catch (Exception e) {
             e.printStackTrace();

Некоторые файлы не были показаны из-за большого количества измененных файлов