Преглед на файлове

提交组卷BUG和其他代码

chenken преди 7 години
родител
ревизия
ae2da533d8

+ 12 - 12
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;
@@ -41,10 +42,8 @@ public class FileDisposeUtil {
 			URL url = new URL(fileUrl);
 			HttpURLConnection connection = (HttpURLConnection) url
 					.openConnection();
-			DataInputStream in = new DataInputStream(
-					connection.getInputStream());
-			DataOutputStream out = new DataOutputStream(new FileOutputStream(
-					fileName));
+			DataInputStream in = new DataInputStream(connection.getInputStream());
+			DataOutputStream out = new DataOutputStream(new FileOutputStream(fileName));
 			byte[] buffer = new byte[4096];
 			int count = 0;
 			while ((count = in.read(buffer)) > 0) {
@@ -64,15 +63,16 @@ public class FileDisposeUtil {
 	 * @param response
 	 */
 	public static void downloadFile(String filename,String fullFilePath,HttpServletResponse response){
-		//获得请求文件名  
-        //设置文件MIME类型  
-		response.setContentType(getContentType(filename));
-        //设置Content-Disposition  
-        response.setHeader("Content-Disposition", "attachment;filename="+filename);  
-        //读取目标文件,通过response将目标文件写到客户端  
-        //获取目标文件的绝对路径  
-        //读取文件  
 		try {
+			//设置编码
+			response.setCharacterEncoding("UTF-8");
+	        //设置文件MIME类型  
+			response.setContentType(getContentType(filename));
+	        //设置Content-Disposition,名称强制为UTF-8
+	        response.setHeader("Content-Disposition", "attachment;filename="+URLEncoder.encode(filename,"UTF-8"));  
+	        //读取目标文件,通过response将目标文件写到客户端  
+	        //获取目标文件的绝对路径  
+	        //读取文件  
 			InputStream in = new FileInputStream(fullFilePath);
 			OutputStream out = response.getOutputStream();  
 	        //写文件  

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

@@ -4,6 +4,7 @@ import java.io.Serializable;
 import java.util.List;
 import java.util.Map;
 
+import com.qmth.cqb.base.model.Course;
 import com.qmth.cqb.genpaper.condition.Condition;
 import com.qmth.cqb.utils.enums.RandomGenPaperPolicy;
 
@@ -20,6 +21,8 @@ public class GenPaperDto implements Serializable {
 
     private String courseName;// 课程名称
     
+    private Course course;
+    
     private CourseLevel level;// 层次
 
     private String paperName;// 试卷名称
@@ -144,5 +147,12 @@ public class GenPaperDto implements Serializable {
 		this.level = level;
 	}
 
+	public Course getCourse() {
+		return course;
+	}
+
+	public void setCourse(Course course) {
+		this.course = course;
+	}
     
 }

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

@@ -13,6 +13,8 @@ import java.util.UUID;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import com.qmth.cqb.base.dao.CourseRepo;
+import com.qmth.cqb.base.model.Course;
 import com.qmth.cqb.genpaper.context.DetailContext;
 import com.qmth.cqb.genpaper.context.PaperContext;
 import com.qmth.cqb.genpaper.context.UnitContext;
@@ -48,6 +50,9 @@ public class GenPaperService {
     @Autowired
     PaperStructRepo paperStructRepo;
 
+    @Autowired
+    CourseRepo courseRepo;
+    
     /**
      * 精确组卷,根据设定试卷结构组卷
      * 
@@ -272,6 +277,8 @@ public class GenPaperService {
             paper.setName(genPaperDto.getPaperName());
             paper.setCourseNo(genPaperDto.getCourseNo());
             paper.setCourseName(genPaperDto.getCourseName());
+            Course course = courseRepo.findFirstByCodeAndOrgId(genPaperDto.getCourseNo(),genPaperDto.getOrgId());
+            paper.setCourse(course);
             paper.setCreator(genPaperDto.getCreator());
             paper.setCreateTime(CommonUtils.getCurDateTime());
             paper.setPaperDetailCount(details.size());

+ 21 - 2
cqb-paper/src/main/java/com/qmth/cqb/paper/model/ExamFile.java

@@ -2,6 +2,10 @@ package com.qmth.cqb.paper.model;
 
 import java.io.Serializable;
 import java.util.Date;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
 
 import org.springframework.data.annotation.Id;
 
@@ -82,7 +86,7 @@ public class ExamFile implements Serializable{
     	
     }
     
-    public ExamFile(ExtractConfig extractConfig,String filePath,ExamFileType examFileType,String fileSuffix){
+    public ExamFile(String paperId,ExtractConfig extractConfig,String filePath,ExamFileType examFileType,String fileSuffix){
     	this.orgId = extractConfig.getOrgId();
     	this.orgName = extractConfig.getOrgName();
     	this.examId = extractConfig.getExamId()+"";
@@ -90,7 +94,22 @@ public class ExamFile implements Serializable{
     	this.examType = ExamType.strToEnum(extractConfig.getExamType());
     	this.courseId = extractConfig.getCourseCode();
     	this.courseName = extractConfig.getCourseName();
-    	this.fileName = extractConfig.getCourseName()+"_"+extractConfig.getCourseCode()+"_"+examFileType.getName()+fileSuffix;
+    	
+    	Map<String,String> paperIdMap = extractConfig.getFinishedPaperIdMap();
+    	Set<Entry<String,String>> entry = paperIdMap.entrySet();
+		Iterator<Entry<String,String>> iterator = entry.iterator();
+		String groupCode = "";
+		while(iterator.hasNext()){
+			Entry<String,String> next = iterator.next();
+			if(paperId.equals(next.getValue())){
+				groupCode = next.getKey();
+				break;
+			}
+		}
+    	this.fileName = extractConfig.getCourseName()+"_"+
+    				    extractConfig.getCourseCode()+"_"+
+    				    examFileType.getName()+"_"+
+    				    groupCode+fileSuffix;
     	this.filePath = filePath;
     	this.examFileType = examFileType;
     }

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

@@ -846,10 +846,10 @@ public abstract class ExportPaperAbstractService {
 			DocxProcessUtil.exportWord(paperExp,paperfileName,template);
 			DocxProcessUtil.processImage(paperfileName,getPkgList(paperExp.getId()));
 			File file  = new File(TEMP_FILE_EXP+paperfileName);
-			String paperFilePath = uploadUrl+extractConfig.getOrgId()+File.separator+paperfileName;
+			String paperFilePath = uploadUrl+extractConfig.getOrgId()+"/"+paperfileName;
             UpYun upyun = new UpYun(bucketName,userName,password);
 			upyun.writeFile(paperFilePath,file,true);
-			examFileService.saveExamFile(new ExamFile(extractConfig,paperFilePath,examFileType,DOCX_SUFFIX),accessUser);
+			examFileService.saveExamFile(new ExamFile(paperExp.getId(),extractConfig,paperFilePath,examFileType,DOCX_SUFFIX),accessUser);
 			file.delete();
 		} catch (Exception e) {
 			e.printStackTrace();
@@ -885,10 +885,10 @@ public abstract class ExportPaperAbstractService {
 			File file = new File(TEMP_FILE_EXP+objectiveFilename);
 			FileOutputStream out = new FileOutputStream(file);
 			objectiveExcelExporter.write(objectiveFilename,objectiveQuestionStructureList,out);
-			String objectiveFilePath = uploadUrl+extractConfig.getOrgId()+File.separator+objectiveFilename;
+			String objectiveFilePath = uploadUrl+extractConfig.getOrgId()+"/"+objectiveFilename;
             UpYun upyun = new UpYun(bucketName,userName,password);
 			upyun.writeFile(objectiveFilePath,file,true);
-			examFileService.saveExamFile(new ExamFile(extractConfig,objectiveFilePath,ExamFileType.PAPER_STRUCTURE_OBJECTIVE,EXCEL_SUFFIX),accessUser);
+			examFileService.saveExamFile(new ExamFile(paperExp.getId(),extractConfig,objectiveFilePath,ExamFileType.PAPER_STRUCTURE_OBJECTIVE,EXCEL_SUFFIX),accessUser);
 			file.delete();
 		} catch (FileNotFoundException e) {
 			e.printStackTrace();
@@ -972,10 +972,10 @@ public abstract class ExportPaperAbstractService {
 			File file = new File(TEMP_FILE_EXP+subjectiveFileName);
 			FileOutputStream out = new FileOutputStream(file);
 			subjectiveExcelExporter.write(subjectiveFileName,subjectiveQuestionStructureList,out);
-			String subjectiveFilePath = uploadUrl+extractConfig.getOrgId()+File.separator+subjectiveFileName;
+			String subjectiveFilePath = uploadUrl+extractConfig.getOrgId()+"/"+subjectiveFileName;
             UpYun upyun = new UpYun(bucketName,userName,password);
 			upyun.writeFile(subjectiveFilePath,file,true);
-			examFileService.saveExamFile(new ExamFile(extractConfig,subjectiveFilePath,ExamFileType.PAPER_STRUCTURE_SUBJECTIVE,EXCEL_SUFFIX),accessUser);
+			examFileService.saveExamFile(new ExamFile(paperExp.getId(),extractConfig,subjectiveFilePath,ExamFileType.PAPER_STRUCTURE_SUBJECTIVE,EXCEL_SUFFIX),accessUser);
 			file.delete();
 		} catch (FileNotFoundException e) {
 			e.printStackTrace();

+ 7 - 4
cqb-paper/src/main/java/com/qmth/cqb/paper/service/impl/ExtractConfigFileServiceImpl.java

@@ -91,6 +91,9 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
 		ExportStructure exportStructure = exportStructureService.findStructureByExamId(extractConfig.getExamId()+"");
 		//生成试卷
 		Map<String, String> finishedPaperIdMap = extractConfigService.saveExtractConfig(extractConfig, orgName, accessUser);
+		extractConfig.setFinishedPaperIdMap(finishedPaperIdMap);
+    	extractConfig.setIfFinish((short)1);
+    	
 		Set<Entry<String,String>> entry = finishedPaperIdMap.entrySet();
 		Iterator<Entry<String,String>> iterator = entry.iterator();
 		while(iterator.hasNext()){
@@ -98,8 +101,6 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
 			accessUser.setRootOrgName(orgName);
 			uploadPaperFile(extractConfig,paperId,exportStructure,accessUser);
 		}
-		extractConfig.setFinishedPaperIdMap(finishedPaperIdMap);
-    	extractConfig.setIfFinish((short)1);
     	extractConfigRepo.save(extractConfig);
 	}
 	
@@ -112,8 +113,10 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
 	 * @throws Exception
 	 */
 	private void uploadPaperFile(ExtractConfig extractConfig,String paperId,ExportStructure exportStructure,AccessUser accessUser) throws Exception {
-		//ExportServiceManage esm = exportServiceManageRepo.findByOrgName(accessUser.getRootOrgName());
-		ExportServiceManage esm = exportServiceManageRepo.findByOrgName("陕西师范大学");
+		ExportServiceManage esm = exportServiceManageRepo.findByOrgName(accessUser.getRootOrgName());
+		if(esm==null){
+			esm = exportServiceManageRepo.findByOrgName("陕西师范大学");
+		}
     	ExportPaperAbstractService exportPaperAbstractService = (ExportPaperAbstractService) SpringContextUtils.getBeanById(esm.getExportServiceName());
     	exportPaperAbstractService.uploadFile(extractConfig,paperId,exportStructure,accessUser);
 	}

+ 2 - 5
cqb-paper/src/main/java/com/qmth/cqb/paper/service/impl/ExtractConfigServiceImpl.java

@@ -614,12 +614,9 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
 			if(extractConfig==null){
 				extractConfig = new ExtractConfig(examCourseDto);
 			}
-			Course course = extractConfig.getCourse();
-			if(course != null && course.getEnable().equals("true")){
-				extractConfigs.add(extractConfig);
-			}
+			extractConfigs.add(extractConfig);
 		}
-		return new PageImpl<ExtractConfig>(extractConfigs,new PageRequest(currentPage,pageSize),extractConfigs.size());
+		return new PageImpl<ExtractConfig>(extractConfigs,new PageRequest(currentPage,pageSize),pageExamCourse.getTotalElements());
 	}
 
 }

+ 0 - 2
cqb-paper/src/main/java/com/qmth/cqb/paper/web/AudioTimeConfigController.java

@@ -10,11 +10,9 @@ import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 import com.qmth.cqb.paper.model.AudioTimeConfig;
-import com.qmth.cqb.paper.model.ExamFile;
 import com.qmth.cqb.paper.service.AudioTimeConfigService;
 
 /**

+ 2 - 2
cqb-starter/src/main/resources/application-dev.properties

@@ -11,8 +11,8 @@ spring.redis.port=6379
 upyun.bucketName=exam-cloud-test
 upyun.userName=examcloud
 upyun.password=examcloud123456
-upyun.uploadUrl=/comm-ques-bank/exam-paper-file/
-upyun.audio.uploadUrl=/comm-ques-bank/audio/
+upyun.uploadUrl=/comm-ques-bank/dev/exam-paper-file/
+upyun.audio.uploadUrl=/comm-ques-bank/dev/audio/
 upyun.downloadUrl=http://exam-cloud-test.b0.upaiyun.com
 upyun.downloadDirectory=paperDirectory
 upyun.zipDirectory=paperZipDirectory

+ 2 - 2
cqb-starter/src/main/resources/application-prod.properties

@@ -11,8 +11,8 @@ spring.redis.port=6379
 upyun.bucketName=exam-cloud-test
 upyun.userName=examcloud
 upyun.password=examcloud123456
-upyun.uploadUrl=/comm-ques-bank/exam-paper-file/
-upyun.audio.uploadUrl=/comm-ques-bank/audio/
+upyun.uploadUrl=/comm-ques-bank/prod/exam-paper-file/
+upyun.audio.uploadUrl=/comm-ques-bank/prod/audio/
 upyun.downloadUrl=http://exam-cloud-test.b0.upaiyun.com
 upyun.downloadDirectory=paperDirectory
 upyun.zipDirectory=paperZipDirectory

+ 2 - 2
cqb-starter/src/main/resources/application-test.properties

@@ -10,8 +10,8 @@ spring.redis.port=6379
 upyun.bucketName=exam-cloud-test
 upyun.userName=examcloud
 upyun.password=examcloud123456
-upyun.uploadUrl=/comm-ques-bank/exam-paper-file/
-upyun.audio.uploadUrl=/comm-ques-bank/audio/
+upyun.uploadUrl=/comm-ques-bank/test/exam-paper-file/
+upyun.audio.uploadUrl=/comm-ques-bank/test/audio/
 upyun.downloadUrl=http://exam-cloud-test.b0.upaiyun.com
 upyun.downloadDirectory=paperDirectory
 upyun.zipDirectory=paperZipDirectory