deason 6 yıl önce
ebeveyn
işleme
b7bfee5d7f

+ 46 - 45
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/impl/ExtractConfigFileServiceImpl.java

@@ -27,7 +27,6 @@ import cn.com.qmth.examcloud.examwork.api.bean.ExamCourseRelationBean;
 import cn.com.qmth.examcloud.examwork.api.request.GetExamCourseListReq;
 import cn.com.qmth.examcloud.examwork.api.response.GetExamCourseListResp;
 import main.java.com.UpYun;
-
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.docx4j.Docx4J;
@@ -39,7 +38,6 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import javax.servlet.http.HttpServletResponse;
-
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -96,7 +94,7 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
 
     @Autowired
     private ExportPaperService exportPaperService;
-    
+
     @Autowired
     private ExamCloudService examCloudService;
 
@@ -120,22 +118,22 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
 
     @Override
     public void saveExtractConfigAndBuildPaperFile(ExtractConfig extractConfig, Integer isbuildFile, User user) throws Exception {
-    	//新增,id为空
-    	if(StringUtils.isBlank(extractConfig.getId())){
-    		//先查询
-        	ExtractConfig tempConfig = extractConfigService.findConfig(extractConfig);
-        	if(tempConfig != null){
-        		extractConfig.setId(tempConfig.getId());
-        	}
-    	}
-    	//查询试卷导出设置
+        //新增,id为空
+        if (StringUtils.isBlank(extractConfig.getId())) {
+            //先查询
+            ExtractConfig tempConfig = extractConfigService.findConfig(extractConfig);
+            if (tempConfig != null) {
+                extractConfig.setId(tempConfig.getId());
+            }
+        }
+        //查询试卷导出设置
         ExportStructure exportStructure = null;
         if (isbuildFile == 1) {
             exportStructure = exportStructureService.findStructureByExamId(extractConfig.getExamId() + "");
         }
         //生成试卷
         List<ExamPaper> examPaperList = extractConfigService.saveExtractConfig(extractConfig, user);
-        if(isbuildFile == 1) {
+        if (isbuildFile == 1) {
             //删除原有试卷文件
             ExamFile examFile = new ExamFile();
             examFile.setExamId(extractConfig.getExamId() + "");
@@ -143,9 +141,9 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
             examFile.setOrgId(extractConfig.getOrgId());
             examFileService.deleteExamFile(examFile);
             //上传抽取试卷对象集合
-            for(ExamPaper examPaper:examPaperList){
-            	String paperId = examPaper.getPaper().getId();
-            	uploadPaperFile(extractConfig, paperId, exportStructure, user, examPaper);
+            for (ExamPaper examPaper : examPaperList) {
+                String paperId = examPaper.getPaper().getId();
+                uploadPaperFile(extractConfig, paperId, exportStructure, user, examPaper);
             }
         }
         /*if (isbuildFile == 1) {
@@ -175,7 +173,7 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
      * @param user
      * @throws Exception
      */
-    private void uploadPaperFile(ExtractConfig extractConfig, String paperId, ExportStructure exportStructure, User user,ExamPaper examPaper) throws Exception {
+    private void uploadPaperFile(ExtractConfig extractConfig, String paperId, ExportStructure exportStructure, User user, ExamPaper examPaper) throws Exception {
         ExportServiceManage esm = exportServiceManageRepo.findByOrgName(user.getRootOrgName());
         if (esm == null) {
             esm = exportServiceManageRepo.findByOrgName("天津大学");
@@ -256,15 +254,15 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
                     Long examId = Long.parseLong(exportModel.getExamId());
                     ExtractConfig extractConfig = extractConfigService.findConfig(new ExtractConfig(examId, examFile.getCourseId()));
                     List<ExamPaper> list = extractConfig.getExamPaperList();
-                    if(list!=null && list.size()>0){
-                    	for(ExamPaper examPaper:list){
-                    		String groupCode = examPaper.getGroupCode();
-                    		String paperId = examPaper.getPaper().getId();
-                    		if (groupCode.equals(examFile.getGroupCode())) {
-                    			downloadAudio(paperId, examFile, downloadDir, orgName);
-                    		}
-                    		
-                    	}
+                    if (list != null && list.size() > 0) {
+                        for (ExamPaper examPaper : list) {
+                            String groupCode = examPaper.getGroupCode();
+                            String paperId = examPaper.getPaper().getId();
+                            if (groupCode.equals(examFile.getGroupCode())) {
+                                downloadAudio(paperId, examFile, downloadDir, orgName);
+                            }
+
+                        }
                     }
                    /* Map<String, String> finishedPaperIdMap = extractConfig.getFinishedPaperIdMap();
                     Set<Entry<String, String>> entrySet = finishedPaperIdMap.entrySet();
@@ -319,8 +317,8 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
                         if (unit.getQuestion().getHasAudio() != null && unit.getQuestion().getHasAudio()) {
                             List<QuestionAudio> questionAudios = questionAudioService.findQuestionAudiosByQuestionId(unit.getQuestion().getId());
                             for (QuestionAudio audio : questionAudios) {
-                                String audioFileName = audio.getId()+
-                                         "_" + exportPaperAbstractService.getAudioFileName(audio, unit, paperDetailExp);
+                                String audioFileName = audio.getId() +
+                                        "_" + exportPaperAbstractService.getAudioFileName(audio, unit, paperDetailExp);
                                 UpYun upyun = new UpYun(bucketName, userName, password);
                                 File file = new File(downloadDir + File.separator + audioFileName);
                                 upyun.readFile(audio.getFileUrl(), file);
@@ -357,7 +355,7 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
      * @return
      */
     @SuppressWarnings("unused")
-	private String getAudioFileName(QuestionAudio audio, PaperDetailUnit unit) {
+    private String getAudioFileName(QuestionAudio audio, PaperDetailUnit unit) {
         String questionAudioId = audio.getId();
         StringBuffer audioFileName = new StringBuffer(unit.getPaperDetail().getNumber() + "_" + unit.getNumber() + "_");
         Question question = unit.getQuestion();
@@ -403,25 +401,29 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
         Long start = 1l;
         int count = 0;
         while (true) {
-        	req.setStart(start);
+            req.setStart(start);
             GetExamCourseListResp resp = examCloudService.getExamCourseList(req);
             examCourseDtoList.addAll(resp.getRelationList());
-            if(start.equals(resp.getNext())){
-            	break;
-            }else {
-            	start = resp.getNext();
-			}
+            if (start.equals(resp.getNext())) {
+                break;
+            } else {
+                start = resp.getNext();
+            }
             count++;
-            if(count>1000){
-            	throw new StatusException("Q-", "考试下课程的数据量过大");
+            if (count > 1000) {
+                throw new StatusException("Q-", "考试下课程的数据量过大");
             }
-		}
-        
+        }
+
         for (ExamCourseRelationBean examCourseDto : examCourseDtoList) {
             ExtractConfig condition = new ExtractConfig();
             condition.setExamId(examCourseDto.getExamId());
             condition.setCourseCode(examCourseDto.getCourseCode());
             ExtractConfig extractConfig = extractConfigService.findConfig(condition);
+//            if (extractConfig == null) {
+//                logger.warn("examId:" + examId + " courseCode:" + examCourseDto.getCourseCode());
+//                continue;
+//            }
             if (extractConfig == null) {
                 throw new RuntimeException("该考试下的课程“" + examCourseDto.getCourseName() + "”没有制定调卷规则,不能批量导出,请保存调卷规则生成文件");
             }
@@ -430,12 +432,12 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
             }
             checkExamFileExists(examId, examCourseDto.getCourseCode(), exportType, examCourseDto.getCourseName());
             List<ExamPaper> examPapers = extractConfig.getExamPaperList();
-            if(examPapers == null || examPapers.size()<1){
-            	throw new RuntimeException("该考试下的课程“" + examCourseDto.getCourseName() + "”没有绑定试卷。");
+            if (examPapers == null || examPapers.size() < 1) {
+                throw new RuntimeException("该考试下的课程“" + examCourseDto.getCourseName() + "”没有绑定试卷。");
             }
-            for(ExamPaper examPaper:examPapers){
-            	String paperId = examPaper.getPaper().getId();
-            	paperIdMap.put(paperId,examPaper.getGroupCode());
+            for (ExamPaper examPaper : examPapers) {
+                String paperId = examPaper.getPaper().getId();
+                paperIdMap.put(paperId, examPaper.getGroupCode());
             }
             
             /*Map<String, String> finishedPaperIdMap = extractConfig.getFinishedPaperIdMap();
@@ -454,7 +456,6 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
      * 检查试卷文件是否存在
      *
      * @param examId
-     * @param examCourseDto
      */
     private void checkExamFileExists(String examId, String code, ExportType exportType, String name) {
         ExamFile examFileCondition = new ExamFile();