feat: 初次启动
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package menu
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type GetMenuListLogic struct {
|
||||
@@ -19,26 +17,10 @@ func NewGetMenuListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMe
|
||||
return &GetMenuListLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *GetMenuListLogic) GetMenuList() (resp interface{}, err error) {
|
||||
var menus []sysModel.SundynixMenu
|
||||
if err := l.svcCtx.DB.Order("sort").Find(&menus).Error; err != nil {
|
||||
return nil, fmt.Errorf("查询菜单列表失败")
|
||||
func (l *GetMenuListLogic) GetMenuList() (interface{}, error) {
|
||||
resp, err := l.svcCtx.SystemRpc.GetMenuList(l.ctx, &system.IdReq{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 构建树形结构
|
||||
menuMap := make(map[string]*sysModel.SundynixMenu)
|
||||
for i := range menus {
|
||||
menus[i].Children = []*sysModel.SundynixMenu{}
|
||||
menuMap[menus[i].ID] = &menus[i]
|
||||
}
|
||||
var tree []*sysModel.SundynixMenu
|
||||
for _, m := range menuMap {
|
||||
if m.ParentID == "0" || m.ParentID == "" {
|
||||
tree = append(tree, m)
|
||||
} else if parent, ok := menuMap[m.ParentID]; ok {
|
||||
parent.Children = append(parent.Children, m)
|
||||
} else {
|
||||
tree = append(tree, m)
|
||||
}
|
||||
}
|
||||
return tree, nil
|
||||
return resp.Menus, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user