package logic import ( "context" "strconv" "lone-services/pkg/modelbase" "lone-services/pkg/utils" "lone-services/pkg/validate" user "lone-services/rpc/user/pb" "lone-services/services/user/internal/dao" "lone-services/services/user/internal/model" "lone-services/services/user/internal/svc" "lone-services/services/user/validator" "github.com/zeromicro/go-zero/core/logx" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) type InternalGetUserInfoLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger } func NewInternalGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InternalGetUserInfoLogic { return &InternalGetUserInfoLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } func (l *InternalGetUserInfoLogic) InternalGetUserInfo(in *user.InternalGetUserInfoReq) (*user.InternalGetUserInfoData, error) { var req validator.InternalGetUserInfoValidator if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty { return nil, status.Error(codes.InvalidArgument, msg) } userModel := model.UserModel{}.Init() var row dao.UserRow if err := userModel.GetOne(modelbase.Params{ Eq: map[string]string{"id": strconv.FormatInt(req.UserId, utils.NumberTen)}, }, &row); err != nil { l.Errorf("internal get user info: %v", err) return nil, status.Error(codes.Internal, utils.Fail.Msg) } if row.Id < utils.NumberOne { return nil, status.Error(codes.NotFound, utils.ErrorNotFund.Msg) } out := &user.InternalGetUserInfoData{ Id: row.Id, Mobile: row.Mobile, Name: row.Name, Avatar: row.Avatar, Gender: uint32(row.Gender), Birthday: row.Birthday.DateString(), Status: uint32(row.Status), CredentialType: req.CredentialType, } if req.CredentialType == utils.StringEmpty { return out, nil } eq := map[string]string{ "user_id": strconv.FormatInt(req.UserId, utils.NumberTen), "credential_type": req.CredentialType, "status": strconv.Itoa(int(dao.StatusEnabled)), } if req.SubjectType != utils.StringEmpty { eq["subject_type"] = req.SubjectType } var cred dao.UserCredential credModel := model.UserCredentialModel{}.Init() if err := credModel.GetOne(modelbase.Params{Eq: eq}, &cred); err != nil { l.Errorf("internal get user credential: %v", err) return nil, status.Error(codes.Internal, utils.Fail.Msg) } if cred.Id > utils.NumberZero { out.Identifier = cred.Identifier } return out, nil }