fix
This commit is contained in:
@@ -41,15 +41,19 @@ type ApiApplicationService interface {
|
||||
|
||||
// 加密参数接口
|
||||
EncryptParams(ctx context.Context, userID string, cmd *commands.EncryptCommand) (string, error)
|
||||
|
||||
|
||||
// 解密参数接口
|
||||
DecryptParams(ctx context.Context, userID string, cmd *commands.DecryptCommand) (map[string]interface{}, error)
|
||||
|
||||
// 获取表单配置
|
||||
GetFormConfig(ctx context.Context, apiCode string) (*dto.FormConfigResponse, error)
|
||||
}
|
||||
|
||||
type ApiApplicationServiceImpl struct {
|
||||
apiCallService services.ApiCallAggregateService
|
||||
apiUserService services.ApiUserAggregateService
|
||||
apiRequestService *services.ApiRequestService
|
||||
formConfigService services.FormConfigService
|
||||
apiCallRepository repositories.ApiCallRepository
|
||||
walletService finance_services.WalletAggregateService
|
||||
contractInfoService user_repositories.ContractInfoRepository
|
||||
@@ -61,8 +65,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, 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}
|
||||
func NewApiApplicationService(apiCallService services.ApiCallAggregateService, apiUserService services.ApiUserAggregateService, apiRequestService *services.ApiRequestService, formConfigService services.FormConfigService, 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, formConfigService: formConfigService, apiCallRepository: apiCallRepository, walletService: walletService, productManagementService: productManagementService, productSubscriptionService: productSubscriptionService, userRepo: userRepo, txManager: txManager, config: config, logger: logger, contractInfoService: contractInfoService}
|
||||
}
|
||||
|
||||
// CallApi 应用服务层统一入口
|
||||
@@ -111,8 +115,8 @@ func (s *ApiApplicationServiceImpl) CallApi(ctx context.Context, cmd *commands.A
|
||||
}
|
||||
// 在开发环境或调试模式下跳过IP白名单校验
|
||||
if s.config.App.IsDevelopment() || cmd.Options.IsDebug {
|
||||
s.logger.Info("跳过IP白名单校验",
|
||||
zap.String("userId", apiUser.UserId),
|
||||
s.logger.Info("跳过IP白名单校验",
|
||||
zap.String("userId", apiUser.UserId),
|
||||
zap.String("ip", cmd.ClientIP),
|
||||
zap.Bool("isDevelopment", s.config.App.IsDevelopment()),
|
||||
zap.Bool("isDebug", cmd.Options.IsDebug))
|
||||
@@ -176,10 +180,10 @@ func (s *ApiApplicationServiceImpl) CallApi(ctx context.Context, cmd *commands.A
|
||||
callContext := &processors.CallContext{
|
||||
ContractCode: contractCode,
|
||||
}
|
||||
|
||||
|
||||
// 将transactionId放入ctx中,供外部服务使用
|
||||
ctxWithTransactionId := context.WithValue(txCtx, "transaction_id", transactionId)
|
||||
|
||||
|
||||
response, err := s.apiRequestService.PreprocessRequestApi(ctxWithTransactionId, cmd.ApiName, requestParams, &cmd.Options, callContext)
|
||||
if err != nil {
|
||||
if errors.Is(err, processors.ErrDatasource) {
|
||||
@@ -527,7 +531,7 @@ func (s *ApiApplicationServiceImpl) EncryptParams(ctx context.Context, userID st
|
||||
s.logger.Error("序列化参数失败", zap.Error(err))
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
// 2. 使用前端传来的SecretKey进行加密
|
||||
encryptedData, err := crypto.AesEncrypt(jsonData, cmd.SecretKey)
|
||||
if err != nil {
|
||||
@@ -546,7 +550,7 @@ func (s *ApiApplicationServiceImpl) DecryptParams(ctx context.Context, userID st
|
||||
s.logger.Error("解密参数失败", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
// 2. 将解密后的JSON字节数组转换为map
|
||||
var result map[string]interface{}
|
||||
err = json.Unmarshal(decryptedData, &result)
|
||||
@@ -557,3 +561,38 @@ func (s *ApiApplicationServiceImpl) DecryptParams(ctx context.Context, userID st
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetFormConfig 获取指定API的表单配置
|
||||
func (s *ApiApplicationServiceImpl) GetFormConfig(ctx context.Context, apiCode string) (*dto.FormConfigResponse, error) {
|
||||
// 调用领域服务获取表单配置
|
||||
config, err := s.formConfigService.GetFormConfig(apiCode)
|
||||
if err != nil {
|
||||
s.logger.Error("获取表单配置失败", zap.String("api_code", apiCode), zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if config == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// 转换为应用层DTO
|
||||
response := &dto.FormConfigResponse{
|
||||
ApiCode: config.ApiCode,
|
||||
Fields: make([]dto.FormField, len(config.Fields)),
|
||||
}
|
||||
|
||||
for i, field := range config.Fields {
|
||||
response.Fields[i] = dto.FormField{
|
||||
Name: field.Name,
|
||||
Label: field.Label,
|
||||
Type: field.Type,
|
||||
Required: field.Required,
|
||||
Validation: field.Validation,
|
||||
Description: field.Description,
|
||||
Example: field.Example,
|
||||
Placeholder: field.Placeholder,
|
||||
}
|
||||
}
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
19
internal/application/api/dto/form_config_dto.go
Normal file
19
internal/application/api/dto/form_config_dto.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package dto
|
||||
|
||||
// FormField 表单字段配置
|
||||
type FormField struct {
|
||||
Name string `json:"name"`
|
||||
Label string `json:"label"`
|
||||
Type string `json:"type"`
|
||||
Required bool `json:"required"`
|
||||
Validation string `json:"validation"`
|
||||
Description string `json:"description"`
|
||||
Example string `json:"example"`
|
||||
Placeholder string `json:"placeholder"`
|
||||
}
|
||||
|
||||
// FormConfigResponse 表单配置响应
|
||||
type FormConfigResponse struct {
|
||||
ApiCode string `json:"api_code"`
|
||||
Fields []FormField `json:"fields"`
|
||||
}
|
||||
Reference in New Issue
Block a user