Raod 2 years ago
parent 973cac42bb
commit 9fb7321fdd

@ -331,7 +331,7 @@ public class ReportDashboardServiceImpl implements ReportDashboardService, Initi
GaeaFile gaeaFile = gaeaFileService.selectOne(queryWrapper); GaeaFile gaeaFile = gaeaFileService.selectOne(queryWrapper);
String uploadPath; String uploadPath;
if (null == gaeaFile) { if (null == gaeaFile) {
GaeaFile upload = gaeaFileService.upload(imageFile, fileName); GaeaFile upload = gaeaFileService.upload(imageFile);
log.info("存入图片: {}", upload.getFilePath()); log.info("存入图片: {}", upload.getFilePath());
uploadPath = upload.getUrlPath(); uploadPath = upload.getUrlPath();
}else { }else {

@ -18,16 +18,6 @@ import java.io.File;
*/ */
public interface GaeaFileService extends GaeaBaseService<GaeaFileParam, GaeaFile> { 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 file
* @param customFileName
* @return * @return
*/ */
GaeaFile upload(File file, String customFileName); GaeaFile upload(File file);
/** /**
* fileId * fileId
* *

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

@ -7,6 +7,7 @@ import com.alibaba.fastjson.serializer.SerializerFeature;
import com.anji.plus.gaea.constant.BaseOperationEnum; import com.anji.plus.gaea.constant.BaseOperationEnum;
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper; import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
import com.anji.plus.gaea.exception.BusinessException; 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.GaeaAssert;
import com.anji.plus.gaea.utils.GaeaBeanUtils; import com.anji.plus.gaea.utils.GaeaBeanUtils;
import com.anjiplus.template.gaea.business.code.ResponseCode; 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.DataSetDto;
import com.anjiplus.template.gaea.business.modules.dataset.controller.dto.OriginalDataDto; 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.dataset.service.DataSetService;
import com.anjiplus.template.gaea.business.modules.file.dao.GaeaFileMapper; import com.anjiplus.template.gaea.business.modules.file.service.GaeaFileService;
import com.anjiplus.template.gaea.business.modules.file.entity.GaeaFile;
import com.anjiplus.template.gaea.business.modules.report.dao.ReportMapper; 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.report.dao.entity.Report;
import com.anjiplus.template.gaea.business.modules.reportexcel.controller.dto.ReportExcelDto; 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.dao.entity.ReportExcel;
import com.anjiplus.template.gaea.business.modules.reportexcel.service.ReportExcelService; 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.CellType;
import com.anjiplus.template.gaea.business.modules.reportexcel.util.XlsSheetUtil;
import com.anjiplus.template.gaea.business.modules.reportexcel.util.XlsUtil; import com.anjiplus.template.gaea.business.modules.reportexcel.util.XlsUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils; 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.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.*; import java.io.File;
import java.util.*; 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 * TODO
@ -54,6 +60,9 @@ public class ReportExcelServiceImpl implements ReportExcelService {
@Autowired @Autowired
private DataSetService dataSetService; private DataSetService dataSetService;
@Autowired
private GaeaFileService gaeaFileService;
@Autowired @Autowired
private ReportMapper reportMapper; private ReportMapper reportMapper;
@ -61,11 +70,7 @@ public class ReportExcelServiceImpl implements ReportExcelService {
@Value("${customer.file.tmp-path:.}") @Value("${customer.file.tmp-path:.}")
private String dictPath; private String dictPath;
@Value("${spring.gaea.subscribes.oss.downloadPath:''}") private final static String ZIP_PATH = "/tmp_zip/";
private String fileDownloadPath;
@Autowired
private GaeaFileMapper gaeaFileMapper;
@Override @Override
@ -139,26 +144,30 @@ public class ReportExcelServiceImpl implements ReportExcelService {
reportExcelDto.setJsonStr(report.getJsonStr()); reportExcelDto.setJsonStr(report.getJsonStr());
String jsonStr = analysisReportData(reportExcelDto); String jsonStr = analysisReportData(reportExcelDto);
List<JSONObject> lists=(List<JSONObject> ) JSON.parse(jsonStr); List<JSONObject> lists=(List<JSONObject> ) JSON.parse(jsonStr);
OutputStream out; OutputStream out = null;
File file = null;
try { try {
String fileId = UUID.randomUUID().toString(); String fileName = report.getReportCode();
String filePath = dictPath + File.separator + fileId + ".xlsx"; File dir = new File(dictPath + ZIP_PATH);
String urlPath = fileDownloadPath + java.io.File.separator + fileId; if (!dir.exists()){
dir.mkdirs();
GaeaFile gaeaFile = new GaeaFile(); }
gaeaFile.setFilePath(filePath); String filePath = dir.getAbsolutePath() + File.separator + fileName + ".xlsx";
gaeaFile.setFileId(fileId); file = new File(filePath);
gaeaFile.setUrlPath(urlPath); out = Files.newOutputStream(Paths.get(filePath));
gaeaFile.setFileType("xlsx");
gaeaFile.setFileInstruction(reportCode + ".xlsx");
out = new FileOutputStream(filePath);
XlsUtil.exportXlsFile(out, true, lists); XlsUtil.exportXlsFile(out, true, lists);
gaeaFileService.upload(file);
gaeaFileMapper.insert(gaeaFile);
logger.info("导出成功:{}", gaeaFile);
} catch (IOException e) { } catch (IOException e) {
logger.error("导出失败", e); logger.error("导出失败", e);
}finally {
try {
out.close();
file.delete();
} catch (IOException e) {
throw BusinessExceptionBuilder.build(ResponseCode.FILE_OPERATION_FAILED, e.getMessage());
}
} }
} }
return true; return true;

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

@ -90,6 +90,9 @@ logging:
customer: customer:
# 跳过token验证和权限验证的url清单 # 跳过token验证和权限验证的url清单
skip-authenticate-urls: /gaeaDict/all, /login, /static, /file/download/, /index.html, /favicon.ico, /reportShare/detailByCode skip-authenticate-urls: /gaeaDict/all, /login, /static, /file/download/, /index.html, /favicon.ico, /reportShare/detailByCode
file:
#导入导出临时文件夹 默认.代表当前目录,拼接/tmp_zip/目录
tmpPath: .
user: user:
##新增用户默认密码 ##新增用户默认密码
default: default:

Loading…
Cancel
Save