gaoxing 8 лет назад
Родитель
Сommit
a40d521976

+ 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();
+   
     }
 
     /**

+ 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;
 

+ 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;
+	}
+
+	
+    
 }

+ 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);

+ 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;
@@ -252,12 +256,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));
+//        }
     }
 
     /**
@@ -265,12 +269,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();