|
@@ -5,9 +5,12 @@ import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.core.util.URLUtil;
|
|
import cn.hutool.core.util.URLUtil;
|
|
|
|
|
+import cn.tr.core.exception.ServiceException;
|
|
|
|
|
+import cn.tr.core.exception.TRExcCode;
|
|
|
import cn.tr.core.utils.JsonUtils;
|
|
import cn.tr.core.utils.JsonUtils;
|
|
|
import cn.tr.module.api.sys.storage.StoragePojo;
|
|
import cn.tr.module.api.sys.storage.StoragePojo;
|
|
|
import cn.tr.module.sys.storage.dto.SysStorageConfigDTO;
|
|
import cn.tr.module.sys.storage.dto.SysStorageConfigDTO;
|
|
@@ -67,10 +70,9 @@ public class StorageFileServiceImpl implements IStorageFileService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void refreshConfig() {
|
|
|
|
|
- SysStorageConfigQueryDTO query = new SysStorageConfigQueryDTO();
|
|
|
|
|
- List<SysStorageConfigDTO> list = storageConfigService.selectSysStorageConfigList(query);
|
|
|
|
|
- for (SysStorageConfigDTO storageConfig : list) {
|
|
|
|
|
|
|
+ public void refreshConfig(String configId) {
|
|
|
|
|
+ SysStorageConfigDTO storageConfig = storageConfigService.selectSysStorageConfigById(configId);
|
|
|
|
|
+ if(ObjectUtil.isNotNull(storageConfig)){
|
|
|
fileClientFactory.createOrUpdateFileClient(storageConfig.getId(), storageConfig.getType(),parseClientConfig(storageConfig.getType(), storageConfig.getConfig()));
|
|
fileClientFactory.createOrUpdateFileClient(storageConfig.getId(), storageConfig.getType(),parseClientConfig(storageConfig.getType(), storageConfig.getConfig()));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -81,7 +83,7 @@ public class StorageFileServiceImpl implements IStorageFileService {
|
|
|
if(StrUtil.isEmpty(configId)){
|
|
if(StrUtil.isEmpty(configId)){
|
|
|
configId=defaultConfig.getId();
|
|
configId=defaultConfig.getId();
|
|
|
}
|
|
}
|
|
|
- FileClient fileClient = fileClientFactory.getFileClient(configId);
|
|
|
|
|
|
|
+ FileClient fileClient = getClient(configId);
|
|
|
String bizName = createBizName(filename);
|
|
String bizName = createBizName(filename);
|
|
|
String suffix = FileUtil.extName(filename);
|
|
String suffix = FileUtil.extName(filename);
|
|
|
fileClient.upload(content,bizName);
|
|
fileClient.upload(content,bizName);
|
|
@@ -111,7 +113,7 @@ public class StorageFileServiceImpl implements IStorageFileService {
|
|
|
.collect(Collectors.groupingBy(SysStorageRecordDTO::getConfigId));
|
|
.collect(Collectors.groupingBy(SysStorageRecordDTO::getConfigId));
|
|
|
List<SysStorageConfigDTO> configs = storageConfigService.selectSysStorageConfigByIds(recordByConfigId.keySet());
|
|
List<SysStorageConfigDTO> configs = storageConfigService.selectSysStorageConfigByIds(recordByConfigId.keySet());
|
|
|
configs.stream()
|
|
configs.stream()
|
|
|
- .map(config->getClient(config))
|
|
|
|
|
|
|
+ .map(config->getClient(config.getId()))
|
|
|
.forEach(client->{
|
|
.forEach(client->{
|
|
|
List<SysStorageRecordDTO> storageRecords = recordByConfigId.get(client.getId());
|
|
List<SysStorageRecordDTO> storageRecords = recordByConfigId.get(client.getId());
|
|
|
for (SysStorageRecordDTO storageRecord : storageRecords) {
|
|
for (SysStorageRecordDTO storageRecord : storageRecords) {
|
|
@@ -123,16 +125,14 @@ public class StorageFileServiceImpl implements IStorageFileService {
|
|
|
@Override
|
|
@Override
|
|
|
public String obtainDownloadPath(String recordId) throws Exception {
|
|
public String obtainDownloadPath(String recordId) throws Exception {
|
|
|
SysStorageRecordDTO record = storageRecordService.selectSysStorageRecordById(recordId);
|
|
SysStorageRecordDTO record = storageRecordService.selectSysStorageRecordById(recordId);
|
|
|
- SysStorageConfigDTO config = storageConfigService.selectSysStorageConfigById(record.getConfigId());
|
|
|
|
|
- FileClient fileClient = getClient(config);
|
|
|
|
|
|
|
+ FileClient fileClient = getClient(record.getConfigId());
|
|
|
return fileClient.downUrl(record.getBizName());
|
|
return fileClient.downUrl(record.getBizName());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public byte[] obtainContent(String recordId) throws Exception {
|
|
public byte[] obtainContent(String recordId) throws Exception {
|
|
|
SysStorageRecordDTO record = storageRecordService.selectSysStorageRecordById(recordId);
|
|
SysStorageRecordDTO record = storageRecordService.selectSysStorageRecordById(recordId);
|
|
|
- SysStorageConfigDTO config = storageConfigService.selectSysStorageConfigById(record.getConfigId());
|
|
|
|
|
- FileClient fileClient = getClient(config);
|
|
|
|
|
|
|
+ FileClient fileClient = getClient(record.getConfigId());
|
|
|
return fileClient.getContent(record.getBizName()).getContent();
|
|
return fileClient.getContent(record.getBizName()).getContent();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -153,8 +153,16 @@ public class StorageFileServiceImpl implements IStorageFileService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- private FileClient getClient(SysStorageConfigDTO storageConfig){
|
|
|
|
|
- return fileClientFactory.getFileClient(storageConfig.getId());
|
|
|
|
|
|
|
+ private FileClient getClient(String id){
|
|
|
|
|
+ FileClient fileClient = fileClientFactory.getFileClient(id);
|
|
|
|
|
+ if(fileClient==null){
|
|
|
|
|
+ SysStorageConfigDTO storageConfig = storageConfigService.selectSysStorageConfigById(id);
|
|
|
|
|
+ if(ObjectUtil.isNull(storageConfig)){
|
|
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"存储配置不存在,请刷新重试");
|
|
|
|
|
+ }
|
|
|
|
|
+ fileClient=fileClientFactory.createOrUpdateFileClient(storageConfig.getId(), storageConfig.getType(),parseClientConfig(storageConfig.getType(), storageConfig.getConfig()));
|
|
|
|
|
+ }
|
|
|
|
|
+ return fileClient;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private FileClientConfig parseClientConfig(String storage, Map<String, Object> config) {
|
|
private FileClientConfig parseClientConfig(String storage, Map<String, Object> config) {
|