From e2778109931e6f944e6bdd9f14dcb0bec8aa32da Mon Sep 17 00:00:00 2001
From: vincentlu <t1341870251@gmail.com>
Date: 星期四, 13 二月 2025 14:00:51 +0800
Subject: [PATCH] #

---
 rsf-server/src/main/java/com/vincent/rsf/server/system/controller/AuthController.java |   13 +++---
 rsf-server/src/main/resources/application-prod.yml                                    |   13 +++++-
 rsf-server/src/main/java/com/vincent/rsf/server/common/service/RedisService.java      |   84 ++++++++++++------------------------------
 rsf-server/src/main/resources/application-dev.yml                                     |    4 -
 4 files changed, 43 insertions(+), 71 deletions(-)

diff --git a/rsf-common/src/main/java/com/vincent/rsf/common/utils/RedisSupport.java b/rsf-server/src/main/java/com/vincent/rsf/server/common/service/RedisService.java
similarity index 82%
rename from rsf-common/src/main/java/com/vincent/rsf/common/utils/RedisSupport.java
rename to rsf-server/src/main/java/com/vincent/rsf/server/common/service/RedisService.java
index 6886d97..87c8a4a 100644
--- a/rsf-common/src/main/java/com/vincent/rsf/common/utils/RedisSupport.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/common/service/RedisService.java
@@ -1,13 +1,15 @@
-package com.vincent.rsf.common.utils;
+package com.vincent.rsf.server.common.service;
 
+import com.vincent.rsf.common.utils.Serialize;
+import com.vincent.rsf.server.common.config.RedisProperties;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
 import redis.clients.jedis.Jedis;
 import redis.clients.jedis.JedisPool;
 import redis.clients.jedis.JedisPoolConfig;
 
 import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
 import java.util.Set;
 
 /**
@@ -15,71 +17,38 @@
  * Created by vincent on 2023-03-13
  */
 @Slf4j
-public class RedisSupport {
-
-	private static final Map<String, RedisSupport> REDIS_CACHE = new HashMap<>();
-
-	public static final String DEFAULT_FLAG = "redis";
+@Service
+public class RedisService {
 
 	private static final String LINK = ".";
 
-	public static RedisSupport defaultRedisSupport = RedisSupport.getRedis(DEFAULT_FLAG);
-
 	protected JedisPool pool;
-
-	protected JedisPoolConfig config;
 
 	Integer index = 0;
 
-	public Boolean initialize = false;
+	public Boolean initialize = true;
 
-	public synchronized static RedisSupport getRedis(String name){
-		RedisSupport redisSupport = REDIS_CACHE.get(name);
-		if (null == redisSupport){
-			redisSupport = new RedisSupport(name);
-			REDIS_CACHE.put(name, redisSupport);
+	@Autowired
+	private RedisProperties redisProperties;
+
+	public JedisPool getPool() {
+		if (null == this.pool) {
+			JedisPoolConfig config = new JedisPoolConfig();
+			config.setTestOnBorrow(false);
+			this.index = redisProperties.getIndex();
+			this.pool = new JedisPool(config
+					, redisProperties.getHost()
+					, redisProperties.getPort()
+					, redisProperties.getTimeout()
+					, redisProperties.getPassword()
+			);
 		}
-		return redisSupport;
-	}
-
-	private RedisSupport(String name) {
-		try {
-			boolean bAll = true;
-			String[] configKeys = {"host", "port", "max", "min", "timeout", "index"};
-			for(String key : configKeys){
-				if(!ConfigHelper.contains(name + "." + key)){
-					bAll = false;
-				}
-			}
-			if (bAll) {
-				config = new JedisPoolConfig();
-				config.setMaxIdle(ConfigHelper.getInteger(name + ".min"));
-		        config.setMaxWaitMillis(ConfigHelper.getLong(name + ".timeout"));
-		        // 鍦╞orrow涓�涓猨edis瀹炰緥鏃讹紝鏄惁鎻愬墠杩涜validate鎿嶄綔锛涘鏋滀负true锛屽垯寰楀埌鐨刯edis瀹炰緥鍧囨槸鍙敤鐨勶紱
-		        config.setTestOnBorrow(false);
-		        // 褰撳墠jedis杩炴帴鐨勫簱鍙�
-				index = ConfigHelper.getInteger(name + ".index");
-				// 瀹炰緥鍖杍edis姹�
-		        String host = ConfigHelper.getString(name + ".host");
-		        int port = ConfigHelper.getInteger(name + ".port");
-		        int timeout = ConfigHelper.getInteger(name + ".timeout");
-		        String password = ConfigHelper.getString(name + ".password");
-
-				pool = new JedisPool(config, host , port, timeout, password);
-				Jedis jedis = this.getJedis();
-				this.pool.returnResource(jedis);
-				initialize = true;
-			} else {
-				log.error("ERROR - 鍒濆鍖朢eids鏃跺嚭閿欙紝鍦ㄩ厤缃枃浠朵腑鏈壘鍒皗}.***灞炴��(host,port,max,min,timeout,index)", name);
-			}
-		} catch (Exception e) {
-			log.error(this.getClass().getSimpleName(), e);
-		}
+		return this.pool;
 	}
 
 	public Jedis getJedis(){
 		try{
-			Jedis jedis = pool.getResource();
+			Jedis jedis = this.getPool().getResource();
 
 			if(this.index != jedis.getDB().intValue()) {
 				jedis.select(this.index);
@@ -88,7 +57,6 @@
 		} catch (Exception e){
 			log.error(this.getClass().getSimpleName(), e);
 		}
-
 		return null;
 	}
 
@@ -518,10 +486,6 @@
 			log.error(this.getClass().getSimpleName(), e);
 		}
 		return null;
-	}
-
-	public static void main(String...strings){
-		RedisSupport redis = RedisSupport.defaultRedisSupport;
 	}
 
 }
diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/system/controller/AuthController.java b/rsf-server/src/main/java/com/vincent/rsf/server/system/controller/AuthController.java
index 415079f..76c5b80 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/system/controller/AuthController.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/system/controller/AuthController.java
@@ -1,7 +1,6 @@
 package com.vincent.rsf.server.system.controller;
 
 import com.vincent.rsf.common.enums.SystemModeType;
-import com.vincent.rsf.common.utils.RedisSupport;
 import com.vincent.rsf.common.utils.Utils;
 import com.vincent.rsf.framework.common.BaseRes;
 import com.vincent.rsf.framework.common.Cools;
@@ -12,6 +11,7 @@
 import com.vincent.rsf.server.common.security.JwtSubject;
 import com.vincent.rsf.server.common.service.EmailService;
 import com.vincent.rsf.server.common.utils.JwtUtil;
+import com.vincent.rsf.server.common.service.RedisService;
 import com.vincent.rsf.server.system.controller.param.LoginParam;
 import com.vincent.rsf.server.system.controller.param.RegisterParam;
 import com.vincent.rsf.server.system.controller.param.UpdatePasswordParam;
@@ -45,8 +45,6 @@
 @RestController
 public class AuthController extends BaseController {
 
-    private final RedisSupport redis = RedisSupport.defaultRedisSupport;
-
     @Resource
     private ConfigProperties configProperties;
     @Resource
@@ -59,6 +57,8 @@
     private TenantService tenantService;
     @Autowired
     private EmailService emailService;
+    @Autowired
+    private RedisService redisService;
 
     @PostMapping("/login")
     public R login(@RequestBody LoginParam param, HttpServletRequest request) {
@@ -90,12 +90,13 @@
         if (null != userService.getByEmail(email, null)) {
             return R.error("Email Already Exist");
         }
-        if (redis.getExpire(EmailType.REGISTER_VERIFY.toString(), email) > (configProperties.getCodeTime() - 60)) {
+        Long expire = redisService.getExpire(EmailType.REGISTER_VERIFY.toString(), email);
+        if (expire > (configProperties.getCodeTime() - 60)) {
             return R.error("Please don't request code too frequently.");
         }
         String code = Utils.randomNumbers(configProperties.getCodeLength());
         if (emailService.sendEmail(email, EmailType.REGISTER_VERIFY, Cools.add("code", code))) {
-            redis.setValue(EmailType.REGISTER_VERIFY.toString(), email, code, configProperties.getCodeTime());
+            redisService.setValue(EmailType.REGISTER_VERIFY.toString(), email, code, configProperties.getCodeTime());
         }
         return R.ok();
     }
@@ -106,7 +107,7 @@
         if (Cools.isEmpty(param.getUsername(), param.getPassword(), param.getEmail(), param.getCode())) {
             return R.parse(BaseRes.PARAM);
         }
-        String cacheCode = redis.getValue(EmailType.REGISTER_VERIFY.toString(), param.getEmail());
+        String cacheCode = redisService.getValue(EmailType.REGISTER_VERIFY.toString(), param.getEmail());
         if (Cools.isEmpty(cacheCode)) {
             return R.error("The verification code has expired.");
         }
diff --git a/rsf-server/src/main/resources/application-dev.yml b/rsf-server/src/main/resources/application-dev.yml
index ea93e7e..c8d7a03 100644
--- a/rsf-server/src/main/resources/application-dev.yml
+++ b/rsf-server/src/main/resources/application-dev.yml
@@ -73,7 +73,5 @@
   host: 127.0.0.1
   password: xltys1995
   port: 6379
-  max: 30
-  min: 10
   timeout: 5000
-  index: 11
\ No newline at end of file
+  index: 15
\ No newline at end of file
diff --git a/rsf-server/src/main/resources/application-prod.yml b/rsf-server/src/main/resources/application-prod.yml
index 890851d..74876c3 100644
--- a/rsf-server/src/main/resources/application-prod.yml
+++ b/rsf-server/src/main/resources/application-prod.yml
@@ -43,12 +43,21 @@
       maxRequestSize: 100MB
   jmx:
     enabled: false
+  mail:
+    from: whatsflow.team@gmail.com
+    host: smtp.gmail.com
+    port: 587
+    username: whatsflow.team@gmail.com
+    password: elpc vfwk twnu uoyy
+    properties:
+      mail:
+        smtp:
+          auth: true
+          starttls.enable: true
 
 redis:
   host: 127.0.0.1
   password: xltys1995
   port: 6379
-  max: 30
-  min: 10
   timeout: 5000
   index: 11
\ No newline at end of file

--
Gitblit v1.9.1