2023-11-15 07:50:18 +00:00
|
|
|
package logic
|
|
|
|
|
|
|
|
import (
|
2023-11-15 08:32:07 +00:00
|
|
|
"fusenapi/constants"
|
|
|
|
"fusenapi/model/gmodel"
|
2023-11-15 07:50:18 +00:00
|
|
|
"fusenapi/utils/auth"
|
|
|
|
"fusenapi/utils/basic"
|
2023-11-15 08:32:07 +00:00
|
|
|
"math"
|
2023-11-15 07:50:18 +00:00
|
|
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"fusenapi/server/ldap-admin/internal/svc"
|
|
|
|
"fusenapi/server/ldap-admin/internal/types"
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
)
|
|
|
|
|
|
|
|
type GetMenusLogic struct {
|
|
|
|
logx.Logger
|
|
|
|
ctx context.Context
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewGetMenusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMenusLogic {
|
|
|
|
return &GetMenusLogic{
|
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
|
ctx: ctx,
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 处理进入前逻辑w,r
|
|
|
|
// func (l *GetMenusLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
|
|
|
// }
|
|
|
|
|
|
|
|
func (l *GetMenusLogic) GetMenus(req *types.GetMenusReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
2023-11-15 08:32:07 +00:00
|
|
|
if req.CurrentPage <= 0 {
|
|
|
|
req.CurrentPage = constants.DEFAULT_PAGE
|
|
|
|
}
|
|
|
|
limit := constants.DEFAULT_PAGE_SIZE
|
|
|
|
status := int64(1)
|
|
|
|
menusReq := gmodel.GetMenuListByParamReq{
|
|
|
|
Name: req.Name,
|
|
|
|
Title: req.Title,
|
|
|
|
Path: req.Path,
|
|
|
|
Status: &status,
|
|
|
|
ParentId: req.ParentId,
|
|
|
|
Sort: "sort DESC",
|
|
|
|
Page: req.CurrentPage,
|
|
|
|
Limit: limit,
|
|
|
|
}
|
|
|
|
menus, total, err := l.svcCtx.AllModels.LdapMenus.GetMenuListByParam(l.ctx, menusReq)
|
|
|
|
if err != nil {
|
|
|
|
logx.Error(err)
|
|
|
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "获取菜单列表失败")
|
|
|
|
}
|
|
|
|
list := make([]types.MenuItem, 0, len(menus))
|
|
|
|
for _, v := range menus {
|
|
|
|
list = append(list, types.MenuItem{
|
|
|
|
Id: v.Id,
|
|
|
|
Name: *v.Name,
|
|
|
|
Title: *v.Title,
|
|
|
|
Icon: *v.Icon,
|
|
|
|
Path: *v.Path,
|
|
|
|
Sort: *v.Sort,
|
|
|
|
ParentId: *v.ParentId,
|
|
|
|
Status: *v.Status,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetMenusRsp{
|
|
|
|
List: list,
|
|
|
|
Meta: types.Meta{
|
|
|
|
TotalCount: total,
|
|
|
|
PageCount: int64(math.Ceil(float64(total) / float64(limit))),
|
|
|
|
CurrentPage: req.CurrentPage,
|
|
|
|
PerPage: limit,
|
|
|
|
},
|
|
|
|
})
|
2023-11-15 07:50:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
|
|
|
// func (l *GetMenusLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
|
|
|
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
|
|
|
// }
|