101 lines
3.1 KiB
Go
101 lines
3.1 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/topfans/backend/pkg/logger"
|
|
pbCommon "github.com/topfans/backend/pkg/proto/common"
|
|
pbTask "github.com/topfans/backend/pkg/proto/task"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// TaskRPCClient Task Service RPC客户端接口
|
|
type TaskRPCClient interface {
|
|
// OnExhibitionCompleted 当展位到期完成时调用,创建展示收益记录
|
|
OnExhibitionCompleted(ctx context.Context, req *OnExhibitionCompletedRequest) (*OnExhibitionCompletedResponse, error)
|
|
}
|
|
|
|
// OnExhibitionCompletedRequest 展位完成请求
|
|
type OnExhibitionCompletedRequest struct {
|
|
ExhibitionId int64
|
|
AssetId int64
|
|
SlotId int64
|
|
OccupierUid int64
|
|
OccupierStarId int64
|
|
SlotOwnerUid int64
|
|
StartTime int64
|
|
ExpireAt int64
|
|
CrystalAmount int64
|
|
}
|
|
|
|
// OnExhibitionCompletedResponse 展位完成响应
|
|
type OnExhibitionCompletedResponse struct {
|
|
RevenueRecordId int64
|
|
}
|
|
|
|
// taskRPCClient Task Service RPC客户端实现
|
|
type taskRPCClient struct {
|
|
client pbTask.TaskInternalService
|
|
}
|
|
|
|
// NewTaskRPCClient 创建Task Service RPC客户端
|
|
func NewTaskRPCClient(client pbTask.TaskInternalService) TaskRPCClient {
|
|
return &taskRPCClient{
|
|
client: client,
|
|
}
|
|
}
|
|
|
|
// OnExhibitionCompleted 当展位到期完成时调用,创建展示收益记录
|
|
func (c *taskRPCClient) OnExhibitionCompleted(ctx context.Context, req *OnExhibitionCompletedRequest) (*OnExhibitionCompletedResponse, error) {
|
|
logger.Logger.Debug("Calling TaskService.OnExhibitionCompleted",
|
|
zap.Int64("exhibition_id", req.ExhibitionId),
|
|
zap.Int64("asset_id", req.AssetId),
|
|
zap.Int64("slot_id", req.SlotId),
|
|
zap.Int64("occupier_uid", req.OccupierUid),
|
|
zap.Int64("slot_owner_uid", req.SlotOwnerUid),
|
|
zap.Int64("crystal_amount", req.CrystalAmount))
|
|
|
|
if c.client == nil {
|
|
logger.Logger.Error("TaskRPCClient: client is nil")
|
|
return nil, errors.New("task client is nil")
|
|
}
|
|
|
|
pbReq := &pbTask.OnExhibitionCompletedRequest{
|
|
ExhibitionId: req.ExhibitionId,
|
|
AssetId: req.AssetId,
|
|
SlotId: req.SlotId,
|
|
OccupierUid: req.OccupierUid,
|
|
OccupierStarId: req.OccupierStarId,
|
|
SlotOwnerUid: req.SlotOwnerUid,
|
|
StartTime: req.StartTime,
|
|
ExpireAt: req.ExpireAt,
|
|
CrystalAmount: req.CrystalAmount,
|
|
}
|
|
|
|
resp, err := c.client.OnExhibitionCompleted(ctx, pbReq)
|
|
if err != nil {
|
|
logger.Logger.Error("Failed to call TaskService.OnExhibitionCompleted",
|
|
zap.Int64("exhibition_id", req.ExhibitionId),
|
|
zap.Error(err))
|
|
return nil, fmt.Errorf("call TaskService.OnExhibitionCompleted failed: %w", err)
|
|
}
|
|
|
|
if resp.Base.Code != pbCommon.StatusCode_STATUS_OK {
|
|
logger.Logger.Warn("TaskService.OnExhibitionCompleted returned error",
|
|
zap.Int64("exhibition_id", req.ExhibitionId),
|
|
zap.Int32("code", int32(resp.Base.Code)),
|
|
zap.String("message", resp.Base.Message))
|
|
return nil, fmt.Errorf("TaskService.OnExhibitionCompleted error: %s", resp.Base.Message)
|
|
}
|
|
|
|
logger.Logger.Info("TaskService.OnExhibitionCompleted successful",
|
|
zap.Int64("exhibition_id", req.ExhibitionId),
|
|
zap.Int64("revenue_record_id", resp.RevenueRecordId))
|
|
|
|
return &OnExhibitionCompletedResponse{
|
|
RevenueRecordId: resp.RevenueRecordId,
|
|
}, nil
|
|
}
|