52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
|
|
package logic
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
"muyu-apiserver/model"
|
||
|
|
"muyu-apiserver/pkg/uid"
|
||
|
|
"muyu-apiserver/rpc/system/internal/svc"
|
||
|
|
"muyu-apiserver/rpc/system/pb"
|
||
|
|
|
||
|
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
|
"google.golang.org/grpc/codes"
|
||
|
|
"google.golang.org/grpc/status"
|
||
|
|
)
|
||
|
|
|
||
|
|
type CreateMenuLogic struct {
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
logx.Logger
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewCreateMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateMenuLogic {
|
||
|
|
return &CreateMenuLogic{
|
||
|
|
ctx: ctx,
|
||
|
|
svcCtx: svcCtx,
|
||
|
|
Logger: logx.WithContext(ctx),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *CreateMenuLogic) CreateMenu(in *pb.CreateMenuReq) (*pb.IdResp, error) {
|
||
|
|
menuId := uid.Generate()
|
||
|
|
|
||
|
|
_, err := l.svcCtx.MenuModel.Insert(l.ctx, &model.SysMenu{
|
||
|
|
MenuId: menuId,
|
||
|
|
ParentId: in.ParentId,
|
||
|
|
MenuName: in.MenuName,
|
||
|
|
MenuType: in.MenuType,
|
||
|
|
Path: in.Path,
|
||
|
|
Component: in.Component,
|
||
|
|
Permission: in.Permission,
|
||
|
|
Icon: in.Icon,
|
||
|
|
SortOrder: in.SortOrder,
|
||
|
|
Visible: 1,
|
||
|
|
Status: 1,
|
||
|
|
})
|
||
|
|
if err != nil {
|
||
|
|
return nil, status.Error(codes.Internal, err.Error())
|
||
|
|
}
|
||
|
|
|
||
|
|
return &pb.IdResp{Id: menuId}, nil
|
||
|
|
}
|