mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-18 17:38:48 +08:00
pom优化,让其更独立
This commit is contained in:
parent
88de9c2447
commit
d7914a897c
@ -1,6 +1,5 @@
|
|||||||
package org.dromara.common.excel.annotation;
|
package org.dromara.common.excel.annotation;
|
||||||
|
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
@ -27,6 +26,6 @@ public @interface ExcelDictFormat {
|
|||||||
/**
|
/**
|
||||||
* 分隔符,读取字符串组内容
|
* 分隔符,读取字符串组内容
|
||||||
*/
|
*/
|
||||||
String separator() default StringUtils.SEPARATOR;
|
String separator() default ",";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,8 @@ package org.dromara.common.excel.convert;
|
|||||||
import cn.hutool.core.annotation.AnnotationUtil;
|
import cn.hutool.core.annotation.AnnotationUtil;
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import com.alibaba.excel.converters.Converter;
|
import com.alibaba.excel.converters.Converter;
|
||||||
import com.alibaba.excel.enums.CellDataTypeEnum;
|
import com.alibaba.excel.enums.CellDataTypeEnum;
|
||||||
import com.alibaba.excel.metadata.GlobalConfiguration;
|
import com.alibaba.excel.metadata.GlobalConfiguration;
|
||||||
@ -11,8 +13,6 @@ import com.alibaba.excel.metadata.data.WriteCellData;
|
|||||||
import com.alibaba.excel.metadata.property.ExcelContentProperty;
|
import com.alibaba.excel.metadata.property.ExcelContentProperty;
|
||||||
import org.dromara.common.excel.annotation.ExcelDictFormat;
|
import org.dromara.common.excel.annotation.ExcelDictFormat;
|
||||||
import org.dromara.common.core.service.DictService;
|
import org.dromara.common.core.service.DictService;
|
||||||
import org.dromara.common.core.utils.SpringUtils;
|
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
|
||||||
import org.dromara.common.excel.utils.ExcelUtil;
|
import org.dromara.common.excel.utils.ExcelUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@ -42,10 +42,10 @@ public class ExcelDictConvert implements Converter<Object> {
|
|||||||
String type = anno.dictType();
|
String type = anno.dictType();
|
||||||
String label = cellData.getStringValue();
|
String label = cellData.getStringValue();
|
||||||
String value;
|
String value;
|
||||||
if (StringUtils.isBlank(type)) {
|
if (StrUtil.isBlank(type)) {
|
||||||
value = ExcelUtil.reverseByExp(label, anno.readConverterExp(), anno.separator());
|
value = ExcelUtil.reverseByExp(label, anno.readConverterExp(), anno.separator());
|
||||||
} else {
|
} else {
|
||||||
value = SpringUtils.getBean(DictService.class).getDictValue(type, label, anno.separator());
|
value = SpringUtil.getBean(DictService.class).getDictValue(type, label, anno.separator());
|
||||||
}
|
}
|
||||||
return Convert.convert(contentProperty.getField().getType(), value);
|
return Convert.convert(contentProperty.getField().getType(), value);
|
||||||
}
|
}
|
||||||
@ -59,10 +59,10 @@ public class ExcelDictConvert implements Converter<Object> {
|
|||||||
String type = anno.dictType();
|
String type = anno.dictType();
|
||||||
String value = Convert.toStr(object);
|
String value = Convert.toStr(object);
|
||||||
String label;
|
String label;
|
||||||
if (StringUtils.isBlank(type)) {
|
if (StrUtil.isBlank(type)) {
|
||||||
label = ExcelUtil.convertByExp(value, anno.readConverterExp(), anno.separator());
|
label = ExcelUtil.convertByExp(value, anno.readConverterExp(), anno.separator());
|
||||||
} else {
|
} else {
|
||||||
label = SpringUtils.getBean(DictService.class).getDictLabel(type, value, anno.separator());
|
label = SpringUtil.getBean(DictService.class).getDictLabel(type, value, anno.separator());
|
||||||
}
|
}
|
||||||
return new WriteCellData<>(label);
|
return new WriteCellData<>(label);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,20 @@
|
|||||||
|
package org.dromara.common.oss.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用常量信息
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public interface Constants {
|
||||||
|
/**
|
||||||
|
* http请求
|
||||||
|
*/
|
||||||
|
String HTTP = "http://";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https请求
|
||||||
|
*/
|
||||||
|
String HTTPS = "https://";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@ -1,7 +1,5 @@
|
|||||||
package org.dromara.common.oss.constant;
|
package org.dromara.common.oss.constant;
|
||||||
|
|
||||||
import org.dromara.common.core.constant.GlobalConstants;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -11,11 +9,19 @@ import java.util.List;
|
|||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
public interface OssConstant {
|
public interface OssConstant {
|
||||||
|
/**
|
||||||
|
* OSS配置 key 全局 redis key (业务无关的key)
|
||||||
|
*/
|
||||||
|
String GLOBAL_REDIS_KEY = "global:";
|
||||||
|
/**
|
||||||
|
* OSS配置 key
|
||||||
|
*/
|
||||||
|
String SYS_OSS_CONFIG = GLOBAL_REDIS_KEY + "sys_oss_config";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认配置KEY
|
* 默认配置KEY
|
||||||
*/
|
*/
|
||||||
String DEFAULT_CONFIG_KEY = GlobalConstants.GLOBAL_REDIS_KEY + "sys_oss:default_config";
|
String DEFAULT_CONFIG_KEY = GLOBAL_REDIS_KEY + "sys_oss:default_config";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 预览列表资源开关Key
|
* 预览列表资源开关Key
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
package org.dromara.common.oss.core;
|
package org.dromara.common.oss.core;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import org.dromara.common.core.constant.Constants;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import org.dromara.common.core.utils.DateUtils;
|
import org.dromara.common.oss.constant.Constants;
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
|
||||||
import org.dromara.common.core.utils.file.FileUtils;
|
|
||||||
import org.dromara.common.oss.constant.OssConstant;
|
import org.dromara.common.oss.constant.OssConstant;
|
||||||
import org.dromara.common.oss.entity.UploadResult;
|
import org.dromara.common.oss.entity.UploadResult;
|
||||||
import org.dromara.common.oss.enumd.AccessPolicyType;
|
import org.dromara.common.oss.enumd.AccessPolicyType;
|
||||||
@ -35,6 +35,7 @@ import java.net.URL;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* S3 存储协议 所有兼容S3协议的云厂商均支持
|
* S3 存储协议 所有兼容S3协议的云厂商均支持
|
||||||
@ -84,7 +85,7 @@ public class OssClient {
|
|||||||
AwsBasicCredentials.create(properties.getAccessKey(), properties.getSecretKey()));
|
AwsBasicCredentials.create(properties.getAccessKey(), properties.getSecretKey()));
|
||||||
|
|
||||||
//MinIO 使用 HTTPS 限制使用域名访问,站点填域名。需要启用路径样式访问
|
//MinIO 使用 HTTPS 限制使用域名访问,站点填域名。需要启用路径样式访问
|
||||||
boolean isStyle = !StringUtils.containsAny(properties.getEndpoint(), OssConstant.CLOUD_SERVICE);
|
boolean isStyle = !StrUtil.containsAny(properties.getEndpoint(), OssConstant.CLOUD_SERVICE);
|
||||||
|
|
||||||
//创建AWS基于 CRT 的 S3 客户端
|
//创建AWS基于 CRT 的 S3 客户端
|
||||||
this.client = S3AsyncClient.crtBuilder()
|
this.client = S3AsyncClient.crtBuilder()
|
||||||
@ -176,7 +177,7 @@ public class OssClient {
|
|||||||
x -> x.putObjectRequest(
|
x -> x.putObjectRequest(
|
||||||
y -> y.bucket(properties.getBucketName())
|
y -> y.bucket(properties.getBucketName())
|
||||||
.key(key)
|
.key(key)
|
||||||
.contentMD5(StringUtils.isNotEmpty(md5Digest) ? md5Digest : null)
|
.contentMD5(StrUtil.isNotEmpty(md5Digest) ? md5Digest : null)
|
||||||
.contentType(contentType)
|
.contentType(contentType)
|
||||||
.acl(getAccessPolicy().getObjectCannedACL())
|
.acl(getAccessPolicy().getObjectCannedACL())
|
||||||
.build())
|
.build())
|
||||||
@ -188,13 +189,13 @@ public class OssClient {
|
|||||||
String eTag = uploadResult.response().eTag();
|
String eTag = uploadResult.response().eTag();
|
||||||
|
|
||||||
// 提取上传结果中的 ETag,并构建一个自定义的 UploadResult 对象
|
// 提取上传结果中的 ETag,并构建一个自定义的 UploadResult 对象
|
||||||
return UploadResult.builder().url(getUrl() + StringUtils.SLASH + key).filename(key).eTag(eTag).build();
|
return UploadResult.builder().url(getUrl() + StrUtil.SLASH + key).filename(key).eTag(eTag).build();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 捕获异常并抛出自定义异常
|
// 捕获异常并抛出自定义异常
|
||||||
throw new OssException("上传文件失败,请检查配置信息:[" + e.getMessage() + "]");
|
throw new OssException("上传文件失败,请检查配置信息:[" + e.getMessage() + "]");
|
||||||
} finally {
|
} finally {
|
||||||
// 无论上传是否成功,最终都会删除临时文件
|
// 无论上传是否成功,最终都会删除临时文件
|
||||||
FileUtils.del(filePath);
|
FileUtil.del(filePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +237,7 @@ public class OssClient {
|
|||||||
String eTag = uploadResult.response().eTag();
|
String eTag = uploadResult.response().eTag();
|
||||||
|
|
||||||
// 提取上传结果中的 ETag,并构建一个自定义的 UploadResult 对象
|
// 提取上传结果中的 ETag,并构建一个自定义的 UploadResult 对象
|
||||||
return UploadResult.builder().url(getUrl() + StringUtils.SLASH + key).filename(key).eTag(eTag).build();
|
return UploadResult.builder().url(getUrl() + StrUtil.SLASH + key).filename(key).eTag(eTag).build();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new OssException("上传文件失败,请检查配置信息:[" + e.getMessage() + "]");
|
throw new OssException("上传文件失败,请检查配置信息:[" + e.getMessage() + "]");
|
||||||
}
|
}
|
||||||
@ -251,7 +252,7 @@ public class OssClient {
|
|||||||
*/
|
*/
|
||||||
public Path fileDownload(String path) {
|
public Path fileDownload(String path) {
|
||||||
// 构建临时文件
|
// 构建临时文件
|
||||||
Path tempFilePath = FileUtils.createTempFile().toPath();
|
Path tempFilePath = FileUtil.createTempFile().toPath();
|
||||||
// 使用 S3TransferManager 下载文件
|
// 使用 S3TransferManager 下载文件
|
||||||
FileDownload downloadFile = transferManager.downloadFile(
|
FileDownload downloadFile = transferManager.downloadFile(
|
||||||
x -> x.getObjectRequest(
|
x -> x.getObjectRequest(
|
||||||
@ -341,7 +342,7 @@ public class OssClient {
|
|||||||
* @throws OssException 如果上传失败,抛出自定义异常
|
* @throws OssException 如果上传失败,抛出自定义异常
|
||||||
*/
|
*/
|
||||||
public UploadResult uploadSuffix(byte[] data, String suffix) {
|
public UploadResult uploadSuffix(byte[] data, String suffix) {
|
||||||
return upload(new ByteArrayInputStream(data), getPath(properties.getPrefix(), suffix), Long.valueOf(data.length), FileUtils.getMimeType(suffix));
|
return upload(new ByteArrayInputStream(data), getPath(properties.getPrefix(), suffix), Long.valueOf(data.length), FileUtil.getMimeType(suffix));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -354,7 +355,7 @@ public class OssClient {
|
|||||||
* @throws OssException 如果上传失败,抛出自定义异常
|
* @throws OssException 如果上传失败,抛出自定义异常
|
||||||
*/
|
*/
|
||||||
public UploadResult uploadSuffix(InputStream inputStream, String suffix, Long length) {
|
public UploadResult uploadSuffix(InputStream inputStream, String suffix, Long length) {
|
||||||
return upload(inputStream, getPath(properties.getPrefix(), suffix), length, FileUtils.getMimeType(suffix));
|
return upload(inputStream, getPath(properties.getPrefix(), suffix), length, FileUtil.getMimeType(suffix));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -366,7 +367,7 @@ public class OssClient {
|
|||||||
* @throws OssException 如果上传失败,抛出自定义异常
|
* @throws OssException 如果上传失败,抛出自定义异常
|
||||||
*/
|
*/
|
||||||
public UploadResult uploadSuffix(File file, String suffix) {
|
public UploadResult uploadSuffix(File file, String suffix) {
|
||||||
return upload(file.toPath(), getPath(properties.getPrefix(), suffix), null, FileUtils.getMimeType(suffix));
|
return upload(file.toPath(), getPath(properties.getPrefix(), suffix), null, FileUtil.getMimeType(suffix));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -381,7 +382,7 @@ public class OssClient {
|
|||||||
// 创建输入流
|
// 创建输入流
|
||||||
InputStream inputStream = Files.newInputStream(tempFilePath);
|
InputStream inputStream = Files.newInputStream(tempFilePath);
|
||||||
// 删除临时文件
|
// 删除临时文件
|
||||||
FileUtils.del(tempFilePath);
|
FileUtil.del(tempFilePath);
|
||||||
// 返回对象内容的输入流
|
// 返回对象内容的输入流
|
||||||
return inputStream;
|
return inputStream;
|
||||||
}
|
}
|
||||||
@ -410,12 +411,12 @@ public class OssClient {
|
|||||||
String header = getIsHttps();
|
String header = getIsHttps();
|
||||||
|
|
||||||
// 如果是云服务商,直接返回域名或终端点
|
// 如果是云服务商,直接返回域名或终端点
|
||||||
if (StringUtils.containsAny(endpoint, OssConstant.CLOUD_SERVICE)) {
|
if (StrUtil.containsAny(endpoint, OssConstant.CLOUD_SERVICE)) {
|
||||||
return StringUtils.isNotEmpty(domain) ? header + domain : header + endpoint;
|
return StrUtil.isNotEmpty(domain) ? header + domain : header + endpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果是 MinIO,处理域名并返回
|
// 如果是 MinIO,处理域名并返回
|
||||||
if (StringUtils.isNotEmpty(domain)) {
|
if (StrUtil.isNotEmpty(domain)) {
|
||||||
return domain.startsWith(Constants.HTTPS) || domain.startsWith(Constants.HTTP) ? domain : header + domain;
|
return domain.startsWith(Constants.HTTPS) || domain.startsWith(Constants.HTTP) ? domain : header + domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -434,7 +435,7 @@ public class OssClient {
|
|||||||
//AWS 区域字符串
|
//AWS 区域字符串
|
||||||
String region = properties.getRegion();
|
String region = properties.getRegion();
|
||||||
// 如果 region 参数非空,使用 Region.of 方法创建对应的 AWS 区域对象,否则返回默认区域
|
// 如果 region 参数非空,使用 Region.of 方法创建对应的 AWS 区域对象,否则返回默认区域
|
||||||
return StringUtils.isNotEmpty(region) ? Region.of(region) : Region.US_EAST_1;
|
return StrUtil.isNotEmpty(region) ? Region.of(region) : Region.US_EAST_1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -447,16 +448,16 @@ public class OssClient {
|
|||||||
String endpoint = properties.getEndpoint();
|
String endpoint = properties.getEndpoint();
|
||||||
String header = getIsHttps();
|
String header = getIsHttps();
|
||||||
// 云服务商直接返回
|
// 云服务商直接返回
|
||||||
if (StringUtils.containsAny(endpoint, OssConstant.CLOUD_SERVICE)) {
|
if (StrUtil.containsAny(endpoint, OssConstant.CLOUD_SERVICE)) {
|
||||||
return header + (StringUtils.isNotEmpty(domain) ? domain : properties.getBucketName() + "." + endpoint);
|
return header + (StrUtil.isNotEmpty(domain) ? domain : properties.getBucketName() + "." + endpoint);
|
||||||
}
|
}
|
||||||
// MinIO 单独处理
|
// MinIO 单独处理
|
||||||
if (StringUtils.isNotEmpty(domain)) {
|
if (StrUtil.isNotEmpty(domain)) {
|
||||||
// 如果 domain 以 "https://" 或 "http://" 开头
|
// 如果 domain 以 "https://" 或 "http://" 开头
|
||||||
return (domain.startsWith(Constants.HTTPS) || domain.startsWith(Constants.HTTP)) ?
|
return (domain.startsWith(Constants.HTTPS) || domain.startsWith(Constants.HTTP)) ?
|
||||||
domain + StringUtils.SLASH + properties.getBucketName() : header + domain + StringUtils.SLASH + properties.getBucketName();
|
domain + StrUtil.SLASH + properties.getBucketName() : header + domain + StrUtil.SLASH + properties.getBucketName();
|
||||||
}
|
}
|
||||||
return header + endpoint + StringUtils.SLASH + properties.getBucketName();
|
return header + endpoint + StrUtil.SLASH + properties.getBucketName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -470,10 +471,10 @@ public class OssClient {
|
|||||||
// 生成uuid
|
// 生成uuid
|
||||||
String uuid = IdUtil.fastSimpleUUID();
|
String uuid = IdUtil.fastSimpleUUID();
|
||||||
// 生成日期路径
|
// 生成日期路径
|
||||||
String datePath = DateUtils.datePath();
|
String datePath = DateUtil.format(new Date(), "yyyy/MM/dd");
|
||||||
// 拼接路径
|
// 拼接路径
|
||||||
String path = StringUtils.isNotEmpty(prefix) ?
|
String path = StrUtil.isNotEmpty(prefix) ?
|
||||||
prefix + StringUtils.SLASH + datePath + StringUtils.SLASH + uuid : datePath + StringUtils.SLASH + uuid;
|
prefix + StrUtil.SLASH + datePath + StrUtil.SLASH + uuid : datePath + StrUtil.SLASH + uuid;
|
||||||
return path + suffix;
|
return path + suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -484,7 +485,7 @@ public class OssClient {
|
|||||||
* @return 去除基础URL后的相对路径
|
* @return 去除基础URL后的相对路径
|
||||||
*/
|
*/
|
||||||
public String removeBaseUrl(String path) {
|
public String removeBaseUrl(String path) {
|
||||||
return path.replace(getUrl() + StringUtils.SLASH, "");
|
return path.replace(getUrl() + StrUtil.SLASH, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
package org.dromara.common.oss.factory;
|
package org.dromara.common.oss.factory;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.dromara.common.core.constant.CacheNames;
|
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
|
||||||
import org.dromara.common.json.utils.JsonUtils;
|
import org.dromara.common.json.utils.JsonUtils;
|
||||||
import org.dromara.common.oss.constant.OssConstant;
|
import org.dromara.common.oss.constant.OssConstant;
|
||||||
import org.dromara.common.oss.core.OssClient;
|
import org.dromara.common.oss.core.OssClient;
|
||||||
@ -32,7 +31,7 @@ public class OssFactory {
|
|||||||
public static OssClient instance() {
|
public static OssClient instance() {
|
||||||
// 获取redis 默认类型
|
// 获取redis 默认类型
|
||||||
String configKey = RedisUtils.getCacheObject(OssConstant.DEFAULT_CONFIG_KEY);
|
String configKey = RedisUtils.getCacheObject(OssConstant.DEFAULT_CONFIG_KEY);
|
||||||
if (StringUtils.isEmpty(configKey)) {
|
if (StrUtil.isEmpty(configKey)) {
|
||||||
throw new OssException("文件存储服务类型无法找到!");
|
throw new OssException("文件存储服务类型无法找到!");
|
||||||
}
|
}
|
||||||
return instance(configKey);
|
return instance(configKey);
|
||||||
@ -42,14 +41,14 @@ public class OssFactory {
|
|||||||
* 根据类型获取实例
|
* 根据类型获取实例
|
||||||
*/
|
*/
|
||||||
public static OssClient instance(String configKey) {
|
public static OssClient instance(String configKey) {
|
||||||
String json = CacheUtils.get(CacheNames.SYS_OSS_CONFIG, configKey);
|
String json = CacheUtils.get(OssConstant.SYS_OSS_CONFIG, configKey);
|
||||||
if (json == null) {
|
if (json == null) {
|
||||||
throw new OssException("系统异常, '" + configKey + "'配置信息不存在!");
|
throw new OssException("系统异常, '" + configKey + "'配置信息不存在!");
|
||||||
}
|
}
|
||||||
OssProperties properties = JsonUtils.parseObject(json, OssProperties.class);
|
OssProperties properties = JsonUtils.parseObject(json, OssProperties.class);
|
||||||
// 使用租户标识避免多个租户相同key实例覆盖
|
// 使用租户标识避免多个租户相同key实例覆盖
|
||||||
String key = configKey;
|
String key = configKey;
|
||||||
if (StringUtils.isNotBlank(properties.getTenantId())) {
|
if (StrUtil.isNotBlank(properties.getTenantId())) {
|
||||||
key = properties.getTenantId() + ":" + configKey;
|
key = properties.getTenantId() + ":" + configKey;
|
||||||
}
|
}
|
||||||
OssClient client = CLIENT_CACHE.get(key);
|
OssClient client = CLIENT_CACHE.get(key);
|
||||||
|
|||||||
@ -18,8 +18,16 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- RuoYi Common Core-->
|
<!-- RuoYi Common Core-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.dromara</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>ruoyi-common-core</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-extra</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--redisson-->
|
<!--redisson-->
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package org.dromara.common.redis.config;
|
package org.dromara.common.redis.config;
|
||||||
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
@ -9,18 +10,18 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|||||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.dromara.common.core.utils.SpringUtils;
|
|
||||||
import org.dromara.common.redis.config.properties.RedissonProperties;
|
import org.dromara.common.redis.config.properties.RedissonProperties;
|
||||||
import org.dromara.common.redis.handler.KeyPrefixHandler;
|
import org.dromara.common.redis.handler.KeyPrefixHandler;
|
||||||
import org.dromara.common.redis.handler.RedisExceptionHandler;
|
|
||||||
import org.redisson.client.codec.StringCodec;
|
import org.redisson.client.codec.StringCodec;
|
||||||
import org.redisson.codec.CompositeCodec;
|
import org.redisson.codec.CompositeCodec;
|
||||||
import org.redisson.codec.TypedJsonJacksonCodec;
|
import org.redisson.codec.TypedJsonJacksonCodec;
|
||||||
import org.redisson.spring.starter.RedissonAutoConfigurationCustomizer;
|
import org.redisson.spring.starter.RedissonAutoConfigurationCustomizer;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.thread.Threading;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.core.task.VirtualThreadTaskExecutor;
|
import org.springframework.core.task.VirtualThreadTaskExecutor;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@ -61,7 +62,7 @@ public class RedisConfig {
|
|||||||
// 缓存 Lua 脚本 减少网络传输(redisson 大部分的功能都是基于 Lua 脚本实现)
|
// 缓存 Lua 脚本 减少网络传输(redisson 大部分的功能都是基于 Lua 脚本实现)
|
||||||
.setUseScriptCache(true)
|
.setUseScriptCache(true)
|
||||||
.setCodec(codec);
|
.setCodec(codec);
|
||||||
if (SpringUtils.isVirtual()) {
|
if (Threading.VIRTUAL.isActive(SpringUtil.getBean(Environment.class))) {
|
||||||
config.setNettyExecutor(new VirtualThreadTaskExecutor("redisson-"));
|
config.setNettyExecutor(new VirtualThreadTaskExecutor("redisson-"));
|
||||||
}
|
}
|
||||||
RedissonProperties.SingleServerConfig singleServerConfig = redissonProperties.getSingleServerConfig();
|
RedissonProperties.SingleServerConfig singleServerConfig = redissonProperties.getSingleServerConfig();
|
||||||
@ -98,13 +99,14 @@ public class RedisConfig {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
//TODO 异常处理应该放在业务代码包里面
|
||||||
* 异常处理器
|
// /**
|
||||||
*/
|
// * 异常处理器
|
||||||
@Bean
|
// */
|
||||||
public RedisExceptionHandler redisExceptionHandler() {
|
// @Bean
|
||||||
return new RedisExceptionHandler();
|
// public RedisExceptionHandler redisExceptionHandler() {
|
||||||
}
|
// return new RedisExceptionHandler();
|
||||||
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* redis集群配置 yml
|
* redis集群配置 yml
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package org.dromara.common.redis.handler;
|
package org.dromara.common.redis.handler;
|
||||||
|
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import org.redisson.api.NameMapper;
|
import org.redisson.api.NameMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -16,7 +16,7 @@ public class KeyPrefixHandler implements NameMapper {
|
|||||||
|
|
||||||
public KeyPrefixHandler(String keyPrefix) {
|
public KeyPrefixHandler(String keyPrefix) {
|
||||||
//前缀为空 则返回空前缀
|
//前缀为空 则返回空前缀
|
||||||
this.keyPrefix = StringUtils.isBlank(keyPrefix) ? "" : keyPrefix + ":";
|
this.keyPrefix = StrUtil.isBlank(keyPrefix) ? "" : keyPrefix + ":";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,10 +24,10 @@ public class KeyPrefixHandler implements NameMapper {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String map(String name) {
|
public String map(String name) {
|
||||||
if (StringUtils.isBlank(name)) {
|
if (StrUtil.isBlank(name)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotBlank(keyPrefix) && !name.startsWith(keyPrefix)) {
|
if (StrUtil.isNotBlank(keyPrefix) && !name.startsWith(keyPrefix)) {
|
||||||
return keyPrefix + name;
|
return keyPrefix + name;
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
@ -38,10 +38,10 @@ public class KeyPrefixHandler implements NameMapper {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String unmap(String name) {
|
public String unmap(String name) {
|
||||||
if (StringUtils.isBlank(name)) {
|
if (StrUtil.isBlank(name)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotBlank(keyPrefix) && name.startsWith(keyPrefix)) {
|
if (StrUtil.isNotBlank(keyPrefix) && name.startsWith(keyPrefix)) {
|
||||||
return name.substring(keyPrefix.length());
|
return name.substring(keyPrefix.length());
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
|
|||||||
@ -1,30 +0,0 @@
|
|||||||
package org.dromara.common.redis.handler;
|
|
||||||
|
|
||||||
import cn.hutool.http.HttpStatus;
|
|
||||||
import com.baomidou.lock.exception.LockFailureException;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.dromara.common.core.domain.R;
|
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Redis异常处理器
|
|
||||||
*
|
|
||||||
* @author AprilWind
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@RestControllerAdvice
|
|
||||||
public class RedisExceptionHandler {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分布式锁Lock4j异常
|
|
||||||
*/
|
|
||||||
@ExceptionHandler(LockFailureException.class)
|
|
||||||
public R<Void> handleLockFailureException(LockFailureException e, HttpServletRequest request) {
|
|
||||||
String requestURI = request.getRequestURI();
|
|
||||||
log.error("获取锁失败了'{}',发生Lock4j异常.", requestURI, e);
|
|
||||||
return R.fail(HttpStatus.HTTP_UNAVAILABLE, "业务处理中,请稍后再试...");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
package org.dromara.common.redis.manager;
|
package org.dromara.common.redis.manager;
|
||||||
|
|
||||||
import org.dromara.common.core.utils.SpringUtils;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import org.springframework.cache.Cache;
|
import org.springframework.cache.Cache;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
@ -13,7 +13,7 @@ import java.util.concurrent.Callable;
|
|||||||
public class CaffeineCacheDecorator implements Cache {
|
public class CaffeineCacheDecorator implements Cache {
|
||||||
|
|
||||||
private static final com.github.benmanes.caffeine.cache.Cache<Object, Object>
|
private static final com.github.benmanes.caffeine.cache.Cache<Object, Object>
|
||||||
CAFFEINE = SpringUtils.getBean("caffeine");
|
CAFFEINE = SpringUtil.getBean("caffeine");
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final Cache cache;
|
private final Cache cache;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package org.dromara.common.redis.utils;
|
package org.dromara.common.redis.utils;
|
||||||
|
|
||||||
import org.dromara.common.core.utils.SpringUtils;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import org.redisson.api.RMap;
|
import org.redisson.api.RMap;
|
||||||
@ -19,7 +19,7 @@ import java.util.Set;
|
|||||||
@SuppressWarnings(value = {"unchecked"})
|
@SuppressWarnings(value = {"unchecked"})
|
||||||
public class CacheUtils {
|
public class CacheUtils {
|
||||||
|
|
||||||
private static final CacheManager CACHE_MANAGER = SpringUtils.getBean(CacheManager.class);
|
private static final CacheManager CACHE_MANAGER = SpringUtil.getBean(CacheManager.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取缓存组内所有的KEY
|
* 获取缓存组内所有的KEY
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
package org.dromara.common.redis.utils;
|
package org.dromara.common.redis.utils;
|
||||||
|
|
||||||
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import org.dromara.common.core.utils.SpringUtils;
|
|
||||||
import org.redisson.api.*;
|
import org.redisson.api.*;
|
||||||
|
|
||||||
import java.util.concurrent.CompletionStage;
|
import java.util.concurrent.CompletionStage;
|
||||||
@ -20,7 +20,7 @@ import java.util.function.Function;
|
|||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class QueueUtils {
|
public class QueueUtils {
|
||||||
|
|
||||||
private static final RedissonClient CLIENT = SpringUtils.getBean(RedissonClient.class);
|
private static final RedissonClient CLIENT = SpringUtil.getBean(RedissonClient.class);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
package org.dromara.common.redis.utils;
|
package org.dromara.common.redis.utils;
|
||||||
|
|
||||||
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import org.dromara.common.core.utils.SpringUtils;
|
|
||||||
import org.redisson.api.*;
|
import org.redisson.api.*;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
@ -24,7 +24,7 @@ import java.util.stream.Stream;
|
|||||||
@SuppressWarnings(value = {"unchecked", "rawtypes"})
|
@SuppressWarnings(value = {"unchecked", "rawtypes"})
|
||||||
public class RedisUtils {
|
public class RedisUtils {
|
||||||
|
|
||||||
private static final RedissonClient CLIENT = SpringUtils.getBean(RedissonClient.class);
|
private static final RedissonClient CLIENT = SpringUtil.getBean(RedissonClient.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 限流
|
* 限流
|
||||||
|
|||||||
@ -16,7 +16,10 @@
|
|||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.dromara</groupId>
|
||||||
|
<artifactId>ruoyi-common-core</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.dromara</groupId>
|
<groupId>org.dromara</groupId>
|
||||||
<artifactId>ruoyi-common-json</artifactId>
|
<artifactId>ruoyi-common-json</artifactId>
|
||||||
|
|||||||
@ -16,6 +16,10 @@
|
|||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.dromara</groupId>
|
||||||
|
<artifactId>ruoyi-common-core</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.dromara</groupId>
|
<groupId>org.dromara</groupId>
|
||||||
<artifactId>ruoyi-common-json</artifactId>
|
<artifactId>ruoyi-common-json</artifactId>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user