nacos配置文件户及数据库文件
This commit is contained in:
parent
15f6d48935
commit
b8d2c08d9e
|
|
@ -20,6 +20,11 @@ public class SysFile
|
|||
*/
|
||||
private String url;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
package com.bonus.system.api.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 返回的文件进行统一封装
|
||||
* 无论是 mongodb还是 oss、还是本地存储 还是obs等 进行统一的 数据返回和文件上传
|
||||
*/
|
||||
@Data
|
||||
public class SysFileVo {
|
||||
|
||||
private String file;
|
||||
|
||||
private String fileId;
|
||||
|
||||
private String fileName;
|
||||
|
||||
private String contentType;
|
||||
|
||||
private String suffix;
|
||||
|
||||
private long fileSize;
|
||||
|
||||
private String sourceId;
|
||||
|
||||
private String id;
|
||||
|
||||
private String fileType;
|
||||
|
||||
private String sourceType;
|
||||
|
||||
private String updaetTime;
|
||||
|
||||
private byte[] data;
|
||||
/**
|
||||
*文件路径
|
||||
*/
|
||||
private String url;
|
||||
|
||||
}
|
||||
|
|
@ -32,5 +32,29 @@ public class SystemGlobal {
|
|||
* POST 请求
|
||||
*/
|
||||
public final static String POST="POST";
|
||||
/**
|
||||
* PUT 请求
|
||||
*/
|
||||
public final static String PUT="PUT";
|
||||
|
||||
/**
|
||||
* 文件存储类型-local
|
||||
*/
|
||||
public final static String LOCAL="local";
|
||||
/**
|
||||
* 文件存储类型-oss
|
||||
*/
|
||||
public final static String OSS="oss";
|
||||
|
||||
/**
|
||||
* 文件存储类型-mongodb
|
||||
*/
|
||||
public final static String MONGODB="mongodb";
|
||||
|
||||
/**
|
||||
* 文件存储类型-obs
|
||||
*/
|
||||
public final static String OBS="obs";
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus-common</artifactId>
|
||||
<version>24.6.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>bonus-common-entity</artifactId>
|
||||
|
||||
<description>
|
||||
bonus-common-entity
|
||||
</description>
|
||||
|
||||
|
||||
|
||||
</project>
|
||||
|
|
@ -18,6 +18,7 @@
|
|||
<module>bonus-common-sensitive</module>
|
||||
<module>bonus-common-datascope</module>
|
||||
<module>bonus-common-datasource</module>
|
||||
<module>bonus-common-entity</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>bonus-common</artifactId>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
package com.bonus.file.controller;
|
||||
|
||||
import com.bonus.common.core.utils.Base64Utils;
|
||||
import com.bonus.common.core.utils.global.SystemGlobal;
|
||||
import com.bonus.file.utils.FileDownloadUtils;
|
||||
import com.bonus.system.api.domain.SysFileVo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
|
@ -23,34 +26,48 @@ import java.io.IOException;
|
|||
* @author bonus
|
||||
*/
|
||||
@RestController
|
||||
public class SysFileController
|
||||
{
|
||||
public class SysFileController {
|
||||
private static final Logger log = LoggerFactory.getLogger(SysFileController.class);
|
||||
|
||||
@Autowired
|
||||
private ISysFileService sysFileService;
|
||||
|
||||
/**
|
||||
* 存储文件
|
||||
*/
|
||||
@Value("${file.save-type}")
|
||||
public String saveType;
|
||||
/**
|
||||
* 文件上传请求
|
||||
*/
|
||||
@PostMapping("upload")
|
||||
public R<SysFile> upload(MultipartFile file)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 上传并返回访问地址
|
||||
String url = sysFileService.uploadFile(file);
|
||||
SysFile sysFile = new SysFile();
|
||||
sysFile.setName(FileUtils.getName(url));
|
||||
sysFile.setUrl(url);
|
||||
return R.ok(sysFile);
|
||||
public R<SysFileVo> upload(MultipartFile file) {
|
||||
try {
|
||||
if(saveType.equals(SystemGlobal.LOCAL)){
|
||||
SysFileVo fileVo= uploadByLocal(file);
|
||||
return R.ok(fileVo);
|
||||
}else {//默认本地存储
|
||||
SysFileVo fileVo= uploadByLocal(file);
|
||||
return R.ok(fileVo);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
catch (Exception e) {
|
||||
log.error("上传文件失败", e);
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 本地文件上传
|
||||
* @return
|
||||
*/
|
||||
public SysFileVo uploadByLocal(MultipartFile file) throws Exception {
|
||||
// 上传并返回访问地址
|
||||
String url = sysFileService.uploadFile(file);
|
||||
SysFileVo sysFile = new SysFileVo();
|
||||
sysFile.setFileName(FileUtils.getName(url));
|
||||
sysFile.setUrl(url);
|
||||
return sysFile;
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/download")
|
||||
public R<Boolean> downloadFile(String url, String destination) {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
<version>24.6.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>bonus-modules-mongodb</artifactId>
|
||||
<artifactId>bonus-mongodb</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
<version>24.6.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>bonus-modules-obs</artifactId>
|
||||
<artifactId>bonus-obs</artifactId>
|
||||
<description>
|
||||
bonus-modules-obs存储服务
|
||||
</description>
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
<module>bonus-job</module>
|
||||
<module>bonus-file</module>
|
||||
<module>bonus-oss</module>
|
||||
<module>app</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>bonus-modules</artifactId>
|
||||
|
|
|
|||
Loading…
Reference in New Issue