替换Jedis-sa-token集成Redisson
This commit is contained in:
@@ -70,18 +70,13 @@
|
||||
<version>${sa-token.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Sa-Token 整合 Redis (使用jackson序列化方式) -->
|
||||
<!-- https://mvnrepository.com/artifact/cn.dev33/sa-token-redisson -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-dao-redis-jackson</artifactId>
|
||||
<artifactId>sa-token-redisson</artifactId>
|
||||
<version>${sa-token.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>software.amazon.awssdk</groupId>
|
||||
<artifactId>sesv2</artifactId>
|
||||
<version>2.30.38</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@@ -1,39 +0,0 @@
|
||||
package com.accompany.admin.config;
|
||||
|
||||
import com.accompany.core.autoconfigure.RedisAutoConfiguration;
|
||||
import com.accompany.core.config.JedisConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
|
||||
/**
|
||||
* @author: liaozetao
|
||||
* @date: 2023/12/8 11:53
|
||||
* @description:
|
||||
*/
|
||||
@Configuration
|
||||
@AutoConfigureAfter(RedisAutoConfiguration.class)
|
||||
public class SaTokenConfig {
|
||||
|
||||
@Bean
|
||||
public RedisConnectionFactory connectionFactory(@Autowired JedisConfig jedisConfig) {
|
||||
//redis连接配置
|
||||
JedisPoolConfig poolConfig = new JedisPoolConfig();
|
||||
poolConfig.setMaxIdle(jedisConfig.getMaxIdle());
|
||||
poolConfig.setMaxTotal(jedisConfig.getMaxTotal());
|
||||
poolConfig.setMaxWaitMillis(jedisConfig.getMaxWait());
|
||||
JedisConnectionFactory connectionFactory = new JedisConnectionFactory(poolConfig);
|
||||
RedisStandaloneConfiguration standaloneConfiguration = connectionFactory.getStandaloneConfiguration();
|
||||
if (standaloneConfiguration != null) {
|
||||
standaloneConfiguration.setHostName(jedisConfig.getHost());
|
||||
standaloneConfiguration.setPort(jedisConfig.getPort());
|
||||
standaloneConfiguration.setPassword(jedisConfig.getPassword());
|
||||
}
|
||||
return connectionFactory;
|
||||
}
|
||||
}
|
@@ -1,62 +0,0 @@
|
||||
package com.accompany.core.autoconfigure;
|
||||
|
||||
import com.accompany.common.redis.JedisPoolManager;
|
||||
import com.accompany.core.config.JedisConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @Author: yangming
|
||||
* @Date: 2020/5/12 12:09
|
||||
* @Description: redis连接池配置
|
||||
**/
|
||||
@Configuration
|
||||
@DependsOn("jedisConfig")
|
||||
@ConditionalOnClass({Jedis.class})
|
||||
public class RedisAutoConfiguration {
|
||||
|
||||
@Autowired
|
||||
private JedisConfig redisConfig;
|
||||
|
||||
@Bean("writeJedisPoolManager")
|
||||
public JedisPoolManager writeJedisPoolManager() {
|
||||
JedisPoolManager jedisPoolManager = new JedisPoolManager();
|
||||
jedisPoolManager.setJedisPools(Collections.singletonList(this.writeJedisPoolMaster()));
|
||||
return jedisPoolManager;
|
||||
}
|
||||
|
||||
@Bean("readJedisPoolManager")
|
||||
public JedisPoolManager readJedisPoolManager() {
|
||||
JedisPoolManager jedisPoolManager = new JedisPoolManager();
|
||||
jedisPoolManager.setJedisPools(Collections.singletonList(this.readJedisPoolMaster()));
|
||||
return jedisPoolManager;
|
||||
}
|
||||
|
||||
|
||||
private JedisPoolConfig jedisPoolConfig() {
|
||||
JedisPoolConfig config = new JedisPoolConfig();
|
||||
config.setMaxIdle(this.redisConfig.getMaxIdle());
|
||||
config.setMaxTotal(this.redisConfig.getMaxTotal());
|
||||
config.setMaxWaitMillis(this.redisConfig.getMaxWait());
|
||||
config.setMinIdle(this.redisConfig.getMinIdle());
|
||||
config.setTestOnReturn(this.redisConfig.isTestOnReturn());
|
||||
config.setTestOnBorrow(this.redisConfig.isTestOnBorrow());
|
||||
return config;
|
||||
}
|
||||
|
||||
private JedisPool writeJedisPoolMaster() {
|
||||
return new JedisPool(this.jedisPoolConfig(), this.redisConfig.getHost(), this.redisConfig.getPort(), this.redisConfig.getTimeout(), this.redisConfig.getPassword(), this.redisConfig.getDatabase());
|
||||
}
|
||||
|
||||
private JedisPool readJedisPoolMaster() {
|
||||
return new JedisPool(this.jedisPoolConfig(), this.redisConfig.getHost(), this.redisConfig.getPort(), this.redisConfig.getTimeout(), this.redisConfig.getPassword(), this.redisConfig.getDatabase());
|
||||
}
|
||||
}
|
@@ -1,39 +0,0 @@
|
||||
package com.accompany.core.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @Author: yangming
|
||||
* @Date: 2020/5/12 11:51
|
||||
* @Description: redis配置
|
||||
**/
|
||||
@Data
|
||||
@RefreshScope
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "spring.redis")
|
||||
public class JedisConfig {
|
||||
|
||||
private String host;
|
||||
|
||||
private int port;
|
||||
|
||||
private int timeout;
|
||||
|
||||
private int maxTotal;
|
||||
|
||||
private int maxIdle;
|
||||
|
||||
private long maxWait;
|
||||
|
||||
private int minIdle;
|
||||
|
||||
private String password;
|
||||
|
||||
private int database = 0;
|
||||
|
||||
private boolean testOnBorrow;
|
||||
private boolean testOnReturn;
|
||||
}
|
@@ -15,7 +15,7 @@ import com.accompany.core.enumeration.PartitionEnum;
|
||||
import com.accompany.core.model.Users;
|
||||
import com.accompany.core.service.region.RegionInfoService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@@ -1,31 +0,0 @@
|
||||
package com.accompany.business.strategy;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.core.service.common.JedisService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @USER: chenli
|
||||
* @DATE: 2021/9/8 16:03
|
||||
* @DESCRIPTION:静态代理类,对过期key处理进行通用的加锁解锁逻辑,防止集群情况下出现多台服务器监听到同一key过期,导致重复调用
|
||||
*/
|
||||
@Component
|
||||
public class RedisKeyOverdueDealProxy {
|
||||
@Autowired
|
||||
private JedisService jedisService;
|
||||
|
||||
public void dealInvoke(String key, DealOverdueRedisKeyStrategyI dealOverdueRedisKeyStrategyI) {
|
||||
String str = key.substring(key.lastIndexOf(StrUtil.UNDERLINE) + 1);
|
||||
|
||||
String lockKey = RedisKey.getCacheSign() + dealOverdueRedisKeyStrategyI.getRedisKeyStrategy().getClazz() + str + "_lock";
|
||||
/**
|
||||
* 1、避免集群环境下多台服务器监听到key过期重复调用此方法,即使加了此锁也并不能完全避免,假设第一台服务器执行完,第二台服务器才收到监听,因此具体策略实现还应注意幂等性
|
||||
* 2、此锁针对单个用户,且均为异步执行,不主动释放锁,避免执行太快锁没起到作用,非此情景最好主动释放锁
|
||||
*/
|
||||
Boolean flag = jedisService.setnx(lockKey, String.valueOf(1), 30);
|
||||
if (!flag) return;
|
||||
dealOverdueRedisKeyStrategyI.dealOverdueRedisKey(key);
|
||||
}
|
||||
}
|
@@ -1,75 +0,0 @@
|
||||
package com.accompany.business.util;
|
||||
|
||||
import com.accompany.business.param.ad.AdPlatfromTrackActiveReqParams;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
import com.accompany.core.model.Account;
|
||||
import com.accompany.core.model.Users;
|
||||
import com.accompany.core.service.account.AccountService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 广告平台工具类
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public final class AdPlatformUtil {
|
||||
|
||||
private static AccountService accountService;
|
||||
@Autowired
|
||||
public void setAccountService(AccountService accountService) {
|
||||
AdPlatformUtil.accountService = accountService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建上报参数
|
||||
* @param user
|
||||
* @param eventType
|
||||
* @return
|
||||
*/
|
||||
public static AdPlatfromTrackActiveReqParams buildReqParams(Users user, Byte eventType) {
|
||||
Account account = accountService.getById(user.getUid());
|
||||
if (null == account) {
|
||||
return null;
|
||||
}
|
||||
DeviceInfo deviceInfo = JSON.parseObject(account.getDeviceInfo(), DeviceInfo.class);
|
||||
if (null == deviceInfo) {
|
||||
return null;
|
||||
}
|
||||
AdPlatfromTrackActiveReqParams params = new AdPlatfromTrackActiveReqParams();
|
||||
params.setEvenType(eventType);
|
||||
params.setIp(account.getRegisterIp());
|
||||
params.setAndroidId(deviceInfo.getAndroidId());
|
||||
params.setOaId(deviceInfo.getOaid());
|
||||
params.setOaIdMd5(deviceInfo.getOaidMd5());
|
||||
params.setUid(user.getUid());
|
||||
params.setIdfa(deviceInfo.getIdfa());
|
||||
params.setPlatOs(turnToAdPlatformOs(account.getOs()));
|
||||
return params;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将系统os转换为广告平台os
|
||||
* @param os
|
||||
* @return
|
||||
*/
|
||||
public static Integer turnToAdPlatformOs(String os) {
|
||||
os = os.toLowerCase();
|
||||
Integer osType = null;
|
||||
switch (os) {
|
||||
case Constant.OsType.ANDROID :
|
||||
osType = 0;
|
||||
break;
|
||||
case Constant.OsType.IOS :
|
||||
osType = 1;
|
||||
break;
|
||||
default:
|
||||
osType = 3;
|
||||
}
|
||||
return osType;
|
||||
}
|
||||
}
|
@@ -1,43 +0,0 @@
|
||||
/**
|
||||
* Base64Utils.java Create on 2014-5-22 下午02:21:02
|
||||
* copyright (c) by DuoWan 2011
|
||||
*/
|
||||
package com.accompany.business.util;
|
||||
import org.bouncycastle.util.encoders.Base64;
|
||||
|
||||
public class Base64Utils {
|
||||
|
||||
/**
|
||||
* 文件读取缓冲区大小
|
||||
*/
|
||||
private static final int CACHE_SIZE = 1024;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* BASE64字符串解码为二进制数据
|
||||
* </p>
|
||||
*
|
||||
* @param base64
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static byte[] decode(String base64) throws Exception {
|
||||
return Base64.decode(base64.getBytes());
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 二进制数据编码为BASE64字符串
|
||||
* </p>
|
||||
*
|
||||
* @param bytes
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String encode(byte[] bytes){
|
||||
return new String(Base64.encode(bytes));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -81,7 +81,7 @@
|
||||
<bcprov-jdk15on.version>1.64</bcprov-jdk15on.version>
|
||||
<zxing.version>3.5.3</zxing.version>
|
||||
<bitwalker.version>1.20</bitwalker.version>
|
||||
<sa-token.version>1.34.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
<pinyin4j.version>2.5.1</pinyin4j.version>
|
||||
<cloudauth20190307.version>1.0.1</cloudauth20190307.version>
|
||||
<aws.version>2.30.37</aws.version>
|
||||
|
Reference in New Issue
Block a user