重构代码 rename 和 若依 原始 类名称相同
This commit is contained in:
parent
7a5df92dfb
commit
553415d9cd
|
|
@ -10,11 +10,11 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件服务
|
* 文件服务
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@EnableConfigurationProperties(value = {
|
@EnableConfigurationProperties(value = {
|
||||||
LocalFileConfig.class,
|
ResourcesConfig.class,
|
||||||
FtpConfig.class,
|
FtpConfig.class,
|
||||||
FastDfsConfig.class,
|
FastDfsConfig.class,
|
||||||
AliyunOssConfig.class,
|
AliyunOssConfig.class,
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package com.ruoyi.file.config;
|
||||||
|
|
||||||
import com.github.tobato.fastdfs.FdfsClientConstants;
|
import com.github.tobato.fastdfs.FdfsClientConstants;
|
||||||
import com.github.tobato.fastdfs.domain.conn.PooledConnectionFactory;
|
import com.github.tobato.fastdfs.domain.conn.PooledConnectionFactory;
|
||||||
import com.ruoyi.file.service.FastSysFileServiceImpl;
|
import com.ruoyi.file.service.FastDfsSysFileServiceImpl;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
@ -10,7 +10,7 @@ import org.springframework.context.annotation.Configuration;
|
||||||
/**
|
/**
|
||||||
* 阿里 fastdfs 配置
|
* 阿里 fastdfs 配置
|
||||||
* @author dazer
|
* @author dazer
|
||||||
* @see FastSysFileServiceImpl
|
* @see FastDfsSysFileServiceImpl
|
||||||
* FastDFS配置 其他参数见:{@link PooledConnectionFactory}
|
* FastDFS配置 其他参数见:{@link PooledConnectionFactory}
|
||||||
*
|
*
|
||||||
* 使用: Docker部署FastDFS(附示例代码) https://www.cnblogs.com/cao-lei/p/13470695.html
|
* 使用: Docker部署FastDFS(附示例代码) https://www.cnblogs.com/cao-lei/p/13470695.html
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package com.ruoyi.file.config;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import com.ruoyi.file.service.LocalFileServiceImpl;
|
import com.ruoyi.file.service.LocalSysFileServiceImpl;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
@ -12,15 +12,16 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
/**
|
/**
|
||||||
* 本地文件配置
|
* 本地文件配置
|
||||||
* 通用映射配置
|
* 通用映射配置
|
||||||
|
* local file config = ResourcesConfig
|
||||||
|
*
|
||||||
|
* @see LocalSysFileServiceImpl
|
||||||
*
|
*
|
||||||
* @see LocalFileServiceImpl
|
|
||||||
*
|
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@RefreshScope
|
@RefreshScope
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConfigurationProperties(prefix = LocalFileConfig.PREFIX)
|
@ConfigurationProperties(prefix = ResourcesConfig.PREFIX)
|
||||||
public class LocalFileConfig implements WebMvcConfigurer
|
public class ResourcesConfig implements WebMvcConfigurer
|
||||||
{
|
{
|
||||||
public static final String PREFIX = "file";
|
public static final String PREFIX = "file";
|
||||||
/**
|
/**
|
||||||
|
|
@ -78,4 +79,4 @@ public class LocalFileConfig implements WebMvcConfigurer
|
||||||
public void setPath(String path) {
|
public void setPath(String path) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -22,9 +22,9 @@ import com.github.tobato.fastdfs.service.FastFileStorageClient;
|
||||||
*/
|
*/
|
||||||
//@Primary
|
//@Primary
|
||||||
@Service()
|
@Service()
|
||||||
public class FastSysFileServiceImpl implements ISysFileService
|
public class FastDfsSysFileServiceImpl implements ISysFileService
|
||||||
{
|
{
|
||||||
private final Logger logger = LoggerFactory.getLogger(FastSysFileServiceImpl.class);
|
private final Logger logger = LoggerFactory.getLogger(FastDfsSysFileServiceImpl.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private FastFileStorageClient storageClient;
|
private FastFileStorageClient storageClient;
|
||||||
|
|
@ -2,7 +2,7 @@ package com.ruoyi.file.service;
|
||||||
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import com.ruoyi.common.core.exception.CustomException;
|
import com.ruoyi.common.core.exception.CustomException;
|
||||||
import com.ruoyi.file.config.LocalFileConfig;
|
import com.ruoyi.file.config.ResourcesConfig;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
@ -16,12 +16,12 @@ import java.io.File;
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@Service()
|
@Service()
|
||||||
public class LocalFileServiceImpl implements ISysFileService
|
public class LocalSysFileServiceImpl implements ISysFileService
|
||||||
{
|
{
|
||||||
private final LocalFileConfig localFileConfig;
|
private final ResourcesConfig resourcesConfig;
|
||||||
|
|
||||||
public LocalFileServiceImpl(LocalFileConfig localFileConfig) {
|
public LocalSysFileServiceImpl(ResourcesConfig resourcesConfig) {
|
||||||
this.localFileConfig = localFileConfig;
|
this.resourcesConfig = resourcesConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -39,9 +39,9 @@ public class LocalFileServiceImpl implements ISysFileService
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String uploadFile(MultipartFile file, String modules) throws Exception {
|
public String uploadFile(MultipartFile file, String modules) throws Exception {
|
||||||
String localFilePath = localFileConfig.getPath();
|
String localFilePath = resourcesConfig.getPath();
|
||||||
String domain = localFileConfig.getDomain();
|
String domain = resourcesConfig.getDomain();
|
||||||
String localFilePrefix = localFileConfig.getPrefix();
|
String localFilePrefix = resourcesConfig.getPrefix();
|
||||||
if (StringUtils.isBlank(localFilePath) ||
|
if (StringUtils.isBlank(localFilePath) ||
|
||||||
StringUtils.isBlank(localFilePath) ||
|
StringUtils.isBlank(localFilePath) ||
|
||||||
StringUtils.isBlank(localFilePath) ) {
|
StringUtils.isBlank(localFilePath) ) {
|
||||||
|
|
@ -58,7 +58,7 @@ public class LocalFileServiceImpl implements ISysFileService
|
||||||
throw new CustomException("fileUrl不能为空!");
|
throw new CustomException("fileUrl不能为空!");
|
||||||
}
|
}
|
||||||
String key = this.getStorePath(fileUrl);
|
String key = this.getStorePath(fileUrl);
|
||||||
String localFilePath = localFileConfig.getPath();
|
String localFilePath = resourcesConfig.getPath();
|
||||||
|
|
||||||
String filePath = localFilePath + "/" + key;
|
String filePath = localFilePath + "/" + key;
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
|
|
@ -74,7 +74,7 @@ public class LocalFileServiceImpl implements ISysFileService
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String objectsCapacityStr() {
|
public String objectsCapacityStr() {
|
||||||
String localFilePath = localFileConfig.getPath();
|
String localFilePath = resourcesConfig.getPath();
|
||||||
File file = new File(localFilePath);
|
File file = new File(localFilePath);
|
||||||
long total = file.getTotalSpace();
|
long total = file.getTotalSpace();
|
||||||
long free = file.getFreeSpace();
|
long free = file.getFreeSpace();
|
||||||
|
|
@ -96,14 +96,14 @@ public class LocalFileServiceImpl implements ISysFileService
|
||||||
*/
|
*/
|
||||||
private String getStorePath(String filePath) {
|
private String getStorePath(String filePath) {
|
||||||
// 使用方式1
|
// 使用方式1
|
||||||
String domain = localFileConfig.getDomain();
|
String domain = resourcesConfig.getDomain();
|
||||||
String localFilePrefix = localFileConfig.getPrefix();
|
String localFilePrefix = resourcesConfig.getPrefix();
|
||||||
String publicPath1 = domain + localFilePrefix;
|
String publicPath1 = domain + localFilePrefix;
|
||||||
String key = filePath.replace(publicPath1, "");
|
String key = filePath.replace(publicPath1, "");
|
||||||
|
|
||||||
if (key.equals(filePath)) {
|
if (key.equals(filePath)) {
|
||||||
// 使用方式2
|
// 使用方式2
|
||||||
String group = localFileConfig.getPrefix();
|
String group = resourcesConfig.getPrefix();
|
||||||
// 获取group起始位置
|
// 获取group起始位置
|
||||||
int pathStartPos = filePath.indexOf(group) + group.length() + 1;
|
int pathStartPos = filePath.indexOf(group) + group.length() + 1;
|
||||||
key = filePath.substring(pathStartPos, filePath.length());
|
key = filePath.substring(pathStartPos, filePath.length());
|
||||||
Loading…
Reference in New Issue