1、project新增生成自动化报告接口
This commit is contained in:
@@ -405,6 +405,17 @@ public class DataFileController implements IDataFeignClient {
|
||||
return IDataFileService.batchAddFileInfo(req);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件到本地临时目录
|
||||
*
|
||||
* @param fileId
|
||||
* @param path
|
||||
*/
|
||||
@PostMapping("/downloadFileToLocal")
|
||||
@Operation(summary = "下载文件到本地临时目录", description = "下载文件到本地临时目录")
|
||||
public void downloadFileToLocal(@RequestParam(value = "fileId") @Validated Long fileId, @RequestParam(value = "path") @Validated String path) {
|
||||
IDataFileService.downloadFileToLocal(fileId,path);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -320,4 +320,9 @@ public interface IDataFileService {
|
||||
|
||||
SdmResponse<List<BatchAddFileInfoResp>> batchAddFileInfo(UploadFilesReq req);
|
||||
|
||||
/**
|
||||
* 下载文件到本地临时目录
|
||||
*/
|
||||
void downloadFileToLocal(Long fileId,String path);
|
||||
|
||||
}
|
||||
@@ -59,10 +59,7 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -2205,4 +2202,30 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
}, nonSensitiveTaskPool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadFileToLocal(Long fileId,String path) {
|
||||
try {
|
||||
FileMetadataInfo fileMetadataInfo = fileMetadataInfoService.lambdaQuery().eq(FileMetadataInfo::getId, fileId).one();
|
||||
if (ObjectUtils.isEmpty(fileMetadataInfo)) {
|
||||
return;
|
||||
}
|
||||
String fileObjectKey = fileMetadataInfo.getObjectKey();
|
||||
boolean hasDownloadPermission = fileUserPermissionService.hasFilePermission(fileMetadataInfo.getId(), ThreadLocalContext.getUserId(), FilePermissionEnum.DOWNLOAD);
|
||||
if (!hasDownloadPermission) {
|
||||
return;
|
||||
}
|
||||
// 从MinIO下载文件
|
||||
byte[] fileData = minioService.downloadFile(fileObjectKey);
|
||||
// 写入响应流
|
||||
File folder = new File(path);
|
||||
folder.mkdir();
|
||||
FileOutputStream outputStream = new FileOutputStream(path + File.separator + fileMetadataInfo.getOriginalName());
|
||||
outputStream.write(fileData);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
} catch (Exception e) {
|
||||
log.error("下载文件失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1548,4 +1548,35 @@ public class SystemFileIDataFileServiceImpl implements IDataFileService {
|
||||
}
|
||||
return SdmResponse.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadFileToLocal(Long fileId,String downloadPath) {
|
||||
if (StringUtils.isNotBlank(downloadPath) && downloadPath.contains("..")) {
|
||||
log.error(downloadPath + "非法文件路径!");
|
||||
return;
|
||||
}
|
||||
String path = Tools.getRootPath(rootPath, String.valueOf(ThreadLocalContext.getTenantId())) + File.separator + downloadPath;
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
log.error("文件不存在" + path);
|
||||
}
|
||||
try {
|
||||
// 以流的形式下载文件
|
||||
InputStream fis = new BufferedInputStream(new FileInputStream(file));
|
||||
byte[] buffer = new byte[fis.available()];
|
||||
// 读取fis的数据到buffer数组里
|
||||
fis.read(buffer);
|
||||
fis.close();
|
||||
byte[] fileBuffer = buffer;
|
||||
OutputStream toClient = new BufferedOutputStream(new FileOutputStream(path));
|
||||
toClient.write(fileBuffer);
|
||||
toClient.flush();
|
||||
toClient.close();
|
||||
} catch (IOException e) {
|
||||
log.error("下载文件失败:" + e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user