浏览代码

system: menu update

Yi 6 天之前
父节点
当前提交
b389a63b6c
共有 6 个文件被更改,包括 85 次插入43 次删除
  1. 1 1
      go.mod
  2. 8 0
      go.sum
  3. 71 29
      model/system_menu.go
  4. 0 6
      module/backend/system_service.go
  5. 3 3
      module/backend/system_service_more.go
  6. 2 4
      module/mqtt/mqtt_handle.go

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20250616015302-2c053d0c13a9
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20250616080546-3ebf4d3f0874
 	gitee.com/xuyiping_admin/pkg v0.0.0-20250613101634-36c36a2d27d0
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/eclipse/paho.mqtt.golang v1.4.3

+ 8 - 0
go.sum

@@ -162,6 +162,14 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20250613080456-430ffc4a0af3 h1:c5JtCkem
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250613080456-430ffc4a0af3/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250616015302-2c053d0c13a9 h1:wJWnnwiFEk/Xz5sKTEFBZfzVdmIoK558cZ+WE6YR41o=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250616015302-2c053d0c13a9/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250616065021-b2676e19b8b0 h1:f0mTagOzCakrey5Y945Kz1ws1pRuZJTTZtGSSpKIsjA=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250616065021-b2676e19b8b0/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250616072406-218faa46b2cf h1:ttzKwwveo/hL43KVVFXipdXsQnFXbOM5zNkyi0ZNqdQ=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250616072406-218faa46b2cf/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250616072843-0099184eb8ca h1:VrwccBb2bAZdXR+GZhUALHs8Jb79qKbBa1dn6MNcZGs=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250616072843-0099184eb8ca/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250616080546-3ebf4d3f0874 h1:jD/wa9PorrqH0TDiasHboBdLgmlXw1oFOc0Fly7Fw/s=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250616080546-3ebf4d3f0874/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/pkg v0.0.0-20241108060137-caea58c59f5b h1:w05MxH7yqveRlaRbxHhbif5YjPrJFodRPfOjYhXn7Zk=
 gitee.com/xuyiping_admin/pkg v0.0.0-20241108060137-caea58c59f5b/go.mod h1:8tF25X6pE9WkFCczlNAC0K2mrjwKvhhp02I7o0HtDxY=
 gitee.com/xuyiping_admin/pkg v0.0.0-20250514071642-f92d2ac9a85d h1:vBXmMRggF7mZVPGRDgavZ87igJgkezwX0a3v1/XtIMQ=

+ 71 - 29
model/system_menu.go

@@ -8,31 +8,44 @@ import (
 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 )
 
+const (
+	PermissionBtnAdd    = "permission:btn:add"
+	PermissionBtnEdit   = "permission:btn:edit"
+	PermissionBtnDelete = "permission:btn:delete"
+)
+
+var PermissionBtnMap = map[pasturePb.ButtonType_Kind]string{
+	pasturePb.ButtonType_Add:    PermissionBtnAdd,
+	pasturePb.ButtonType_Edit:   PermissionBtnEdit,
+	pasturePb.ButtonType_Delete: PermissionBtnDelete,
+}
+
 type SystemMenu struct {
-	Id              int64                   `json:"id"`
-	Name            string                  `json:"name"`
-	Title           string                  `json:"title"`
-	Path            string                  `json:"path"`
-	Icon            string                  `json:"icon"`
-	Component       string                  `json:"component"`
-	Redirect        string                  `json:"redirect"`
-	Auths           string                  `json:"auths"`
-	MenuType        pasturePb.MenuType_Kind `json:"menuType"`
-	ParentId        int64                   `json:"parentId"`
-	Rank            int32                   `json:"rank"`
-	ExtraIcon       string                  `json:"extraIcon"`
-	EnterTransition string                  `json:"enterTransition"`
-	ActivePath      string                  `json:"activePath"`
-	FrameSrc        string                  `json:"frameSrc"`
-	FrameLoading    pasturePb.IsShow_Kind   `json:"frameLoading"`
-	Keepalive       pasturePb.IsShow_Kind   `json:"keepalive"`
-	HiddenTag       pasturePb.IsShow_Kind   `json:"hiddenTag"`
-	ShowLink        pasturePb.IsShow_Kind   `json:"showLink"`
-	ShowParent      pasturePb.IsShow_Kind   `json:"showParent"`
-	IsShow          pasturePb.IsShow_Kind   `json:"isShow"`
-	IsDelete        pasturePb.IsShow_Kind   `json:"isDelete"`
-	CreatedAt       int64                   `json:"createdAt"`
-	UpdatedAt       int64                   `json:"updatedAt"`
+	Id              int64                     `json:"id"`
+	Name            string                    `json:"name"`
+	Title           string                    `json:"title"`
+	Path            string                    `json:"path"`
+	Icon            string                    `json:"icon"`
+	Component       string                    `json:"component"`
+	Redirect        string                    `json:"redirect"`
+	Auths           string                    `json:"auths"`
+	MenuType        pasturePb.MenuType_Kind   `json:"menuType"`
+	ButtonType      pasturePb.ButtonType_Kind `json:"buttonType"`
+	ParentId        int64                     `json:"parentId"`
+	Rank            int32                     `json:"rank"`
+	ExtraIcon       string                    `json:"extraIcon"`
+	EnterTransition string                    `json:"enterTransition"`
+	ActivePath      string                    `json:"activePath"`
+	FrameSrc        string                    `json:"frameSrc"`
+	FrameLoading    pasturePb.IsShow_Kind     `json:"frameLoading"`
+	Keepalive       pasturePb.IsShow_Kind     `json:"keepalive"`
+	HiddenTag       pasturePb.IsShow_Kind     `json:"hiddenTag"`
+	ShowLink        pasturePb.IsShow_Kind     `json:"showLink"`
+	ShowParent      pasturePb.IsShow_Kind     `json:"showParent"`
+	IsShow          pasturePb.IsShow_Kind     `json:"isShow"`
+	IsDelete        pasturePb.IsShow_Kind     `json:"isDelete"`
+	CreatedAt       int64                     `json:"createdAt"`
+	UpdatedAt       int64                     `json:"updatedAt"`
 }
 
 func (s *SystemMenu) TableName() string {
@@ -152,22 +165,26 @@ func (s SystemMenuSlice) ToTree() []*pasturePb.MenuTree {
 
 	for i, v := range s {
 		res[i] = &pasturePb.MenuTree{
-			Id:       int32(v.Id),
-			Path:     v.Path,
-			ParentId: int32(v.ParentId),
-			Name:     v.Name,
+			Id:         int32(v.Id),
+			Path:       v.Path,
+			ParentId:   int32(v.ParentId),
+			Name:       v.Name,
+			ButtonType: v.ButtonType,
 			Meta: &pasturePb.MenuMeta{
 				Icon:     v.Icon,
 				Title:    v.Title,
 				Rank:     v.Rank,
 				Roles:    []string{},
 				ShowLink: v.ShowLink == pasturePb.IsShow_Ok,
+				Auths:    make([]string, 0),
 			},
 			Children: make([]*pasturePb.MenuTree, 0),
 		}
 	}
 	// 构建树
-	return buildTree(res)
+	tree := buildTree(res)
+	processMenuType4Nodes(tree)
+	return tree
 }
 
 func buildTree(menuTreeList []*pasturePb.MenuTree) []*pasturePb.MenuTree {
@@ -197,6 +214,31 @@ func findByID(menuTreeList []*pasturePb.MenuTree, id int32) *pasturePb.MenuTree
 	return nil
 }
 
+// 新增函数:处理 menu_type == 4 的节点
+func processMenuType4Nodes(menus []*pasturePb.MenuTree) {
+	// 首先构建一个快速查找表
+	nodeMap := make(map[int32]*pasturePb.MenuTree)
+	buildNodeMap(menus, nodeMap)
+
+	// 遍历所有节点
+	for _, menu := range nodeMap {
+		if menu.MenuType == pasturePb.MenuType_Button && menu.ButtonType > pasturePb.ButtonType_Invalid {
+			parent := nodeMap[menu.ParentId]
+			if parent != nil && parent.Meta != nil {
+				parent.Meta.Auths = append(parent.Meta.Auths, PermissionBtnMap[menu.ButtonType])
+			}
+		}
+	}
+}
+
+// 新增函数:构建节点映射表
+func buildNodeMap(menus []*pasturePb.MenuTree, nodeMap map[int32]*pasturePb.MenuTree) {
+	for _, menu := range menus {
+		nodeMap[menu.Id] = menu
+		buildNodeMap(menu.Children, nodeMap)
+	}
+}
+
 type MenuItem struct {
 	Path     string      `json:"path"`
 	Name     string      `json:"name"`

+ 0 - 6
module/backend/system_service.go

@@ -406,12 +406,6 @@ func (s *StoreEntry) GetSystemUserMenu(ctx context.Context) (*pasturePb.SystemUs
 		return nil, xerr.WithStack(err)
 	}
 
-	zaplog.Info("获取用户菜单权限",
-		zap.Any("user", systemUser),
-		zap.Any("menuIds", menuIds),
-		zap.Any("systemMenuList", systemMenuList),
-		zap.Any("data", model.SystemMenuSlice(systemMenuList).ToTree()),
-	)
 	// 获取菜单权限
 	return &pasturePb.SystemUserMenuTreeResponse{
 		Code: http.StatusOK,

+ 3 - 3
module/backend/system_service_more.go

@@ -529,17 +529,17 @@ func (s *StoreEntry) RoleMenuSave(ctx context.Context, res *pasturePb.SystemRole
 		Where("pasture_id = ?", userModel.AppPasture.Id).
 		First(systemRole).Error; err != nil {
 		if errors.Is(err, gorm.ErrRecordNotFound) {
-			return xerr.Custom("该数据不存在")
+			return xerr.Custom("该角色数据不存在")
 		}
 		return xerr.WithStack(err)
 	}
 
 	if systemRole.IsDelete == pasturePb.IsShow_No {
-		return xerr.Custom("该数据已删除")
+		return xerr.Custom("该角色数据已删除")
 	}
 
 	if systemRole.IsShow == pasturePb.IsShow_No {
-		return xerr.Custom("该数据已禁用")
+		return xerr.Custom("该角色数据已禁用")
 	}
 
 	if err = s.DB.Transaction(func(tx *gorm.DB) error {

+ 2 - 4
module/mqtt/mqtt_handle.go

@@ -38,23 +38,21 @@ func (e *Entry) InitReceiverMapUpdater() {
 	go func() {
 		ticker := time.NewTicker(2 * time.Hour)
 		defer ticker.Stop()
+		zaplog.Info("ReceiverMap updated successfully1")
 		for {
 			select {
 			case <-ticker.C:
 				receiverMutex.Lock()
 				receiverMap = e.FindAppPastureReceiver()
 				receiverMutex.Unlock()
-				zaplog.Info("ReceiverMap updated successfully")
+				zaplog.Info("ReceiverMap updated successfully2")
 			}
 		}
 	}()
 }
 
 func (e *Entry) NeckRingHandle(data []byte) {
-	receiverMutex.Lock()
 	newReceiverMap := receiverMap
-	receiverMutex.Unlock()
-
 	newData := e.MsgDataFormat2(data, newReceiverMap)
 	if newData == nil {
 		return