Răsfoiți Sursa

feat:医械通权限调整

wangshan 2 ani în urmă
părinte
comite
3fc619bac6
5 a modificat fișierele cu 152 adăugiri și 112 ștergeri
  1. 0 16
      entity/ent.go
  2. 23 0
      entity/source.go
  3. 45 29
      entity/user.go
  4. 72 11
      entity/workDesktop.go
  5. 12 56
      service/workDesktop.go

+ 0 - 16
entity/ent.go

@@ -858,19 +858,3 @@ func GetEntByPhone(mys *mysql.Mysql, phone string) (entId, entUserId int64) {
 	}
 	return 0, 0
 }
-
-//获取用户资源信息
-func GetResources(appId, baseUserId string, entId, entUserId int64) []string {
-	baseUserIdInt, _ := strconv.ParseInt(baseUserId, 10, 0)
-	req := &resourcepb.HaspowersReq{
-		EntId:     entId,
-		UserId:    baseUserIdInt,
-		EntUserId: entUserId,
-		Appid:     appId,
-	}
-	powerList, err := ResourceLib.Haspowers(context.Background(), req)
-	if err == nil && len(powerList.Powers) > 0 {
-		return powerList.Powers
-	}
-	return []string{}
-}

+ 23 - 0
entity/source.go

@@ -0,0 +1,23 @@
+package entity
+
+import (
+	resourcepb "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"
+	"context"
+	"strconv"
+)
+
+//获取用户资源信息
+func GetResources(appId, baseUserId string, entId, entUserId int64) []string {
+	baseUserIdInt, _ := strconv.ParseInt(baseUserId, 10, 0)
+	req := &resourcepb.HaspowersReq{
+		EntId:     entId,
+		UserId:    baseUserIdInt,
+		EntUserId: entUserId,
+		Appid:     appId,
+	}
+	powerList, err := ResourceLib.Haspowers(context.Background(), req)
+	if err == nil && len(powerList.Powers) > 0 {
+		return powerList.Powers
+	}
+	return []string{}
+}

+ 45 - 29
entity/user.go

@@ -43,7 +43,7 @@ var (
 *测试用例放的地方不对 待调整
  */
 //用户权限 初始化
-func AutoUserPowerInfo(userId, appId string, entId int64) map[string]int {
+func (m *WorkDesktopMenu) AutoUserPowerInfo() map[string]int {
 	/*
 	* 商机管理--》新版商机管理vs老版商机管理
 	* 大会员--》bigmember_service
@@ -52,7 +52,7 @@ func AutoUserPowerInfo(userId, appId string, entId int64) map[string]int {
 	 */
 	var UserPowerMap = map[string]int{}
 	//redis newother 查询是否存在用户功能信息
-	userPowerRedisKey := fmt.Sprintf(UserPowerRedisKey, appId, time.Now().Day(), 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 {
@@ -60,11 +60,13 @@ func AutoUserPowerInfo(userId, appId string, entId int64) map[string]int {
 		}
 	}
 	//查询用户信息
-	data, ok := Mgo.FindById("user", userId, `{"s_phone":1,"s_m_phone":1,i_member_status":1,“i_member_endtime”:1,"s_member_mainid":1,"i_member_sub_status":1,"i_vip_status":1,"l_vip_endtime":1,"o_vipjy":1,"o_jy":1,"l_registedate":1}`)
+	data, ok := Mgo.FindById("user", m.UserId, `{"s_phone":1,"s_m_phone":1,i_member_status":1,“i_member_endtime”:1,"s_member_mainid":1,"i_member_sub_status":1,"i_vip_status":1,"l_vip_endtime":1,"o_vipjy":1,"o_jy":1,"l_registedate":1}`)
 	if ok && *data != nil && len(*data) > 0 {
 		var (
-			isFree             = true
-			domainBool         = false //第一版领域化权限判断  ;第二版:超级订阅||大会员 到期时间超过90天
+			isFree = true
+			//第一版领域化权限判断  ;第二版:超级订阅||大会员 到期时间超过90天
+			//商机管理服务 前提是超级订阅、大会员、医械通
+			domainBool         = false
 			registerTime int64 = 0
 		)
 		phone, _ := MC.If((*data)["s_phone"] != nil, (*data)["s_phone"], (*data)["s_m_phone"]).(string)
@@ -77,7 +79,7 @@ func AutoUserPowerInfo(userId, appId string, entId int64) map[string]int {
 				for _, entNicheInfo := range *entNicheInfos {
 					//判断是否是当前企业
 					ent_id := MC.Int64All(entNicheInfo["ent_id"])
-					if entId > 0 && ent_id != entId {
+					if m.EntId > 0 && ent_id != m.EntId {
 						continue
 					}
 					//entNicheInfo := (*entNicheInfos)[0]
@@ -103,7 +105,7 @@ func AutoUserPowerInfo(userId, appId string, entId int64) map[string]int {
 			}
 			//大会员
 			if memberStatus := MC.IntAll((*data)["i_member_status"]); memberStatus > 0 || ConfigJson.BigMemberOff {
-				mainUserId := userId
+				mainUserId := m.UserId
 				if memberStatus > 0 {
 					registerTime = MC.Int64All((*data)["i_member_endtime"])
 					domainBool = true
@@ -152,6 +154,13 @@ func AutoUserPowerInfo(userId, appId string, entId int64) map[string]int {
 			if Mysql.CountBySql(`select count(*) from privatedata where phone = ?`, phone) > 0 {
 				UserPowerMap["400"] = 1
 			}
+			//资源中台获取权限
+			powerList := GetResources(m.AppId, m.NewUserId, m.EntId, m.EntUserId)
+			if len(powerList) > 0 {
+				for _, plv := range powerList {
+					UserPowerMap[plv] = 1
+				}
+			}
 			//领域化产品权限
 			//第一版:必须是大会员或者超级订阅用户 且留资 留资表:capital_retention;source = 'medical_domain',未留资提示留资信息
 			//第二版:调资源中台rpc获取用户是否有使用领域化产品的权限 无权限则去购买
@@ -160,7 +169,7 @@ func AutoUserPowerInfo(userId, appId string, entId int64) map[string]int {
 			//2:判断用户是否留资  否:提示用去留资;是:>-3
 			//3:资源中台获取用户权限码判断是否有权限 否:提示用户去联系客服
 			if domainBool {
-				userRegisterTimeKey := fmt.Sprintf(UserRegisterTime, userId)
+				userRegisterTimeKey := fmt.Sprintf(UserRegisterTime, m.UserId)
 				redis.Put(RedisCode, userRegisterTimeKey, strconv.Itoa(int(registerTime)), int(registerTime))
 				UserPowerMap["500"] = 1
 			}
@@ -169,10 +178,10 @@ func AutoUserPowerInfo(userId, appId string, entId int64) map[string]int {
 			bytes, err := json.Marshal(UserPowerMap)
 			if err == nil && len(bytes) > 0 {
 				redis.PutBytes(RedisCode, userPowerRedisKey, &bytes, ConfigJson.InternalTime)
-				if entId > 0 {
+				if m.EntId > 0 {
 					//商机管理用户entId 缓存
-					userEntIdKey := fmt.Sprintf(UserEntIdKey, appId, time.Now().Day(), userId)
-					redis.Put(RedisCode, userEntIdKey, entId, ConfigJson.InternalTime)
+					userEntIdKey := fmt.Sprintf(UserEntIdKey, m.AppId, time.Now().Day(), m.UserId)
+					redis.Put(RedisCode, userEntIdKey, m.EntId, ConfigJson.InternalTime)
 				}
 			}
 		}
@@ -229,8 +238,10 @@ func UserRolePowerInit(strs []string) {
 */
 /*存在超级订阅 或 大会员到期  而医械通未到期的情况*/
 
-// CheckCapitalResources  是否需要留资 且权限验证
-func CheckCapitalResources(menu *JYMenu, wd *WorkDesktopMenu, b bool) (title, content, confirmUrl, confirmText, appType, openType string, isShowCancel, usable bool) {
+// CheckCapitalResources  是否需要留资 且权限验证--弹窗处理
+//b 一级权限(超级订阅、大会员等)
+//p 二级权限(请求资源中台:医械通等)
+func CheckCapitalResources(menu *JYMenu, wd *WorkDesktopMenu, b, p bool) (title, content, confirmUrl, confirmText, appType, openType string, isShowCancel, usable bool) {
 	OverallLock.Lock()
 	userInfo := UserInfoMap[wd.NewUserId]
 	if userInfo == nil {
@@ -283,23 +294,28 @@ func CheckCapitalResources(menu *JYMenu, wd *WorkDesktopMenu, b bool) (title, co
 		if menu.PermissionCode != "" {
 			permissionBool = false
 			if (menu.CapitalCode != "" && capitalBool) || menu.CapitalCode == "" {
-				for _, pv := range strings.Split(menu.PermissionCode, ",") {
-					if userInfo.Permissions[pv] == 0 {
-						userInfo.Permissions[pv] = -1
-						powerList := GetResources(wd.AppId, wd.NewUserId, wd.EntId, wd.EntUserId)
-						if len(powerList) > 0 {
-							for _, plv := range powerList {
-								userInfo.Permissions[plv] = 1
-							}
-						}
-					}
-					if userInfo.Permissions[pv] >= 0 {
-						title = ""
-						permissionBool = true
-						customPopup = false
-						break
-					}
+				if p {
+					title = ""
+					permissionBool = true
+					customPopup = false
 				}
+				//for _, pv := range strings.Split(menu.PermissionCode, ",") {
+				//	if userInfo.Permissions[pv] == 0 {
+				//		userInfo.Permissions[pv] = -1
+				//		powerList := GetResources(wd.AppId, wd.NewUserId, wd.EntId, wd.EntUserId)
+				//		if len(powerList) > 0 {
+				//			for _, plv := range powerList {
+				//				userInfo.Permissions[plv] = 1
+				//			}
+				//		}
+				//	}
+				//	if userInfo.Permissions[pv] >= 0 {
+				//		title = ""
+				//		permissionBool = true
+				//		customPopup = false
+				//		break
+				//	}
+				//}
 			}
 		}
 		//有用户权限 查看功能权限

+ 72 - 11
entity/workDesktop.go

@@ -5,6 +5,8 @@ import (
 	"app.yhyue.com/moapp/jybase/encrypt"
 	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
 	"database/sql"
+	"encoding/json"
+	"errors"
 	"github.com/zeromicro/go-zero/core/logx"
 	"sort"
 	"strconv"
@@ -13,12 +15,14 @@ import (
 
 // WorkDesktopMenu 工作桌面菜单信息
 type WorkDesktopMenu struct {
-	MenuTree  []*JYMenu
-	UserId    string
-	NewUserId string
-	EntId     int64
-	EntUserId int64
-	AppId     string
+	MenuTree     []*JYMenu //菜单
+	UserId       string    //用户id
+	NewUserId    string    //base_userid
+	EntId        int64     //企业id
+	EntUserId    int64     //企业用户id
+	AppId        string    //appid 剑鱼:10000
+	IntranetBool bool      //是否开启内网访问模式
+	Platform     string    //平台来源
 }
 
 // JYMenu 工作桌面菜单内容
@@ -39,7 +43,7 @@ type JYMenu struct {
 	PermissionCode string     //功能代码
 	CapitalCode    string     //留资代码
 	CapitalInfo    Additional //留资弹窗
-	Children       []*JYMenu
+	Children       []*JYMenu  //菜单s
 }
 
 type Additional struct {
@@ -52,6 +56,61 @@ type Additional struct {
 	OpenType     string `json:"openType,optional,omitempty"`
 }
 
+// 获取有效菜单数据
+func (m *WorkDesktopMenu) GetMenuTreeData() error {
+	//tidb数据
+	query := `SELECT * FROM ` + WorkMenu + ` WHERE  appid=? AND status=0 ORDER BY id ASC`
+	//是否开启内网访问数据权限---对应 api 配置文件
+	if m.IntranetBool {
+		query = `SELECT * FROM ` + WorkMenu + ` WHERE  appid=? AND status>=0 ORDER BY id ASC`
+	}
+	menuData := BaseMysql.SelectBySql(query, m.AppId)
+	if menuData == nil || len(*menuData) == 0 {
+		return errors.New("查询数据异常")
+	}
+	for _, v := range *menuData {
+		menu := &JYMenu{
+			Id:             MC.IntAll(v["id"]),
+			Name:           MC.ObjToString(v["name"]),
+			Match:          MC.ObjToString(v["match"]),
+			OrderId:        MC.IntAll(v["orderid"]),
+			ParentId:       MC.IntAll(v["parentid"]),
+			PowerIds:       MC.ObjToString(v["powerids"]),
+			CheckCode:      MC.IntAll(v["checkcode"]),
+			Icon:           MC.ObjToString(v["icon"]),
+			AppType:        MC.ObjToString(v["apptype"]),
+			OpenType:       MC.ObjToString(v["opentype"]),
+			Status:         MC.IntAll(v["status"]),
+			PermissionCode: MC.ObjToString(v["permissioncode"]),
+			CapitalCode:    MC.ObjToString(v["capitalcode"]),
+		}
+		switch m.Platform {
+		case "WX":
+			menu.Url = MC.ObjToString(v["wxurl"])
+		case "APP":
+			menu.Url = MC.ObjToString(v["appurl"])
+		default:
+			menu.Url = MC.ObjToString(v["pcurl"])
+		}
+		if additionalInfo := MC.ObjToString(v["additionalinfo"]); additionalInfo != "" {
+			additional := Additional{}
+			if json.Unmarshal([]byte(additionalInfo), &additional) == nil {
+				menu.AdditionalInfo = additional
+			}
+		}
+		if capitalinfo := MC.ObjToString(v["capitalinfo"]); capitalinfo != "" {
+			additional := Additional{}
+			if json.Unmarshal([]byte(capitalinfo), &additional) == nil {
+				menu.CapitalInfo = additional
+			}
+		}
+		if menu.Id > 0 {
+			m.MenuTree = append(m.MenuTree, menu)
+		}
+	}
+	return nil
+}
+
 // WorkMenuTree 菜单-格式化-tree
 func (m *WorkDesktopMenu) WorkMenuTree(parentId int) (jyMenu []*JYMenu) {
 	jyMenu = make([]*JYMenu, 0)
@@ -155,7 +214,7 @@ func (m *WorkDesktopMenu) WorkMenuFormat() ([]*pb.MenuList, error) {
 							//用户是否需要留资
 							//资源中台获取用户权限--没有权限:title等置空
 							//ResourceLib.PowerHandle()
-							title, content, confirmUrl, confirmText, appType, openType, isShowCancel, feasibility = CheckCapitalResources(tv, m, usable)
+							title, content, confirmUrl, confirmText, appType, openType, isShowCancel, feasibility = CheckCapitalResources(tv, m, usable, m.VerifyPermissions(tv.PermissionCode))
 						}
 						threeLevel := &pb.ThreeLevelMenu{
 							Name:     tv.Name,
@@ -186,7 +245,9 @@ func (m *WorkDesktopMenu) WorkMenuFormat() ([]*pb.MenuList, error) {
 									//用户是否需要留资
 									//资源中台获取用户权限--没有权限:title等置空
 									//ResourceLib.PowerHandle()
-									title, content, confirmUrl, confirmText, appType, openType, isShowCancel, feasibility = CheckCapitalResources(fv, m, usable)
+									//判断资源中台权限
+
+									title, content, confirmUrl, confirmText, appType, openType, isShowCancel, feasibility = CheckCapitalResources(fv, m, usable, m.VerifyPermissions(fv.PermissionCode))
 
 								}
 								threeLevel.Url = MC.If(fv.Url != "", fv.Url, tv.Url).(string)
@@ -194,7 +255,7 @@ func (m *WorkDesktopMenu) WorkMenuFormat() ([]*pb.MenuList, error) {
 								threeLevel.AppType = fv.AppType
 								threeLevel.OpenType = fv.OpenType
 								threeLevel.Usable = feasibility
-								if fv.AdditionalInfo.Title != "" {
+								if title != "" {
 									threeLevel.TipInfo = &pb.TipInfo{
 										Title:        title,
 										Content:      content,
@@ -258,7 +319,7 @@ func (m *WorkDesktopMenu) VerifyPermissions(powerIds string) (b bool) {
 		return true
 	}
 	if len(strings.Split(powerIds, ",")) > 0 {
-		userPower := AutoUserPowerInfo(m.UserId, m.AppId, m.EntId) //m.TimeOut, m.BigMemberOff,
+		userPower := m.AutoUserPowerInfo() //m.TimeOut, m.BigMemberOff,
 		func(powerIds string) {
 			for _, pv := range strings.Split(powerIds, ",") {
 				if userPower[pv] > 0 {

+ 12 - 56
service/workDesktop.go

@@ -8,7 +8,6 @@ import (
 	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
 	. "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter"
 	"encoding/json"
-	"errors"
 	"fmt"
 	"github.com/zeromicro/go-zero/core/logx"
 	"math/rand"
@@ -197,66 +196,23 @@ func GetWordDesktopMenuTree(in *WorkDesktopMenuInfoReq) ([]*pb.MenuList, error)
 			return menuList, nil
 		}
 	}
-	//tidb数据
-	query := `SELECT * FROM ` + entity.WorkMenu + ` WHERE  appid=? AND status=0 ORDER BY id ASC`
-	//是否开启内网访问数据权限
-	if in.IntranetBool {
-		query = `SELECT * FROM ` + entity.WorkMenu + ` WHERE  appid=? AND status>=0 ORDER BY id ASC`
-	}
-	menuData := entity.BaseMysql.SelectBySql(query, in.AppId)
-	if menuData == nil || len(*menuData) == 0 {
-		return nil, errors.New("查询数据异常")
-	}
 	wdm := &entity.WorkDesktopMenu{
-		MenuTree:  []*entity.JYMenu{},
-		UserId:    in.UserId,
-		NewUserId: in.NewUserId,
-		AppId:     in.AppId,
-		EntId:     in.EntId,
-		EntUserId: in.EntUserId,
+		MenuTree:     []*entity.JYMenu{},
+		UserId:       in.UserId,
+		NewUserId:    in.NewUserId,
+		AppId:        in.AppId,
+		EntId:        in.EntId,
+		EntUserId:    in.EntUserId,
+		Platform:     in.Platform,
+		IntranetBool: in.IntranetBool,
 	}
-	for _, v := range *menuData {
-		menu := &entity.JYMenu{
-			Id:             MC.IntAll(v["id"]),
-			Name:           MC.ObjToString(v["name"]),
-			Match:          MC.ObjToString(v["match"]),
-			OrderId:        MC.IntAll(v["orderid"]),
-			ParentId:       MC.IntAll(v["parentid"]),
-			PowerIds:       MC.ObjToString(v["powerids"]),
-			CheckCode:      MC.IntAll(v["checkcode"]),
-			Icon:           MC.ObjToString(v["icon"]),
-			AppType:        MC.ObjToString(v["apptype"]),
-			OpenType:       MC.ObjToString(v["opentype"]),
-			Status:         MC.IntAll(v["status"]),
-			PermissionCode: MC.ObjToString(v["permissioncode"]),
-			CapitalCode:    MC.ObjToString(v["capitalcode"]),
-		}
-		switch in.Platform {
-		case "WX":
-			menu.Url = MC.ObjToString(v["wxurl"])
-		case "APP":
-			menu.Url = MC.ObjToString(v["appurl"])
-		default:
-			menu.Url = MC.ObjToString(v["pcurl"])
-		}
-		if additionalInfo := MC.ObjToString(v["additionalinfo"]); additionalInfo != "" {
-			additional := entity.Additional{}
-			if json.Unmarshal([]byte(additionalInfo), &additional) == nil {
-				menu.AdditionalInfo = additional
-			}
-		}
-		if capitalinfo := MC.ObjToString(v["capitalinfo"]); capitalinfo != "" {
-			additional := entity.Additional{}
-			if json.Unmarshal([]byte(capitalinfo), &additional) == nil {
-				menu.CapitalInfo = additional
-			}
-		}
-		if menu.Id > 0 {
-			wdm.MenuTree = append(wdm.MenuTree, menu)
-		}
+	//获取菜单树的数据
+	if err := wdm.GetMenuTreeData(); err != nil {
+		return nil, err
 	}
 	logx.Info("数据长度:", len(wdm.MenuTree), "-- 查询菜单数据耗时:", time.Since(t1))
 	//jyMenu := wdm.WorkMenuTree(0)
+	//菜单树生成
 	wdm.MenuTree = wdm.WorkMenuTree(0)
 	logx.Info("菜单树生成耗时:", time.Since(t1))
 	menuList, err = wdm.WorkMenuFormat()