This commit is contained in:
77
2024-05-20 12:32:57 +08:00
parent 5bfdde942c
commit 6970319697
9 changed files with 46 additions and 9 deletions

View File

@@ -22,6 +22,10 @@ public class ExecutorConstant {
COMMON_EXECUTOR = TtlExecutors.getTtlExecutor(commonExecutor);
}
public static void main(String[] args) {
}
private static ThreadFactory init(String nameFormat){
return new ThreadFactoryBuilder().setNameFormat(nameFormat).build();
}

View File

@@ -137,6 +137,24 @@ public class OssClient {
}
}
public UploadResult uploadFile(byte[] data, String tenantPrefix, String suffix, String contentType) {
return upload(data, getPath(properties.getPrefix(),tenantPrefix, suffix), contentType);
}
private String getPath(String prefix,String tenantPrefix, String suffix) {
// 生成uuid
String uuid = IdUtil.fastSimpleUUID();
// 文件路径
String path = DateUtils.datePath() + "/" + uuid;
if(StringUtils.isNotBlank(tenantPrefix)){
path = tenantPrefix + "/" + path;
}
if (StringUtils.isNotBlank(prefix)) {
path = prefix + "/" + path;
}
return path + suffix;
}
public UploadResult uploadSuffix(byte[] data, String suffix, String contentType) {
return upload(data, getPath(properties.getPrefix(), suffix), contentType);
}

View File

@@ -110,11 +110,12 @@ public class TenantHelper {
* @param handle 处理执行方法
*/
public static void dynamic(String tenantId, Runnable handle) {
String oldTenant = getTenantId();
setTenantId(tenantId);
try {
handle.run();
} finally {
clearTenant();
setTenantId(oldTenant);
}
}
@@ -124,11 +125,12 @@ public class TenantHelper {
* @param handle 处理执行方法
*/
public static <T> T dynamic(String tenantId, Supplier<T> handle) {
String oldTenant = getTenantId();
setTenantId(tenantId);
try {
return handle.get();
} finally {
clearTenant();
setTenantId(oldTenant);
}
}