feat: 初次启动

This commit is contained in:
Blizzard
2026-04-27 21:23:13 +08:00
parent e515f6a287
commit bb8ad4d515
148 changed files with 8602 additions and 5678 deletions
@@ -1,13 +1,11 @@
// 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"
"sundynix-micro-go/app/system/api/internal/types"
sysModel "sundynix-micro-go/app/system/model"
"sundynix-micro-go/app/system/rpc/system"
)
type CreateMenuLogic struct {
@@ -21,16 +19,10 @@ func NewCreateMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Create
}
func (l *CreateMenuLogic) CreateMenu(req *types.MenuReq) error {
menu := sysModel.SundynixMenu{
ParentID: req.ParentId, Category: req.Category, Name: req.Name, Title: req.Title,
_, err := l.svcCtx.SystemRpc.CreateMenu(l.ctx, &system.MenuReq{
ParentId: req.ParentId, Category: int32(req.Category), Name: req.Name, Title: req.Title,
Code: req.Code, Path: req.Path, Permission: req.Permission, Locale: req.Locale,
Icon: req.Icon, Sort: req.Sort,
}
if menu.ParentID == "" {
menu.ParentID = "0"
}
if err := l.svcCtx.DB.Create(&menu).Error; err != nil {
return fmt.Errorf("创建菜单失败")
}
return nil
Icon: req.Icon, Sort: int32(req.Sort),
})
return err
}
@@ -1,13 +1,11 @@
// 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"
"sundynix-micro-go/app/system/api/internal/types"
sysModel "sundynix-micro-go/app/system/model"
"sundynix-micro-go/app/system/rpc/system"
)
type DeleteMenuLogic struct {
@@ -21,8 +19,6 @@ func NewDeleteMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Delete
}
func (l *DeleteMenuLogic) DeleteMenu(req *types.IdsReq) error {
if err := l.svcCtx.DB.Where("id IN ?", req.Ids).Delete(&sysModel.SundynixMenu{}).Error; err != nil {
return fmt.Errorf("删除菜单失败")
}
return nil
_, err := l.svcCtx.SystemRpc.DeleteMenu(l.ctx, &system.IdsReq{Ids: req.Ids})
return err
}
@@ -1,13 +1,11 @@
// 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"
"sundynix-micro-go/app/system/api/internal/types"
sysModel "sundynix-micro-go/app/system/model"
"sundynix-micro-go/app/system/rpc/system"
)
type GetMenuByRoleLogic struct {
@@ -20,10 +18,10 @@ func NewGetMenuByRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Get
return &GetMenuByRoleLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
}
func (l *GetMenuByRoleLogic) GetMenuByRole(req *types.IdReq) (resp interface{}, err error) {
var role sysModel.SundynixRole
if err := l.svcCtx.DB.Preload("Menus").Where("id = ?", req.Id).First(&role).Error; err != nil {
return nil, fmt.Errorf("查询角色菜单失败")
func (l *GetMenuByRoleLogic) GetMenuByRole(req *types.IdReq) (interface{}, error) {
resp, err := l.svcCtx.SystemRpc.GetMenusByRoleId(l.ctx, &system.GetMenusByRoleIdReq{RoleId: req.Id})
if err != nil {
return nil, err
}
return role.Menus, nil
return resp.Menus, nil
}
@@ -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
}
@@ -1,13 +1,11 @@
// 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"
"sundynix-micro-go/app/system/api/internal/types"
sysModel "sundynix-micro-go/app/system/model"
"sundynix-micro-go/app/system/rpc/system"
)
type UpdateMenuLogic struct {
@@ -21,41 +19,10 @@ func NewUpdateMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Update
}
func (l *UpdateMenuLogic) UpdateMenu(req *types.MenuUpdateReq) error {
updates := map[string]interface{}{}
if req.ParentId != "" {
updates["parent_id"] = req.ParentId
}
if req.Name != "" {
updates["name"] = req.Name
}
if req.Title != "" {
updates["title"] = req.Title
}
if req.Code != "" {
updates["code"] = req.Code
}
if req.Path != "" {
updates["path"] = req.Path
}
if req.Permission != "" {
updates["permission"] = req.Permission
}
if req.Locale != "" {
updates["locale"] = req.Locale
}
if req.Icon != "" {
updates["icon"] = req.Icon
}
if req.Sort > 0 {
updates["sort"] = req.Sort
}
if req.Category > 0 {
updates["category"] = req.Category
}
if len(updates) > 0 {
if err := l.svcCtx.DB.Model(&sysModel.SundynixMenu{}).Where("id = ?", req.Id).Updates(updates).Error; err != nil {
return fmt.Errorf("更新菜单失败")
}
}
return nil
_, err := l.svcCtx.SystemRpc.UpdateMenu(l.ctx, &system.MenuUpdateReq{
Id: req.Id, ParentId: req.ParentId, Category: int32(req.Category), Name: req.Name, Title: req.Title,
Code: req.Code, Path: req.Path, Permission: req.Permission, Locale: req.Locale,
Icon: req.Icon, Sort: int32(req.Sort),
})
return err
}