From e32759dd950fa2da8e2c4cd19bc6e301e4e3d972 Mon Sep 17 00:00:00 2001 From: liangzai <2440983361@qq.com> Date: Thu, 25 Jun 2026 16:33:09 +0800 Subject: [PATCH] f --- .../api/api_application_service.go | 11 ++++++++ internal/application/api/errors.go | 2 ++ .../processors/qygl/qygl4b2e_processor.go | 2 +- .../processors/qygl/qygl6s1b_processor.go | 25 +++++++++++-------- .../processors/qygl/qygl7d9a_processor.go | 2 +- .../processors/qygl/qygl8b4d_processor.go | 2 +- .../external/shujubao/shujubao_errors.go | 4 +-- 7 files changed, 32 insertions(+), 16 deletions(-) diff --git a/internal/application/api/api_application_service.go b/internal/application/api/api_application_service.go index 1a4113d..63746b1 100644 --- a/internal/application/api/api_application_service.go +++ b/internal/application/api/api_application_service.go @@ -24,6 +24,7 @@ import ( subordinate_repositories "tyapi-server/internal/domains/subordinate/repositories" user_repositories "tyapi-server/internal/domains/user/repositories" task_entities "tyapi-server/internal/infrastructure/task/entities" + "tyapi-server/internal/infrastructure/external/shujubao" "tyapi-server/internal/infrastructure/task/interfaces" "tyapi-server/internal/shared/crypto" "tyapi-server/internal/shared/database" @@ -165,6 +166,11 @@ func (s *ApiApplicationServiceImpl) CallApi(ctx context.Context, cmd *commands.A // 3. 同步调用外部API(核心业务) response, err := s.callExternalApi(ctx, cmd, validationResult) + if errors.Is(err, ErrQueryEmptyBillable) { + go s.asyncSaveApiCall(context.Background(), apiCall, validationResult, "") + go s.asyncProcessDeduction(context.Background(), apiCall, validationResult) + return transactionId, "", ErrQueryEmpty + } if err != nil { // 异步记录失败状态 go s.asyncRecordFailure(context.Background(), apiCall, err) @@ -399,6 +405,11 @@ func (s *ApiApplicationServiceImpl) callExternalApi(ctx context.Context, cmd *co callContext) if err != nil { + // 数据宝 10001/10006:查空但计费,由 CallApi 统一处理 + if errors.Is(err, shujubao.ErrQueryEmpty) { + return "", ErrQueryEmptyBillable + } + mappedErrorType := entities.ApiCallErrorSystem if errors.Is(err, processors.ErrDatasource) { mappedErrorType = entities.ApiCallErrorDatasource diff --git a/internal/application/api/errors.go b/internal/application/api/errors.go index 8314044..6a6e653 100644 --- a/internal/application/api/errors.go +++ b/internal/application/api/errors.go @@ -5,6 +5,8 @@ import "errors" // API调用相关错误类型 var ( ErrQueryEmpty = errors.New("查询为空") + // ErrQueryEmptyBillable 数据宝查空(10001/10006):对外返回查询为空,但仍正常扣费 + ErrQueryEmptyBillable = errors.New("查询为空") ErrQueryFailed = errors.New("查询失败") ErrSystem = errors.New("接口异常") ErrDecryptFail = errors.New("解密失败") diff --git a/internal/domains/api/services/processors/qygl/qygl4b2e_processor.go b/internal/domains/api/services/processors/qygl/qygl4b2e_processor.go index 5d4db59..cdac32a 100644 --- a/internal/domains/api/services/processors/qygl/qygl4b2e_processor.go +++ b/internal/domains/api/services/processors/qygl/qygl4b2e_processor.go @@ -65,7 +65,7 @@ func ProcessQYGL4B2ERequest( return nil, errors.Join(processors.ErrDatasource, err) } if errors.Is(err, shujubao.ErrQueryEmpty) { - data = map[string]interface{}{} + return nil, errors.Join(processors.ErrNotFound, err) } else { return nil, errors.Join(processors.ErrSystem, err) } diff --git a/internal/domains/api/services/processors/qygl/qygl6s1b_processor.go b/internal/domains/api/services/processors/qygl/qygl6s1b_processor.go index f258356..3218523 100644 --- a/internal/domains/api/services/processors/qygl/qygl6s1b_processor.go +++ b/internal/domains/api/services/processors/qygl/qygl6s1b_processor.go @@ -11,6 +11,19 @@ import ( "tyapi-server/internal/infrastructure/external/shujubao" ) +// emptyQYGL6S1BResult 数据宝成功但无 resultData 时返回的空业务结构 +func emptyQYGL6S1BResult() ([]byte, error) { + emptyResult := map[string]interface{}{ + "caseInfoList": []interface{}{}, + "legRepInfoList": []interface{}{}, + "lossPromiseList": []interface{}{}, + "performerList": []interface{}{}, + "ryPosPerList": []interface{}{}, + "shareholderList": []interface{}{}, + } + return json.Marshal(emptyResult) +} + // ProcessQYGL6S1BRequest QYGL6S1B API处理方法 - 董监高司法综合信息核验(使用数据宝服务) func ProcessQYGL6S1BRequest(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) { @@ -38,7 +51,6 @@ func ProcessQYGL6S1BRequest(ctx context.Context, params []byte, deps *processors } if errors.Is(err, shujubao.ErrQueryEmpty) { return nil, errors.Join(processors.ErrNotFound, err) - // data = map[string]interface{}{} } else { return nil, errors.Join(processors.ErrSystem, err) } @@ -58,16 +70,7 @@ func ProcessQYGL6S1BRequest(ctx context.Context, params []byte, deps *processors resultDataValue, exists := resultData["resultData"] if !exists { - // 如果 resultData 不存在,说明查询为空,返回空的业务数据结构 - emptyResult := map[string]interface{}{ - "caseInfoList": []interface{}{}, - "legRepInfoList": []interface{}{}, - "lossPromiseList": []interface{}{}, - "performerList": []interface{}{}, - "ryPosPerList": []interface{}{}, - "shareholderList": []interface{}{}, - } - return json.Marshal(emptyResult) + return emptyQYGL6S1BResult() } // 转换数据类型:将数字字段转换为字符串 diff --git a/internal/domains/api/services/processors/qygl/qygl7d9a_processor.go b/internal/domains/api/services/processors/qygl/qygl7d9a_processor.go index 083352c..dc8e1d4 100644 --- a/internal/domains/api/services/processors/qygl/qygl7d9a_processor.go +++ b/internal/domains/api/services/processors/qygl/qygl7d9a_processor.go @@ -95,7 +95,7 @@ func ProcessQYGL7D9ARequest(ctx context.Context, params []byte, deps *processors return nil, errors.Join(processors.ErrDatasource, err) } if errors.Is(err, shujubao.ErrQueryEmpty) { - data = map[string]interface{}{} + return nil, errors.Join(processors.ErrNotFound, err) } else { return nil, errors.Join(processors.ErrSystem, err) } diff --git a/internal/domains/api/services/processors/qygl/qygl8b4d_processor.go b/internal/domains/api/services/processors/qygl/qygl8b4d_processor.go index f4e43b6..885d336 100644 --- a/internal/domains/api/services/processors/qygl/qygl8b4d_processor.go +++ b/internal/domains/api/services/processors/qygl/qygl8b4d_processor.go @@ -86,7 +86,7 @@ func ProcessQYGL8B4DRequest(ctx context.Context, params []byte, deps *processors return nil, errors.Join(processors.ErrDatasource, err) } if errors.Is(err, shujubao.ErrQueryEmpty) { - data = map[string]interface{}{} + return nil, errors.Join(processors.ErrNotFound, err) } else { return nil, errors.Join(processors.ErrSystem, err) } diff --git a/internal/infrastructure/external/shujubao/shujubao_errors.go b/internal/infrastructure/external/shujubao/shujubao_errors.go index 6368b4c..3c5fd00 100644 --- a/internal/infrastructure/external/shujubao/shujubao_errors.go +++ b/internal/infrastructure/external/shujubao/shujubao_errors.go @@ -4,8 +4,8 @@ import ( "fmt" ) -// GetQueryEmptyErrByCode 将数据宝错误码归类为“查询为空/不扣费”错误。 -// 说明:上游通常依赖 errors.Is(err, ErrQueryEmpty) 来决定是否扣费。 +// GetQueryEmptyErrByCode 将数据宝错误码归类为“查询为空”错误(10001/10006)。 +// 说明:应用层识别 ErrQueryEmpty 后对外返回 code=1000,并正常扣费。 func GetQueryEmptyErrByCode(code string) error { switch code { case "10001", "10006":