wangshan 2 жил өмнө
parent
commit
dff6bcd186
2 өөрчлөгдсөн 20 нэмэгдсэн , 16 устгасан
  1. 14 14
      entity/user.go
  2. 6 2
      entity/workDesktop.go

+ 14 - 14
entity/user.go

@@ -1,6 +1,7 @@
 package entity
 
 import (
+	"encoding/json"
 	"fmt"
 	"strconv"
 	"strings"
@@ -52,15 +53,14 @@ func (m *WorkDesktopMenu) AutoUserPowerInfo() map[string]int {
 	* 用户资源 通过 资源中台rpc获取
 	 */
 	var UserPowerMap = map[string]int{}
-	//***P207 权益中台 有缓存 此处缓存删除/
 	//redis newother 查询是否存在用户功能信息
-	//userPowerRedisKey := fmt.Sprintf(UserPowerRedisKey, m.AppId, time.Now().Day(), m.UserId)
-	//bytes, err := redis.GetBytes(RedisCode, userPowerRedisKey)
-	//if err == nil && len(*bytes) > 0 {
-	//	if err = json.Unmarshal(*bytes, &UserPowerMap); err == nil {
-	//		return UserPowerMap
-	//	}
-	//}
+	userPowerRedisKey := fmt.Sprintf(UserPowerRedisKey, m.AppId, time.Now().Day(), m.UserId)
+	bytes, err := redis.GetBytes(RedisCode, userPowerRedisKey)
+	if err == nil && len(*bytes) > 0 {
+		if err = json.Unmarshal(*bytes, &UserPowerMap); err == nil {
+			return UserPowerMap
+		}
+	}
 	//数据库查询 、资源中台获取、权益中台获取 查询用户信息
 	var (
 		registerTime int64
@@ -224,12 +224,12 @@ func (m *WorkDesktopMenu) AutoUserPowerInfo() map[string]int {
 		}
 	}(m.MgoUserId)
 	//缓存
-	//if UserPowerMap != nil {
-	//	bytes, err := json.Marshal(UserPowerMap)
-	//	if err == nil && len(bytes) > 0 {
-	//		redis.PutBytes(RedisCode, userPowerRedisKey, &bytes, ConfigJson.InternalTime)
-	//	}
-	//}
+	if UserPowerMap != nil {
+		bytes, err := json.Marshal(UserPowerMap)
+		if err == nil && len(bytes) > 0 {
+			redis.PutBytes(RedisCode, userPowerRedisKey, &bytes, ConfigJson.InternalTime)
+		}
+	}
 	return UserPowerMap
 }
 

+ 6 - 2
entity/workDesktop.go

@@ -1,6 +1,7 @@
 package entity
 
 import (
+	"app.yhyue.com/moapp/jybase/redis"
 	"database/sql"
 	"encoding/json"
 	"errors"
@@ -8,6 +9,7 @@ import (
 	"sort"
 	"strconv"
 	"strings"
+	"time"
 
 	MC "app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/encrypt"
@@ -325,7 +327,7 @@ func (m *WorkDesktopMenu) WorkMenuFormat() ([]*pb.MenuList, error) {
 		menuList = append(menuList, oneLevel)
 	}
 	//清用户内存信息
-	func(baseUserid int64) {
+	func(baseUserid int64, appId, userId string) {
 		OverallLock.Lock()
 		defer OverallLock.Unlock()
 		userInfo := UserInfoMap[baseUserid]
@@ -334,8 +336,10 @@ func (m *WorkDesktopMenu) WorkMenuFormat() ([]*pb.MenuList, error) {
 			defer userInfo.Lock.Unlock()
 			userInfo.Permissions = map[string]int{}
 			userInfo.Capitals = map[string]int{}
+			//一次菜单请求 一次缓存
+			redis.Del(RedisCode, fmt.Sprintf(UserPowerRedisKey, appId, time.Now().Day(), userId))
 		}
-	}(m.NewUserId)
+	}(m.NewUserId, m.AppId, m.UserId)
 	//bytes, _ := json.MarshalIndent(menuList, "", "   ")
 	//fmt.Printf("%s\n", bytes)
 	return menuList, nil