Raod 3 년 전
부모
커밋
9fb7321fdd

+ 1 - 1
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 {

+ 1 - 12
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<GaeaFileParam, GaeaFile> {
 
-    /**
-     * 文件上传
-     *
-     * @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<GaeaFileParam, GaeaFile
      * 文件上传
      *
      * @param file 二选一
-     * @param customFileName 自定义文件名
      * @return
      */
-    GaeaFile upload(File file, String customFileName);
+    GaeaFile upload(File file);
     /**
      * 根据fileId显示图片或者下载文件
      *

+ 10 - 22
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/file/service/impl/GaeaFileServiceImpl.java

@@ -57,10 +57,14 @@ public class GaeaFileServiceImpl implements GaeaFileService {
         return gaeaFileMapper;
     }
 
-
+    /**
+     * 文件上传
+     *
+     * @param multipartFile 文件
+     * @return
+     */
     @Override
-    @Transactional(rollbackFor = Exception.class)
-    public GaeaFile upload(MultipartFile multipartFile, File file, String customFileName) {
+    public GaeaFile upload(MultipartFile multipartFile) {
         String originalFilename =  multipartFile.getOriginalFilename();
 
         if (StringUtils.isBlank(originalFilename)) {
@@ -69,12 +73,8 @@ public class GaeaFileServiceImpl implements GaeaFileService {
         // 文件后缀 .png
         String suffixName = originalFilename.substring(originalFilename.lastIndexOf("."));
         // 生成文件唯一性标识
-        String fileId;
-        if (StringUtils.isBlank(customFileName)) {
-            fileId = UUID.randomUUID().toString();
-        } else {
-            fileId = customFileName;
-        }
+        String fileId = UUID.randomUUID().toString();
+
         // 生成在oss中存储的文件名 402b6193e70e40a9bf5b73a78ea1e8ab.png
         String fileObjectName = fileId + suffixName;
         // 生成链接通过fileId http访问路径 http://10.108.3.121:9089/meta/file/download/402b6193e70e40a9bf5b73a78ea1e8ab
@@ -117,26 +117,14 @@ public class GaeaFileServiceImpl implements GaeaFileService {
         return multipartFile;
     }
 
-    /**
-     * 文件上传
-     *
-     * @param multipartFile 文件
-     * @return
-     */
-    @Override
-    public GaeaFile upload(MultipartFile multipartFile) {
-        return upload(multipartFile, null, null);
-    }
-
     /**
      * 文件上传
      *
      * @param file           文件
-     * @param customFileName 自定义文件名
      * @return
      */
     @Override
-    public GaeaFile upload(File file, String customFileName) {
+    public GaeaFile upload(File file) {
         return upload(getMultipartFile(file));
     }
 

+ 34 - 25
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/service/impl/ReportExcelServiceImpl.java

@@ -7,6 +7,7 @@ import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.anji.plus.gaea.constant.BaseOperationEnum;
 import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
 import com.anji.plus.gaea.exception.BusinessException;
+import com.anji.plus.gaea.exception.BusinessExceptionBuilder;
 import com.anji.plus.gaea.utils.GaeaAssert;
 import com.anji.plus.gaea.utils.GaeaBeanUtils;
 import com.anjiplus.template.gaea.business.code.ResponseCode;
@@ -14,8 +15,7 @@ import com.anjiplus.template.gaea.business.enums.ExportTypeEnum;
 import com.anjiplus.template.gaea.business.modules.dataset.controller.dto.DataSetDto;
 import com.anjiplus.template.gaea.business.modules.dataset.controller.dto.OriginalDataDto;
 import com.anjiplus.template.gaea.business.modules.dataset.service.DataSetService;
-import com.anjiplus.template.gaea.business.modules.file.dao.GaeaFileMapper;
-import com.anjiplus.template.gaea.business.modules.file.entity.GaeaFile;
+import com.anjiplus.template.gaea.business.modules.file.service.GaeaFileService;
 import com.anjiplus.template.gaea.business.modules.report.dao.ReportMapper;
 import com.anjiplus.template.gaea.business.modules.report.dao.entity.Report;
 import com.anjiplus.template.gaea.business.modules.reportexcel.controller.dto.ReportExcelDto;
@@ -23,7 +23,6 @@ import com.anjiplus.template.gaea.business.modules.reportexcel.dao.ReportExcelMa
 import com.anjiplus.template.gaea.business.modules.reportexcel.dao.entity.ReportExcel;
 import com.anjiplus.template.gaea.business.modules.reportexcel.service.ReportExcelService;
 import com.anjiplus.template.gaea.business.modules.reportexcel.util.CellType;
-import com.anjiplus.template.gaea.business.modules.reportexcel.util.XlsSheetUtil;
 import com.anjiplus.template.gaea.business.modules.reportexcel.util.XlsUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import org.apache.commons.lang3.StringUtils;
@@ -34,8 +33,15 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
-import java.io.*;
-import java.util.*;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * TODO
@@ -54,6 +60,9 @@ public class ReportExcelServiceImpl implements ReportExcelService {
     @Autowired
     private DataSetService dataSetService;
 
+    @Autowired
+    private GaeaFileService gaeaFileService;
+
 
     @Autowired
     private ReportMapper reportMapper;
@@ -61,11 +70,7 @@ public class ReportExcelServiceImpl implements ReportExcelService {
     @Value("${customer.file.tmp-path:.}")
     private String dictPath;
 
-    @Value("${spring.gaea.subscribes.oss.downloadPath:''}")
-    private String fileDownloadPath;
-
-    @Autowired
-    private GaeaFileMapper gaeaFileMapper;
+    private final static String ZIP_PATH = "/tmp_zip/";
 
 
     @Override
@@ -139,26 +144,30 @@ public class ReportExcelServiceImpl implements ReportExcelService {
             reportExcelDto.setJsonStr(report.getJsonStr());
             String jsonStr = analysisReportData(reportExcelDto);
             List<JSONObject> lists=(List<JSONObject> ) 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;

+ 2 - 0
report-core/src/main/resources/bootstrap-dev.yml

@@ -16,3 +16,5 @@ spring:
           path: D:\\aaa\\
 
 
+
+

+ 3 - 0
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: