temp
This commit is contained in:
85
apps/user/client/apirequestservice/apirequestservice.go
Normal file
85
apps/user/client/apirequestservice/apirequestservice.go
Normal file
@@ -0,0 +1,85 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.7.2
|
||||
// Source: user.proto
|
||||
|
||||
package apirequestservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/user/user"
|
||||
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type (
|
||||
AddApiRequestRequest = user.AddApiRequestRequest
|
||||
AddApiRequestResponse = user.AddApiRequestResponse
|
||||
ApiRequest = user.ApiRequest
|
||||
Deduction = user.Deduction
|
||||
EmptyResponse = user.EmptyResponse
|
||||
EnterpriseAuthReq = user.EnterpriseAuthReq
|
||||
EnterpriseItem = user.EnterpriseItem
|
||||
GetApiRequestByTransactionIdRequest = user.GetApiRequestByTransactionIdRequest
|
||||
GetApiRequestByTransactionIdResponse = user.GetApiRequestByTransactionIdResponse
|
||||
GetApiRequestsRequest = user.GetApiRequestsRequest
|
||||
GetApiRequestsResponse = user.GetApiRequestsResponse
|
||||
GetDeductionByTransactionIdRequest = user.GetDeductionByTransactionIdRequest
|
||||
GetDeductionByTransactionIdResponse = user.GetDeductionByTransactionIdResponse
|
||||
GetDeductionsRequest = user.GetDeductionsRequest
|
||||
GetDeductionsResponse = user.GetDeductionsResponse
|
||||
GetEnterpriseAuthStatusReq = user.GetEnterpriseAuthStatusReq
|
||||
GetEnterpriseAuthStatusResp = user.GetEnterpriseAuthStatusResp
|
||||
GetPendingEnterpriseReq = user.GetPendingEnterpriseReq
|
||||
GetPendingEnterpriseResp = user.GetPendingEnterpriseResp
|
||||
GetUserInfoResp = user.GetUserInfoResp
|
||||
GetWalletRequest = user.GetWalletRequest
|
||||
GetWalletResponse = user.GetWalletResponse
|
||||
LoginReq = user.LoginReq
|
||||
LoginResp = user.LoginResp
|
||||
PhoneLoginReq = user.PhoneLoginReq
|
||||
RegisterReq = user.RegisterReq
|
||||
ReviewEnterpriseReq = user.ReviewEnterpriseReq
|
||||
UpdateWalletRequest = user.UpdateWalletRequest
|
||||
UpdateWalletResponse = user.UpdateWalletResponse
|
||||
UserInfoReq = user.UserInfoReq
|
||||
UserInfoResp = user.UserInfoResp
|
||||
|
||||
ApiRequestService interface {
|
||||
// 添加API请求记录
|
||||
AddApiRequest(ctx context.Context, in *AddApiRequestRequest, opts ...grpc.CallOption) (*AddApiRequestResponse, error)
|
||||
// 查询API请求记录
|
||||
GetApiRequests(ctx context.Context, in *GetApiRequestsRequest, opts ...grpc.CallOption) (*GetApiRequestsResponse, error)
|
||||
// 查询API请求记录ByTransactionId
|
||||
GetApiRequestByTransactionId(ctx context.Context, in *GetApiRequestByTransactionIdRequest, opts ...grpc.CallOption) (*GetApiRequestByTransactionIdResponse, error)
|
||||
}
|
||||
|
||||
defaultApiRequestService struct {
|
||||
cli zrpc.Client
|
||||
}
|
||||
)
|
||||
|
||||
func NewApiRequestService(cli zrpc.Client) ApiRequestService {
|
||||
return &defaultApiRequestService{
|
||||
cli: cli,
|
||||
}
|
||||
}
|
||||
|
||||
// 添加API请求记录
|
||||
func (m *defaultApiRequestService) AddApiRequest(ctx context.Context, in *AddApiRequestRequest, opts ...grpc.CallOption) (*AddApiRequestResponse, error) {
|
||||
client := user.NewApiRequestServiceClient(m.cli.Conn())
|
||||
return client.AddApiRequest(ctx, in, opts...)
|
||||
}
|
||||
|
||||
// 查询API请求记录
|
||||
func (m *defaultApiRequestService) GetApiRequests(ctx context.Context, in *GetApiRequestsRequest, opts ...grpc.CallOption) (*GetApiRequestsResponse, error) {
|
||||
client := user.NewApiRequestServiceClient(m.cli.Conn())
|
||||
return client.GetApiRequests(ctx, in, opts...)
|
||||
}
|
||||
|
||||
// 查询API请求记录ByTransactionId
|
||||
func (m *defaultApiRequestService) GetApiRequestByTransactionId(ctx context.Context, in *GetApiRequestByTransactionIdRequest, opts ...grpc.CallOption) (*GetApiRequestByTransactionIdResponse, error) {
|
||||
client := user.NewApiRequestServiceClient(m.cli.Conn())
|
||||
return client.GetApiRequestByTransactionId(ctx, in, opts...)
|
||||
}
|
||||
@@ -14,20 +14,37 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
EmptyResponse = user.EmptyResponse
|
||||
EnterpriseAuthReq = user.EnterpriseAuthReq
|
||||
EnterpriseItem = user.EnterpriseItem
|
||||
GetEnterpriseAuthStatusReq = user.GetEnterpriseAuthStatusReq
|
||||
GetEnterpriseAuthStatusResp = user.GetEnterpriseAuthStatusResp
|
||||
GetPendingEnterpriseReq = user.GetPendingEnterpriseReq
|
||||
GetPendingEnterpriseResp = user.GetPendingEnterpriseResp
|
||||
LoginReq = user.LoginReq
|
||||
LoginResp = user.LoginResp
|
||||
PhoneLoginReq = user.PhoneLoginReq
|
||||
RegisterReq = user.RegisterReq
|
||||
ReviewEnterpriseReq = user.ReviewEnterpriseReq
|
||||
UserInfoReq = user.UserInfoReq
|
||||
UserInfoResp = user.UserInfoResp
|
||||
AddApiRequestRequest = user.AddApiRequestRequest
|
||||
AddApiRequestResponse = user.AddApiRequestResponse
|
||||
ApiRequest = user.ApiRequest
|
||||
Deduction = user.Deduction
|
||||
EmptyResponse = user.EmptyResponse
|
||||
EnterpriseAuthReq = user.EnterpriseAuthReq
|
||||
EnterpriseItem = user.EnterpriseItem
|
||||
GetApiRequestByTransactionIdRequest = user.GetApiRequestByTransactionIdRequest
|
||||
GetApiRequestByTransactionIdResponse = user.GetApiRequestByTransactionIdResponse
|
||||
GetApiRequestsRequest = user.GetApiRequestsRequest
|
||||
GetApiRequestsResponse = user.GetApiRequestsResponse
|
||||
GetDeductionByTransactionIdRequest = user.GetDeductionByTransactionIdRequest
|
||||
GetDeductionByTransactionIdResponse = user.GetDeductionByTransactionIdResponse
|
||||
GetDeductionsRequest = user.GetDeductionsRequest
|
||||
GetDeductionsResponse = user.GetDeductionsResponse
|
||||
GetEnterpriseAuthStatusReq = user.GetEnterpriseAuthStatusReq
|
||||
GetEnterpriseAuthStatusResp = user.GetEnterpriseAuthStatusResp
|
||||
GetPendingEnterpriseReq = user.GetPendingEnterpriseReq
|
||||
GetPendingEnterpriseResp = user.GetPendingEnterpriseResp
|
||||
GetUserInfoResp = user.GetUserInfoResp
|
||||
GetWalletRequest = user.GetWalletRequest
|
||||
GetWalletResponse = user.GetWalletResponse
|
||||
LoginReq = user.LoginReq
|
||||
LoginResp = user.LoginResp
|
||||
PhoneLoginReq = user.PhoneLoginReq
|
||||
RegisterReq = user.RegisterReq
|
||||
ReviewEnterpriseReq = user.ReviewEnterpriseReq
|
||||
UpdateWalletRequest = user.UpdateWalletRequest
|
||||
UpdateWalletResponse = user.UpdateWalletResponse
|
||||
UserInfoReq = user.UserInfoReq
|
||||
UserInfoResp = user.UserInfoResp
|
||||
|
||||
Auth interface {
|
||||
// 注册接口
|
||||
|
||||
@@ -14,20 +14,37 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
EmptyResponse = user.EmptyResponse
|
||||
EnterpriseAuthReq = user.EnterpriseAuthReq
|
||||
EnterpriseItem = user.EnterpriseItem
|
||||
GetEnterpriseAuthStatusReq = user.GetEnterpriseAuthStatusReq
|
||||
GetEnterpriseAuthStatusResp = user.GetEnterpriseAuthStatusResp
|
||||
GetPendingEnterpriseReq = user.GetPendingEnterpriseReq
|
||||
GetPendingEnterpriseResp = user.GetPendingEnterpriseResp
|
||||
LoginReq = user.LoginReq
|
||||
LoginResp = user.LoginResp
|
||||
PhoneLoginReq = user.PhoneLoginReq
|
||||
RegisterReq = user.RegisterReq
|
||||
ReviewEnterpriseReq = user.ReviewEnterpriseReq
|
||||
UserInfoReq = user.UserInfoReq
|
||||
UserInfoResp = user.UserInfoResp
|
||||
AddApiRequestRequest = user.AddApiRequestRequest
|
||||
AddApiRequestResponse = user.AddApiRequestResponse
|
||||
ApiRequest = user.ApiRequest
|
||||
Deduction = user.Deduction
|
||||
EmptyResponse = user.EmptyResponse
|
||||
EnterpriseAuthReq = user.EnterpriseAuthReq
|
||||
EnterpriseItem = user.EnterpriseItem
|
||||
GetApiRequestByTransactionIdRequest = user.GetApiRequestByTransactionIdRequest
|
||||
GetApiRequestByTransactionIdResponse = user.GetApiRequestByTransactionIdResponse
|
||||
GetApiRequestsRequest = user.GetApiRequestsRequest
|
||||
GetApiRequestsResponse = user.GetApiRequestsResponse
|
||||
GetDeductionByTransactionIdRequest = user.GetDeductionByTransactionIdRequest
|
||||
GetDeductionByTransactionIdResponse = user.GetDeductionByTransactionIdResponse
|
||||
GetDeductionsRequest = user.GetDeductionsRequest
|
||||
GetDeductionsResponse = user.GetDeductionsResponse
|
||||
GetEnterpriseAuthStatusReq = user.GetEnterpriseAuthStatusReq
|
||||
GetEnterpriseAuthStatusResp = user.GetEnterpriseAuthStatusResp
|
||||
GetPendingEnterpriseReq = user.GetPendingEnterpriseReq
|
||||
GetPendingEnterpriseResp = user.GetPendingEnterpriseResp
|
||||
GetUserInfoResp = user.GetUserInfoResp
|
||||
GetWalletRequest = user.GetWalletRequest
|
||||
GetWalletResponse = user.GetWalletResponse
|
||||
LoginReq = user.LoginReq
|
||||
LoginResp = user.LoginResp
|
||||
PhoneLoginReq = user.PhoneLoginReq
|
||||
RegisterReq = user.RegisterReq
|
||||
ReviewEnterpriseReq = user.ReviewEnterpriseReq
|
||||
UpdateWalletRequest = user.UpdateWalletRequest
|
||||
UpdateWalletResponse = user.UpdateWalletResponse
|
||||
UserInfoReq = user.UserInfoReq
|
||||
UserInfoResp = user.UserInfoResp
|
||||
|
||||
Enterprise interface {
|
||||
// 获取待审核企业列表
|
||||
|
||||
@@ -14,24 +14,42 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
EmptyResponse = user.EmptyResponse
|
||||
EnterpriseAuthReq = user.EnterpriseAuthReq
|
||||
EnterpriseItem = user.EnterpriseItem
|
||||
GetEnterpriseAuthStatusReq = user.GetEnterpriseAuthStatusReq
|
||||
GetEnterpriseAuthStatusResp = user.GetEnterpriseAuthStatusResp
|
||||
GetPendingEnterpriseReq = user.GetPendingEnterpriseReq
|
||||
GetPendingEnterpriseResp = user.GetPendingEnterpriseResp
|
||||
LoginReq = user.LoginReq
|
||||
LoginResp = user.LoginResp
|
||||
PhoneLoginReq = user.PhoneLoginReq
|
||||
RegisterReq = user.RegisterReq
|
||||
ReviewEnterpriseReq = user.ReviewEnterpriseReq
|
||||
UserInfoReq = user.UserInfoReq
|
||||
UserInfoResp = user.UserInfoResp
|
||||
AddApiRequestRequest = user.AddApiRequestRequest
|
||||
AddApiRequestResponse = user.AddApiRequestResponse
|
||||
ApiRequest = user.ApiRequest
|
||||
Deduction = user.Deduction
|
||||
EmptyResponse = user.EmptyResponse
|
||||
EnterpriseAuthReq = user.EnterpriseAuthReq
|
||||
EnterpriseItem = user.EnterpriseItem
|
||||
GetApiRequestByTransactionIdRequest = user.GetApiRequestByTransactionIdRequest
|
||||
GetApiRequestByTransactionIdResponse = user.GetApiRequestByTransactionIdResponse
|
||||
GetApiRequestsRequest = user.GetApiRequestsRequest
|
||||
GetApiRequestsResponse = user.GetApiRequestsResponse
|
||||
GetDeductionByTransactionIdRequest = user.GetDeductionByTransactionIdRequest
|
||||
GetDeductionByTransactionIdResponse = user.GetDeductionByTransactionIdResponse
|
||||
GetDeductionsRequest = user.GetDeductionsRequest
|
||||
GetDeductionsResponse = user.GetDeductionsResponse
|
||||
GetEnterpriseAuthStatusReq = user.GetEnterpriseAuthStatusReq
|
||||
GetEnterpriseAuthStatusResp = user.GetEnterpriseAuthStatusResp
|
||||
GetPendingEnterpriseReq = user.GetPendingEnterpriseReq
|
||||
GetPendingEnterpriseResp = user.GetPendingEnterpriseResp
|
||||
GetUserInfoResp = user.GetUserInfoResp
|
||||
GetWalletRequest = user.GetWalletRequest
|
||||
GetWalletResponse = user.GetWalletResponse
|
||||
LoginReq = user.LoginReq
|
||||
LoginResp = user.LoginResp
|
||||
PhoneLoginReq = user.PhoneLoginReq
|
||||
RegisterReq = user.RegisterReq
|
||||
ReviewEnterpriseReq = user.ReviewEnterpriseReq
|
||||
UpdateWalletRequest = user.UpdateWalletRequest
|
||||
UpdateWalletResponse = user.UpdateWalletResponse
|
||||
UserInfoReq = user.UserInfoReq
|
||||
UserInfoResp = user.UserInfoResp
|
||||
|
||||
User interface {
|
||||
// 获取用户信息
|
||||
UserInfo(ctx context.Context, in *UserInfoReq, opts ...grpc.CallOption) (*UserInfoResp, error)
|
||||
GetUserInfo(ctx context.Context, in *UserInfoReq, opts ...grpc.CallOption) (*GetUserInfoResp, error)
|
||||
GetEnterpriseAuthStatus(ctx context.Context, in *GetEnterpriseAuthStatusReq, opts ...grpc.CallOption) (*GetEnterpriseAuthStatusResp, error)
|
||||
}
|
||||
|
||||
@@ -52,6 +70,11 @@ func (m *defaultUser) UserInfo(ctx context.Context, in *UserInfoReq, opts ...grp
|
||||
return client.UserInfo(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultUser) GetUserInfo(ctx context.Context, in *UserInfoReq, opts ...grpc.CallOption) (*GetUserInfoResp, error) {
|
||||
client := user.NewUserClient(m.cli.Conn())
|
||||
return client.GetUserInfo(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultUser) GetEnterpriseAuthStatus(ctx context.Context, in *GetEnterpriseAuthStatusReq, opts ...grpc.CallOption) (*GetEnterpriseAuthStatusResp, error) {
|
||||
client := user.NewUserClient(m.cli.Conn())
|
||||
return client.GetEnterpriseAuthStatus(ctx, in, opts...)
|
||||
|
||||
91
apps/user/client/walletservice/walletservice.go
Normal file
91
apps/user/client/walletservice/walletservice.go
Normal file
@@ -0,0 +1,91 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.7.2
|
||||
// Source: user.proto
|
||||
|
||||
package walletservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/user/user"
|
||||
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type (
|
||||
AddApiRequestRequest = user.AddApiRequestRequest
|
||||
AddApiRequestResponse = user.AddApiRequestResponse
|
||||
ApiRequest = user.ApiRequest
|
||||
Deduction = user.Deduction
|
||||
EmptyResponse = user.EmptyResponse
|
||||
EnterpriseAuthReq = user.EnterpriseAuthReq
|
||||
EnterpriseItem = user.EnterpriseItem
|
||||
GetApiRequestByTransactionIdRequest = user.GetApiRequestByTransactionIdRequest
|
||||
GetApiRequestByTransactionIdResponse = user.GetApiRequestByTransactionIdResponse
|
||||
GetApiRequestsRequest = user.GetApiRequestsRequest
|
||||
GetApiRequestsResponse = user.GetApiRequestsResponse
|
||||
GetDeductionByTransactionIdRequest = user.GetDeductionByTransactionIdRequest
|
||||
GetDeductionByTransactionIdResponse = user.GetDeductionByTransactionIdResponse
|
||||
GetDeductionsRequest = user.GetDeductionsRequest
|
||||
GetDeductionsResponse = user.GetDeductionsResponse
|
||||
GetEnterpriseAuthStatusReq = user.GetEnterpriseAuthStatusReq
|
||||
GetEnterpriseAuthStatusResp = user.GetEnterpriseAuthStatusResp
|
||||
GetPendingEnterpriseReq = user.GetPendingEnterpriseReq
|
||||
GetPendingEnterpriseResp = user.GetPendingEnterpriseResp
|
||||
GetUserInfoResp = user.GetUserInfoResp
|
||||
GetWalletRequest = user.GetWalletRequest
|
||||
GetWalletResponse = user.GetWalletResponse
|
||||
LoginReq = user.LoginReq
|
||||
LoginResp = user.LoginResp
|
||||
PhoneLoginReq = user.PhoneLoginReq
|
||||
RegisterReq = user.RegisterReq
|
||||
ReviewEnterpriseReq = user.ReviewEnterpriseReq
|
||||
UpdateWalletRequest = user.UpdateWalletRequest
|
||||
UpdateWalletResponse = user.UpdateWalletResponse
|
||||
UserInfoReq = user.UserInfoReq
|
||||
UserInfoResp = user.UserInfoResp
|
||||
|
||||
WalletService interface {
|
||||
// 修改钱包余额
|
||||
UpdateWallet(ctx context.Context, in *UpdateWalletRequest, opts ...grpc.CallOption) (*UpdateWalletResponse, error)
|
||||
// 查询钱包信息
|
||||
GetWallet(ctx context.Context, in *GetWalletRequest, opts ...grpc.CallOption) (*GetWalletResponse, error)
|
||||
// 查询扣款记录
|
||||
GetDeductions(ctx context.Context, in *GetDeductionsRequest, opts ...grpc.CallOption) (*GetDeductionsResponse, error)
|
||||
GetDeductionByTransactionId(ctx context.Context, in *GetDeductionByTransactionIdRequest, opts ...grpc.CallOption) (*GetDeductionByTransactionIdResponse, error)
|
||||
}
|
||||
|
||||
defaultWalletService struct {
|
||||
cli zrpc.Client
|
||||
}
|
||||
)
|
||||
|
||||
func NewWalletService(cli zrpc.Client) WalletService {
|
||||
return &defaultWalletService{
|
||||
cli: cli,
|
||||
}
|
||||
}
|
||||
|
||||
// 修改钱包余额
|
||||
func (m *defaultWalletService) UpdateWallet(ctx context.Context, in *UpdateWalletRequest, opts ...grpc.CallOption) (*UpdateWalletResponse, error) {
|
||||
client := user.NewWalletServiceClient(m.cli.Conn())
|
||||
return client.UpdateWallet(ctx, in, opts...)
|
||||
}
|
||||
|
||||
// 查询钱包信息
|
||||
func (m *defaultWalletService) GetWallet(ctx context.Context, in *GetWalletRequest, opts ...grpc.CallOption) (*GetWalletResponse, error) {
|
||||
client := user.NewWalletServiceClient(m.cli.Conn())
|
||||
return client.GetWallet(ctx, in, opts...)
|
||||
}
|
||||
|
||||
// 查询扣款记录
|
||||
func (m *defaultWalletService) GetDeductions(ctx context.Context, in *GetDeductionsRequest, opts ...grpc.CallOption) (*GetDeductionsResponse, error) {
|
||||
client := user.NewWalletServiceClient(m.cli.Conn())
|
||||
return client.GetDeductions(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultWalletService) GetDeductionByTransactionId(ctx context.Context, in *GetDeductionByTransactionIdRequest, opts ...grpc.CallOption) (*GetDeductionByTransactionIdResponse, error) {
|
||||
client := user.NewWalletServiceClient(m.cli.Conn())
|
||||
return client.GetDeductionByTransactionId(ctx, in, opts...)
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package apirequestservicelogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tianyuan-api/apps/user/internal/model"
|
||||
"tianyuan-api/apps/user/internal/svc"
|
||||
"tianyuan-api/apps/user/user"
|
||||
"tianyuan-api/pkg/sqlutil"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AddApiRequestLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewAddApiRequestLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddApiRequestLogic {
|
||||
return &AddApiRequestLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 添加API请求记录
|
||||
func (l *AddApiRequestLogic) AddApiRequest(in *user.AddApiRequestRequest) (*user.AddApiRequestResponse, error) {
|
||||
chargesValue := int64(0)
|
||||
if in.Charges {
|
||||
chargesValue = 1
|
||||
}
|
||||
parsedTime, err := time.Parse(time.RFC3339Nano, in.Timestamp)
|
||||
if err != nil {
|
||||
// 错误处理,比如日志输出或返回错误
|
||||
parsedTime = time.Now()
|
||||
}
|
||||
_, err = l.svcCtx.ApiRequestsModel.Insert(l.ctx, &model.ApiRequests{
|
||||
TransactionId: in.TransactionId,
|
||||
UserId: in.UserId,
|
||||
ProductCode: in.ProductCode,
|
||||
Status: in.Status,
|
||||
Charges: chargesValue,
|
||||
Remark: sqlutil.StringToNullString(in.Remark),
|
||||
Timestamp: parsedTime,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &user.AddApiRequestResponse{}, nil
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package apirequestservicelogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/user/internal/svc"
|
||||
"tianyuan-api/apps/user/user"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetApiRequestByTransactionIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetApiRequestByTransactionIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetApiRequestByTransactionIdLogic {
|
||||
return &GetApiRequestByTransactionIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 查询API请求记录ByTransactionId
|
||||
func (l *GetApiRequestByTransactionIdLogic) GetApiRequestByTransactionId(in *user.GetApiRequestByTransactionIdRequest) (*user.GetApiRequestByTransactionIdResponse, error) {
|
||||
apiRequest, err := l.svcCtx.ApiRequestsModel.FindOneByTransactionId(l.ctx, in.TransactionId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &user.GetApiRequestByTransactionIdResponse{
|
||||
Id: apiRequest.Id,
|
||||
TransactionId: apiRequest.TransactionId,
|
||||
UserId: apiRequest.UserId,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package apirequestservicelogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/user/internal/svc"
|
||||
"tianyuan-api/apps/user/user"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetApiRequestsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetApiRequestsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetApiRequestsLogic {
|
||||
return &GetApiRequestsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 查询API请求记录
|
||||
func (l *GetApiRequestsLogic) GetApiRequests(in *user.GetApiRequestsRequest) (*user.GetApiRequestsResponse, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &user.GetApiRequestsResponse{}, nil
|
||||
}
|
||||
@@ -72,7 +72,10 @@ func (l *ReviewEnterpriseLogic) ReviewEnterprise(in *user.ReviewEnterpriseReq) (
|
||||
if insertEnterpriseErr != nil {
|
||||
return insertEnterpriseErr
|
||||
}
|
||||
|
||||
_, InsertWalletsTransErr := l.svcCtx.WalletsModel.InsertWalletsTrans(l.ctx, &model.Wallets{UserId: enterpriseAuth.UserId}, session)
|
||||
if InsertWalletsTransErr != nil {
|
||||
return InsertWalletsTransErr
|
||||
}
|
||||
_, createSecretErr := l.svcCtx.SecretRpc.CreateSecret(l.ctx, &secret.CreateSecretRequest{
|
||||
UserId: enterpriseAuth.UserId,
|
||||
})
|
||||
|
||||
41
apps/user/internal/logic/user/getuserinfologic.go
Normal file
41
apps/user/internal/logic/user/getuserinfologic.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package userlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"tianyuan-api/apps/user/internal/svc"
|
||||
"tianyuan-api/apps/user/user"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetUserInfoLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserInfoLogic {
|
||||
return &GetUserInfoLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetUserInfoLogic) GetUserInfo(in *user.UserInfoReq) (*user.GetUserInfoResp, error) {
|
||||
// 查询用户信息
|
||||
users, err := l.svcCtx.UserModel.FindOne(l.ctx, in.UserId)
|
||||
if err != nil {
|
||||
return nil, errors.New("用户不存在")
|
||||
}
|
||||
|
||||
// 正常返回用户和企业信息
|
||||
return &user.GetUserInfoResp{
|
||||
Username: users.Username,
|
||||
Phone: users.Phone,
|
||||
Disable: users.Disable,
|
||||
QuotaExceeded: users.QuotaExceeded,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package walletservicelogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/user/internal/svc"
|
||||
"tianyuan-api/apps/user/user"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetDeductionByTransactionIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetDeductionByTransactionIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDeductionByTransactionIdLogic {
|
||||
return &GetDeductionByTransactionIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetDeductionByTransactionIdLogic) GetDeductionByTransactionId(in *user.GetDeductionByTransactionIdRequest) (*user.GetDeductionByTransactionIdResponse, error) {
|
||||
deduction, err := l.svcCtx.DeductionsModel.FindOneByTransactionId(l.ctx, in.TransactionId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &user.GetDeductionByTransactionIdResponse{
|
||||
Id: deduction.Id,
|
||||
UserId: deduction.UserId,
|
||||
Amount: deduction.Amount,
|
||||
TransactionId: deduction.TransactionId,
|
||||
CreatedAt: deduction.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
}, nil
|
||||
}
|
||||
31
apps/user/internal/logic/walletservice/getdeductionslogic.go
Normal file
31
apps/user/internal/logic/walletservice/getdeductionslogic.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package walletservicelogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/user/internal/svc"
|
||||
"tianyuan-api/apps/user/user"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetDeductionsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetDeductionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDeductionsLogic {
|
||||
return &GetDeductionsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 查询扣款记录
|
||||
func (l *GetDeductionsLogic) GetDeductions(in *user.GetDeductionsRequest) (*user.GetDeductionsResponse, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &user.GetDeductionsResponse{}, nil
|
||||
}
|
||||
31
apps/user/internal/logic/walletservice/getwalletlogic.go
Normal file
31
apps/user/internal/logic/walletservice/getwalletlogic.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package walletservicelogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/user/internal/svc"
|
||||
"tianyuan-api/apps/user/user"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetWalletLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetWalletLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWalletLogic {
|
||||
return &GetWalletLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 查询钱包信息
|
||||
func (l *GetWalletLogic) GetWallet(in *user.GetWalletRequest) (*user.GetWalletResponse, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &user.GetWalletResponse{}, nil
|
||||
}
|
||||
114
apps/user/internal/logic/walletservice/updatewalletlogic.go
Normal file
114
apps/user/internal/logic/walletservice/updatewalletlogic.go
Normal file
@@ -0,0 +1,114 @@
|
||||
package walletservicelogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"tianyuan-api/apps/sentinel/client/product"
|
||||
"tianyuan-api/apps/user/internal/model"
|
||||
"time"
|
||||
|
||||
"tianyuan-api/apps/user/internal/svc"
|
||||
"tianyuan-api/apps/user/user"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateWalletLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdateWalletLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateWalletLogic {
|
||||
return &UpdateWalletLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
const maxRetries = 5 // 最大重试次数
|
||||
// 修改钱包余额
|
||||
func (l *UpdateWalletLogic) UpdateWallet(in *user.UpdateWalletRequest) (*user.UpdateWalletResponse, error) {
|
||||
if !in.Charge {
|
||||
return nil, errors.New("不需要扣款")
|
||||
}
|
||||
// 获取产品信息
|
||||
consumeProduct, getProductByCodeErr := l.svcCtx.ProductRpc.GetProductByCode(l.ctx, &product.GetRecordByCodeRequest{Code: in.ProductCode})
|
||||
if getProductByCodeErr != nil {
|
||||
return nil, getProductByCodeErr
|
||||
}
|
||||
|
||||
// 检查是否已经扣款
|
||||
deduction, FindOneByTransactionIdErr := l.svcCtx.DeductionsModel.FindOneByTransactionId(l.ctx, in.TransactionId)
|
||||
if FindOneByTransactionIdErr != nil {
|
||||
if FindOneByTransactionIdErr == sql.ErrNoRows {
|
||||
} else {
|
||||
// 其他错误,直接返回
|
||||
return nil, FindOneByTransactionIdErr
|
||||
}
|
||||
} else if deduction != nil {
|
||||
// 找到扣款记录,不能重复扣款
|
||||
return nil, errors.New("该订单已扣款")
|
||||
}
|
||||
|
||||
// 启动事务
|
||||
err := l.svcCtx.WalletsModel.TransCtx(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
var err error
|
||||
// 尝试多次更新余额(用于乐观锁)
|
||||
for i := 0; i < maxRetries; i++ {
|
||||
err = l.svcCtx.WalletsModel.UpdateBalance(session, l.ctx, in.UserId, -consumeProduct.ProductPrice)
|
||||
if err == nil {
|
||||
// 成功,退出循环
|
||||
break
|
||||
}
|
||||
if errors.Is(err, model.ErrVersionMismatch) {
|
||||
// 版本号不匹配,重试
|
||||
time.Sleep(100 * time.Millisecond) // 重试前的延迟
|
||||
continue
|
||||
} else {
|
||||
// 其他错误,直接返回
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 更新余额成功后,插入扣款记录
|
||||
_, err = l.svcCtx.DeductionsModel.InsertDeductionsTrans(ctx, &model.Deductions{
|
||||
TransactionId: in.TransactionId,
|
||||
UserId: in.UserId,
|
||||
Amount: consumeProduct.ProductPrice,
|
||||
}, session)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 获取最新的用户余额
|
||||
wallet, err := l.svcCtx.WalletsModel.FindOneByUserId(l.ctx, in.UserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 如果余额小于 0,更新 QuotaExceeded 字段为 1
|
||||
if wallet.Balance < 0 {
|
||||
users, findOneErr := l.svcCtx.UserModel.FindOne(l.ctx, in.UserId)
|
||||
if findOneErr != nil {
|
||||
return nil, findOneErr
|
||||
}
|
||||
users.QuotaExceeded = 1
|
||||
updateErr := l.svcCtx.UserModel.Update(l.ctx, users)
|
||||
if updateErr != nil {
|
||||
return nil, updateErr
|
||||
}
|
||||
}
|
||||
return &user.UpdateWalletResponse{}, nil
|
||||
}
|
||||
27
apps/user/internal/model/apirequestsmodel.go
Normal file
27
apps/user/internal/model/apirequestsmodel.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ ApiRequestsModel = (*customApiRequestsModel)(nil)
|
||||
|
||||
type (
|
||||
// ApiRequestsModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customApiRequestsModel.
|
||||
ApiRequestsModel interface {
|
||||
apiRequestsModel
|
||||
}
|
||||
|
||||
customApiRequestsModel struct {
|
||||
*defaultApiRequestsModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewApiRequestsModel returns a model for the database table.
|
||||
func NewApiRequestsModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) ApiRequestsModel {
|
||||
return &customApiRequestsModel{
|
||||
defaultApiRequestsModel: newApiRequestsModel(conn, c, opts...),
|
||||
}
|
||||
}
|
||||
152
apps/user/internal/model/apirequestsmodel_gen.go
Normal file
152
apps/user/internal/model/apirequestsmodel_gen.go
Normal file
@@ -0,0 +1,152 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// versions:
|
||||
// goctl version: 1.7.2
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
apiRequestsFieldNames = builder.RawFieldNames(&ApiRequests{})
|
||||
apiRequestsRows = strings.Join(apiRequestsFieldNames, ",")
|
||||
apiRequestsRowsExpectAutoSet = strings.Join(stringx.Remove(apiRequestsFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
apiRequestsRowsWithPlaceHolder = strings.Join(stringx.Remove(apiRequestsFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
|
||||
cacheApiRequestsIdPrefix = "cache:apiRequests:id:"
|
||||
cacheApiRequestsTransactionIdPrefix = "cache:apiRequests:transactionId:"
|
||||
)
|
||||
|
||||
type (
|
||||
apiRequestsModel interface {
|
||||
Insert(ctx context.Context, data *ApiRequests) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*ApiRequests, error)
|
||||
FindOneByTransactionId(ctx context.Context, transactionId string) (*ApiRequests, error)
|
||||
Update(ctx context.Context, data *ApiRequests) error
|
||||
Delete(ctx context.Context, id int64) error
|
||||
}
|
||||
|
||||
defaultApiRequestsModel struct {
|
||||
sqlc.CachedConn
|
||||
table string
|
||||
}
|
||||
|
||||
ApiRequests struct {
|
||||
Id int64 `db:"id"` // 请求记录ID
|
||||
TransactionId string `db:"transaction_id"` // 交易ID
|
||||
UserId int64 `db:"user_id"` // 用户ID
|
||||
ProductCode string `db:"product_code"` // 产品编码
|
||||
Status string `db:"status"` // 请求状态:success=成功,failed=失败
|
||||
Charges int64 `db:"charges"` // 是否需要付费
|
||||
Remark sql.NullString `db:"remark"` // 备注
|
||||
Timestamp time.Time `db:"timestamp"` // 请求时间
|
||||
}
|
||||
)
|
||||
|
||||
func newApiRequestsModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultApiRequestsModel {
|
||||
return &defaultApiRequestsModel{
|
||||
CachedConn: sqlc.NewConn(conn, c, opts...),
|
||||
table: "`api_requests`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultApiRequestsModel) Delete(ctx context.Context, id int64) error {
|
||||
data, err := m.FindOne(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
apiRequestsIdKey := fmt.Sprintf("%s%v", cacheApiRequestsIdPrefix, id)
|
||||
apiRequestsTransactionIdKey := fmt.Sprintf("%s%v", cacheApiRequestsTransactionIdPrefix, data.TransactionId)
|
||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
return conn.ExecCtx(ctx, query, id)
|
||||
}, apiRequestsIdKey, apiRequestsTransactionIdKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultApiRequestsModel) FindOne(ctx context.Context, id int64) (*ApiRequests, error) {
|
||||
apiRequestsIdKey := fmt.Sprintf("%s%v", cacheApiRequestsIdPrefix, id)
|
||||
var resp ApiRequests
|
||||
err := m.QueryRowCtx(ctx, &resp, apiRequestsIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", apiRequestsRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultApiRequestsModel) FindOneByTransactionId(ctx context.Context, transactionId string) (*ApiRequests, error) {
|
||||
apiRequestsTransactionIdKey := fmt.Sprintf("%s%v", cacheApiRequestsTransactionIdPrefix, transactionId)
|
||||
var resp ApiRequests
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, apiRequestsTransactionIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `transaction_id` = ? limit 1", apiRequestsRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, transactionId); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Id, nil
|
||||
}, m.queryPrimary)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultApiRequestsModel) Insert(ctx context.Context, data *ApiRequests) (sql.Result, error) {
|
||||
apiRequestsIdKey := fmt.Sprintf("%s%v", cacheApiRequestsIdPrefix, data.Id)
|
||||
apiRequestsTransactionIdKey := fmt.Sprintf("%s%v", cacheApiRequestsTransactionIdPrefix, data.TransactionId)
|
||||
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?)", m.table, apiRequestsRowsExpectAutoSet)
|
||||
return conn.ExecCtx(ctx, query, data.TransactionId, data.UserId, data.ProductCode, data.Status, data.Charges, data.Remark, data.Timestamp)
|
||||
}, apiRequestsIdKey, apiRequestsTransactionIdKey)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultApiRequestsModel) Update(ctx context.Context, newData *ApiRequests) error {
|
||||
data, err := m.FindOne(ctx, newData.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
apiRequestsIdKey := fmt.Sprintf("%s%v", cacheApiRequestsIdPrefix, data.Id)
|
||||
apiRequestsTransactionIdKey := fmt.Sprintf("%s%v", cacheApiRequestsTransactionIdPrefix, data.TransactionId)
|
||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, apiRequestsRowsWithPlaceHolder)
|
||||
return conn.ExecCtx(ctx, query, newData.TransactionId, newData.UserId, newData.ProductCode, newData.Status, newData.Charges, newData.Remark, newData.Timestamp, newData.Id)
|
||||
}, apiRequestsIdKey, apiRequestsTransactionIdKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultApiRequestsModel) formatPrimary(primary any) string {
|
||||
return fmt.Sprintf("%s%v", cacheApiRequestsIdPrefix, primary)
|
||||
}
|
||||
|
||||
func (m *defaultApiRequestsModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", apiRequestsRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary)
|
||||
}
|
||||
|
||||
func (m *defaultApiRequestsModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
52
apps/user/internal/model/deductionsmodel.go
Normal file
52
apps/user/internal/model/deductionsmodel.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ DeductionsModel = (*customDeductionsModel)(nil)
|
||||
|
||||
type (
|
||||
// DeductionsModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customDeductionsModel.
|
||||
DeductionsModel interface {
|
||||
deductionsModel
|
||||
InsertDeductionsTrans(ctx context.Context, deductions *Deductions, session sqlx.Session) (sql.Result, error)
|
||||
}
|
||||
|
||||
customDeductionsModel struct {
|
||||
*defaultDeductionsModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewDeductionsModel returns a model for the database table.
|
||||
func NewDeductionsModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) DeductionsModel {
|
||||
return &customDeductionsModel{
|
||||
defaultDeductionsModel: newDeductionsModel(conn, c, opts...),
|
||||
}
|
||||
}
|
||||
func (m *customDeductionsModel) InsertDeductionsTrans(ctx context.Context, deductions *Deductions, session sqlx.Session) (sql.Result, error) {
|
||||
|
||||
query := fmt.Sprintf("INSERT INTO %s (%s) VALUES (?, ?, ?)", m.table, deductionsRowsExpectAutoSet)
|
||||
ret, err := session.ExecCtx(ctx, query, deductions.UserId, deductions.Amount, deductions.TransactionId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
deductionsTransactionIdKey := fmt.Sprintf("%s%v", cacheDeductionsTransactionIdPrefix, deductions.TransactionId)
|
||||
// 2. 更新缓存,保证所有缓存操作成功
|
||||
cacheKeys := []string{deductionsTransactionIdKey}
|
||||
cacheErrors := make([]error, len(cacheKeys))
|
||||
|
||||
cacheErrors[0] = m.DelCacheCtx(ctx, deductionsTransactionIdKey)
|
||||
// 3. 检查缓存操作是否全部成功
|
||||
for _, cacheErr := range cacheErrors {
|
||||
if cacheErr != nil {
|
||||
return nil, cacheErr // 返回第一个缓存更新失败的错误
|
||||
}
|
||||
}
|
||||
return ret, err
|
||||
}
|
||||
149
apps/user/internal/model/deductionsmodel_gen.go
Normal file
149
apps/user/internal/model/deductionsmodel_gen.go
Normal file
@@ -0,0 +1,149 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// versions:
|
||||
// goctl version: 1.7.2
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
deductionsFieldNames = builder.RawFieldNames(&Deductions{})
|
||||
deductionsRows = strings.Join(deductionsFieldNames, ",")
|
||||
deductionsRowsExpectAutoSet = strings.Join(stringx.Remove(deductionsFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
deductionsRowsWithPlaceHolder = strings.Join(stringx.Remove(deductionsFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
|
||||
cacheDeductionsIdPrefix = "cache:deductions:id:"
|
||||
cacheDeductionsTransactionIdPrefix = "cache:deductions:transactionId:"
|
||||
)
|
||||
|
||||
type (
|
||||
deductionsModel interface {
|
||||
Insert(ctx context.Context, data *Deductions) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*Deductions, error)
|
||||
FindOneByTransactionId(ctx context.Context, transactionId string) (*Deductions, error)
|
||||
Update(ctx context.Context, data *Deductions) error
|
||||
Delete(ctx context.Context, id int64) error
|
||||
}
|
||||
|
||||
defaultDeductionsModel struct {
|
||||
sqlc.CachedConn
|
||||
table string
|
||||
}
|
||||
|
||||
Deductions struct {
|
||||
Id int64 `db:"id"` // 扣款记录ID
|
||||
UserId int64 `db:"user_id"` // 用户ID
|
||||
Amount float64 `db:"amount"` // 扣款金额
|
||||
TransactionId string `db:"transaction_id"` // 交易流水号
|
||||
CreatedAt time.Time `db:"created_at"` // 扣款时间
|
||||
}
|
||||
)
|
||||
|
||||
func newDeductionsModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultDeductionsModel {
|
||||
return &defaultDeductionsModel{
|
||||
CachedConn: sqlc.NewConn(conn, c, opts...),
|
||||
table: "`deductions`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultDeductionsModel) Delete(ctx context.Context, id int64) error {
|
||||
data, err := m.FindOne(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
deductionsIdKey := fmt.Sprintf("%s%v", cacheDeductionsIdPrefix, id)
|
||||
deductionsTransactionIdKey := fmt.Sprintf("%s%v", cacheDeductionsTransactionIdPrefix, data.TransactionId)
|
||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
return conn.ExecCtx(ctx, query, id)
|
||||
}, deductionsIdKey, deductionsTransactionIdKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultDeductionsModel) FindOne(ctx context.Context, id int64) (*Deductions, error) {
|
||||
deductionsIdKey := fmt.Sprintf("%s%v", cacheDeductionsIdPrefix, id)
|
||||
var resp Deductions
|
||||
err := m.QueryRowCtx(ctx, &resp, deductionsIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", deductionsRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultDeductionsModel) FindOneByTransactionId(ctx context.Context, transactionId string) (*Deductions, error) {
|
||||
deductionsTransactionIdKey := fmt.Sprintf("%s%v", cacheDeductionsTransactionIdPrefix, transactionId)
|
||||
var resp Deductions
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, deductionsTransactionIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `transaction_id` = ? limit 1", deductionsRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, transactionId); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Id, nil
|
||||
}, m.queryPrimary)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultDeductionsModel) Insert(ctx context.Context, data *Deductions) (sql.Result, error) {
|
||||
deductionsIdKey := fmt.Sprintf("%s%v", cacheDeductionsIdPrefix, data.Id)
|
||||
deductionsTransactionIdKey := fmt.Sprintf("%s%v", cacheDeductionsTransactionIdPrefix, data.TransactionId)
|
||||
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?)", m.table, deductionsRowsExpectAutoSet)
|
||||
return conn.ExecCtx(ctx, query, data.UserId, data.Amount, data.TransactionId)
|
||||
}, deductionsIdKey, deductionsTransactionIdKey)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultDeductionsModel) Update(ctx context.Context, newData *Deductions) error {
|
||||
data, err := m.FindOne(ctx, newData.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
deductionsIdKey := fmt.Sprintf("%s%v", cacheDeductionsIdPrefix, data.Id)
|
||||
deductionsTransactionIdKey := fmt.Sprintf("%s%v", cacheDeductionsTransactionIdPrefix, data.TransactionId)
|
||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, deductionsRowsWithPlaceHolder)
|
||||
return conn.ExecCtx(ctx, query, newData.UserId, newData.Amount, newData.TransactionId, newData.Id)
|
||||
}, deductionsIdKey, deductionsTransactionIdKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultDeductionsModel) formatPrimary(primary any) string {
|
||||
return fmt.Sprintf("%s%v", cacheDeductionsIdPrefix, primary)
|
||||
}
|
||||
|
||||
func (m *defaultDeductionsModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", deductionsRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary)
|
||||
}
|
||||
|
||||
func (m *defaultDeductionsModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
@@ -45,13 +45,16 @@ type (
|
||||
}
|
||||
|
||||
Users struct {
|
||||
Id int64 `db:"id"` // 用户ID
|
||||
Username string `db:"username"` // 用户名
|
||||
Password string `db:"password"` // 用户密码
|
||||
Phone string `db:"phone"` // 用户手机号
|
||||
AuthStatus string `db:"auth_status"` // 认证状态:unverified=未提交,pending=待审核,approved=审核通过,rejected=审核拒绝
|
||||
CreatedAt time.Time `db:"created_at"` // 用户创建时间
|
||||
UpdatedAt time.Time `db:"updated_at"` // 用户更新时间
|
||||
Id int64 `db:"id"` // 用户ID
|
||||
Username string `db:"username"` // 用户名
|
||||
Password string `db:"password"` // 用户密码
|
||||
Phone string `db:"phone"` // 用户手机号
|
||||
AuthStatus string `db:"auth_status"` // 认证状态:unverified=未提交,pending=待审核,approved=审核通过,rejected=审核拒绝
|
||||
Disable int64 `db:"disable"` // 是否禁用,0=未禁用,1=禁用
|
||||
Internal int64 `db:"internal"` // 是否内部人员,0=否,1=是
|
||||
QuotaExceeded int64 `db:"quota_exceeded"` // 是否额度用完,0=否,1=是
|
||||
CreatedAt time.Time `db:"created_at"` // 用户创建时间
|
||||
UpdatedAt time.Time `db:"updated_at"` // 用户更新时间
|
||||
}
|
||||
)
|
||||
|
||||
@@ -140,8 +143,8 @@ func (m *defaultUsersModel) Insert(ctx context.Context, data *Users) (sql.Result
|
||||
usersPhoneKey := fmt.Sprintf("%s%v", cacheUsersPhonePrefix, data.Phone)
|
||||
usersUsernameKey := fmt.Sprintf("%s%v", cacheUsersUsernamePrefix, data.Username)
|
||||
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?)", m.table, usersRowsExpectAutoSet)
|
||||
return conn.ExecCtx(ctx, query, data.Username, data.Password, data.Phone, data.AuthStatus)
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?)", m.table, usersRowsExpectAutoSet)
|
||||
return conn.ExecCtx(ctx, query, data.Username, data.Password, data.Phone, data.AuthStatus, data.Disable, data.Internal, data.QuotaExceeded)
|
||||
}, usersIdKey, usersPhoneKey, usersUsernameKey)
|
||||
return ret, err
|
||||
}
|
||||
@@ -157,7 +160,7 @@ func (m *defaultUsersModel) Update(ctx context.Context, newData *Users) error {
|
||||
usersUsernameKey := fmt.Sprintf("%s%v", cacheUsersUsernamePrefix, data.Username)
|
||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, usersRowsWithPlaceHolder)
|
||||
return conn.ExecCtx(ctx, query, newData.Username, newData.Password, newData.Phone, newData.AuthStatus, newData.Id)
|
||||
return conn.ExecCtx(ctx, query, newData.Username, newData.Password, newData.Phone, newData.AuthStatus, newData.Disable, newData.Internal, newData.QuotaExceeded, newData.Id)
|
||||
}, usersIdKey, usersPhoneKey, usersUsernameKey)
|
||||
return err
|
||||
}
|
||||
|
||||
89
apps/user/internal/model/walletsmodel.go
Normal file
89
apps/user/internal/model/walletsmodel.go
Normal file
@@ -0,0 +1,89 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ WalletsModel = (*customWalletsModel)(nil)
|
||||
|
||||
type (
|
||||
// WalletsModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customWalletsModel.
|
||||
WalletsModel interface {
|
||||
walletsModel
|
||||
InsertWalletsTrans(ctx context.Context, wallets *Wallets, session sqlx.Session) (sql.Result, error)
|
||||
UpdateBalance(session sqlx.Session, ctx context.Context, userId int64, amount float64) error
|
||||
TransCtx(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error
|
||||
}
|
||||
|
||||
customWalletsModel struct {
|
||||
*defaultWalletsModel
|
||||
}
|
||||
)
|
||||
|
||||
var ErrBalanceNotEnough = errors.New("余额不足")
|
||||
var ErrVersionMismatch = errors.New("版本号不匹配,请重试")
|
||||
|
||||
// NewWalletsModel returns a model for the database table.
|
||||
func NewWalletsModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) WalletsModel {
|
||||
return &customWalletsModel{
|
||||
defaultWalletsModel: newWalletsModel(conn, c, opts...),
|
||||
}
|
||||
}
|
||||
func (m *customWalletsModel) TransCtx(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error {
|
||||
// 使用带 ctx 的事务处理
|
||||
err := m.TransactCtx(ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
return fn(ctx, session)
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
// 更新余额的方法
|
||||
func (m *customWalletsModel) UpdateBalance(session sqlx.Session, ctx context.Context, userId int64, amount float64) error {
|
||||
|
||||
wallet, err := m.FindOneByUserId(ctx, userId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 检查余额是否足够
|
||||
if wallet.Balance+amount < 0 {
|
||||
return ErrBalanceNotEnough
|
||||
}
|
||||
|
||||
// 使用乐观锁更新余额
|
||||
result, err := session.Exec("UPDATE wallets SET balance = balance + ?, version = version + 1 WHERE user_id = ? AND version = ?", amount, userId, wallet.Version)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 检查影响的行数,确保更新成功
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if rowsAffected == 0 {
|
||||
return ErrVersionMismatch
|
||||
}
|
||||
|
||||
walletsUserIdKey := fmt.Sprintf("%s%v", cacheWalletsUserIdPrefix, userId)
|
||||
cacheErrors := m.DelCacheCtx(ctx, walletsUserIdKey)
|
||||
if cacheErrors != nil {
|
||||
return cacheErrors
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *customWalletsModel) InsertWalletsTrans(ctx context.Context, wallets *Wallets, session sqlx.Session) (sql.Result, error) {
|
||||
query := fmt.Sprintf("INSERT INTO %s (%s) VALUES (?, ?, ?)", m.table, walletsRowsExpectAutoSet)
|
||||
ret, err := session.ExecCtx(ctx, query, wallets.UserId, wallets.Balance, wallets.Version)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ret, err
|
||||
}
|
||||
150
apps/user/internal/model/walletsmodel_gen.go
Normal file
150
apps/user/internal/model/walletsmodel_gen.go
Normal file
@@ -0,0 +1,150 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// versions:
|
||||
// goctl version: 1.7.2
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
walletsFieldNames = builder.RawFieldNames(&Wallets{})
|
||||
walletsRows = strings.Join(walletsFieldNames, ",")
|
||||
walletsRowsExpectAutoSet = strings.Join(stringx.Remove(walletsFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
walletsRowsWithPlaceHolder = strings.Join(stringx.Remove(walletsFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
|
||||
cacheWalletsIdPrefix = "cache:wallets:id:"
|
||||
cacheWalletsUserIdPrefix = "cache:wallets:userId:"
|
||||
)
|
||||
|
||||
type (
|
||||
walletsModel interface {
|
||||
Insert(ctx context.Context, data *Wallets) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*Wallets, error)
|
||||
FindOneByUserId(ctx context.Context, userId int64) (*Wallets, error)
|
||||
Update(ctx context.Context, data *Wallets) error
|
||||
Delete(ctx context.Context, id int64) error
|
||||
}
|
||||
|
||||
defaultWalletsModel struct {
|
||||
sqlc.CachedConn
|
||||
table string
|
||||
}
|
||||
|
||||
Wallets struct {
|
||||
Id int64 `db:"id"` // 钱包ID
|
||||
UserId int64 `db:"user_id"` // 用户ID
|
||||
Balance float64 `db:"balance"` // 钱包余额
|
||||
Version int64 `db:"version"` // 乐观锁版本号
|
||||
CreatedAt time.Time `db:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `db:"updated_at"` // 更新时间
|
||||
}
|
||||
)
|
||||
|
||||
func newWalletsModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultWalletsModel {
|
||||
return &defaultWalletsModel{
|
||||
CachedConn: sqlc.NewConn(conn, c, opts...),
|
||||
table: "`wallets`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWalletsModel) Delete(ctx context.Context, id int64) error {
|
||||
data, err := m.FindOne(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
walletsIdKey := fmt.Sprintf("%s%v", cacheWalletsIdPrefix, id)
|
||||
walletsUserIdKey := fmt.Sprintf("%s%v", cacheWalletsUserIdPrefix, data.UserId)
|
||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
return conn.ExecCtx(ctx, query, id)
|
||||
}, walletsIdKey, walletsUserIdKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultWalletsModel) FindOne(ctx context.Context, id int64) (*Wallets, error) {
|
||||
walletsIdKey := fmt.Sprintf("%s%v", cacheWalletsIdPrefix, id)
|
||||
var resp Wallets
|
||||
err := m.QueryRowCtx(ctx, &resp, walletsIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", walletsRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWalletsModel) FindOneByUserId(ctx context.Context, userId int64) (*Wallets, error) {
|
||||
walletsUserIdKey := fmt.Sprintf("%s%v", cacheWalletsUserIdPrefix, userId)
|
||||
var resp Wallets
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, walletsUserIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `user_id` = ? limit 1", walletsRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, userId); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Id, nil
|
||||
}, m.queryPrimary)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWalletsModel) Insert(ctx context.Context, data *Wallets) (sql.Result, error) {
|
||||
walletsIdKey := fmt.Sprintf("%s%v", cacheWalletsIdPrefix, data.Id)
|
||||
walletsUserIdKey := fmt.Sprintf("%s%v", cacheWalletsUserIdPrefix, data.UserId)
|
||||
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?)", m.table, walletsRowsExpectAutoSet)
|
||||
return conn.ExecCtx(ctx, query, data.UserId, data.Balance, data.Version)
|
||||
}, walletsIdKey, walletsUserIdKey)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultWalletsModel) Update(ctx context.Context, newData *Wallets) error {
|
||||
data, err := m.FindOne(ctx, newData.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
walletsIdKey := fmt.Sprintf("%s%v", cacheWalletsIdPrefix, data.Id)
|
||||
walletsUserIdKey := fmt.Sprintf("%s%v", cacheWalletsUserIdPrefix, data.UserId)
|
||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, walletsRowsWithPlaceHolder)
|
||||
return conn.ExecCtx(ctx, query, newData.UserId, newData.Balance, newData.Version, newData.Id)
|
||||
}, walletsIdKey, walletsUserIdKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultWalletsModel) formatPrimary(primary any) string {
|
||||
return fmt.Sprintf("%s%v", cacheWalletsIdPrefix, primary)
|
||||
}
|
||||
|
||||
func (m *defaultWalletsModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", walletsRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary)
|
||||
}
|
||||
|
||||
func (m *defaultWalletsModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.7.2
|
||||
// Source: user.proto
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/user/internal/logic/apirequestservice"
|
||||
"tianyuan-api/apps/user/internal/svc"
|
||||
"tianyuan-api/apps/user/user"
|
||||
)
|
||||
|
||||
type ApiRequestServiceServer struct {
|
||||
svcCtx *svc.ServiceContext
|
||||
user.UnimplementedApiRequestServiceServer
|
||||
}
|
||||
|
||||
func NewApiRequestServiceServer(svcCtx *svc.ServiceContext) *ApiRequestServiceServer {
|
||||
return &ApiRequestServiceServer{
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 添加API请求记录
|
||||
func (s *ApiRequestServiceServer) AddApiRequest(ctx context.Context, in *user.AddApiRequestRequest) (*user.AddApiRequestResponse, error) {
|
||||
l := apirequestservicelogic.NewAddApiRequestLogic(ctx, s.svcCtx)
|
||||
return l.AddApiRequest(in)
|
||||
}
|
||||
|
||||
// 查询API请求记录
|
||||
func (s *ApiRequestServiceServer) GetApiRequests(ctx context.Context, in *user.GetApiRequestsRequest) (*user.GetApiRequestsResponse, error) {
|
||||
l := apirequestservicelogic.NewGetApiRequestsLogic(ctx, s.svcCtx)
|
||||
return l.GetApiRequests(in)
|
||||
}
|
||||
|
||||
// 查询API请求记录ByTransactionId
|
||||
func (s *ApiRequestServiceServer) GetApiRequestByTransactionId(ctx context.Context, in *user.GetApiRequestByTransactionIdRequest) (*user.GetApiRequestByTransactionIdResponse, error) {
|
||||
l := apirequestservicelogic.NewGetApiRequestByTransactionIdLogic(ctx, s.svcCtx)
|
||||
return l.GetApiRequestByTransactionId(in)
|
||||
}
|
||||
@@ -29,6 +29,11 @@ func (s *UserServer) UserInfo(ctx context.Context, in *user.UserInfoReq) (*user.
|
||||
return l.UserInfo(in)
|
||||
}
|
||||
|
||||
func (s *UserServer) GetUserInfo(ctx context.Context, in *user.UserInfoReq) (*user.GetUserInfoResp, error) {
|
||||
l := userlogic.NewGetUserInfoLogic(ctx, s.svcCtx)
|
||||
return l.GetUserInfo(in)
|
||||
}
|
||||
|
||||
func (s *UserServer) GetEnterpriseAuthStatus(ctx context.Context, in *user.GetEnterpriseAuthStatusReq) (*user.GetEnterpriseAuthStatusResp, error) {
|
||||
l := userlogic.NewGetEnterpriseAuthStatusLogic(ctx, s.svcCtx)
|
||||
return l.GetEnterpriseAuthStatus(in)
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.7.2
|
||||
// Source: user.proto
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/user/internal/logic/walletservice"
|
||||
"tianyuan-api/apps/user/internal/svc"
|
||||
"tianyuan-api/apps/user/user"
|
||||
)
|
||||
|
||||
type WalletServiceServer struct {
|
||||
svcCtx *svc.ServiceContext
|
||||
user.UnimplementedWalletServiceServer
|
||||
}
|
||||
|
||||
func NewWalletServiceServer(svcCtx *svc.ServiceContext) *WalletServiceServer {
|
||||
return &WalletServiceServer{
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 修改钱包余额
|
||||
func (s *WalletServiceServer) UpdateWallet(ctx context.Context, in *user.UpdateWalletRequest) (*user.UpdateWalletResponse, error) {
|
||||
l := walletservicelogic.NewUpdateWalletLogic(ctx, s.svcCtx)
|
||||
return l.UpdateWallet(in)
|
||||
}
|
||||
|
||||
// 查询钱包信息
|
||||
func (s *WalletServiceServer) GetWallet(ctx context.Context, in *user.GetWalletRequest) (*user.GetWalletResponse, error) {
|
||||
l := walletservicelogic.NewGetWalletLogic(ctx, s.svcCtx)
|
||||
return l.GetWallet(in)
|
||||
}
|
||||
|
||||
// 查询扣款记录
|
||||
func (s *WalletServiceServer) GetDeductions(ctx context.Context, in *user.GetDeductionsRequest) (*user.GetDeductionsResponse, error) {
|
||||
l := walletservicelogic.NewGetDeductionsLogic(ctx, s.svcCtx)
|
||||
return l.GetDeductions(in)
|
||||
}
|
||||
|
||||
func (s *WalletServiceServer) GetDeductionByTransactionId(ctx context.Context, in *user.GetDeductionByTransactionIdRequest) (*user.GetDeductionByTransactionIdResponse, error) {
|
||||
l := walletservicelogic.NewGetDeductionByTransactionIdLogic(ctx, s.svcCtx)
|
||||
return l.GetDeductionByTransactionId(in)
|
||||
}
|
||||
@@ -15,7 +15,11 @@ type ServiceContext struct {
|
||||
UserModel model.UsersModel // 用户表的模型
|
||||
EnterpriseModel model.EnterpriseInfoModel
|
||||
EnterpriseAuthModel model.EnterpriseAuthModel
|
||||
WalletsModel model.WalletsModel
|
||||
DeductionsModel model.DeductionsModel
|
||||
ApiRequestsModel model.ApiRequestsModel
|
||||
SecretRpc sentinel.SecretClient
|
||||
ProductRpc sentinel.ProductClient
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
@@ -34,6 +38,10 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
UserModel: model.NewUsersModel(db, c.CacheRedis), // 注入UserModel
|
||||
EnterpriseModel: model.NewEnterpriseInfoModel(db, c.CacheRedis),
|
||||
EnterpriseAuthModel: model.NewEnterpriseAuthModel(db, c.CacheRedis),
|
||||
WalletsModel: model.NewWalletsModel(db, c.CacheRedis),
|
||||
DeductionsModel: model.NewDeductionsModel(db, c.CacheRedis),
|
||||
ApiRequestsModel: model.NewApiRequestsModel(db, c.CacheRedis),
|
||||
SecretRpc: sentinel.NewSecretClient(zrpc.MustNewClient(c.SentinelRpc).Conn()),
|
||||
ProductRpc: sentinel.NewProductClient(zrpc.MustNewClient(c.SentinelRpc).Conn()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,11 @@ import (
|
||||
"os"
|
||||
|
||||
"tianyuan-api/apps/user/internal/config"
|
||||
apirequestserviceServer "tianyuan-api/apps/user/internal/server/apirequestservice"
|
||||
authServer "tianyuan-api/apps/user/internal/server/auth"
|
||||
enterpriseServer "tianyuan-api/apps/user/internal/server/enterprise"
|
||||
userServer "tianyuan-api/apps/user/internal/server/user"
|
||||
walletserviceServer "tianyuan-api/apps/user/internal/server/walletservice"
|
||||
"tianyuan-api/apps/user/internal/svc"
|
||||
"tianyuan-api/apps/user/user"
|
||||
|
||||
@@ -46,6 +48,8 @@ func main() {
|
||||
user.RegisterEnterpriseServer(grpcServer, enterpriseServer.NewEnterpriseServer(ctx))
|
||||
user.RegisterAuthServer(grpcServer, authServer.NewAuthServer(ctx))
|
||||
user.RegisterUserServer(grpcServer, userServer.NewUserServer(ctx))
|
||||
user.RegisterWalletServiceServer(grpcServer, walletserviceServer.NewWalletServiceServer(ctx))
|
||||
user.RegisterApiRequestServiceServer(grpcServer, apirequestserviceServer.NewApiRequestServiceServer(ctx))
|
||||
|
||||
if c.Mode == service.DevMode || c.Mode == service.TestMode {
|
||||
reflection.Register(grpcServer)
|
||||
|
||||
@@ -107,10 +107,18 @@ message UserInfoReq {
|
||||
message UserInfoResp{
|
||||
string username = 1;
|
||||
string phone = 2;
|
||||
string enterpriseAuthStatus = 3;
|
||||
string enterpriseName = 4;
|
||||
string creditCode = 5;
|
||||
string legalPerson = 6;
|
||||
int64 disable = 3;
|
||||
int64 quotaExceeded = 4;
|
||||
string enterpriseAuthStatus = 5;
|
||||
string enterpriseName = 6;
|
||||
string creditCode = 7;
|
||||
string legalPerson = 8;
|
||||
}
|
||||
message GetUserInfoResp{
|
||||
string username = 1;
|
||||
string phone = 2;
|
||||
int64 disable = 3;
|
||||
int64 quotaExceeded = 4;
|
||||
}
|
||||
|
||||
message GetEnterpriseAuthStatusReq {
|
||||
@@ -122,5 +130,142 @@ message GetEnterpriseAuthStatusResp {
|
||||
service User {
|
||||
// 获取用户信息
|
||||
rpc UserInfo(UserInfoReq) returns (UserInfoResp);
|
||||
|
||||
rpc GetUserInfo(UserInfoReq) returns (GetUserInfoResp);
|
||||
|
||||
rpc GetEnterpriseAuthStatus(GetEnterpriseAuthStatusReq) returns (GetEnterpriseAuthStatusResp);
|
||||
}
|
||||
|
||||
|
||||
// 定义钱包服务
|
||||
service WalletService {
|
||||
|
||||
|
||||
// 修改钱包余额
|
||||
rpc UpdateWallet (UpdateWalletRequest) returns (UpdateWalletResponse);
|
||||
|
||||
// 查询钱包信息
|
||||
rpc GetWallet (GetWalletRequest) returns (GetWalletResponse);
|
||||
|
||||
// 查询扣款记录
|
||||
rpc GetDeductions (GetDeductionsRequest) returns (GetDeductionsResponse);
|
||||
|
||||
rpc GetDeductionByTransactionId (GetDeductionByTransactionIdRequest) returns (GetDeductionByTransactionIdResponse);
|
||||
}
|
||||
|
||||
// 更新钱包余额
|
||||
message UpdateWalletRequest {
|
||||
int64 user_id = 1;
|
||||
string transaction_id = 2;
|
||||
string product_code = 3;
|
||||
string remark = 4;
|
||||
bool charge = 5;
|
||||
}
|
||||
|
||||
message UpdateWalletResponse {
|
||||
|
||||
}
|
||||
|
||||
// 查询钱包信息
|
||||
message GetWalletRequest {
|
||||
int64 id = 1;
|
||||
}
|
||||
|
||||
message GetWalletResponse {
|
||||
int64 id = 1;
|
||||
int64 user_id = 2;
|
||||
double balance = 3;
|
||||
int64 version = 4;
|
||||
}
|
||||
|
||||
// 查询扣款记录
|
||||
message GetDeductionsRequest {
|
||||
int64 user_id = 1;
|
||||
int64 page = 2;
|
||||
int64 size = 3;
|
||||
}
|
||||
|
||||
message GetDeductionsResponse {
|
||||
repeated Deduction deductions = 1;
|
||||
}
|
||||
message GetDeductionByTransactionIdRequest {
|
||||
string transaction_id = 1;
|
||||
}
|
||||
message GetDeductionByTransactionIdResponse {
|
||||
int64 id = 1;
|
||||
int64 user_id = 2;
|
||||
double amount = 3;
|
||||
string transaction_id = 4;
|
||||
string created_at = 5;
|
||||
}
|
||||
message Deduction {
|
||||
int64 id = 1;
|
||||
int64 user_id = 2;
|
||||
double amount = 3;
|
||||
string transaction_id = 4;
|
||||
string created_at = 5;
|
||||
}
|
||||
|
||||
|
||||
service ApiRequestService {
|
||||
// 添加API请求记录
|
||||
rpc AddApiRequest (AddApiRequestRequest) returns (AddApiRequestResponse);
|
||||
|
||||
// 查询API请求记录
|
||||
rpc GetApiRequests (GetApiRequestsRequest) returns (GetApiRequestsResponse);
|
||||
|
||||
// 查询API请求记录ByTransactionId
|
||||
rpc GetApiRequestByTransactionId (GetApiRequestByTransactionIdRequest) returns (GetApiRequestByTransactionIdResponse);
|
||||
}
|
||||
// 添加API请求记录
|
||||
message AddApiRequestRequest {
|
||||
string transaction_id = 1;
|
||||
int64 user_id = 2;
|
||||
string product_code = 3;
|
||||
string status = 4;
|
||||
bool charges = 5;
|
||||
string remark = 6;
|
||||
string timestamp = 7;
|
||||
}
|
||||
|
||||
message AddApiRequestResponse {
|
||||
bool success = 1;
|
||||
}
|
||||
|
||||
// 查询API请求记录
|
||||
message GetApiRequestsRequest {
|
||||
int64 user_id = 1;
|
||||
int64 page = 2;
|
||||
int64 size = 3;
|
||||
}
|
||||
|
||||
message GetApiRequestsResponse {
|
||||
repeated ApiRequest api_requests = 1;
|
||||
}
|
||||
|
||||
message ApiRequest {
|
||||
int64 id = 1;
|
||||
string transaction_id = 2;
|
||||
int64 user_id = 3;
|
||||
string product_code = 4;
|
||||
string status = 5;
|
||||
double charges = 6;
|
||||
string remark = 7;
|
||||
string timestamp = 8;
|
||||
}
|
||||
|
||||
// 查询API请求记录
|
||||
message GetApiRequestByTransactionIdRequest {
|
||||
string transaction_id = 1;
|
||||
}
|
||||
|
||||
message GetApiRequestByTransactionIdResponse {
|
||||
int64 id = 1;
|
||||
string transaction_id = 2;
|
||||
int64 user_id = 3;
|
||||
string product_code = 4;
|
||||
string status = 5;
|
||||
double charges = 6;
|
||||
string remark = 7;
|
||||
string timestamp = 8;
|
||||
}
|
||||
@@ -4,6 +4,9 @@ CREATE TABLE users (
|
||||
password VARCHAR(100) NOT NULL COMMENT '用户密码',
|
||||
phone VARCHAR(15) NOT NULL UNIQUE COMMENT '用户手机号',
|
||||
auth_status ENUM('unverified','pending', 'approved', 'rejected') DEFAULT 'unverified' COMMENT '认证状态:unverified=未提交,pending=待审核,approved=审核通过,rejected=审核拒绝',
|
||||
disable TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否禁用,0=未禁用,1=禁用',
|
||||
internal TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否内部人员,0=否,1=是',
|
||||
quota_exceeded TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否额度用完,0=否,1=是',
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '用户创建时间',
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '用户更新时间',
|
||||
PRIMARY KEY (id)
|
||||
@@ -35,3 +38,35 @@ CREATE TABLE enterprise_auth (
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '认证更新时间',
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='企业认证表,存储企业认证的相关信息';
|
||||
|
||||
|
||||
CREATE TABLE wallets (
|
||||
id INT(11) NOT NULL AUTO_INCREMENT COMMENT '钱包ID',
|
||||
user_id INT(11) NOT NULL UNIQUE COMMENT '用户ID',
|
||||
balance DECIMAL(10, 2) DEFAULT 0.00 COMMENT '钱包余额',
|
||||
version INT(11) DEFAULT 0 COMMENT '乐观锁版本号',
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='钱包表,存储用户的余额信息';
|
||||
|
||||
CREATE TABLE deductions (
|
||||
id INT(11) NOT NULL AUTO_INCREMENT COMMENT '扣款记录ID',
|
||||
user_id INT(11) NOT NULL COMMENT '用户ID',
|
||||
amount DECIMAL(10, 2) NOT NULL COMMENT '扣款金额',
|
||||
transaction_id VARCHAR(50) NOT NULL UNIQUE COMMENT '交易流水号',
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '扣款时间',
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='扣款记录表,存储用户的扣款历史记录';
|
||||
|
||||
CREATE TABLE api_requests (
|
||||
id INT(11) NOT NULL AUTO_INCREMENT COMMENT '请求记录ID',
|
||||
transaction_id VARCHAR(50) NOT NULL UNIQUE COMMENT '交易ID',
|
||||
user_id INT(11) NOT NULL COMMENT '用户ID',
|
||||
product_code VARCHAR(100) NOT NULL COMMENT '产品编码',
|
||||
status ENUM('success', 'failed') DEFAULT 'success' COMMENT '请求状态:success=成功,failed=失败',
|
||||
charges TINYINT(1) NOT NULL COMMENT '是否需要付费',
|
||||
remark VARCHAR(255) COMMENT '备注',
|
||||
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '请求时间',
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='API请求记录表,存储API请求的相关信息';
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -374,6 +374,7 @@ var Auth_ServiceDesc = grpc.ServiceDesc{
|
||||
|
||||
const (
|
||||
User_UserInfo_FullMethodName = "/User/UserInfo"
|
||||
User_GetUserInfo_FullMethodName = "/User/GetUserInfo"
|
||||
User_GetEnterpriseAuthStatus_FullMethodName = "/User/GetEnterpriseAuthStatus"
|
||||
)
|
||||
|
||||
@@ -383,6 +384,7 @@ const (
|
||||
type UserClient interface {
|
||||
// 获取用户信息
|
||||
UserInfo(ctx context.Context, in *UserInfoReq, opts ...grpc.CallOption) (*UserInfoResp, error)
|
||||
GetUserInfo(ctx context.Context, in *UserInfoReq, opts ...grpc.CallOption) (*GetUserInfoResp, error)
|
||||
GetEnterpriseAuthStatus(ctx context.Context, in *GetEnterpriseAuthStatusReq, opts ...grpc.CallOption) (*GetEnterpriseAuthStatusResp, error)
|
||||
}
|
||||
|
||||
@@ -404,6 +406,16 @@ func (c *userClient) UserInfo(ctx context.Context, in *UserInfoReq, opts ...grpc
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *userClient) GetUserInfo(ctx context.Context, in *UserInfoReq, opts ...grpc.CallOption) (*GetUserInfoResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetUserInfoResp)
|
||||
err := c.cc.Invoke(ctx, User_GetUserInfo_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *userClient) GetEnterpriseAuthStatus(ctx context.Context, in *GetEnterpriseAuthStatusReq, opts ...grpc.CallOption) (*GetEnterpriseAuthStatusResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetEnterpriseAuthStatusResp)
|
||||
@@ -420,6 +432,7 @@ func (c *userClient) GetEnterpriseAuthStatus(ctx context.Context, in *GetEnterpr
|
||||
type UserServer interface {
|
||||
// 获取用户信息
|
||||
UserInfo(context.Context, *UserInfoReq) (*UserInfoResp, error)
|
||||
GetUserInfo(context.Context, *UserInfoReq) (*GetUserInfoResp, error)
|
||||
GetEnterpriseAuthStatus(context.Context, *GetEnterpriseAuthStatusReq) (*GetEnterpriseAuthStatusResp, error)
|
||||
mustEmbedUnimplementedUserServer()
|
||||
}
|
||||
@@ -431,6 +444,9 @@ type UnimplementedUserServer struct {
|
||||
func (UnimplementedUserServer) UserInfo(context.Context, *UserInfoReq) (*UserInfoResp, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method UserInfo not implemented")
|
||||
}
|
||||
func (UnimplementedUserServer) GetUserInfo(context.Context, *UserInfoReq) (*GetUserInfoResp, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetUserInfo not implemented")
|
||||
}
|
||||
func (UnimplementedUserServer) GetEnterpriseAuthStatus(context.Context, *GetEnterpriseAuthStatusReq) (*GetEnterpriseAuthStatusResp, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetEnterpriseAuthStatus not implemented")
|
||||
}
|
||||
@@ -465,6 +481,24 @@ func _User_UserInfo_Handler(srv interface{}, ctx context.Context, dec func(inter
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _User_GetUserInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(UserInfoReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(UserServer).GetUserInfo(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: User_GetUserInfo_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(UserServer).GetUserInfo(ctx, req.(*UserInfoReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _User_GetEnterpriseAuthStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetEnterpriseAuthStatusReq)
|
||||
if err := dec(in); err != nil {
|
||||
@@ -494,6 +528,10 @@ var User_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "UserInfo",
|
||||
Handler: _User_UserInfo_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetUserInfo",
|
||||
Handler: _User_GetUserInfo_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetEnterpriseAuthStatus",
|
||||
Handler: _User_GetEnterpriseAuthStatus_Handler,
|
||||
@@ -502,3 +540,391 @@ var User_ServiceDesc = grpc.ServiceDesc{
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "user.proto",
|
||||
}
|
||||
|
||||
const (
|
||||
WalletService_UpdateWallet_FullMethodName = "/WalletService/UpdateWallet"
|
||||
WalletService_GetWallet_FullMethodName = "/WalletService/GetWallet"
|
||||
WalletService_GetDeductions_FullMethodName = "/WalletService/GetDeductions"
|
||||
WalletService_GetDeductionByTransactionId_FullMethodName = "/WalletService/GetDeductionByTransactionId"
|
||||
)
|
||||
|
||||
// WalletServiceClient is the client API for WalletService service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
//
|
||||
// 定义钱包服务
|
||||
type WalletServiceClient interface {
|
||||
// 修改钱包余额
|
||||
UpdateWallet(ctx context.Context, in *UpdateWalletRequest, opts ...grpc.CallOption) (*UpdateWalletResponse, error)
|
||||
// 查询钱包信息
|
||||
GetWallet(ctx context.Context, in *GetWalletRequest, opts ...grpc.CallOption) (*GetWalletResponse, error)
|
||||
// 查询扣款记录
|
||||
GetDeductions(ctx context.Context, in *GetDeductionsRequest, opts ...grpc.CallOption) (*GetDeductionsResponse, error)
|
||||
GetDeductionByTransactionId(ctx context.Context, in *GetDeductionByTransactionIdRequest, opts ...grpc.CallOption) (*GetDeductionByTransactionIdResponse, error)
|
||||
}
|
||||
|
||||
type walletServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewWalletServiceClient(cc grpc.ClientConnInterface) WalletServiceClient {
|
||||
return &walletServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *walletServiceClient) UpdateWallet(ctx context.Context, in *UpdateWalletRequest, opts ...grpc.CallOption) (*UpdateWalletResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(UpdateWalletResponse)
|
||||
err := c.cc.Invoke(ctx, WalletService_UpdateWallet_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *walletServiceClient) GetWallet(ctx context.Context, in *GetWalletRequest, opts ...grpc.CallOption) (*GetWalletResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetWalletResponse)
|
||||
err := c.cc.Invoke(ctx, WalletService_GetWallet_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *walletServiceClient) GetDeductions(ctx context.Context, in *GetDeductionsRequest, opts ...grpc.CallOption) (*GetDeductionsResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetDeductionsResponse)
|
||||
err := c.cc.Invoke(ctx, WalletService_GetDeductions_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *walletServiceClient) GetDeductionByTransactionId(ctx context.Context, in *GetDeductionByTransactionIdRequest, opts ...grpc.CallOption) (*GetDeductionByTransactionIdResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetDeductionByTransactionIdResponse)
|
||||
err := c.cc.Invoke(ctx, WalletService_GetDeductionByTransactionId_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// WalletServiceServer is the server API for WalletService service.
|
||||
// All implementations must embed UnimplementedWalletServiceServer
|
||||
// for forward compatibility
|
||||
//
|
||||
// 定义钱包服务
|
||||
type WalletServiceServer interface {
|
||||
// 修改钱包余额
|
||||
UpdateWallet(context.Context, *UpdateWalletRequest) (*UpdateWalletResponse, error)
|
||||
// 查询钱包信息
|
||||
GetWallet(context.Context, *GetWalletRequest) (*GetWalletResponse, error)
|
||||
// 查询扣款记录
|
||||
GetDeductions(context.Context, *GetDeductionsRequest) (*GetDeductionsResponse, error)
|
||||
GetDeductionByTransactionId(context.Context, *GetDeductionByTransactionIdRequest) (*GetDeductionByTransactionIdResponse, error)
|
||||
mustEmbedUnimplementedWalletServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedWalletServiceServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedWalletServiceServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedWalletServiceServer) UpdateWallet(context.Context, *UpdateWalletRequest) (*UpdateWalletResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method UpdateWallet not implemented")
|
||||
}
|
||||
func (UnimplementedWalletServiceServer) GetWallet(context.Context, *GetWalletRequest) (*GetWalletResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetWallet not implemented")
|
||||
}
|
||||
func (UnimplementedWalletServiceServer) GetDeductions(context.Context, *GetDeductionsRequest) (*GetDeductionsResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetDeductions not implemented")
|
||||
}
|
||||
func (UnimplementedWalletServiceServer) GetDeductionByTransactionId(context.Context, *GetDeductionByTransactionIdRequest) (*GetDeductionByTransactionIdResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetDeductionByTransactionId not implemented")
|
||||
}
|
||||
func (UnimplementedWalletServiceServer) mustEmbedUnimplementedWalletServiceServer() {}
|
||||
|
||||
// UnsafeWalletServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to WalletServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeWalletServiceServer interface {
|
||||
mustEmbedUnimplementedWalletServiceServer()
|
||||
}
|
||||
|
||||
func RegisterWalletServiceServer(s grpc.ServiceRegistrar, srv WalletServiceServer) {
|
||||
s.RegisterService(&WalletService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _WalletService_UpdateWallet_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(UpdateWalletRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(WalletServiceServer).UpdateWallet(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: WalletService_UpdateWallet_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(WalletServiceServer).UpdateWallet(ctx, req.(*UpdateWalletRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _WalletService_GetWallet_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetWalletRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(WalletServiceServer).GetWallet(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: WalletService_GetWallet_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(WalletServiceServer).GetWallet(ctx, req.(*GetWalletRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _WalletService_GetDeductions_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetDeductionsRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(WalletServiceServer).GetDeductions(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: WalletService_GetDeductions_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(WalletServiceServer).GetDeductions(ctx, req.(*GetDeductionsRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _WalletService_GetDeductionByTransactionId_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetDeductionByTransactionIdRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(WalletServiceServer).GetDeductionByTransactionId(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: WalletService_GetDeductionByTransactionId_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(WalletServiceServer).GetDeductionByTransactionId(ctx, req.(*GetDeductionByTransactionIdRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// WalletService_ServiceDesc is the grpc.ServiceDesc for WalletService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var WalletService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "WalletService",
|
||||
HandlerType: (*WalletServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "UpdateWallet",
|
||||
Handler: _WalletService_UpdateWallet_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetWallet",
|
||||
Handler: _WalletService_GetWallet_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetDeductions",
|
||||
Handler: _WalletService_GetDeductions_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetDeductionByTransactionId",
|
||||
Handler: _WalletService_GetDeductionByTransactionId_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "user.proto",
|
||||
}
|
||||
|
||||
const (
|
||||
ApiRequestService_AddApiRequest_FullMethodName = "/ApiRequestService/AddApiRequest"
|
||||
ApiRequestService_GetApiRequests_FullMethodName = "/ApiRequestService/GetApiRequests"
|
||||
ApiRequestService_GetApiRequestByTransactionId_FullMethodName = "/ApiRequestService/GetApiRequestByTransactionId"
|
||||
)
|
||||
|
||||
// ApiRequestServiceClient is the client API for ApiRequestService service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type ApiRequestServiceClient interface {
|
||||
// 添加API请求记录
|
||||
AddApiRequest(ctx context.Context, in *AddApiRequestRequest, opts ...grpc.CallOption) (*AddApiRequestResponse, error)
|
||||
// 查询API请求记录
|
||||
GetApiRequests(ctx context.Context, in *GetApiRequestsRequest, opts ...grpc.CallOption) (*GetApiRequestsResponse, error)
|
||||
// 查询API请求记录ByTransactionId
|
||||
GetApiRequestByTransactionId(ctx context.Context, in *GetApiRequestByTransactionIdRequest, opts ...grpc.CallOption) (*GetApiRequestByTransactionIdResponse, error)
|
||||
}
|
||||
|
||||
type apiRequestServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewApiRequestServiceClient(cc grpc.ClientConnInterface) ApiRequestServiceClient {
|
||||
return &apiRequestServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *apiRequestServiceClient) AddApiRequest(ctx context.Context, in *AddApiRequestRequest, opts ...grpc.CallOption) (*AddApiRequestResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(AddApiRequestResponse)
|
||||
err := c.cc.Invoke(ctx, ApiRequestService_AddApiRequest_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *apiRequestServiceClient) GetApiRequests(ctx context.Context, in *GetApiRequestsRequest, opts ...grpc.CallOption) (*GetApiRequestsResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetApiRequestsResponse)
|
||||
err := c.cc.Invoke(ctx, ApiRequestService_GetApiRequests_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *apiRequestServiceClient) GetApiRequestByTransactionId(ctx context.Context, in *GetApiRequestByTransactionIdRequest, opts ...grpc.CallOption) (*GetApiRequestByTransactionIdResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetApiRequestByTransactionIdResponse)
|
||||
err := c.cc.Invoke(ctx, ApiRequestService_GetApiRequestByTransactionId_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ApiRequestServiceServer is the server API for ApiRequestService service.
|
||||
// All implementations must embed UnimplementedApiRequestServiceServer
|
||||
// for forward compatibility
|
||||
type ApiRequestServiceServer interface {
|
||||
// 添加API请求记录
|
||||
AddApiRequest(context.Context, *AddApiRequestRequest) (*AddApiRequestResponse, error)
|
||||
// 查询API请求记录
|
||||
GetApiRequests(context.Context, *GetApiRequestsRequest) (*GetApiRequestsResponse, error)
|
||||
// 查询API请求记录ByTransactionId
|
||||
GetApiRequestByTransactionId(context.Context, *GetApiRequestByTransactionIdRequest) (*GetApiRequestByTransactionIdResponse, error)
|
||||
mustEmbedUnimplementedApiRequestServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedApiRequestServiceServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedApiRequestServiceServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedApiRequestServiceServer) AddApiRequest(context.Context, *AddApiRequestRequest) (*AddApiRequestResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method AddApiRequest not implemented")
|
||||
}
|
||||
func (UnimplementedApiRequestServiceServer) GetApiRequests(context.Context, *GetApiRequestsRequest) (*GetApiRequestsResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetApiRequests not implemented")
|
||||
}
|
||||
func (UnimplementedApiRequestServiceServer) GetApiRequestByTransactionId(context.Context, *GetApiRequestByTransactionIdRequest) (*GetApiRequestByTransactionIdResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetApiRequestByTransactionId not implemented")
|
||||
}
|
||||
func (UnimplementedApiRequestServiceServer) mustEmbedUnimplementedApiRequestServiceServer() {}
|
||||
|
||||
// UnsafeApiRequestServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to ApiRequestServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeApiRequestServiceServer interface {
|
||||
mustEmbedUnimplementedApiRequestServiceServer()
|
||||
}
|
||||
|
||||
func RegisterApiRequestServiceServer(s grpc.ServiceRegistrar, srv ApiRequestServiceServer) {
|
||||
s.RegisterService(&ApiRequestService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _ApiRequestService_AddApiRequest_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(AddApiRequestRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ApiRequestServiceServer).AddApiRequest(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ApiRequestService_AddApiRequest_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ApiRequestServiceServer).AddApiRequest(ctx, req.(*AddApiRequestRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _ApiRequestService_GetApiRequests_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetApiRequestsRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ApiRequestServiceServer).GetApiRequests(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ApiRequestService_GetApiRequests_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ApiRequestServiceServer).GetApiRequests(ctx, req.(*GetApiRequestsRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _ApiRequestService_GetApiRequestByTransactionId_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetApiRequestByTransactionIdRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ApiRequestServiceServer).GetApiRequestByTransactionId(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ApiRequestService_GetApiRequestByTransactionId_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ApiRequestServiceServer).GetApiRequestByTransactionId(ctx, req.(*GetApiRequestByTransactionIdRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// ApiRequestService_ServiceDesc is the grpc.ServiceDesc for ApiRequestService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var ApiRequestService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "ApiRequestService",
|
||||
HandlerType: (*ApiRequestServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "AddApiRequest",
|
||||
Handler: _ApiRequestService_AddApiRequest_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetApiRequests",
|
||||
Handler: _ApiRequestService_GetApiRequests_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetApiRequestByTransactionId",
|
||||
Handler: _ApiRequestService_GetApiRequestByTransactionId_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "user.proto",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user