You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
1.8 KiB
86 lines
1.8 KiB
// Code scaffolded by goctl. Safe to edit.
|
|
// goctl 1.9.2
|
|
|
|
package menu
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/youruser/base/internal/svc"
|
|
"github.com/youruser/base/internal/types"
|
|
"github.com/youruser/base/model"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type UpdateMenuLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 更新菜单
|
|
func NewUpdateMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateMenuLogic {
|
|
return &UpdateMenuLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *UpdateMenuLogic) UpdateMenu(req *types.UpdateMenuRequest) (resp *types.MenuItem, err error) {
|
|
menu, err := model.MenuFindOne(l.ctx, l.svcCtx.DB, req.Id)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("菜单不存在: %v", err)
|
|
}
|
|
|
|
if req.ParentId != nil {
|
|
menu.ParentId = *req.ParentId
|
|
}
|
|
if req.Name != "" {
|
|
menu.Name = req.Name
|
|
}
|
|
if req.Path != "" {
|
|
menu.Path = req.Path
|
|
}
|
|
if req.Icon != "" {
|
|
menu.Icon = req.Icon
|
|
}
|
|
if req.Component != "" {
|
|
menu.Component = req.Component
|
|
}
|
|
if req.Type != "" {
|
|
menu.Type = req.Type
|
|
}
|
|
if req.SortOrder != nil {
|
|
menu.SortOrder = *req.SortOrder
|
|
}
|
|
if req.Visible != nil {
|
|
menu.Visible = *req.Visible
|
|
}
|
|
if req.Status != nil {
|
|
menu.Status = *req.Status
|
|
}
|
|
|
|
err = model.MenuUpdate(l.ctx, l.svcCtx.DB, menu)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("更新菜单失败: %v", err)
|
|
}
|
|
|
|
return &types.MenuItem{
|
|
Id: menu.Id,
|
|
ParentId: menu.ParentId,
|
|
Name: menu.Name,
|
|
Path: menu.Path,
|
|
Icon: menu.Icon,
|
|
Component: menu.Component,
|
|
Type: menu.Type,
|
|
SortOrder: menu.SortOrder,
|
|
Visible: menu.Visible,
|
|
Status: menu.Status,
|
|
Children: []types.MenuItem{},
|
|
CreatedAt: menu.CreatedAt.Format("2006-01-02 15:04:05"),
|
|
UpdatedAt: menu.UpdatedAt.Format("2006-01-02 15:04:05"),
|
|
}, nil
|
|
}
|
|
|