|
@@ -1,6 +1,6 @@
|
|
package com.qmth.sop.common.util;
|
|
package com.qmth.sop.common.util;
|
|
|
|
|
|
-import com.qmth.boot.core.fss.service.FileService;
|
|
|
|
|
|
+import com.qmth.boot.core.fss.service.FileStoreService;
|
|
import com.qmth.boot.core.fss.store.FileStore;
|
|
import com.qmth.boot.core.fss.store.FileStore;
|
|
import com.qmth.sop.common.config.DictionaryConfig;
|
|
import com.qmth.sop.common.config.DictionaryConfig;
|
|
import com.qmth.sop.common.contant.SystemConstant;
|
|
import com.qmth.sop.common.contant.SystemConstant;
|
|
@@ -25,10 +25,11 @@ import java.util.Objects;
|
|
*/
|
|
*/
|
|
@Component
|
|
@Component
|
|
public class FileStoreUtil {
|
|
public class FileStoreUtil {
|
|
|
|
+
|
|
private final static Logger log = LoggerFactory.getLogger(FileStoreUtil.class);
|
|
private final static Logger log = LoggerFactory.getLogger(FileStoreUtil.class);
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
- private FileService fileService;
|
|
|
|
|
|
+ private FileStoreService fileService;
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private DictionaryConfig dictionaryConfig;
|
|
private DictionaryConfig dictionaryConfig;
|
|
@@ -38,19 +39,27 @@ public class FileStoreUtil {
|
|
}
|
|
}
|
|
|
|
|
|
public String uploadFileEnumConfig(UploadFileEnum type) {
|
|
public String uploadFileEnumConfig(UploadFileEnum type) {
|
|
- return type == UploadFileEnum.FILE ? dictionaryConfig.fssPublicDomain().getConfig() : dictionaryConfig.fssPrivateDomain().getConfig();
|
|
|
|
|
|
+ return type == UploadFileEnum.FILE ?
|
|
|
|
+ dictionaryConfig.fssPublicDomain().getConfig() :
|
|
|
|
+ dictionaryConfig.fssPrivateDomain().getConfig();
|
|
}
|
|
}
|
|
|
|
|
|
public boolean privateIsOss(UploadFileEnum type) {
|
|
public boolean privateIsOss(UploadFileEnum type) {
|
|
- return Objects.nonNull(dictionaryConfig.fssPrivateDomain()) ? dictionaryConfig.fssPrivateDomain().getConfig().trim().startsWith("oss:") : false;
|
|
|
|
|
|
+ return Objects.nonNull(dictionaryConfig.fssPrivateDomain()) ?
|
|
|
|
+ dictionaryConfig.fssPrivateDomain().getConfig().trim().startsWith("oss:") :
|
|
|
|
+ false;
|
|
}
|
|
}
|
|
|
|
|
|
public boolean publicIsOss() {
|
|
public boolean publicIsOss() {
|
|
- return Objects.nonNull(dictionaryConfig.fssPublicDomain()) ? dictionaryConfig.fssPublicDomain().getConfig().trim().startsWith("oss:") : false;
|
|
|
|
|
|
+ return Objects.nonNull(dictionaryConfig.fssPublicDomain()) ?
|
|
|
|
+ dictionaryConfig.fssPublicDomain().getConfig().trim().startsWith("oss:") :
|
|
|
|
+ false;
|
|
}
|
|
}
|
|
|
|
|
|
public boolean privateIsOss() {
|
|
public boolean privateIsOss() {
|
|
- return Objects.nonNull(dictionaryConfig.fssPrivateDomain()) ? dictionaryConfig.fssPrivateDomain().getConfig().trim().startsWith("oss:") : false;
|
|
|
|
|
|
+ return Objects.nonNull(dictionaryConfig.fssPrivateDomain()) ?
|
|
|
|
+ dictionaryConfig.fssPrivateDomain().getConfig().trim().startsWith("oss:") :
|
|
|
|
+ false;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -88,7 +97,8 @@ public class FileStoreUtil {
|
|
*/
|
|
*/
|
|
public void ossUpload(String dirName, String content, String type) throws Exception {
|
|
public void ossUpload(String dirName, String content, String type) throws Exception {
|
|
log.info("ossUpload is come in");
|
|
log.info("ossUpload is come in");
|
|
- fileService.getFileStore(type).write(dirName, new ByteArrayInputStream(content.getBytes()), DigestUtils.md5Hex(new ByteArrayInputStream(content.getBytes())));
|
|
|
|
|
|
+ fileService.getFileStore(type).write(dirName, new ByteArrayInputStream(content.getBytes()),
|
|
|
|
+ DigestUtils.md5Hex(new ByteArrayInputStream(content.getBytes())));
|
|
log.info("dirName:{}", dirName);
|
|
log.info("dirName:{}", dirName);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -172,7 +182,7 @@ public class FileStoreUtil {
|
|
} else if ("private".equals(type)) {
|
|
} else if ("private".equals(type)) {
|
|
if (this.privateIsOss()) {
|
|
if (this.privateIsOss()) {
|
|
FileStore fileStore = fileService.getFileStore(type);
|
|
FileStore fileStore = fileService.getFileStore(type);
|
|
- return fileStore.getPresignedUrl(objectPath, Duration.ofMinutes(5L));
|
|
|
|
|
|
+ return fileStore.getServerUrl(objectPath, Duration.ofMinutes(5L));
|
|
} else {
|
|
} else {
|
|
return dictionaryConfig.fssPrivateDomain().getServer() + objectPath;
|
|
return dictionaryConfig.fssPrivateDomain().getServer() + objectPath;
|
|
}
|
|
}
|
|
@@ -197,9 +207,9 @@ public class FileStoreUtil {
|
|
if (this.privateIsOss()) {
|
|
if (this.privateIsOss()) {
|
|
FileStore fileStore = fileService.getFileStore(type);
|
|
FileStore fileStore = fileService.getFileStore(type);
|
|
if (isExpire) {
|
|
if (isExpire) {
|
|
- return fileStore.getPresignedUrl(objectPath, Duration.ofMinutes(5L));
|
|
|
|
|
|
+ return fileStore.getServerUrl(objectPath, Duration.ofMinutes(5L));
|
|
} else {
|
|
} else {
|
|
- return fileStore.getPresignedUrl(objectPath, Duration.ofMinutes(300L));
|
|
|
|
|
|
+ return fileStore.getServerUrl(objectPath, Duration.ofMinutes(300L));
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
return dictionaryConfig.fssPrivateDomain().getServer() + SystemConstant.ORG_SPLIT + objectPath;
|
|
return dictionaryConfig.fssPrivateDomain().getServer() + SystemConstant.ORG_SPLIT + objectPath;
|
|
@@ -240,9 +250,9 @@ public class FileStoreUtil {
|
|
desFile.getParentFile().mkdirs(); //目标文件目录不存在的话需要创建目录
|
|
desFile.getParentFile().mkdirs(); //目标文件目录不存在的话需要创建目录
|
|
desFile.createNewFile();
|
|
desFile.createNewFile();
|
|
}
|
|
}
|
|
-// if (desFile.length() > 0) {
|
|
|
|
-// return desFile;
|
|
|
|
-// }
|
|
|
|
|
|
+ // if (desFile.length() > 0) {
|
|
|
|
+ // return desFile;
|
|
|
|
+ // }
|
|
try {
|
|
try {
|
|
FileUtils.copyInputStreamToFile(inputStream, desFile);
|
|
FileUtils.copyInputStreamToFile(inputStream, desFile);
|
|
return desFile;
|
|
return desFile;
|