851348ed5c
CI / changes (push) Successful in 37s
CI / ad (push) Successful in 1s
CI / admin (push) Successful in 0s
CI / bff (push) Successful in 23s
CI / chore (push) Successful in 0s
CI / equipment (push) Successful in 0s
CI / express (push) Successful in 1s
CI / factory (push) Successful in 0s
CI / message (push) Successful in 0s
CI / order (push) Successful in 1s
CI / payment (push) Successful in 33s
CI / product (push) Successful in 0s
CI / record (push) Successful in 0s
CI / sale (push) Successful in 0s
CI / support (push) Successful in 0s
CI / task (push) Successful in 0s
CI / user (push) Successful in 18s
CI / wecom (push) Successful in 0s
87 lines
2.5 KiB
Go
87 lines
2.5 KiB
Go
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
|
|
}
|