Chever John 71a2d912e2 feat: initial commit for muyu-apiserver
Go service with gateway, RPC, model layers and k8s deploy configs.

Made-with: Cursor
2026-02-28 15:29:16 +08:00

72 lines
1.8 KiB
Go

package logic
import (
"context"
"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 ListUserLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewListUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListUserLogic {
return &ListUserLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *ListUserLogic) ListUser(in *pb.ListUserReq) (*pb.ListUserResp, error) {
users, total, err := l.svcCtx.UserModel.FindList(l.ctx, in.Page, in.PageSize, in.Username, in.RealName, in.Phone, in.Status)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
list := make([]*pb.UserInfo, 0, len(users))
for _, user := range users {
var roleId, roleName string
userRole, _ := l.svcCtx.UserRoleModel.FindByUserId(l.ctx, user.UserId)
if userRole != nil {
roleId = userRole.RoleId
role, _ := l.svcCtx.RoleModel.FindOneByRoleId(l.ctx, userRole.RoleId)
if role != nil {
roleName = role.RoleName
}
}
var lastLoginTime string
if user.LastLoginTime.Valid {
lastLoginTime = user.LastLoginTime.Time.Format("2006-01-02 15:04:05")
}
list = append(list, &pb.UserInfo{
UserId: user.UserId,
Username: user.Username,
RealName: user.RealName,
Phone: user.Phone,
Email: user.Email,
Avatar: user.Avatar,
Status: user.Status,
RoleId: roleId,
RoleName: roleName,
LastLoginTime: lastLoginTime,
CreatedAt: user.CreatedAt.Format("2006-01-02 15:04:05"),
UpdatedAt: user.UpdatedAt.Format("2006-01-02 15:04:05"),
})
}
return &pb.ListUserResp{
Total: total,
List: list,
}, nil
}