Skip to content

Commit

Permalink
Merge pull request young-datafan-ooooo1#62 from EchoXiaoLang/feature/…
Browse files Browse the repository at this point in the history
…minIo-config

[ADD]文件管理实现minIo
  • Loading branch information
EchoXiaoLang authored Apr 8, 2022
2 parents ffa2699 + ff881b1 commit 2ce47ab
Show file tree
Hide file tree
Showing 17 changed files with 648 additions and 158 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.youngdatafan.dataintegration.file.management.dto;

import java.util.Date;
import lombok.Data;

/**
* 文件信息.
*
* @author songxiaolang
* @since 2022-03-30 15:26
*/
@Data
public class FileSummary {
/**
* 最后修改时间.
*/
private Date lastModified;

/**
* 文件大小.
*/
private long size;

/**
* 文件key.
*/
private String key;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
<poi.version>3.17</poi.version>
<mysql.version>5.1.47</mysql.version>
<swagger2.version>3.0.0</swagger2.version>
<minio.version>8.3.7</minio.version>
<okhttp.version>4.9.0</okhttp.version>
</properties>
<dependencies>

Expand Down Expand Up @@ -213,6 +215,19 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>${minio.version}</version>
</dependency>
<!-- minio依赖于okhttp3,所以pom文件还需要引入一下okhttp3 -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${okhttp.version}</version>
</dependency>


</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class FileServerProperties {
* 采用的服务器.
*/
@ApiModelProperty("采用的服务器")
private FileServerType useServer;
private String useServer;

/**
* ftp服务器相关属性.
Expand All @@ -36,4 +36,10 @@ public class FileServerProperties {
*/
@ApiModelProperty("s3服务器")
private S3Properties s3;

/**
* s3服务器相关属性.
*/
@ApiModelProperty("s3服务器")
private MinIoProperties minIos3;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.youngdatafan.dataintegration.file.management.config;

import io.swagger.annotations.ApiModel;
import lombok.Data;

/**
* MinIoProperties.
*
* @author songxiaolang
* @since 2022-03-29 14:47
*/
@Data
@ApiModel("MinIo文件服务器")
public class MinIoProperties {

/**
* minio地址+端口号.
*/
private String url;

/**
* minio用户名.
*/
private String accessKey;

/**
* minio密码.
*/
private String secretKey;

/**
* 文件桶的名称.
*/
private String bucketName;

/**
* 文件根路径名称.
*/
private String rootPath;

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.youngdatafan.dataintegration.file.management.service.DpPortalFileManagerService;
import com.youngdatafan.dataintegration.file.management.service.FileSystemManagerService;
import com.youngdatafan.dataintegration.file.management.vo.FileSheetVO;
import java.io.InputStream;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
Expand Down Expand Up @@ -58,20 +59,19 @@ public Result<List<String>, Object> getSheetList(String roleCode, String userId,
if (!dpPortalFileManager.getFileType().equals("xls") && !dpPortalFileManager.getFileType().equals("xlsx")) {
return Result.fail(StatusCode.CODE_10010, null, "不是excel文件");
}

S3Object fileObject = fileSystemManagerService.getFileObject(dpPortalFileManager.getFilePath());
InputStream fileObject = fileSystemManagerService.getFileObject(dpPortalFileManager.getFilePath());
Workbook workbook = null;

try {
List<String> sheetList = new ArrayList<>();
if (fileObject == null || fileObject.getObjectContent() == null) {
if (fileObject == null ) {
return Result.fail(StatusCode.CODE_10010, null, "文件不存在");
}

if (dpPortalFileManager.getFileType().equalsIgnoreCase("xls")) {
workbook = new HSSFWorkbook(fileObject.getObjectContent());
workbook = new HSSFWorkbook(fileObject);
} else if (dpPortalFileManager.getFileType().equalsIgnoreCase("xlsx")) {
workbook = new XSSFWorkbook(fileObject.getObjectContent());
workbook = new XSSFWorkbook(fileObject);
}

int sheetCnt = workbook.getNumberOfSheets();
Expand Down Expand Up @@ -109,20 +109,20 @@ public Result<List<FieldInfoDTO>, Object> fileHeader(String roleCode, String use
return Result.fail(StatusCode.CODE_10010, null, "文件未找到");
}

S3Object fileObject = fileSystemManagerService.getFileObject(dpPortalFileManager.getFilePath());
InputStream fileObject = fileSystemManagerService.getFileObject(dpPortalFileManager.getFilePath());
Workbook workbook = null;

try {
List<FieldInfoDTO> fieldInfoDTOS = new ArrayList<>();
if (fileObject == null || fileObject.getObjectContent() == null) {
if (fileObject == null ) {
return Result.fail(StatusCode.CODE_10010, null, "文件不存在");
}

if (dpPortalFileManager.getFileType().equalsIgnoreCase("xls") || dpPortalFileManager.getFileType().equalsIgnoreCase("xlsx")) {
if (dpPortalFileManager.getFileType().equalsIgnoreCase("xls")) {
workbook = new HSSFWorkbook(fileObject.getObjectContent());
workbook = new HSSFWorkbook(fileObject);
} else if (dpPortalFileManager.getFileType().equalsIgnoreCase("xlsx")) {
workbook = new XSSFWorkbook(fileObject.getObjectContent());
workbook = new XSSFWorkbook(fileObject);
}
Sheet sheet = workbook.getSheet(sheetName);
Row row = sheet.getRow(0);
Expand Down Expand Up @@ -178,7 +178,7 @@ public Result<List<FieldInfoDTO>, Object> fileHeader(String roleCode, String use

}
} else {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileObject.getObjectContent()));
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileObject));
String firstLine = bufferedReader.readLine();
String[] fields = firstLine.split(split);
for (int i = 0; i < fields.length; i++) {
Expand Down Expand Up @@ -228,18 +228,18 @@ public Result<Set<String>, Object> getMoreSheetList(String roleCode, String user
return Result.fail(StatusCode.CODE_10010, null, "不是excel文件");
}

S3Object fileObject = fileSystemManagerService.getFileObject(dpPortalFileManager.getFilePath());
InputStream fileObject = fileSystemManagerService.getFileObject(dpPortalFileManager.getFilePath());
Workbook workbook = null;

try {
if (fileObject == null || fileObject.getObjectContent() == null) {
if (fileObject == null ) {
return Result.fail(StatusCode.CODE_10010, null, "文件不存在");
}

if (dpPortalFileManager.getFileType().equalsIgnoreCase("xls")) {
workbook = new HSSFWorkbook(fileObject.getObjectContent());
workbook = new HSSFWorkbook(fileObject);
} else if (dpPortalFileManager.getFileType().equalsIgnoreCase("xlsx")) {
workbook = new XSSFWorkbook(fileObject.getObjectContent());
workbook = new XSSFWorkbook(fileObject);
}

int sheetCnt = workbook.getNumberOfSheets();
Expand Down
Loading

0 comments on commit 2ce47ab

Please sign in to comment.