feat: 初次启动
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package role
|
||||
|
||||
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 GetRoleListLogic struct {
|
||||
@@ -20,23 +18,12 @@ func NewGetRoleListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRo
|
||||
return &GetRoleListLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *GetRoleListLogic) GetRoleList(req *types.RoleListReq) (resp interface{}, err error) {
|
||||
var roles []sysModel.SundynixRole
|
||||
var total int64
|
||||
db := l.svcCtx.DB.Model(&sysModel.SundynixRole{})
|
||||
if req.Name != "" {
|
||||
db = db.Where("name LIKE ?", "%"+req.Name+"%")
|
||||
func (l *GetRoleListLogic) GetRoleList(req *types.RoleListReq) (interface{}, error) {
|
||||
resp, err := l.svcCtx.SystemRpc.GetRoleList(l.ctx, &system.RoleListReq{
|
||||
Current: int32(req.Current), PageSize: int32(req.PageSize), Name: req.Name,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
db.Count(&total)
|
||||
current, pageSize := req.Current, req.PageSize
|
||||
if current <= 0 {
|
||||
current = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
if err := db.Preload("Menus").Offset((current - 1) * pageSize).Limit(pageSize).Order("sort").Find(&roles).Error; err != nil {
|
||||
return nil, fmt.Errorf("查询角色列表失败")
|
||||
}
|
||||
return map[string]interface{}{"list": roles, "total": total, "current": current, "size": pageSize}, nil
|
||||
return map[string]interface{}{"list": resp.List, "total": resp.Total}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user