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