Browse Source

feat: 回滚springboot版本

yangliu 3 months ago
parent
commit
24ddfd73fc

+ 7 - 0
pom.xml

@@ -204,6 +204,13 @@
                 <artifactId>easyexcel</artifactId>
                 <version>${easyexcel.version}</version> <!-- 请检查最新版本 -->
             </dependency>
+
+
+            <dependency>
+                <groupId>cn.hfln.framework</groupId>
+                <artifactId>redis-spring-boot-starter</artifactId>
+                <version>1.0.0-SNAPSHOT</version>
+            </dependency>
         </dependencies>
     </dependencyManagement>
 

+ 4 - 0
portal-service-common/pom.xml

@@ -34,6 +34,10 @@
             <groupId>com.alibaba</groupId>
             <artifactId>easyexcel</artifactId>
         </dependency>
+        <dependency>
+            <groupId>cn.hfln.framework</groupId>
+            <artifactId>redis-spring-boot-starter</artifactId>
+        </dependency>
 
         <!-- Alibaba Fastjson -->
         <dependency>

+ 4 - 0
portal-service-domain/pom.xml

@@ -23,6 +23,10 @@
         </dependency>
 
         <dependency>
+            <groupId>cn.hfln.framework</groupId>
+            <artifactId>redis-spring-boot-starter</artifactId>
+        </dependency>
+        <dependency>
             <groupId>com.alibaba.fastjson2</groupId>
             <artifactId>fastjson2</artifactId>
         </dependency>

+ 1 - 5
portal-service-domain/src/main/java/com/hfln/portal/domain/customer/util/WxOfficeAccountClient.java

@@ -1,6 +1,5 @@
 package com.hfln.portal.domain.customer.util;
 
-import cn.hfln.framework.common.redis.service.RedisService;
 import com.alibaba.fastjson2.JSON;
 import com.google.gson.Gson;
 import lombok.extern.slf4j.Slf4j;
@@ -36,7 +35,7 @@ import java.util.concurrent.TimeUnit;
 @Component
 public class WxOfficeAccountClient {
 
-    private final RedisService redisService;
+//    private final RedisUtil redisService;
 
     @Autowired
     private StringRedisTemplate stringRedisTemplate;
@@ -57,9 +56,6 @@ public class WxOfficeAccountClient {
 
     private static final Gson gson = new Gson();
 
-    public WxOfficeAccountClient(RedisService redisService) {
-        this.redisService = redisService;
-    }
 
     public void sendMsg(String devId, String devName, String phoneNo, String fwhOpenId, String msg) {
         // 1. 获取 access_token

+ 31 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/config/RedisConfig.java

@@ -0,0 +1,31 @@
+package com.hfln.portal.infrastructure.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.connection.RedisConnectionFactory;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.serializer.StringRedisSerializer;
+
+/**
+ * Redis 配置类
+ * 手动注册 RedisTemplate,确保与自研 Redis Starter 兼容
+ */
+@Configuration
+public class RedisConfig {
+
+    @Bean
+    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
+        RedisTemplate<String, Object> template = new RedisTemplate<>();
+        template.setConnectionFactory(connectionFactory);
+
+        // 使用 StringRedisSerializer 进行序列化
+        StringRedisSerializer stringSerializer = new StringRedisSerializer();
+        template.setKeySerializer(stringSerializer);
+        template.setValueSerializer(stringSerializer);
+        template.setHashKeySerializer(stringSerializer);
+        template.setHashValueSerializer(stringSerializer);
+
+        template.afterPropertiesSet();
+        return template;
+    }
+}

+ 4 - 4
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/config/UserAuthService.java

@@ -1,7 +1,7 @@
 package com.hfln.portal.infrastructure.config;
 
 import cn.dev33.satoken.stp.StpUtil;
-import cn.hfln.framework.common.redis.service.RedisService;
+import cn.hfln.framework.redis.util.RedisUtil;
 import com.hfln.portal.common.constant.redis.RedisCacheConstant;
 import com.hfln.portal.infrastructure.po.TblPermission;
 import com.hfln.portal.infrastructure.po.TblRole;
@@ -43,7 +43,7 @@ public class UserAuthService {
 	private UserRoleService userRoleService;
 
 	@Autowired
-	private RedisService redisService;
+	private RedisUtil redisService;
 
 	public void cacheRolesAndPermissions() {
 
@@ -53,14 +53,14 @@ public class UserAuthService {
 			if (!redisService.hasKey(RedisCacheConstant.USER_ROLE_KEY_PRE+StpUtil.getLoginId())) {
 				// 这里从更改用户角色的地方修改最好
 //				redisService.deleteObject(RedisCacheConstant.USER_ROLE_KEY_PRE+StpUtil.getLoginId());
-				redisService.setCacheSet(RedisCacheConstant.USER_ROLE_KEY_PRE+ StpUtil.getLoginId(), roleCodeSet);
+				redisService.set(RedisCacheConstant.USER_ROLE_KEY_PRE+ StpUtil.getLoginId(), roleCodeSet);
 			}
 			for (String roleCode : roleCodeSet) {
 				if (!redisService.hasKey(RedisCacheConstant.ROLE_PERM_KEY_PRE+roleCode)) {
 					// 这里从更改角色权限的地方修改最好
 					// redisService.deleteObject(RedisCacheConstant.ROLE_PERM_KEY_PRE+roleCode);
 					Set<String> permCodeSet = this.getPermCodeSet(roleCode);
-					redisService.setCacheSet(RedisCacheConstant.ROLE_PERM_KEY_PRE+roleCode, permCodeSet);
+					redisService.set(RedisCacheConstant.ROLE_PERM_KEY_PRE+roleCode, permCodeSet);
 				}
 			}
 		}

+ 4 - 4
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/AdminGatewayImpl.java

@@ -3,8 +3,8 @@ package com.hfln.portal.infrastructure.gateway.impl;
 import cn.dev33.satoken.stp.SaTokenInfo;
 import cn.dev33.satoken.stp.StpUtil;
 import cn.dev33.satoken.stp.parameter.SaLoginParameter;
-import cn.hfln.framework.common.redis.service.RedisService;
 import cn.hfln.framework.extension.BizException;
+import cn.hfln.framework.redis.util.RedisUtil;
 import com.alibaba.excel.EasyExcel;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.hfln.portal.common.constant.redis.RedisCacheConstant;
@@ -53,7 +53,7 @@ public class AdminGatewayImpl implements AdminGateway {
     private DevInfoService devInfoService;
 
     @Autowired
-    private RedisService redisService;
+    private RedisUtil redisService;
 
     @Autowired
     private AdminUserService adminUserService;
@@ -190,7 +190,7 @@ public class AdminGatewayImpl implements AdminGateway {
         String redisKey = RedisCacheConstant.SMS_RESET_CODE + request.getPhone();
         log.info("验证注册验证码:手机号={}, 输入验证码={}, Redis key={}", request.getPhone(), request.getCode(), redisKey);
 
-        Object cacheCodeObj = redisService.getCacheObject(redisKey);
+        Object cacheCodeObj = redisService.get(redisKey);
         log.info("从Redis获取验证码:key={}, value={}", redisKey, cacheCodeObj);
 
         if (Objects.isNull(cacheCodeObj)) {
@@ -207,7 +207,7 @@ public class AdminGatewayImpl implements AdminGateway {
         }
 
         // 验证通过 清除验证码入库
-        redisService.deleteObject(redisKey);
+        redisService.del(redisKey);
 
         AdminUserInfo adminUser = adminUserService.queryByPhone(request.getPhone());
         if (adminUser == null) {

+ 6 - 6
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/UserGatewayImpl.java

@@ -4,8 +4,8 @@ package com.hfln.portal.infrastructure.gateway.impl;
 import cn.dev33.satoken.session.SaSession;
 import cn.dev33.satoken.stp.SaTokenInfo;
 import cn.dev33.satoken.stp.StpUtil;
-import cn.hfln.framework.common.redis.service.RedisService;
 import cn.hfln.framework.extension.BizException;
+import cn.hfln.framework.redis.util.RedisUtil;
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -67,7 +67,7 @@ public class UserGatewayImpl implements UserGateway {
     private RestTemplate restTemplate;
 
     @Autowired
-    private RedisService redisService;
+    private RedisUtil redisService;
 
     @Autowired
     private UserService userService;
@@ -209,7 +209,7 @@ public class UserGatewayImpl implements UserGateway {
         String redisKey = RedisCacheConstant.SMS_SIGNUP_CODE + request.getPhone();
         log.info("验证注册验证码:手机号={}, 输入验证码={}, Redis key={}", request.getPhone(), request.getCode(), redisKey);
         
-        Object cacheCodeObj = redisService.getCacheObject(redisKey);
+        Object cacheCodeObj = redisService.get(redisKey);
         log.info("从Redis获取验证码:key={}, value={}", redisKey, cacheCodeObj);
         
         if (Objects.isNull(cacheCodeObj)) {
@@ -228,7 +228,7 @@ public class UserGatewayImpl implements UserGateway {
             throw new BizException(ErrorEnum.USER_ALREADY_EXISTS.getErrorCode(), ErrorEnum.USER_ALREADY_EXISTS.getErrorMessage());
         }
         // 验证通过 清除验证码入库
-        redisService.deleteObject(redisKey);
+        redisService.del(redisKey);
         UserInfo user = new UserInfo();
         user.setPhone(request.getPhone());
         String encryptedPassword = PasswordUtil.encrypt(request.getPassword());
@@ -266,7 +266,7 @@ public class UserGatewayImpl implements UserGateway {
             String redisKey = RedisCacheConstant.SMS_LOGIN_CODE + phone;
             log.info("验证登录验证码:手机号={}, 输入验证码={}, Redis key={}", phone, request.getSmsCode(), redisKey);
             
-            Object cacheSmsCodeObj = redisService.getCacheObject(redisKey);
+            Object cacheSmsCodeObj = redisService.get(redisKey);
             log.info("从Redis获取登录验证码:key={}, value={}", redisKey, cacheSmsCodeObj);
             
             if (Objects.isNull(cacheSmsCodeObj)) {
@@ -280,7 +280,7 @@ public class UserGatewayImpl implements UserGateway {
                 log.warn("登录验证码错误:手机号={}, 输入={}, 缓存={}", phone, request.getSmsCode(), cacheSmsCode);
                 throw new BizException(ErrorEnum.SMS_CODE_ERROR.getErrorCode(), ErrorEnum.SMS_CODE_ERROR.getErrorMessage());
             }
-            redisService.deleteObject(redisKey);
+            redisService.del(redisKey);
         }
         BeanUtils.copyProperties(user, userDto);
         userDto.setUserId(user.getUserId()

+ 8 - 8
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/sms/SmsGatewayImpl.java

@@ -1,7 +1,7 @@
 package com.hfln.portal.infrastructure.gateway.impl.sms;
 
-import cn.hfln.framework.common.redis.service.RedisService;
 import cn.hfln.framework.extension.BizException;
+import cn.hfln.framework.redis.util.RedisUtil;
 import com.hfln.portal.common.constant.redis.RedisCacheConstant;
 import com.hfln.portal.domain.customer.util.MsgClient;
 import com.hfln.portal.domain.exception.ErrorEnum;
@@ -22,7 +22,7 @@ public class SmsGatewayImpl implements SmsGateway {
     private MsgClient msgClient;
 
     @Autowired
-    private RedisService redisService;
+    private RedisUtil redisService;
 
 
     @Override
@@ -33,12 +33,12 @@ public class SmsGatewayImpl implements SmsGateway {
         if (hasKey) {
             throw new BizException(ErrorEnum.FREQUENT_SMS_SENDING.getErrorCode(), ErrorEnum.FREQUENT_SMS_SENDING.getErrorMessage());
         }
-        redisService.setCacheObject(key, 1, 1L, TimeUnit.MINUTES);
+        redisService.set(key, 1, 1L, TimeUnit.MINUTES);
         int captcha = (int) ((Math.random() * 9 + 1) * 1000);
         String sentLoginMsg = msgClient.sendLoginMsg(phone, String.valueOf(captcha));
         if (Objects.nonNull(sentLoginMsg)) {
             // 存入redis  过期时间十分钟
-            redisService.setCacheObject(RedisCacheConstant.SMS_LOGIN_CODE + phone, captcha,10L, TimeUnit.MINUTES);
+            redisService.set(RedisCacheConstant.SMS_LOGIN_CODE + phone, captcha,10L, TimeUnit.MINUTES);
             return true;
         }
         return false;
@@ -59,11 +59,11 @@ public class SmsGatewayImpl implements SmsGateway {
         if (Objects.nonNull(sentLoginMsg)) {
             // 存入redis  过期时间十分钟
             String redisKey = RedisCacheConstant.SMS_SIGNUP_CODE + phone;
-            redisService.setCacheObject(redisKey, captcha, 10L, TimeUnit.MINUTES);
+            redisService.set(redisKey, captcha, 10L, TimeUnit.MINUTES);
             log.info("验证码已存入Redis:key={}, value={}, 过期时间=10分钟", redisKey, captcha);
             
             // 验证是否存储成功
-            Object storedValue = redisService.getCacheObject(redisKey);
+            Object storedValue = redisService.get(redisKey);
             log.info("验证存储结果:key={}, 存储的值={}", redisKey, storedValue);
             return true;
         }
@@ -86,11 +86,11 @@ public class SmsGatewayImpl implements SmsGateway {
         if (Objects.nonNull(sentLoginMsg)) {
             // 存入redis  过期时间十分钟
             String redisKey = RedisCacheConstant.SMS_RESET_CODE + phone;
-            redisService.setCacheObject(redisKey, captcha, 10L, TimeUnit.MINUTES);
+            redisService.set(redisKey, captcha, 10L, TimeUnit.MINUTES);
             log.info("验证码已存入Redis:key={}, value={}, 过期时间=10分钟", redisKey, captcha);
 
             // 验证是否存储成功
-            Object storedValue = redisService.getCacheObject(redisKey);
+            Object storedValue = redisService.get(redisKey);
             log.info("验证存储结果:key={}, 存储的值={}", redisKey, storedValue);
             return true;
         }

+ 1 - 3
portal-service-server/src/main/java/com/hfln/portal/server/Application.java

@@ -1,7 +1,5 @@
 package com.hfln.portal.server;
 
-import cn.hfln.framework.common.jackson.JacksonConfiguration;
-import cn.hfln.framework.common.redis.RedisConfig;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -15,7 +13,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
 @EnableDiscoveryClient
 @MapperScan("com.hfln.portal.infrastructure.mapper")
 @EnableFeignClients(basePackages = "com.hfln.portal.client.api")
-@SpringBootApplication(scanBasePackages = {"com.hfln.portal.**"}, scanBasePackageClasses = {RedisConfig.class, JacksonConfiguration.class})
+@SpringBootApplication(scanBasePackages = {"com.hfln.portal.**"})
 public class Application {
     public static void main(String[] args) {
         SpringApplication.run(Application.class, args);

+ 5 - 19
portal-service-server/src/main/resources/bootstrap-local.yml

@@ -11,30 +11,16 @@ spring:
         namespace: local
         file-extension: yaml
   redis:
-    # 地址
     host: 8.130.28.21
-    # 端口
     port: 6379
-    # 数据库索引
     database: 5
-    # 连接超时时间
-    timeout: 30s
-    #TCP连接建立超时
-    connect-timeout: 10s
+    timeout: 10s
     lettuce:
       pool:
-        # 连接池中的最小空闲连接
-        min-idle: 10
-        # 连接池中的最大空闲连接
-        max-idle: 20
-        # 连接池的最大数据库连接数
-        max-active: 50
-        # #连接池最大阻塞等待时间(使用负值表示没有限制)
-        max-wait: 5000ms
-        # 连接空闲超时
-      shutdown-timeout: 100ms
-      # Redis命令执行最大耗时(含网络传输)。若超过该时间将抛出超时异常。
-      command-timeout: 30ms
+        min-idle: 0
+        max-idle: 8
+        max-active: 8
+        max-wait: -1ms
   datasource:
     driver-class-name: com.mysql.cj.jdbc.Driver
     url: jdbc:mysql://8.130.28.21:3306/lnxx_dev?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=Asia/Shanghai