This commit is contained in:
Mrx
2026-06-01 14:39:45 +08:00
parent 928ff4d766
commit 8ab2a6d81d
14 changed files with 495 additions and 67 deletions

View File

@@ -7,54 +7,40 @@ import (
"tyapi-server/internal/domains/api/dto"
"tyapi-server/internal/domains/api/services/processors"
"tyapi-server/internal/infrastructure/external/huibo"
"tyapi-server/internal/infrastructure/external/haiyuapi"
)
// ProcessFLXGHB4FRequest FLXGHB4F API处理方法 - 个人涉诉案件查询汇博
// ProcessFLXGHB4FRequest FLXGHB4F API处理方法 - 个人涉诉案件查询海宇API
func ProcessFLXGHB4FRequest(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
var paramsDto dto.FLXGHB4FReq
if err := json.Unmarshal(params, &paramsDto); err != nil {
return nil, errors.Join(processors.ErrSystem, err)
}
if deps.HuiboService == nil {
return nil, errors.Join(processors.ErrSystem, errors.New("汇博服务未初始化"))
if err := deps.Validator.ValidateStruct(paramsDto); err != nil {
return nil, errors.Join(processors.ErrInvalidParam, err)
}
// 使用 MD5 加密 name 和 idCard
// encryptedName := "MD5:" + huibo.MD5Encrypt(paramsDto.Name, deps.HuiboService.GetConfig().AppKey)
// encryptedIDCard := "MD5:" + huibo.MD5Encrypt(paramsDto.IDCard, deps.HuiboService.GetConfig().AppKey)
reqdata := map[string]interface{}{
"name": paramsDto.Name,
"idCard": paramsDto.IDCard,
if deps.HaiyuapiService == nil {
return nil, errors.Join(processors.ErrSystem, errors.New("海宇API服务未初始化"))
}
respBytes, err := deps.HuiboService.CallAPI2(ctx, "P_004_0271", reqdata)
reqParams := map[string]interface{}{
"name": paramsDto.Name,
"id_card": paramsDto.IDCard,
}
apiPath := "/api/v1/FLXGHB4F"
respBytes, err := deps.HaiyuapiService.CallAPI(ctx, apiPath, reqParams)
if err != nil {
return nil, errors.Join(processors.ErrDatasource, err)
}
// 解析响应
var response huibo.CallAPI2Response
if err := json.Unmarshal(respBytes, &response); err != nil {
if errors.Is(err, haiyuapi.ErrNotFound) {
return nil, errors.Join(processors.ErrNotFound, err)
}
if errors.Is(err, haiyuapi.ErrDatasource) {
return nil, errors.Join(processors.ErrDatasource, err)
}
return nil, errors.Join(processors.ErrSystem, err)
}
// 处理状态码
switch response.Code {
case huibo.CallAPI2StatusSuccess:
// 查询成功
if response.Data == nil {
return []byte("{}"), 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))
}
return respBytes, nil
}