This commit is contained in:
2026-06-25 16:33:09 +08:00
parent baf82898b5
commit e32759dd95
7 changed files with 32 additions and 16 deletions

View File

@@ -24,6 +24,7 @@ import (
subordinate_repositories "tyapi-server/internal/domains/subordinate/repositories" subordinate_repositories "tyapi-server/internal/domains/subordinate/repositories"
user_repositories "tyapi-server/internal/domains/user/repositories" user_repositories "tyapi-server/internal/domains/user/repositories"
task_entities "tyapi-server/internal/infrastructure/task/entities" task_entities "tyapi-server/internal/infrastructure/task/entities"
"tyapi-server/internal/infrastructure/external/shujubao"
"tyapi-server/internal/infrastructure/task/interfaces" "tyapi-server/internal/infrastructure/task/interfaces"
"tyapi-server/internal/shared/crypto" "tyapi-server/internal/shared/crypto"
"tyapi-server/internal/shared/database" "tyapi-server/internal/shared/database"
@@ -165,6 +166,11 @@ func (s *ApiApplicationServiceImpl) CallApi(ctx context.Context, cmd *commands.A
// 3. 同步调用外部API核心业务 // 3. 同步调用外部API核心业务
response, err := s.callExternalApi(ctx, cmd, validationResult) 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 { if err != nil {
// 异步记录失败状态 // 异步记录失败状态
go s.asyncRecordFailure(context.Background(), apiCall, err) go s.asyncRecordFailure(context.Background(), apiCall, err)
@@ -399,6 +405,11 @@ func (s *ApiApplicationServiceImpl) callExternalApi(ctx context.Context, cmd *co
callContext) callContext)
if err != nil { if err != nil {
// 数据宝 10001/10006查空但计费由 CallApi 统一处理
if errors.Is(err, shujubao.ErrQueryEmpty) {
return "", ErrQueryEmptyBillable
}
mappedErrorType := entities.ApiCallErrorSystem mappedErrorType := entities.ApiCallErrorSystem
if errors.Is(err, processors.ErrDatasource) { if errors.Is(err, processors.ErrDatasource) {
mappedErrorType = entities.ApiCallErrorDatasource mappedErrorType = entities.ApiCallErrorDatasource

View File

@@ -5,6 +5,8 @@ import "errors"
// API调用相关错误类型 // API调用相关错误类型
var ( var (
ErrQueryEmpty = errors.New("查询为空") ErrQueryEmpty = errors.New("查询为空")
// ErrQueryEmptyBillable 数据宝查空10001/10006对外返回查询为空但仍正常扣费
ErrQueryEmptyBillable = errors.New("查询为空")
ErrQueryFailed = errors.New("查询失败") ErrQueryFailed = errors.New("查询失败")
ErrSystem = errors.New("接口异常") ErrSystem = errors.New("接口异常")
ErrDecryptFail = errors.New("解密失败") ErrDecryptFail = errors.New("解密失败")

View File

@@ -65,7 +65,7 @@ func ProcessQYGL4B2ERequest(
return nil, errors.Join(processors.ErrDatasource, err) return nil, errors.Join(processors.ErrDatasource, err)
} }
if errors.Is(err, shujubao.ErrQueryEmpty) { if errors.Is(err, shujubao.ErrQueryEmpty) {
data = map[string]interface{}{} return nil, errors.Join(processors.ErrNotFound, err)
} else { } else {
return nil, errors.Join(processors.ErrSystem, err) return nil, errors.Join(processors.ErrSystem, err)
} }

View File

@@ -11,6 +11,19 @@ import (
"tyapi-server/internal/infrastructure/external/shujubao" "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处理方法 - 董监高司法综合信息核验(使用数据宝服务) // ProcessQYGL6S1BRequest QYGL6S1B API处理方法 - 董监高司法综合信息核验(使用数据宝服务)
func ProcessQYGL6S1BRequest(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) { 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) { if errors.Is(err, shujubao.ErrQueryEmpty) {
return nil, errors.Join(processors.ErrNotFound, err) return nil, errors.Join(processors.ErrNotFound, err)
// data = map[string]interface{}{}
} else { } else {
return nil, errors.Join(processors.ErrSystem, err) return nil, errors.Join(processors.ErrSystem, err)
} }
@@ -58,16 +70,7 @@ func ProcessQYGL6S1BRequest(ctx context.Context, params []byte, deps *processors
resultDataValue, exists := resultData["resultData"] resultDataValue, exists := resultData["resultData"]
if !exists { if !exists {
// 如果 resultData 不存在,说明查询为空,返回空的业务数据结构 return emptyQYGL6S1BResult()
emptyResult := map[string]interface{}{
"caseInfoList": []interface{}{},
"legRepInfoList": []interface{}{},
"lossPromiseList": []interface{}{},
"performerList": []interface{}{},
"ryPosPerList": []interface{}{},
"shareholderList": []interface{}{},
}
return json.Marshal(emptyResult)
} }
// 转换数据类型:将数字字段转换为字符串 // 转换数据类型:将数字字段转换为字符串

View File

@@ -95,7 +95,7 @@ func ProcessQYGL7D9ARequest(ctx context.Context, params []byte, deps *processors
return nil, errors.Join(processors.ErrDatasource, err) return nil, errors.Join(processors.ErrDatasource, err)
} }
if errors.Is(err, shujubao.ErrQueryEmpty) { if errors.Is(err, shujubao.ErrQueryEmpty) {
data = map[string]interface{}{} return nil, errors.Join(processors.ErrNotFound, err)
} else { } else {
return nil, errors.Join(processors.ErrSystem, err) return nil, errors.Join(processors.ErrSystem, err)
} }

View File

@@ -86,7 +86,7 @@ func ProcessQYGL8B4DRequest(ctx context.Context, params []byte, deps *processors
return nil, errors.Join(processors.ErrDatasource, err) return nil, errors.Join(processors.ErrDatasource, err)
} }
if errors.Is(err, shujubao.ErrQueryEmpty) { if errors.Is(err, shujubao.ErrQueryEmpty) {
data = map[string]interface{}{} return nil, errors.Join(processors.ErrNotFound, err)
} else { } else {
return nil, errors.Join(processors.ErrSystem, err) return nil, errors.Join(processors.ErrSystem, err)
} }

View File

@@ -4,8 +4,8 @@ import (
"fmt" "fmt"
) )
// GetQueryEmptyErrByCode 将数据宝错误码归类为“查询为空/不扣费”错误。 // GetQueryEmptyErrByCode 将数据宝错误码归类为“查询为空”错误10001/10006
// 说明:上游通常依赖 errors.Is(err, ErrQueryEmpty) 来决定是否扣费。 // 说明:应用层识别 ErrQueryEmpty 后对外返回 code=1000并正常扣费。
func GetQueryEmptyErrByCode(code string) error { func GetQueryEmptyErrByCode(code string) error {
switch code { switch code {
case "10001", "10006": case "10001", "10006":