浏览代码

feat:常用功能

wangshan 2 年之前
父节点
当前提交
71d756f815

+ 6 - 13
entity/user.go

@@ -14,9 +14,8 @@ import (
 
 const (
 	RedisCode         = "newother"
-	RedisMenuKey      = "jy_workdesktopmenu_%s_%s_%s_%s"
-	UserPowerRedisKey = "jy_userpowerredis_%s_%d_%d_%s"
-	UserEntIdKey      = "jy_userentid_%s_%d_%s"
+	RedisMenuKey      = "jy_workdesktopmenu_%s_%s_%s"
+	UserPowerRedisKey = "jy_userpowerredis_%s_%d_%s"
 	UserRegisterTime  = "jy_userregistertime_%s"
 )
 
@@ -53,7 +52,7 @@ func (m *WorkDesktopMenu) AutoUserPowerInfo() map[string]int {
 	 */
 	var UserPowerMap = map[string]int{}
 	//redis newother 查询是否存在用户功能信息
-	userPowerRedisKey := fmt.Sprintf(UserPowerRedisKey, m.AppId, time.Now().Day(), m.EntId, m.UserId)
+	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 {
@@ -211,23 +210,17 @@ func (m *WorkDesktopMenu) AutoUserPowerInfo() map[string]int {
 		bytes, err := json.Marshal(UserPowerMap)
 		if err == nil && len(bytes) > 0 {
 			redis.PutBytes(RedisCode, userPowerRedisKey, &bytes, ConfigJson.InternalTime)
-			if m.EntId > 0 {
-				//商机管理用户entId 缓存 --- 用户判断 下次是否是当前企业
-				userEntIdKey := fmt.Sprintf(UserEntIdKey, m.AppId, time.Now().Day(), m.UserId)
-				redis.Put(RedisCode, userEntIdKey, m.EntId, ConfigJson.InternalTime)
-			}
 		}
 	}
 	return UserPowerMap
 }
 
 // ClearUserPowerFunc clear One
-func ClearUserPowerFunc(userId, appId, entId string) {
-	entIdInt, _ := strconv.Atoi(entId)
-	userPowerRedisKey := fmt.Sprintf(UserPowerRedisKey, appId, time.Now().Day(), entIdInt, userId)
+func ClearUserPowerFunc(userId, appId string) {
+	userPowerRedisKey := fmt.Sprintf(UserPowerRedisKey, appId, time.Now().Day(), userId)
 	redis.Del(RedisCode, userPowerRedisKey)
 	for _, v := range []string{"PC", "APP", "WX"} {
-		RedisMenuKey := fmt.Sprintf(RedisMenuKey, appId, v, userId, entId)
+		RedisMenuKey := fmt.Sprintf(RedisMenuKey, appId, v, userId)
 		redis.Del(RedisCode, RedisMenuKey)
 	}
 }

+ 16 - 6
entity/workDesktop.go

@@ -125,9 +125,9 @@ func (m *WorkDesktopMenu) GetMenuTreeData() error {
 				menu.AdditionalInfo = additional
 			}
 		}
-		if capitalinfo := MC.ObjToString(v["capitalinfo"]); capitalinfo != "" {
+		if capitalInfo := MC.ObjToString(v["capitalinfo"]); capitalInfo != "" {
 			additional := Additional{}
-			if json.Unmarshal([]byte(capitalinfo), &additional) == nil {
+			if json.Unmarshal([]byte(capitalInfo), &additional) == nil {
 				menu.CapitalInfo = additional
 			}
 		}
@@ -385,19 +385,29 @@ func CommonlyUpdate(in *pb.WorkDesktopComprehensiveReq) (B bool, M string) {
 	//更新此用户设置的常用功能
 	if B = BaseMysql.ExecTx("常用功能批量更新", func(tx *sql.Tx) bool {
 		//查询此用户常用功能是否已存在记录
-		var id = 0
-		existingData := BaseMysql.SelectBySqlByTx(tx, `SELECT id  FROM `+WorkCommonly+` WHERE base_userid = ? AND appid = ? AND field = ?  ORDER BY id DESC `, in.NewUserId, in.AppId, in.ActionMode)
+		var (
+			id           = 0
+			existingData *[]map[string]interface{}
+		)
+		//P278 身份切换  常用功能和职业id 绑定
+		existingData = BaseMysql.SelectBySqlByTx(tx, `SELECT id  FROM `+WorkCommonly+` WHERE base_userid = ? AND appid = ? AND field = ? AND userid = ?  ORDER BY id DESC `, in.NewUserId, in.AppId, in.ActionMode, in.UserId)
 		if existingData != nil && len(*existingData) > 0 {
 			id = MC.IntAll((*existingData)[0]["id"])
+		} else {
+			//P278 之前版本查询逻辑
+			existingData = BaseMysql.SelectBySqlByTx(tx, `SELECT id  FROM `+WorkCommonly+` WHERE base_userid = ? AND appid = ? AND field = ?  ORDER BY id DESC `, in.NewUserId, in.AppId, in.ActionMode)
+			if existingData != nil && len(*existingData) > 0 {
+				id = MC.IntAll((*existingData)[0]["id"])
+			}
 		}
 		switch {
 		case id > 0: //更新
-			if BaseMysql.UpdateOrDeleteBySqlByTx(tx, `UPDATE `+WorkCommonly+` SET value = ?  WHERE id = ?`, strings.Join(ids, ","), id) < 0 {
+			if BaseMysql.UpdateOrDeleteBySqlByTx(tx, `UPDATE `+WorkCommonly+` SET value = ?,userid = ?  WHERE id = ?`, strings.Join(ids, ","), in.UserId, id) < 0 {
 				logx.Info("常用功能-更新数据失败")
 				return false
 			}
 		default: //插入
-			if BaseMysql.InsertBySqlByTx(tx, `INSERT INTO `+WorkCommonly+`  (appid,base_userid,platform,field,value) VALUES (?,?,?,?,?)`, in.AppId, in.NewUserId, in.Platform, in.ActionMode, strings.Join(ids, ",")) < 0 {
+			if BaseMysql.InsertBySqlByTx(tx, `INSERT INTO `+WorkCommonly+`  (appid,base_userid,platform,field,value,userid) VALUES (?,?,?,?,?,?)`, in.AppId, in.NewUserId, in.Platform, in.ActionMode, strings.Join(ids, ","), in.UserId) < 0 {
 				logx.Info("常用功能-插入数据失败")
 				return false
 			}

+ 2 - 2
rpc/internal/logic/workdesktopclearuserinfologic.go

@@ -24,12 +24,12 @@ func NewWorkDesktopClearUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceCo
 	}
 }
 
-// 手动清除用户功能内存信息
+// WorkDesktopClearUserInfo 手动清除用户功能内存信息
 func (l *WorkDesktopClearUserInfoLogic) WorkDesktopClearUserInfo(in *pb.WorkDesktopClearUserInfoReq) (*pb.WorkDesktopComprehensiveResp, error) {
 	//in.UserIds 不为空;清此用户内存信息
 	if in.UserIds != "" {
 		for _, uv := range strings.Split(in.UserIds, ",") {
-			go entity.ClearUserPowerFunc(uv, in.AppId, in.EntId)
+			go entity.ClearUserPowerFunc(uv, in.AppId)
 		}
 	}
 	return &pb.WorkDesktopComprehensiveResp{}, nil

+ 2 - 0
rpc/internal/logic/workdesktopmenuinfologic.go

@@ -1,6 +1,7 @@
 package logic
 
 import (
+	MC "app.yhyue.com/moapp/jybase/common"
 	"bp.jydev.jianyu360.cn/BaseService/userCenter/service"
 	"context"
 
@@ -38,6 +39,7 @@ func (l *WorkDesktopMenuInfoLogic) WorkDesktopMenuInfo(in *pb.WorkDesktopMenuInf
 		errorMsg        = ""
 		menuMode        = "all"
 	)
+	in.UserId = MC.If(in.PositionId != "", in.PositionId, in.UserId).(string) //p278职位id(没有企业 职位id是个人职位id,职位id对应相应的企业)  职位id 慢慢替换 userId
 	//菜单树
 	menuList, err := service.GetWordDesktopMenuTree(in)
 	//菜单模式

+ 24 - 18
service/workDesktop.go

@@ -20,6 +20,7 @@ import (
 //工作桌面--常用功能更新
 //工作桌面--常用功能列表
 func RenewWorkDesktopMenuModeOrCommonly(in *WorkDesktopComprehensiveReq) (r *WorkDesktopComprehensiveResp) {
+	in.UserId = MC.If(in.PositionId != "", in.PositionId, in.UserId).(string) //职位id替换原userId
 	r = &WorkDesktopComprehensiveResp{}
 	switch in.ActionMode {
 	case "commonlyRenew": //常用功能更新
@@ -31,17 +32,19 @@ func RenewWorkDesktopMenuModeOrCommonly(in *WorkDesktopComprehensiveReq) (r *Wor
 	case "commonlyList":
 		//查询常用功能列表
 		in.ActionMode = "commonlyRenew"
-		//existingData := entity.BaseMysql.SelectBySql(`SELECT value  FROM `+entity.WorkCommonly+` WHERE base_userid = ? AND appid = ? AND field = ? AND platform = ?  ORDER BY id DESC `, in.NewUserId, in.AppId, in.ActionMode, in.Platform)
-		//常用功能不再分平台,来自需求
-		existingData := entity.BaseMysql.SelectBySql(`SELECT value  FROM `+entity.WorkCommonly+` WHERE base_userid = ? AND appid = ? AND field = ? ORDER BY id DESC `, in.NewUserId, in.AppId, in.ActionMode)
 		var (
 			pIds []string
 		)
+		//常用功能查看
+		existingData := entity.BaseMysql.SelectBySql(`SELECT value  FROM `+entity.WorkCommonly+` WHERE base_userid = ? AND appid = ? AND field = ? AND userid = ? ORDER BY id DESC `, in.NewUserId, in.AppId, in.ActionMode, in.UserId)
+		if existingData == nil || len(*existingData) == 0 {
+			//P278原查询逻辑
+			existingData = entity.BaseMysql.SelectBySql(`SELECT value  FROM `+entity.WorkCommonly+` WHERE base_userid = ? AND appid = ? AND field = ? ORDER BY id DESC `, in.NewUserId, in.AppId, in.ActionMode)
+		}
 		if existingData != nil && len(*existingData) > 0 {
 			eData := (*existingData)[0]
 			if MC.ObjToString(eData["value"]) != "" {
 				for _, pv := range strings.Split(MC.ObjToString(eData["value"]), ",") {
-					//params = append(params, "?")
 					if pv == "" {
 						continue
 					}
@@ -226,20 +229,23 @@ func GetWorkDesktopMenuMode(in *WorkDesktopMenuInfoReq) (str string, err error)
 
 // GetWordDesktopMenuTree 获取工作桌面菜单树
 func GetWordDesktopMenuTree(in *WorkDesktopMenuInfoReq) ([]*pb.MenuList, error) {
-	if in.EntId != "" {
-		//判断商机管理用户是否切换企业
-		userEntIdKey := fmt.Sprintf(entity.UserEntIdKey, in.AppId, time.Now().Day(), in.UserId)
-		redisEntId := redis.GetInt(entity.RedisCode, userEntIdKey)
-		entId, err := strconv.Atoi(in.EntId)
-		if err == nil && int64(redisEntId) >= 0 && redisEntId != entId {
-			//商机管理用户切换企业---清除用户权限缓存&&清除用户菜单缓存
-			entity.ClearUserPowerFunc(in.UserId, in.AppId, in.EntId)
-		}
-	}
+	//P278 身份切换 此处逻辑已不需要
+	//if in.EntId != "" {
+	//	//判断商机管理用户是否切换企业
+	//	userEntIdKey := fmt.Sprintf(entity.UserEntIdKey, in.AppId, time.Now().Day(), in.UserId)
+	//	redisEntId := redis.GetInt(entity.RedisCode, userEntIdKey)
+	//	entId, err := strconv.Atoi(in.EntId)
+	//	if err == nil && int64(redisEntId) >= 0 && redisEntId != entId {
+	//		//商机管理用户切换企业---清除用户权限缓存&&清除用户菜单缓存
+	//		entity.ClearUserPowerFunc(in.UserId, in.AppId, in.EntId)
+	//	}
+	//}
 	t1 := time.Now()
-	//redis缓存
-	var menuList []*pb.MenuList
-	RedisMenuKey := fmt.Sprintf(entity.RedisMenuKey, in.AppId, in.Platform, in.UserId, in.EntId)
+	//菜单redis缓存
+	var (
+		menuList []*pb.MenuList
+	)
+	RedisMenuKey := fmt.Sprintf(entity.RedisMenuKey, in.AppId, in.Platform, in.UserId)
 	logx.Info("RedisMenuKey:", RedisMenuKey)
 	menuBytes, err := redis.GetBytes(entity.RedisCode, RedisMenuKey)
 	if in.WorkStatus == 0 && err == nil && len(*menuBytes) > 0 {
@@ -255,7 +261,7 @@ func GetWordDesktopMenuTree(in *WorkDesktopMenuInfoReq) ([]*pb.MenuList, error)
 	positionId, _ := strconv.ParseInt(in.PositionId, 10, 64)
 	wdm := &entity.WorkDesktopMenu{
 		MenuTree:     []*entity.JYMenu{},
-		UserId:       in.UserId,
+		UserId:       in.UserId, //userId 会取消,职位id
 		NewUserId:    newUserId,
 		AppId:        in.AppId,
 		EntId:        entId,

+ 2 - 1
service/workDesktop_test.go

@@ -1,6 +1,7 @@
 package service
 
 import (
+	MC "app.yhyue.com/moapp/jybase/common"
 	"context"
 	"fmt"
 	"log"
@@ -66,7 +67,7 @@ func Test_WorkDesktopMenuTree(t *testing.T) {
 	for _, in := range tests {
 		t.Run(in.name, func(t *testing.T) {
 			if !redisMap[in.args.Platform] {
-				RedisMenuKey := fmt.Sprintf(entity.RedisMenuKey, in.args.AppId, in.args.Platform, in.args.UserId, in.args.EntId)
+				RedisMenuKey := fmt.Sprintf(entity.RedisMenuKey, in.args.AppId, in.args.Platform, MC.If(in.args.PositionId != "", in.args.PositionId, in.args.UserId).(string))
 				redis.Del(entity.RedisCode, RedisMenuKey)
 			}
 			res, err := GetWordDesktopMenuTree(in.args)