temp
This commit is contained in:
41
apps/api/internal/service/apirequest_mqs_service.go
Normal file
41
apps/api/internal/service/apirequest_mqs_service.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/zeromicro/go-queue/kq"
|
||||
"tianyuan-api/pkg/models"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ApiRequestMqsService struct {
|
||||
KqPusherClient *kq.Pusher
|
||||
}
|
||||
|
||||
// NewApiRequestMqsService
|
||||
func NewApiRequestMqsService(KqPusherClient *kq.Pusher) *ApiRequestMqsService {
|
||||
return &ApiRequestMqsService{
|
||||
KqPusherClient: KqPusherClient,
|
||||
}
|
||||
}
|
||||
func (s *ApiRequestMqsService) SendApiRequestMessage(ctx context.Context, transactionID string, userId int64, productCode string, status string, charges bool, remark string) error {
|
||||
message := models.ApiRequestMessage{
|
||||
TransactionID: transactionID,
|
||||
UserId: userId,
|
||||
ProductCode: productCode,
|
||||
Status: status,
|
||||
Charges: charges,
|
||||
Remark: remark,
|
||||
Timestamp: time.Now(),
|
||||
}
|
||||
|
||||
msgBytes, marshalErr := json.Marshal(message)
|
||||
if marshalErr != nil {
|
||||
return marshalErr
|
||||
}
|
||||
|
||||
if pushErr := s.KqPusherClient.Push(ctx, string(msgBytes)); pushErr != nil {
|
||||
return pushErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user