Kaynağa Gözat

附件修改

wangliang 2 yıl önce
ebeveyn
işleme
3b6b35fe84

+ 8 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/DownloadServiceImpl.java

@@ -168,11 +168,19 @@ public class DownloadServiceImpl implements DownloadService {
 
                     // html
                     File htmlFile = new File(cardHtmlPath);
+                    if(!htmlFile.exists()){
+                        htmlFile.getParentFile().mkdirs();
+                        htmlFile.createNewFile();
+                    }
                     // 生成html文件
                     FileCopyUtils.copy(htmlContent.getBytes(), htmlFile);
                     fileList.add(htmlFile);
                     // 转pdf文件
                     File pdfFile = new File(cardPdfPath);
+                    if(!pdfFile.exists()){
+                        pdfFile.getParentFile().mkdirs();
+                        pdfFile.createNewFile();
+                    }
                     HtmlToPdfUtil.convert(cardHtmlPath, cardPdfPath, PageSizeEnum.A3);
                     fileList.add(pdfFile);
                 }

+ 14 - 6
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamTaskServiceImpl.java

@@ -232,7 +232,7 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
         userName = SystemConstant.translateSpecificSign(userName);
         createName = SystemConstant.translateSpecificSign(createName);
         SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
-        DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission(schoolId,requestUser.getId(),ServletUtil.getRequest().getServletPath());
+        DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission(schoolId, requestUser.getId(), ServletUtil.getRequest().getServletPath());
         Page<ExamTaskDto> page = new Page<>(pageNumber, pageSize);
         IPage<ExamTaskDto> examTaskDtoIPage = this.baseMapper.listPage(page, schoolId, semesterId, examId, enable, status, cardRuleId, courseCode, paperNumber, startTime, endTime, dpr, userName, createName);
         for (ExamTaskDto record : examTaskDtoIPage.getRecords()) {
@@ -771,7 +771,7 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
         userName = SystemConstant.translateSpecificSign(userName);
         Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
-        DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission(schoolId,sysUser.getId(),ServletUtil.getRequest().getServletPath());
+        DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission(schoolId, sysUser.getId(), ServletUtil.getRequest().getServletPath());
         IPage<ExamTaskDto> examTaskDtoIPage = this.baseMapper.listTaskApply(new Page<>(pageNumber, pageSize), schoolId, semesterId, examId, auditStatus, cardRuleId, courseCode, paperNumber, startTime, endTime, sysUser.getId(), dpr, userName);
         for (ExamTaskDto record : examTaskDtoIPage.getRecords()) {
             if ((record.getReview() && FlowStatusEnum.FINISH.name().equals(record.getAuditStatus()) && !ExamModelEnum.MODEL3.equals(record.getExamModel()))) {
@@ -789,7 +789,7 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
         createName = SystemConstant.translateSpecificSign(createName);
         Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
-        DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission(schoolId,sysUser.getId(),ServletUtil.getRequest().getServletPath());
+        DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission(schoolId, sysUser.getId(), ServletUtil.getRequest().getServletPath());
         return this.baseMapper.listTaskReviewUnaudited(new Page<>(pageNumber, pageSize), schoolId, semesterId, examId, courseCode, paperNumber, userId, cardRuleId, startTime, endTime, dpr, startCreateTime, endCreateTime, createName, sysUser.getId());
     }
 
@@ -834,7 +834,7 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
         boolean containsQuestionTeacher = false;
         Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
         SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
-        DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission(schoolId,requestUser.getId(),ServletUtil.getRequest().getServletPath());
+        DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission(schoolId, requestUser.getId(), ServletUtil.getRequest().getServletPath());
         Page<ExamTaskDetailDto> page = new Page<>(pageNumber, pageSize);
         return this.baseMapper.listTaskPaper(page, schoolId, semesterId, examId, courseCode, paperNumber, startTime, endTime, dpr, containsQuestionTeacher, sysUser.getId(), makeMethod, cardRuleId);
     }
@@ -843,8 +843,8 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
     public List<RelatePaperDto> listPaperTypes(Long examTaskId, Long printPlanId, String courseCode) {
         Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
         SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
-        DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission(schoolId,requestUser.getId(),ServletUtil.getRequest().getServletPath());
-        List<RelatePaperDto> list = this.baseMapper.listPaperNumbers(schoolId, courseCode, ExamStatusEnum.SUBMIT.name(),dpr);
+        DataPermissionRule dpr = basicRoleDataPermissionService.findDataPermission(schoolId, requestUser.getId(), ServletUtil.getRequest().getServletPath());
+        List<RelatePaperDto> list = this.baseMapper.listPaperNumbers(schoolId, courseCode, ExamStatusEnum.SUBMIT.name(), dpr);
         for (RelatePaperDto relatePaperDto : list) {
             QueryWrapper<ExamTaskDetail> queryWrapper = new QueryWrapper<>();
             queryWrapper.lambda().eq(ExamTaskDetail::getExamTaskId, relatePaperDto.getId()).eq(ExamTaskDetail::getEnable, true);
@@ -1051,11 +1051,19 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
 
                     // html
                     File htmlFile = new File(cardHtmlPath);
+                    if (!htmlFile.exists()) {
+                        htmlFile.getParentFile().mkdirs();
+                        htmlFile.createNewFile();
+                    }
                     // 生成html文件
                     FileCopyUtils.copy(htmlContent.getBytes(), htmlFile);
                     fileList.add(htmlFile);
                     // 转pdf文件
                     File pdfFile = new File(cardPdfPath);
+                    if (!pdfFile.exists()) {
+                        pdfFile.getParentFile().mkdirs();
+                        pdfFile.createNewFile();
+                    }
                     HtmlToPdfUtil.convert(cardHtmlPath, cardPdfPath, PageSizeEnum.A3);
                     fileList.add(pdfFile);
                 }

+ 44 - 14
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/impl/TaskLogicServiceImpl.java

@@ -936,7 +936,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 sourceFileList = new ArrayList<>(examDetailList.size() * 5);
                 for (ExamDetailPdfDownloadDto e : examDetailList) {
                     StringJoiner dirPath = new StringJoiner("")
-                            .add(String.valueOf(time)).add(File.separator)
+                            .add(zipLocalRootPath).add(File.separator)
                             .add(e.getSemesterName()).add(File.separator)
                             .add(e.getExamName()).add(File.separator)
                             .add(e.getCourseNameCode()).add(File.separator)
@@ -1021,12 +1021,23 @@ public class TaskLogicServiceImpl implements TaskLogicService {
      * @throws Exception
      */
     private File getJsonFile(JSONObject jsonObject, String pathName) throws Exception {
-        File file = SystemConstant.getFileTempDirVar(pathName, null);
-        String attachmentType = (String) jsonObject.get(SystemConstant.TYPE);
+        File file = new File(pathName);
+        if (!file.exists()) {
+            file.getParentFile().mkdirs();
+            file.createNewFile();
+        }
+        String attachmentType = jsonObject.getString(SystemConstant.TYPE);
         if (Objects.nonNull(attachmentType) && !Objects.equals(attachmentType, SystemConstant.LOCAL)) {
-            file = fileStoreUtil.ossDownload((String) jsonObject.get(SystemConstant.PDF_PATH), file, UploadFileEnum.PDF.getFssType());
+            file = fileStoreUtil.ossDownload(jsonObject.getString(SystemConstant.PDF_PATH), file, UploadFileEnum.PDF.getFssType());
         } else {
-            FileCopyUtils.copy(new File((String) jsonObject.get(SystemConstant.PDF_PATH)), file);
+            String path = SystemConstant.getLocalFilePath(jsonObject.getString(SystemConstant.PDF_PATH));
+            File sourceFile = null;
+            if (dictionaryConfig.fssPrivateDomain().getConfig().startsWith(SystemConstant.START_PARENT) || dictionaryConfig.fssPublicDomain().getConfig().startsWith(SystemConstant.START_PARENT)) {
+                sourceFile = new File(dictionaryConfig.fssPrivateDomain().getConfig(), jsonObject.getString(SystemConstant.PDF_PATH));
+            } else {
+                sourceFile = new File(path);
+            }
+            FileUtils.copyFile(sourceFile, file);
         }
         return file;
     }
@@ -1042,14 +1053,25 @@ public class TaskLogicServiceImpl implements TaskLogicService {
     private File getAttachmentFile(BasicAttachment attachment, String pathName) throws Exception {
         File file = null;
         if (Objects.nonNull(attachment) && Objects.nonNull(attachment.getPath())) {
-            file = SystemConstant.getFileTempDirVar(pathName, null);
+            file = new File(pathName);
+            if (!file.exists()) {
+                file.getParentFile().mkdirs();
+                file.createNewFile();
+            }
             JSONObject jsonObject = JSONObject.parseObject(attachment.getPath());
-            String attachmentType = (String) jsonObject.get(SystemConstant.TYPE);
-            UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
+            String attachmentType = jsonObject.getString(SystemConstant.TYPE);
+            UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf(jsonObject.getString(SystemConstant.UPLOAD_TYPE));
             if (Objects.nonNull(attachmentType) && !Objects.equals(attachmentType, SystemConstant.LOCAL)) {
-                file = fileStoreUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), file, uploadFileEnum.getFssType());
+                file = fileStoreUtil.ossDownload(jsonObject.getString(SystemConstant.PATH), file, uploadFileEnum.getFssType());
             } else {
-                FileCopyUtils.copy(new File((String) jsonObject.get(SystemConstant.PATH)), file);
+                String path = SystemConstant.getLocalFilePath(jsonObject.getString(SystemConstant.PATH));
+                File sourceFile = null;
+                if (dictionaryConfig.fssPrivateDomain().getConfig().startsWith(SystemConstant.START_PARENT) || dictionaryConfig.fssPublicDomain().getConfig().startsWith(SystemConstant.START_PARENT)) {
+                    sourceFile = new File(dictionaryConfig.fssPrivateDomain().getConfig(), jsonObject.getString(SystemConstant.PATH));
+                } else {
+                    sourceFile = new File(path);
+                }
+                FileUtils.copyFile(sourceFile, file);
             }
         }
         return file;
@@ -1241,7 +1263,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 stringJoiner.add(dictionaryConfig.fssPublicDomain().getConfig()).add(File.separator);
             }
             stringJoiner = SystemConstant.getDirName(stringJoiner, UploadFileEnum.FILE, true);
-            stringJoiner.add("命题任务审核样本导出_" + time).add(SystemConstant.ZIP_PREFIX);
+            stringJoiner.add("卷库查询管理试卷、空白题卡批量下载_" + time).add(SystemConstant.ZIP_PREFIX);
 
             String zipDirName = stringJoiner.toString().replaceAll("\\\\", SystemConstant.ORG_SPLIT);
             zipFile = SystemConstant.getFileTempDirVar(SystemConstant.ZIP_PREFIX);
@@ -1252,7 +1274,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 ExamTaskDetailPdfDownloadDto examTaskDetailPdfDownloadDto = examTaskDetailService.findPdfDownload(Long.valueOf(examTask.getId()));
 
                 StringJoiner dirPath = new StringJoiner("");
-                dirPath = dirPath.add(String.valueOf(time)).add(File.separator)
+                dirPath = dirPath.add(zipLocalRootPath).add(File.separator)
                         .add(examTaskDetailPdfDownloadDto.getSemesterName()).add(File.separator)
                         .add(examTaskDetailPdfDownloadDto.getExamName()).add(File.separator)
                         .add(examTaskDetailPdfDownloadDto.getCourseNameCode()).add(File.separator)
@@ -1293,12 +1315,20 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                             htmlContent = createPdfUtil.replaceHtmlCard(examCardDetail, basicCardRule);
                         }
                         // html
-                        File localFile = SystemConstant.getFileTempDirVar(cardHtmlPath, null);
+                        File localFile = new File(cardHtmlPath);
+                        if (!localFile.exists()) {
+                            localFile.getParentFile().mkdirs();
+                            localFile.createNewFile();
+                        }
                         // 生成html文件
                         FileCopyUtils.copy(htmlContent.getBytes(), localFile);
                         sourceFileList.add(localFile);
                         // 转pdf文件
-                        File file = SystemConstant.getFileTempDirVar(cardPdfPath, null);
+                        File file = new File(cardPdfPath);
+                        if (!file.exists()) {
+                            file.getParentFile().mkdirs();
+                            file.createNewFile();
+                        }
                         HtmlToPdfUtil.convert(cardHtmlPath, cardPdfPath, PageSizeEnum.A3);
                         sourceFileList.add(file);
                     }

+ 10 - 5
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/AttachmentCommonServiceImpl.java

@@ -11,6 +11,7 @@ import com.qmth.teachcloud.common.service.AttachmentCommonService;
 import com.qmth.teachcloud.common.util.ConvertUtil;
 import com.qmth.teachcloud.common.util.FileStoreUtil;
 import com.qmth.teachcloud.common.util.Zip4jUtil;
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -58,20 +59,24 @@ public class AttachmentCommonServiceImpl implements AttachmentCommonService {
                 fileName = SystemConstant.getNanoId() + basicAttachment.getType();
             }
 
+            File localPath = new File(rootPath, fileName);
             // oss存储
             if (type.equals(SystemConstant.OSS)) {
-                File localPath = new File(rootPath, fileName);
                 try {
                     return fileStoreUtil.ossDownload(filePath, localPath.getPath(), uploadType.getFssType());
                 } catch (IOException e) {
                     throw ExceptionResultEnum.ERROR.exception("从OSS上下载文件失败");
                 }
             } else {
-                File file = new File(filePath);
-                if (!file.exists()) {
-                    throw ExceptionResultEnum.ERROR.exception("本地文件不存在");
+                File file = null;
+                String pathNew = SystemConstant.getLocalFilePath(filePath);
+                if (dictionaryConfig.fssPrivateDomain().getConfig().startsWith(SystemConstant.START_PARENT) || dictionaryConfig.fssPublicDomain().getConfig().startsWith(SystemConstant.START_PARENT)) {
+                    file = new File(dictionaryConfig.fssPrivateDomain().getConfig(), filePath);
+                } else {
+                    file = new File(pathNew);
                 }
-                return file;
+                FileUtils.copyFile(file, localPath);
+                return localPath;
             }
         } catch (Exception e) {
             log.error(SystemConstant.LOG_ERROR, e);

+ 13 - 4
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/TeachcloudCommonServiceImpl.java

@@ -549,9 +549,12 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
                 if (type.equals(SystemConstant.OSS)) {
                     fis = fileStoreUtil.ossDownloadIs(filePath, uploadType.getFssType());
                 } else {
-                    File file = new File(filePath);
-                    if (!file.exists()) {
-                        throw ExceptionResultEnum.ERROR.exception("附件文件不存在");
+                    path = SystemConstant.getLocalFilePath(filePath);
+                    File file = null;
+                    if (dictionaryConfig.fssPrivateDomain().getConfig().startsWith(SystemConstant.START_PARENT) || dictionaryConfig.fssPublicDomain().getConfig().startsWith(SystemConstant.START_PARENT)) {
+                        file = new File(dictionaryConfig.fssPublicDomain().getConfig(), filePath);
+                    } else {
+                        file = new File(path);
                     }
                     fis = new FileInputStream(file);
                 }
@@ -592,7 +595,13 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
             fileTempList.add(fileTemp);
             file = fileStoreUtil.ossDownload(filePath, fileTemp, uploadType.getFssType());
         } else {
-            file = new File(filePath);
+            String pathNew = SystemConstant.getLocalFilePath(filePath);
+            File sourceFile = null;
+            if (dictionaryConfig.fssPrivateDomain().getConfig().startsWith(SystemConstant.START_PARENT) || dictionaryConfig.fssPublicDomain().getConfig().startsWith(SystemConstant.START_PARENT)) {
+                file = new File(dictionaryConfig.fssPrivateDomain().getConfig(), filePath);
+            } else {
+                file = new File(pathNew);
+            }
         }
         return file;
     }