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.4 KiB
60 lines
1.4 KiB
package user
|
|
|
|
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 GetUserListLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 获取用户列表
|
|
func NewGetUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserListLogic {
|
|
return &GetUserListLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetUserListLogic) GetUserList(req *types.UserListRequest) (resp *types.UserListResponse, err error) {
|
|
// 查询数据库
|
|
users, total, err := model.FindList(l.ctx, l.svcCtx.DB,
|
|
int64(req.Page), int64(req.PageSize), req.Keyword, int64(req.Status))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("查询用户列表失败: %v", err)
|
|
}
|
|
|
|
// 转换为返回类型
|
|
list := make([]types.UserInfo, 0, len(users))
|
|
for _, user := range users {
|
|
list = append(list, types.UserInfo{
|
|
Id: user.Id,
|
|
Username: user.Username,
|
|
Email: user.Email,
|
|
Phone: user.Phone,
|
|
Role: user.Role,
|
|
Source: user.Source,
|
|
Remark: user.Remark,
|
|
Status: int(user.Status),
|
|
CreatedAt: user.CreatedAt.Format("2006-01-02 15:04:05"),
|
|
UpdatedAt: user.UpdatedAt.Format("2006-01-02 15:04:05"),
|
|
})
|
|
}
|
|
|
|
resp = &types.UserListResponse{
|
|
Total: total,
|
|
List: list,
|
|
}
|
|
|
|
return resp, nil
|
|
}
|
|
|