From 83bfd0bf23c932d97877e895e67ad854fbd7c53b Mon Sep 17 00:00:00 2001
From: wangting <675591594@qq.com>
Date: 星期五, 27 九月 2024 10:03:34 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/redis/RedisService.java |   38 ++++++++++++++++++++++++++------------
 1 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/redis/RedisService.java b/Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/redis/RedisService.java
similarity index 91%
rename from Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/redis/RedisService.java
rename to Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/redis/RedisService.java
index 7172e62..b795342 100644
--- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/redis/RedisService.java
+++ b/Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/redis/RedisService.java
@@ -1,4 +1,4 @@
-package com.vci.web.redis;
+package com.vci.starter.web.redis;
 
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -11,6 +11,7 @@
 import org.springframework.data.redis.serializer.RedisSerializer;
 import org.springframework.data.redis.serializer.StringRedisSerializer;
 import org.springframework.stereotype.Component;
+import org.springframework.stereotype.Service;
 
 import java.io.IOException;
 import java.util.*;
@@ -21,10 +22,9 @@
  * @author dangsn
  **/
 @SuppressWarnings(value = { "unchecked", "rawtypes" })
-@Component
+@Service
 @Slf4j
-public class RedisService
-{
+public class RedisService {
     @Autowired(required = false)
     public RedisTemplate redisTemplate;
 
@@ -393,19 +393,33 @@
     /**
      * 鐢ㄦ埛鐧诲綍
      * @param currentLoggedUserKey
-     * @param username
      */
-    public void userLogin(String currentLoggedUserKey,String username) {
-        redisTemplate.opsForSet().add(currentLoggedUserKey, username);
+    public void increOnlineUser(String currentLoggedUserKey) {
+        // 妫�鏌ラ敭鏄惁瀛樺湪
+        if (!redisTemplate.hasKey(currentLoggedUserKey)) {
+            // 濡傛灉閿笉瀛樺湪锛屽垵濮嬪寲涓�0
+            redisTemplate.opsForValue().set(currentLoggedUserKey, 0);
+        }
+        // 鑷鍦ㄧ嚎鐢ㄦ埛鏁�
+        redisTemplate.opsForValue().increment(currentLoggedUserKey);
     }
 
     /**
      * 鐢ㄦ埛鐧诲嚭
      * @param currentLoggedUserKey
-     * @param username
      */
-    public void userLogout(String currentLoggedUserKey,String username) {
-        redisTemplate.opsForSet().remove(currentLoggedUserKey, username);
+    public void decreOnlineUser(String currentLoggedUserKey) {
+        // 妫�鏌ュ綋鍓嶅湪绾跨敤鎴锋暟
+        String currentLoggedUser = (String)redisTemplate.opsForValue().get(currentLoggedUserKey);
+
+        if (currentLoggedUser != null) {
+            Long currentCount = Long.parseLong((String)redisTemplate.opsForValue().get(currentLoggedUserKey));
+            if(currentCount > 0){
+
+            }
+            // 鑷噺鍦ㄧ嚎鐢ㄦ埛鏁�
+            redisTemplate.opsForValue().decrement(currentLoggedUserKey);
+        }
     }
 
     /**
@@ -413,8 +427,8 @@
      * @param currentLoggedUserKey
      * @return
      */
-    public long getCurrentLoggedUserCount(String currentLoggedUserKey) {
-        return redisTemplate.opsForSet().size(currentLoggedUserKey);
+    public long getCurrentOnlineUserCount(String currentLoggedUserKey) {
+        return Long.parseLong(redisTemplate.opsForValue().get(currentLoggedUserKey).toString());
     }
 
     /**

--
Gitblit v1.9.3