f
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
|||||||
|
|
||||||
"hyapi-server/internal/domains/api/dto"
|
"hyapi-server/internal/domains/api/dto"
|
||||||
"hyapi-server/internal/domains/api/services/processors"
|
"hyapi-server/internal/domains/api/services/processors"
|
||||||
"hyapi-server/internal/infrastructure/external/huibo"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ProcessFLXGHB4FRequest FLXGHB4F API处理方法 - 个人涉诉案件查询汇博
|
// ProcessFLXGHB4FRequest FLXGHB4F API处理方法 - 个人涉诉案件查询汇博
|
||||||
@@ -38,27 +37,5 @@ func ProcessFLXGHB4FRequest(ctx context.Context, params []byte, deps *processors
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Join(processors.ErrDatasource, err)
|
return nil, errors.Join(processors.ErrDatasource, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析响应
|
|
||||||
var response huibo.CallAPI2Response
|
|
||||||
if err := json.Unmarshal(respBytes, &response); err != nil {
|
|
||||||
return nil, errors.Join(processors.ErrSystem, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理状态码
|
|
||||||
switch response.Code {
|
|
||||||
case huibo.CallAPI2StatusSuccess:
|
|
||||||
// 查询成功
|
|
||||||
if response.Data == nil {
|
|
||||||
return []byte("{}"), nil
|
|
||||||
}
|
|
||||||
return respBytes, nil
|
return respBytes, nil
|
||||||
case huibo.CallAPI2StatusNoData:
|
|
||||||
// 查询成功,无数据 - 按产品约定按调用成功计费
|
|
||||||
return []byte("{}"), nil
|
|
||||||
default:
|
|
||||||
// 其他错误状态码
|
|
||||||
message := huibo.GetCallAPI2StatusMessage(response.Code)
|
|
||||||
return nil, errors.Join(processors.ErrDatasource, errors.New(message))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
|
|
||||||
"hyapi-server/internal/domains/api/dto"
|
"hyapi-server/internal/domains/api/dto"
|
||||||
"hyapi-server/internal/domains/api/services/processors"
|
"hyapi-server/internal/domains/api/services/processors"
|
||||||
"hyapi-server/internal/infrastructure/external/huibo"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ProcessQYGLBH7YRequest QYGLBH7Y API处理方法 - 企业案件查询汇博
|
// ProcessQYGLBH7YRequest QYGLBH7Y API处理方法 - 企业案件查询汇博
|
||||||
@@ -33,27 +32,5 @@ func ProcessQYGLBH7YRequest(ctx context.Context, params []byte, deps *processors
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Join(processors.ErrDatasource, err)
|
return nil, errors.Join(processors.ErrDatasource, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析响应
|
|
||||||
var response huibo.CallAPI2Response
|
|
||||||
if err := json.Unmarshal(respBytes, &response); err != nil {
|
|
||||||
return nil, errors.Join(processors.ErrSystem, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理状态码
|
|
||||||
switch response.Code {
|
|
||||||
case huibo.CallAPI2StatusSuccess:
|
|
||||||
// 查询成功
|
|
||||||
if response.Data == nil {
|
|
||||||
return []byte("{}"), nil
|
|
||||||
}
|
|
||||||
return respBytes, nil
|
return respBytes, nil
|
||||||
case huibo.CallAPI2StatusNoData:
|
|
||||||
// 查询成功,无数据 - 按产品约定按调用成功计费
|
|
||||||
return []byte("{}"), nil
|
|
||||||
default:
|
|
||||||
// 其他错误状态码
|
|
||||||
message := huibo.GetCallAPI2StatusMessage(response.Code)
|
|
||||||
return nil, errors.Join(processors.ErrDatasource, errors.New(message))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,25 @@ type responseWrapper struct {
|
|||||||
type CallAPI2Response struct {
|
type CallAPI2Response struct {
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
Data map[string]interface{} `json:"data"`
|
Data map[string]interface{} `json:"data"`
|
||||||
|
Message string `json:"message"`
|
||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
|
OrderNo string `json:"orderNo"`
|
||||||
|
Charge bool `json:"charge"`
|
||||||
|
Pcode string `json:"pcode"`
|
||||||
|
Param interface{} `json:"param"`
|
||||||
|
Time json.RawMessage `json:"time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// extractCallAPI2Data 从已解析的 CallAPI2 响应中提取 data 字段,不透传 code/orderNo/charge 等外层元数据
|
||||||
|
func extractCallAPI2Data(response *CallAPI2Response) ([]byte, error) {
|
||||||
|
if response == nil || response.Data == nil {
|
||||||
|
return []byte("{}"), nil
|
||||||
|
}
|
||||||
|
dataBytes, err := json.Marshal(response.Data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("data 序列化失败: %w", err)
|
||||||
|
}
|
||||||
|
return dataBytes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHuiboService(config HuiboConfig, logger *external_logger.ExternalServiceLogger) *HuiboService {
|
func NewHuiboService(config HuiboConfig, logger *external_logger.ExternalServiceLogger) *HuiboService {
|
||||||
@@ -561,7 +579,6 @@ func (s *HuiboService) CallAPI2(ctx context.Context, pcode string, requestData m
|
|||||||
// 根据业务状态码进行处理
|
// 根据业务状态码进行处理
|
||||||
switch response.Code {
|
switch response.Code {
|
||||||
case CallAPI2StatusSuccess:
|
case CallAPI2StatusSuccess:
|
||||||
// 查询成功
|
|
||||||
if s.logger != nil {
|
if s.logger != nil {
|
||||||
s.logger.LogInfo(
|
s.logger.LogInfo(
|
||||||
"汇博 CallAPI2 查询成功",
|
"汇博 CallAPI2 查询成功",
|
||||||
@@ -571,7 +588,6 @@ func (s *HuiboService) CallAPI2(ctx context.Context, pcode string, requestData m
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
case CallAPI2StatusNoData:
|
case CallAPI2StatusNoData:
|
||||||
// 查询成功,无数据
|
|
||||||
if s.logger != nil {
|
if s.logger != nil {
|
||||||
s.logger.LogInfo(
|
s.logger.LogInfo(
|
||||||
"汇博 CallAPI2 查询成功但无数据",
|
"汇博 CallAPI2 查询成功但无数据",
|
||||||
@@ -580,8 +596,17 @@ func (s *HuiboService) CallAPI2(ctx context.Context, pcode string, requestData m
|
|||||||
zap.String("transaction_id", transactionID),
|
zap.String("transaction_id", transactionID),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
if s.logger != nil {
|
||||||
|
s.logger.LogInfo(
|
||||||
|
"汇博 CallAPI2 请求响应",
|
||||||
|
zap.String("curl", curlCmd),
|
||||||
|
zap.String("response_body", string(respBody)),
|
||||||
|
zap.String("transaction_id", transactionID),
|
||||||
|
)
|
||||||
|
s.logger.LogResponse("", transactionID, "huibo_callapi2", http.StatusOK, time.Since(startTime))
|
||||||
|
}
|
||||||
|
return []byte("{}"), nil
|
||||||
default:
|
default:
|
||||||
// 其他错误状态码
|
|
||||||
message := GetCallAPI2StatusMessage(response.Code)
|
message := GetCallAPI2StatusMessage(response.Code)
|
||||||
if s.logger != nil {
|
if s.logger != nil {
|
||||||
s.logger.LogErrorWithFields("汇博 CallAPI2 业务状态异常",
|
s.logger.LogErrorWithFields("汇博 CallAPI2 业务状态异常",
|
||||||
@@ -594,7 +619,6 @@ func (s *HuiboService) CallAPI2(ctx context.Context, pcode string, requestData m
|
|||||||
return nil, errors.Join(ErrDatasource, fmt.Errorf("业务状态异常(code=%s,msg=%s)", response.Code, message))
|
return nil, errors.Join(ErrDatasource, fmt.Errorf("业务状态异常(code=%s,msg=%s)", response.Code, message))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 记录 curl 命令和响应
|
|
||||||
if s.logger != nil {
|
if s.logger != nil {
|
||||||
s.logger.LogInfo(
|
s.logger.LogInfo(
|
||||||
"汇博 CallAPI2 请求响应",
|
"汇博 CallAPI2 请求响应",
|
||||||
@@ -604,9 +628,14 @@ func (s *HuiboService) CallAPI2(ctx context.Context, pcode string, requestData m
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dataBytes, err := extractCallAPI2Data(&response)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Join(ErrDatasource, err)
|
||||||
|
}
|
||||||
|
|
||||||
if s.logger != nil {
|
if s.logger != nil {
|
||||||
s.logger.LogResponse("", transactionID, "huibo_callapi2", http.StatusOK, time.Since(startTime))
|
s.logger.LogResponse("", transactionID, "huibo_callapi2", http.StatusOK, time.Since(startTime))
|
||||||
}
|
}
|
||||||
|
|
||||||
return respBody, nil
|
return dataBytes, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user