ソースを参照

1.修改完形填空的题干,把是“__数字__”,还原成“##数字##”
2.增加多套试卷导出功能
3.卷库导出bug修改,压缩包名称为 “试卷名称_课程代码”

weiwenhai 7 年 前
コミット
978e0912b1

+ 5 - 3
cqb-comm-utils/src/main/java/com/qmth/cqb/utils/FileDisposeUtil.java

@@ -13,6 +13,7 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.HttpURLConnection;
 import java.net.URL;
+import java.net.URLEncoder;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -103,9 +104,10 @@ public class FileDisposeUtil {
 	        //设置文件MIME类型  
 			response.setContentType(getContentType(filename));
 	        //设置Content-Disposition,名称强制为UTF-8
-			String fileEncode = System.getProperty("file.encoding");
-	        response.setHeader("Content-Disposition", "attachment;filename="+new String(filename.getBytes(fileEncode),"UTF-8"));
-	         // 设置强制下载不打开
+			//String fileEncode = System.getProperty("file.encoding");
+	        //response.setHeader("Content-Disposition", "attachment;filename="+new String(filename.getBytes(fileEncode),"UTF-8"));
+			response.setHeader("Content-Disposition", "attachment;filename="+URLEncoder.encode(filename,"UTF-8")); 
+			// 设置强制下载不打开
 	         response.setContentType("application/octet-stream;charset=utf-8");
 	        //读取目标文件,通过response将目标文件写到客户端  
 	        //获取目标文件的绝对路径  

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

@@ -1,11 +1,13 @@
 package com.qmth.cqb.paper.service;
 
+import java.util.List;
+
 import javax.servlet.http.HttpServletResponse;
 
 public interface ExportPaperService {
 
 	/**
-	 * 导出试卷,答案,机考数据包
+	 * 导出单个试卷,答案,机考数据包
 	 * @param examId
 	 * @param courseNo
 	 * @param paperType
@@ -14,4 +16,15 @@ public interface ExportPaperService {
 	 * @throws Exception
 	 */
 	public void exportPaperFile(String paperId,String serviceName,String exportContentList,HttpServletResponse response, String loginName)  throws Exception;
+
+	/**
+	 * 批量导出试卷,答案,机考数据包
+	 * @param paperIds
+	 * @param serviceName
+	 * @param exportContentList
+	 * @param response
+	 * @param loginName
+	 * @throws Exception
+	 */
+	public void exportPaperFiles(List<String> paperList,String serviceName,String exportContentList,HttpServletResponse response, String loginName)  throws Exception;
 }

+ 45 - 0
cqb-paper/src/main/java/com/qmth/cqb/paper/service/impl/ExportPaperServiceImpl.java

@@ -16,6 +16,12 @@ import javax.servlet.http.HttpServletResponse;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.domain.Sort.Direction;
+import org.springframework.data.domain.Sort.Order;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.stereotype.Service;
 
 import com.google.gson.Gson;
@@ -39,6 +45,7 @@ import com.qmth.cqb.question.model.Question;
 import com.qmth.cqb.utils.CommonUtils;
 import com.qmth.cqb.utils.FileDisposeUtil;
 import com.qmth.cqb.utils.SpringContextUtils;
+import com.qmth.cqb.utils.enums.PaperType;
 
 @Service("exportPaperService")
 public class ExportPaperServiceImpl implements ExportPaperService{
@@ -53,6 +60,9 @@ public class ExportPaperServiceImpl implements ExportPaperService{
 	
 	@Autowired
 	private PaperDetailService paperDetailService;
+	
+	@Autowired
+    private MongoTemplate mongoTemplate;
 
 	@Override
 	public void exportPaperFile(String paperId,String serviceName,String exportContentList,HttpServletResponse response,String loginName) throws Exception {
@@ -312,4 +322,39 @@ public class ExportPaperServiceImpl implements ExportPaperService{
 		}
     }
 
+	@Override
+	public void exportPaperFiles(List<String> paperIds,String serviceName,String exportContentList, HttpServletResponse response,String loginName) throws Exception {
+		ExportPaperAbstractService exportPaperAbstractService = (ExportPaperAbstractService) SpringContextUtils.getBeanById(serviceName);
+		//根据试卷id查询所有试卷
+		List<Paper> papers = CommonUtils.toList(paperRepo.findAll(paperIds));
+		String zipFileName = loginName;
+		//创建压缩文件夹
+		File directory = new File(TEMP_FILE_EXP + File.separator + zipFileName);
+		if(!directory.exists()){
+			directory.mkdirs();
+		}
+		//下载试卷
+		if(exportContentList.indexOf("PAPER")>-1){
+			for(Paper paper:papers){
+				exportPaperAbstractService.downloadPaper(paper.getId(),zipFileName);
+			}
+		}
+		//下载答案
+		if(exportContentList.indexOf("ANSWER")>-1){
+			for(Paper paper:papers){
+				exportPaperAbstractService.downloadPaperAnswer(paper.getId(),zipFileName);
+			}
+		}
+		//下载机考数据包
+		if(exportContentList.indexOf("COMPUTERTEST_PACKAGE")>-1){
+			for(Paper paper:papers){
+				ComputerTestPaper computerTestPaper = buildComputerTestPapers(paper);
+				makeComputerTestPaperToJsonFile(paper.getCourse().getCode()+ "_" +paper.getName(),computerTestPaper,TEMP_FILE_EXP+File.separator+zipFileName);
+			}
+		}
+		FileDisposeUtil.fileToZip(TEMP_FILE_EXP+File.separator+zipFileName,TEMP_FILE_EXP,zipFileName);
+		FileDisposeUtil.downloadFile(CommonUtils.getCurDate() +".zip", TEMP_FILE_EXP+File.separator+zipFileName+".zip",response);
+		deteleFolder(TEMP_FILE_EXP,zipFileName);
+	}
+	
 }

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

@@ -1,5 +1,9 @@
 package com.qmth.cqb.paper.web;
 
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
 import cn.com.qmth.examcloud.common.uac.annotation.Uac;
 import cn.com.qmth.examcloud.common.uac.enums.RoleMeta;
 import cn.com.qmth.examcloud.common.uac.enums.UacPolicy;
@@ -38,7 +42,7 @@ public class ExportPaperController {
     @Autowired
     private ExportPaperService exportPaperService;
     /**
-     * 导出试卷
+     * 导出单个试卷
      * @param id
      * @return
      */
@@ -60,4 +64,31 @@ public class ExportPaperController {
     	log.info("导出结束");
     }
 
+    /**
+     * 批量导出试卷
+     * @param request
+     * @param response
+     * @param paperIds
+     * @param orgName
+     * @param exportContentList
+     * @param loginName
+     */
+    @ApiOperation(value="批量导出试卷", notes="批量导出")
+    @GetMapping(value = "/paper/batch_export/{paperIds}/{exportContentList}/{orgName}/{loginName}")
+    public void getPaperByIds(HttpServletRequest request ,HttpServletResponse response,
+    						  @PathVariable String paperIds,
+    						  @PathVariable String orgName,
+    						  @PathVariable String exportContentList,
+    						  @PathVariable String loginName){
+    	log.info("批量导出");
+    	List<String> paperList = Stream.of(paperIds.split(",")).collect(Collectors.toList());
+    	ExportServiceManage esm = exportServiceManageRepo.findByOrgName(orgName);
+    	try {
+			exportPaperService.exportPaperFiles(paperList,esm.getExportServiceName(), exportContentList, response, loginName);
+		} catch (Exception e) {
+			e.printStackTrace();
+			log.error("导出异常:"+e.getMessage());
+		}
+    	log.info("导出结束");
+    }
 }

+ 9 - 1
cqb-question-resource/src/main/java/com/qmth/cqb/question/service/impl/QuesServiceImpl.java

@@ -6,6 +6,7 @@ import java.util.regex.Pattern;
 
 import com.qmth.cqb.question.dao.QuesPkgPathRepo;
 import com.qmth.cqb.question.model.*;
+
 import org.apache.commons.lang3.StringEscapeUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.docx4j.Docx4J;
@@ -156,6 +157,8 @@ public class QuesServiceImpl implements QuesService{
         setSelectQuestionAnswer(question,"");
         updateSubId(question);
         updateQuesWord(question);
+        //更新QuesBody,把  下划线  转成  ##
+        updateQuesBody(question);
         if(question.getHasAudio()!=null&&question.getHasAudio()){
         	questionAudioService.deleteAudioNotInQuestion(question);
         	//如果根据questionId查询不出音频了,将hasAudio设置为false
@@ -167,7 +170,12 @@ public class QuesServiceImpl implements QuesService{
         return quesRepo.save(question);
     }
 
-    /**
+    private void updateQuesBody(Question question) {
+    	String newQuesBody = question.getQuesBody().replaceAll("___", "##");
+        question.setQuesBody(newQuesBody);
+	}
+
+	/**
      * 批量保存试题
      *
      * @param list