add new processor

This commit is contained in:
2025-11-13 20:43:35 +08:00
parent f00cee7410
commit 00a3f0f1e9
15 changed files with 961 additions and 1 deletions

View File

@@ -0,0 +1,63 @@
package qygl
import (
"context"
"encoding/json"
"errors"
"fmt"
"tyapi-server/internal/domains/api/dto"
"tyapi-server/internal/domains/api/services/processors"
"tyapi-server/internal/infrastructure/external/zhicha"
)
// ProcessQYGL2B5CRequest QYGL2B5C API处理方法 - 企业联系人实际经营地址
func ProcessQYGL2B5CRequest(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
var paramsDto dto.QYGL2B5CReq
if err := json.Unmarshal(params, &paramsDto); err != nil {
return nil, errors.Join(processors.ErrSystem, err)
}
if err := deps.Validator.ValidateStruct(paramsDto); err != nil {
return nil, errors.Join(processors.ErrInvalidParam, err)
}
// 两选一校验EntName 和 EntCode 至少传一个
var keyword string
if paramsDto.EntName != "" && paramsDto.EntCode != "" {
return nil, fmt.Errorf("%s: %w", processors.ErrInvalidParam, errors.New("企业名称和企业统一信用代码只能传其中一个"))
}
if paramsDto.EntName == "" && paramsDto.EntCode == "" {
return nil, fmt.Errorf("%s: %w", processors.ErrInvalidParam, errors.New("必须提供企业名称或企业统一信用代码中的其中一个"))
}
// 确定使用哪个值作为 keyword
if paramsDto.EntName != "" {
keyword = paramsDto.EntName
} else {
keyword = paramsDto.EntCode
}
reqData := map[string]interface{}{
"keyword": keyword,
"authorized": paramsDto.Authorized,
}
respData, err := deps.ZhichaService.CallAPI(ctx, "ZCI050", 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)
}
}
// 将响应数据转换为 JSON 字节
respBytes, err := json.Marshal(respData)
if err != nil {
return nil, errors.Join(processors.ErrSystem, err)
}
return respBytes, nil
}