新增部分接口合同授权码

This commit is contained in:
2025-08-04 22:02:09 +08:00
parent f482f0a6e8
commit 3f4c3086f3
6 changed files with 57 additions and 21 deletions

View File

@@ -34,7 +34,7 @@ type ApiApplicationService interface {
// 获取用户API调用记录
GetUserApiCalls(ctx context.Context, userID string, filters map[string]interface{}, options interfaces.ListOptions) (*dto.ApiCallListResponse, error)
// 管理端API调用记录
GetAdminApiCalls(ctx context.Context, filters map[string]interface{}, options interfaces.ListOptions) (*dto.ApiCallListResponse, error)
}
@@ -45,6 +45,7 @@ type ApiApplicationServiceImpl struct {
apiRequestService *services.ApiRequestService
apiCallRepository repositories.ApiCallRepository
walletService finance_services.WalletAggregateService
contractInfoService user_repositories.ContractInfoRepository
productManagementService *product_services.ProductManagementService
productSubscriptionService *product_services.ProductSubscriptionService
userRepo user_repositories.UserRepository
@@ -53,8 +54,8 @@ type ApiApplicationServiceImpl struct {
logger *zap.Logger
}
func NewApiApplicationService(apiCallService services.ApiCallAggregateService, apiUserService services.ApiUserAggregateService, apiRequestService *services.ApiRequestService, apiCallRepository repositories.ApiCallRepository, walletService finance_services.WalletAggregateService, productManagementService *product_services.ProductManagementService, productSubscriptionService *product_services.ProductSubscriptionService, userRepo user_repositories.UserRepository, txManager *database.TransactionManager, config *config.Config, logger *zap.Logger) ApiApplicationService {
return &ApiApplicationServiceImpl{apiCallService: apiCallService, apiUserService: apiUserService, apiRequestService: apiRequestService, apiCallRepository: apiCallRepository, walletService: walletService, productManagementService: productManagementService, productSubscriptionService: productSubscriptionService, userRepo: userRepo, txManager: txManager, config: config, logger: logger}
func NewApiApplicationService(apiCallService services.ApiCallAggregateService, apiUserService services.ApiUserAggregateService, apiRequestService *services.ApiRequestService, apiCallRepository repositories.ApiCallRepository, walletService finance_services.WalletAggregateService, productManagementService *product_services.ProductManagementService, productSubscriptionService *product_services.ProductSubscriptionService, userRepo user_repositories.UserRepository, txManager *database.TransactionManager, config *config.Config, logger *zap.Logger, contractInfoService user_repositories.ContractInfoRepository) ApiApplicationService {
return &ApiApplicationServiceImpl{apiCallService: apiCallService, apiUserService: apiUserService, apiRequestService: apiRequestService, apiCallRepository: apiCallRepository, walletService: walletService, productManagementService: productManagementService, productSubscriptionService: productSubscriptionService, userRepo: userRepo, txManager: txManager, config: config, logger: logger, contractInfoService: contractInfoService}
}
// CallApi 应用服务层统一入口
@@ -149,7 +150,22 @@ func (s *ApiApplicationServiceImpl) CallApi(ctx context.Context, cmd *commands.A
}
// 6. 调用API
response, err := s.apiRequestService.PreprocessRequestApi(txCtx, cmd.ApiName, requestParams, &cmd.Options)
// 查询用户的合同信息获取合同编号
contractCode := "" // 默认空字符串
contractInfo, err := s.contractInfoService.FindByUserID(txCtx, apiUser.UserId)
if err == nil && len(contractInfo) > 0 {
contractCode = contractInfo[0].ContractCode
} else {
s.logger.Error("查合同信息失败", zap.Error(err))
businessError = ErrSystem
return ErrSystem
}
// 创建CallContext传递合同编号
callContext := &processors.CallContext{
ContractCode: contractCode,
}
response, err := s.apiRequestService.PreprocessRequestApi(txCtx, cmd.ApiName, requestParams, &cmd.Options, callContext)
if err != nil {
if errors.Is(err, processors.ErrDatasource) {
s.logger.Error("调用API失败", zap.Error(err))