From 37293925c1e2ebb6d7803b89b4fa79b797bc378f Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期二, 31 十月 2023 13:41:40 +0800
Subject: [PATCH] fix

---
 middleware/refresh_user.go |    8 +++++---
 model/user.go              |    4 ++--
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/middleware/refresh_user.go b/middleware/refresh_user.go
index c1ae38d..c9b5b44 100644
--- a/middleware/refresh_user.go
+++ b/middleware/refresh_user.go
@@ -1,6 +1,7 @@
 package middleware
 
 import (
+	"aps_crm/pkg/logx"
 	"context"
 	"fmt"
 	"sync"
@@ -71,8 +72,10 @@
 			UserID:         userID,
 			lastActiveTime: time.Now().Unix(),
 		}
+		logx.Infof("add active user :%+v", r.Users[userID])
 	} else {
 		r.Users[userID].lastActiveTime = time.Now().Unix()
+		logx.Infof("refresh active time, user:%+v", r.Users[userID])
 	}
 }
 
@@ -88,11 +91,11 @@
 		select {
 		case <-ticker.C:
 			nowTs := time.Now().Unix()
-			fmt.Println("it is time to RemoveInActiveUser:", nowTs)
 			r.mu.RLock()
 			for userID, user := range r.Users {
 				if nowTs-user.lastActiveTime > r.expireSecond {
 					r.mu.Lock()
+					logx.Infof("removed in active user:%+v", user)
 					delete(r.Users, userID)
 					r.mu.Unlock()
 				}
@@ -113,8 +116,6 @@
 	for {
 		select {
 		case <-ticker.C:
-			nowTs := time.Now().Unix()
-			fmt.Println("it is time to RefreshUserInfo:", nowTs)
 			r.mu.RLock()
 			userIds := make([]string, len(r.Users))
 			for userID := range r.Users {
@@ -122,6 +123,7 @@
 			}
 			r.mu.RUnlock()
 			if len(userIds) != 0 {
+				logx.Infof("RefreshUserInfo, user ids: ", userIds)
 				SyncUserInfo(userIds)
 			}
 		case <-r.ctx.Done():
diff --git a/model/user.go b/model/user.go
index 17da6c3..b931f71 100644
--- a/model/user.go
+++ b/model/user.go
@@ -303,13 +303,13 @@
 	} else if old.Username != record.Username ||
 		old.UserType != record.UserType ||
 		old.NickName != record.NickName ||
-		old.SubUserIds != record.SubUserIds {
+		record.SubUserIds != "" && old.SubUserIds != record.SubUserIds {
 		old.Username = record.Username
 		old.UserType = record.UserType
 		old.NickName = record.NickName
 		old.SubUserIds = record.SubUserIds
 		if err := db.Updates(&record).Error; err != nil {
-			return fmt.Errorf("update user err: %v, record: %+v", err, record)
+			return fmt.Errorf("update user err: %v, old record: %+v", err, old)
 		}
 	}
 

--
Gitblit v1.8.0