From 9fb7321fdd3e524b216dc90d98f3541bec1c6fd3 Mon Sep 17 00:00:00 2001 From: Raod <1130305001@qq.com> Date: Fri, 2 Sep 2022 16:20:34 +0800 Subject: [PATCH] gaea oss --- .../impl/ReportDashboardServiceImpl.java | 2 +- .../modules/file/service/GaeaFileService.java | 13 +--- .../service/impl/GaeaFileServiceImpl.java | 32 ++++------ .../service/impl/ReportExcelServiceImpl.java | 59 +++++++++++-------- .../src/main/resources/bootstrap-dev.yml | 2 + report-core/src/main/resources/bootstrap.yml | 3 + 6 files changed, 51 insertions(+), 60 deletions(-) diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dashboard/service/impl/ReportDashboardServiceImpl.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dashboard/service/impl/ReportDashboardServiceImpl.java index f6d7811b..8cf36c49 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dashboard/service/impl/ReportDashboardServiceImpl.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dashboard/service/impl/ReportDashboardServiceImpl.java @@ -331,7 +331,7 @@ public class ReportDashboardServiceImpl implements ReportDashboardService, Initi GaeaFile gaeaFile = gaeaFileService.selectOne(queryWrapper); String uploadPath; if (null == gaeaFile) { - GaeaFile upload = gaeaFileService.upload(imageFile, fileName); + GaeaFile upload = gaeaFileService.upload(imageFile); log.info("存入图片: {}", upload.getFilePath()); uploadPath = upload.getUrlPath(); }else { diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/file/service/GaeaFileService.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/file/service/GaeaFileService.java index 9cceea1e..0581399c 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/file/service/GaeaFileService.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/file/service/GaeaFileService.java @@ -18,16 +18,6 @@ import java.io.File; */ public interface GaeaFileService extends GaeaBaseService { - /** - * 文件上传 - * - * @param multipartFile 文件 - * @param file 文件 - * @param customFileName 自定义文件名,默认给null - * @return - */ - GaeaFile upload(MultipartFile multipartFile, File file, String customFileName); - /** * 文件上传 * @@ -41,10 +31,9 @@ public interface GaeaFileService extends GaeaBaseService lists=(List ) JSON.parse(jsonStr); - OutputStream out; + OutputStream out = null; + File file = null; try { - String fileId = UUID.randomUUID().toString(); - String filePath = dictPath + File.separator + fileId + ".xlsx"; - String urlPath = fileDownloadPath + java.io.File.separator + fileId; - - GaeaFile gaeaFile = new GaeaFile(); - gaeaFile.setFilePath(filePath); - gaeaFile.setFileId(fileId); - gaeaFile.setUrlPath(urlPath); - gaeaFile.setFileType("xlsx"); - gaeaFile.setFileInstruction(reportCode + ".xlsx"); - - out = new FileOutputStream(filePath); + String fileName = report.getReportCode(); + File dir = new File(dictPath + ZIP_PATH); + if (!dir.exists()){ + dir.mkdirs(); + } + String filePath = dir.getAbsolutePath() + File.separator + fileName + ".xlsx"; + file = new File(filePath); + out = Files.newOutputStream(Paths.get(filePath)); XlsUtil.exportXlsFile(out, true, lists); + gaeaFileService.upload(file); - gaeaFileMapper.insert(gaeaFile); - logger.info("导出成功:{}", gaeaFile); } catch (IOException e) { logger.error("导出失败", e); + }finally { + try { + out.close(); + file.delete(); + } catch (IOException e) { + throw BusinessExceptionBuilder.build(ResponseCode.FILE_OPERATION_FAILED, e.getMessage()); + } + } } return true; diff --git a/report-core/src/main/resources/bootstrap-dev.yml b/report-core/src/main/resources/bootstrap-dev.yml index e11aeecb..f8383dc7 100644 --- a/report-core/src/main/resources/bootstrap-dev.yml +++ b/report-core/src/main/resources/bootstrap-dev.yml @@ -16,3 +16,5 @@ spring: path: D:\\aaa\\ + + diff --git a/report-core/src/main/resources/bootstrap.yml b/report-core/src/main/resources/bootstrap.yml index 3eb10d5b..c48b776c 100644 --- a/report-core/src/main/resources/bootstrap.yml +++ b/report-core/src/main/resources/bootstrap.yml @@ -90,6 +90,9 @@ logging: customer: # 跳过token验证和权限验证的url清单 skip-authenticate-urls: /gaeaDict/all, /login, /static, /file/download/, /index.html, /favicon.ico, /reportShare/detailByCode + file: + #导入导出临时文件夹 默认.代表当前目录,拼接/tmp_zip/目录 + tmpPath: . user: ##新增用户默认密码 default: