浏览代码

1.0.5 bug

haogh 10 月之前
父节点
当前提交
77f05ea357

+ 26 - 11
paper-library-business/src/main/java/com/qmth/paper/library/business/templete/service/impl/TaskLogicServiceImpl.java

@@ -761,6 +761,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 throw ExceptionResultEnum.ERROR.exception("扫描任务不存在");
             }
             BasicSchool school = basicSchoolService.getById(scanTask.getSchoolId());
+            BasicExam basicExam = basicExamService.getById(scanTask.getExamId());
+            BasicSemester basicSemester = basicSemesterService.getById(basicExam.getSemesterId());
             pictureLocalPath = rootPath + File.separator + school.getName();
             //查询考生数据
             if (!studentIdList.isEmpty()) {
@@ -822,19 +824,17 @@ public class TaskLogicServiceImpl implements TaskLogicService {
 
                 //试卷写入到pdf
                 if(!fileList.isEmpty()) {
-                    String pdfPath = generateStudentPaperPdf(result.getStudentCode(), fileList, school.getName(), courseNameCode);
-                    //更新考生
                     ExamStudent student = examStudentService.getById(result.getStudentId());
+                    String pdfPath = generateStudentPaperPdf(scanTask,student, result.getStudentCode(), fileList);
+                    //更新考生
                     student.setFilePath(pdfPath);
                     examStudentService.updateById(student);
                 }
             }
 
             map.put("size", successMap.size());
-
             //执行情况写入到excel
-            String path = fileStoreUtil.buildPath(UploadFileEnum.PDF, true);
-            path += File.separator + school.getName();
+            String path = fileStoreUtil.buildPath(UploadFileEnum.PDF, false, school.getName(), basicSemester.getName(),basicExam.getName());
             createPdfExcel(path, toBeGeneratedList, successMap, errorMap);
         } catch (Exception e) {
             throw ExceptionResultEnum.ERROR.exception(e.getMessage());
@@ -847,15 +847,14 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         return map;
     }
 
-    private String generateStudentPaperPdf(String pdfName, List<File> fileList, String... paths) {
-        StringBuilder pdfRootPath = new StringBuilder(fileStoreUtil.buildPath(UploadFileEnum.PDF, true));
-        for (String path : paths) {
-            pdfRootPath.append(File.separator).append(path);
-        }
-        File dir = new File(pdfRootPath.toString());
+    private String generateStudentPaperPdf(PaperScanTask paperScanTask, ExamStudent student, String pdfName, List<File> fileList) {
+        String pdfRootPath = getPdfRootPath(paperScanTask, student);
+        File dir = new File(pdfRootPath);
         if (!dir.exists()) {
             dir.mkdirs();
         }
+
+        //文件的完整路径
         String pdfPath = pdfRootPath + File.separator + pdfName + SystemConstant.PDF_SUFFIX;
 
         Document document = null;
@@ -876,6 +875,22 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         return pdfPath;
     }
 
+    private String getPdfRootPath(PaperScanTask paperScanTask, ExamStudent examStudent) {
+        BasicSchool basicSchool = basicSchoolService.getById(paperScanTask.getSchoolId());
+        BasicExam basicExam = basicExamService.getById(paperScanTask.getExamId());
+        BasicSemester basicSemester = basicSemesterService.getById(basicExam.getSemesterId());
+        String courseNameCode = String.format("%s(%s)", paperScanTask.getCourseName(), paperScanTask.getCourseCode());
+        String rootPath = fileStoreUtil.buildPath(UploadFileEnum.PDF, false, basicSchool.getName(), basicSemester.getName(), basicExam.getName(), courseNameCode);
+        if (StoreTypeEnum.ROOM.equals(paperScanTask.getStoreType())) {
+            rootPath = fileStoreUtil.buildPath(UploadFileEnum.PDF, false, basicSchool.getName(), basicSemester.getName(), basicExam.getName(), courseNameCode, examStudent.getExamRoom());
+        } else if (StoreTypeEnum.CLASS.equals(paperScanTask.getStoreType())) {
+            rootPath = fileStoreUtil.buildPath(UploadFileEnum.PDF, false, basicSchool.getName(), basicSemester.getName(), basicExam.getName(), courseNameCode, examStudent.getClassName());
+        } else if (StoreTypeEnum.COURSE.equals(paperScanTask.getStoreType())) {
+            rootPath = fileStoreUtil.buildPath(UploadFileEnum.PDF, false, basicSchool.getName(), basicSemester.getName(), basicExam.getName(), courseNameCode, examStudent.getStudentCode());
+        }
+        return rootPath;
+    }
+
     private void createPdfExcel(String path, List<DocManageDetailResult> list, Map<Long, Integer> successMap,
             Map<Long, Integer> errorMap) throws IOException {
         String fileName = "执行清单-" + System.currentTimeMillis() +".xlsx";