up
This commit is contained in:
@@ -4,13 +4,14 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"tyapi-server/internal/domains/api/dto"
|
||||
"tyapi-server/internal/domains/api/services/processors"
|
||||
"tyapi-server/internal/infrastructure/external/zhicha"
|
||||
"tyapi-server/internal/infrastructure/external/shujubao"
|
||||
)
|
||||
|
||||
// ProcessQYGL6S1BRequest QYGL6S1B API处理方法 - 董监高司法综合信息核验
|
||||
// ProcessQYGL6S1BRequest QYGL6S1B API处理方法 - 董监高司法综合信息核验(使用数据宝服务)
|
||||
|
||||
func ProcessQYGL6S1BRequest(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
|
||||
var paramsDto dto.QYGL6S1BReq
|
||||
@@ -22,31 +23,106 @@ func ProcessQYGL6S1BRequest(ctx context.Context, params []byte, deps *processors
|
||||
return nil, errors.Join(processors.ErrInvalidParam, err)
|
||||
}
|
||||
|
||||
encryptedIdCard, err := deps.ZhichaService.Encrypt(paramsDto.IDCard)
|
||||
// 构建数据宝入参
|
||||
reqParams := map[string]interface{}{
|
||||
"key": "1cce582f0a6f3ca40de80f1bea9b9698",
|
||||
"idcard": paramsDto.IDCard,
|
||||
}
|
||||
|
||||
// 调用数据宝API
|
||||
apiPath := "/communication/personal/10166"
|
||||
data, err := deps.ShujubaoService.CallAPI(ctx, apiPath, reqParams)
|
||||
if err != nil {
|
||||
if errors.Is(err, shujubao.ErrDatasource) {
|
||||
return nil, errors.Join(processors.ErrDatasource, err)
|
||||
}
|
||||
if errors.Is(err, shujubao.ErrQueryEmpty) {
|
||||
return nil, errors.Join(processors.ErrNotFound, err)
|
||||
}
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
|
||||
// 解析响应中的 JSON 字符串(使用 RecursiveParse)
|
||||
parsedResp, err := RecursiveParse(data)
|
||||
if err != nil {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
|
||||
// 构建API调用参数
|
||||
reqData := map[string]interface{}{
|
||||
"idCard": encryptedIdCard,
|
||||
"authorized": paramsDto.Authorized,
|
||||
// 提取 resultData 字段
|
||||
resultData, ok := parsedResp.(map[string]interface{})
|
||||
if !ok {
|
||||
return nil, errors.Join(processors.ErrSystem, errors.New("invalid response format"))
|
||||
}
|
||||
|
||||
respData, err := deps.ZhichaService.CallAPI(ctx, "ZCI043", reqData)
|
||||
if err != nil {
|
||||
if errors.Is(err, zhicha.ErrDatasource) {
|
||||
return nil, errors.Join(processors.ErrDatasource, err)
|
||||
} else {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
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)
|
||||
}
|
||||
|
||||
// 将响应数据转换为JSON字节
|
||||
respBytes, err := json.Marshal(respData)
|
||||
// 转换数据类型:将数字字段转换为字符串
|
||||
convertedData, err := convertDataTypes(resultDataValue)
|
||||
if err != nil {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
|
||||
respBytes, err := json.Marshal(convertedData)
|
||||
if err != nil {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
|
||||
return respBytes, nil
|
||||
}
|
||||
|
||||
// convertDataTypes 递归转换数据类型,将数字字段转换为字符串以保持与原有格式一致
|
||||
func convertDataTypes(data interface{}) (interface{}, error) {
|
||||
switch v := data.(type) {
|
||||
case map[string]interface{}:
|
||||
for key, val := range v {
|
||||
converted, err := convertDataTypes(val)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v[key] = converted
|
||||
}
|
||||
return v, nil
|
||||
case []interface{}:
|
||||
for i, item := range v {
|
||||
converted, err := convertDataTypes(item)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v[i] = converted
|
||||
}
|
||||
return v, nil
|
||||
case float64:
|
||||
// 将 float64 类型转换为字符串(JSON 解析后数字默认为 float64)
|
||||
if v == float64(int64(v)) {
|
||||
return strconv.FormatInt(int64(v), 10), nil
|
||||
}
|
||||
return strconv.FormatFloat(v, 'f', -1, 64), nil
|
||||
case int:
|
||||
return strconv.Itoa(v), nil
|
||||
case int32:
|
||||
return strconv.FormatInt(int64(v), 10), nil
|
||||
case int64:
|
||||
return strconv.FormatInt(v, 10), nil
|
||||
case string:
|
||||
// 尝试解析字符串中的 JSON
|
||||
var parsed interface{}
|
||||
if err := json.Unmarshal([]byte(v), &parsed); err == nil {
|
||||
return convertDataTypes(parsed)
|
||||
}
|
||||
return v, nil
|
||||
default:
|
||||
return v, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user