更新处理器

This commit is contained in:
2026-06-10 20:32:24 +08:00
parent a29265f901
commit 45ae6cf36e
293 changed files with 2028 additions and 23462 deletions

View File

@@ -0,0 +1,53 @@
package processors
import (
"context"
"encoding/json"
"errors"
"hyapi-server/internal/infrastructure/external/tianyuanapi"
)
// CallTianyuanByProduct 将处理器入参 JSON 转发至天远平台对应产品(使用天远侧产品编号)
func CallTianyuanByProduct(ctx context.Context, deps *ProcessorDependencies, productCode string, params []byte) ([]byte, error) {
if deps == nil || deps.TianyuanapiService == nil {
return nil, errors.Join(ErrSystem, errors.New("天远 API 服务未配置"))
}
var paramsMap map[string]interface{}
if err := json.Unmarshal(params, &paramsMap); err != nil {
return nil, errors.Join(ErrSystem, err)
}
respBytes, err := deps.TianyuanapiService.CallAPI(ctx, productCode, paramsMap)
if err != nil {
if errors.Is(err, tianyuanapi.ErrNotFound) {
return nil, errors.Join(ErrNotFound, err)
}
if errors.Is(err, tianyuanapi.ErrDatasource) {
return nil, errors.Join(ErrDatasource, err)
}
if errors.Is(err, tianyuanapi.ErrSystem) {
return nil, errors.Join(ErrSystem, err)
}
return nil, errors.Join(ErrSystem, err)
}
return respBytes, nil
}
// MapTianyuanError 将天远服务错误映射为处理器层错误(直接调用 CallAPI 时使用)
func MapTianyuanError(err error) error {
if err == nil {
return nil
}
if errors.Is(err, tianyuanapi.ErrNotFound) {
return errors.Join(ErrNotFound, err)
}
if errors.Is(err, tianyuanapi.ErrDatasource) {
return errors.Join(ErrDatasource, err)
}
if errors.Is(err, tianyuanapi.ErrSystem) {
return errors.Join(ErrSystem, err)
}
return errors.Join(ErrSystem, err)
}