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.
60 lines
1.3 KiB
60 lines
1.3 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 SortMenusLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 批量排序菜单
|
|
func NewSortMenusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SortMenusLogic {
|
|
return &SortMenusLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *SortMenusLogic) SortMenus(req *types.SortMenusRequest) (resp *types.Response, err error) {
|
|
if len(req.Items) == 0 {
|
|
return &types.Response{Code: 0, Message: "ok", Success: true}, nil
|
|
}
|
|
|
|
items := make([]struct {
|
|
Id int64
|
|
SortOrder int
|
|
ParentId int64
|
|
}, len(req.Items))
|
|
|
|
for i, item := range req.Items {
|
|
items[i] = struct {
|
|
Id int64
|
|
SortOrder int
|
|
ParentId int64
|
|
}{
|
|
Id: item.Id,
|
|
SortOrder: item.SortOrder,
|
|
ParentId: item.ParentId,
|
|
}
|
|
}
|
|
|
|
if err := model.MenuBatchUpdateSort(l.ctx, l.svcCtx.DB, items); err != nil {
|
|
return nil, fmt.Errorf("批量更新排序失败: %v", err)
|
|
}
|
|
|
|
return &types.Response{Code: 0, Message: "ok", Success: true}, nil
|
|
}
|
|
|