temp
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user