new
This commit is contained in:
74
internal/domains/api/services/processors/comb/README.md
Normal file
74
internal/domains/api/services/processors/comb/README.md
Normal file
@@ -0,0 +1,74 @@
|
||||
# 组合包处理器说明
|
||||
|
||||
## 🚀 动态组合包机制
|
||||
|
||||
从现在开始,组合包支持**动态处理机制**,大大简化了组合包的开发和维护工作。
|
||||
|
||||
## 📋 工作原理
|
||||
|
||||
### 1. 自动识别
|
||||
- 所有以 `COMB` 开头的API编码会被自动识别为组合包
|
||||
- 系统会自动调用通用组合包处理器处理请求
|
||||
|
||||
### 2. 处理流程
|
||||
1. **优先级检查**:首先检查是否有注册的自定义处理器
|
||||
2. **通用处理**:如果没有自定义处理器,且API编码以COMB开头,使用通用处理器
|
||||
3. **数据库驱动**:根据数据库中的组合包配置自动调用相应的子产品处理器
|
||||
|
||||
## 🛠️ 使用方式
|
||||
|
||||
### 普通组合包(无自定义逻辑)
|
||||
**只需要在数据库配置,无需编写任何代码!**
|
||||
|
||||
1. 在 `products` 表中创建组合包产品:
|
||||
```sql
|
||||
INSERT INTO products (code, name, is_package, ...)
|
||||
VALUES ('COMB1234', '新组合包', true, ...);
|
||||
```
|
||||
|
||||
2. 在 `product_package_items` 表中配置子产品:
|
||||
```sql
|
||||
INSERT INTO product_package_items (package_id, product_id, sort_order)
|
||||
VALUES
|
||||
('组合包产品ID', '子产品1ID', 1),
|
||||
('组合包产品ID', '子产品2ID', 2);
|
||||
```
|
||||
|
||||
3. **直接调用**:无需任何额外编码,API立即可用!
|
||||
|
||||
### 自定义组合包(有特殊逻辑)
|
||||
如果需要对组合包结果进行后处理,才需要编写代码:
|
||||
|
||||
1. **创建处理器文件**:`combXXXX_processor.go`
|
||||
2. **注册处理器**:在 `api_request_service.go` 中注册
|
||||
3. **实现自定义逻辑**:在处理器中实现特殊业务逻辑
|
||||
|
||||
## 📁 现有组合包示例
|
||||
|
||||
### COMB86PM(自定义处理器)
|
||||
```go
|
||||
// 有自定义逻辑:重命名子产品ApiCode
|
||||
for _, resp := range combinedResult.Responses {
|
||||
if resp.ApiCode == "FLXGBC21" {
|
||||
resp.ApiCode = "FLXG54F5"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### COMB298Y(通用处理器)
|
||||
- **无需编码**:已删除专门的处理器文件
|
||||
- **自动处理**:通过数据库配置自动工作
|
||||
|
||||
## ✅ 优势
|
||||
|
||||
1. **零配置**:普通组合包只需数据库配置,无需编码
|
||||
2. **灵活性**:特殊需求仍可通过自定义处理器实现
|
||||
3. **维护性**:减少重复代码,统一处理逻辑
|
||||
4. **扩展性**:新增组合包极其简单,配置即用
|
||||
|
||||
## 🔧 开发建议
|
||||
|
||||
1. **优先使用通用处理器**:除非有特殊业务逻辑,否则不要编写自定义处理器
|
||||
2. **命名规范**:组合包编码必须以 `COMB` 开头
|
||||
3. **数据库配置**:确保组合包在数据库中正确配置了 `is_package=true` 和子产品关系
|
||||
4. **排序控制**:通过 `sort_order` 字段控制子产品在响应中的顺序
|
||||
@@ -1,30 +0,0 @@
|
||||
package comb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"tyapi-server/internal/domains/api/dto"
|
||||
"tyapi-server/internal/domains/api/services/processors"
|
||||
)
|
||||
|
||||
// ProcessCOMB298YRequest COMB298Y API处理方法
|
||||
func ProcessCOMB298YRequest(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
|
||||
var paramsDto dto.COMB298YReq
|
||||
if err := json.Unmarshal(params, ¶msDto); err != nil {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
|
||||
if err := deps.Validator.ValidateStruct(paramsDto); err != nil {
|
||||
return nil, errors.Join(processors.ErrInvalidParam, err)
|
||||
}
|
||||
|
||||
// 调用组合包服务处理请求
|
||||
// Options会自动传递给所有子处理器
|
||||
combinedResult, err := deps.CombService.ProcessCombRequest(ctx, params, deps, "COMB298Y")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return json.Marshal(combinedResult)
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package qygl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"tyapi-server/internal/domains/api/dto"
|
||||
"tyapi-server/internal/domains/api/services/processors"
|
||||
)
|
||||
|
||||
// ProcessQYGL5A3CRequest QYGL5A3C API处理方法 - 对外投资历史
|
||||
func ProcessQYGL5A3CRequest(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
|
||||
var paramsDto dto.QYGL5A3CReq
|
||||
if err := json.Unmarshal(params, ¶msDto); err != nil {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
|
||||
if err := deps.Validator.ValidateStruct(paramsDto); err != nil {
|
||||
return nil, errors.Join(processors.ErrInvalidParam, err)
|
||||
}
|
||||
|
||||
// 设置默认值
|
||||
pageSize := paramsDto.PageSize
|
||||
if pageSize == 0 {
|
||||
pageSize = 20
|
||||
}
|
||||
pageNum := paramsDto.PageNum
|
||||
if pageNum == 0 {
|
||||
pageNum = 1
|
||||
}
|
||||
|
||||
// 构建API调用参数
|
||||
apiParams := map[string]string{
|
||||
"keyword": paramsDto.EntCode,
|
||||
"pageSize": strconv.Itoa(pageSize),
|
||||
"pageNum": strconv.Itoa(pageNum),
|
||||
}
|
||||
|
||||
// 调用天眼查API - 对外投资历史
|
||||
response, err := deps.TianYanChaService.CallAPI(ctx, "InvestHistory", apiParams)
|
||||
if err != nil {
|
||||
if err.Error() == "数据源异常" {
|
||||
return nil, errors.Join(processors.ErrDatasource, err)
|
||||
} else {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
}
|
||||
|
||||
// 检查天眼查API调用是否成功
|
||||
if !response.Success {
|
||||
return nil, errors.Join(processors.ErrDatasource, errors.New(response.Message))
|
||||
}
|
||||
|
||||
// 返回天眼查响应数据
|
||||
respBytes, err := json.Marshal(response.Data)
|
||||
if err != nil {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
|
||||
return respBytes, nil
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package qygl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"tyapi-server/internal/domains/api/dto"
|
||||
"tyapi-server/internal/domains/api/services/processors"
|
||||
)
|
||||
|
||||
// ProcessQYGL7C1ARequest QYGL7C1A API处理方法 - 经营异常
|
||||
func ProcessQYGL7C1ARequest(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
|
||||
var paramsDto dto.QYGL7C1AReq
|
||||
if err := json.Unmarshal(params, ¶msDto); err != nil {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
|
||||
if err := deps.Validator.ValidateStruct(paramsDto); err != nil {
|
||||
return nil, errors.Join(processors.ErrInvalidParam, err)
|
||||
}
|
||||
|
||||
// 设置默认值
|
||||
pageSize := paramsDto.PageSize
|
||||
if pageSize == 0 {
|
||||
pageSize = 20
|
||||
}
|
||||
pageNum := paramsDto.PageNum
|
||||
if pageNum == 0 {
|
||||
pageNum = 1
|
||||
}
|
||||
|
||||
// 构建API调用参数
|
||||
apiParams := map[string]string{
|
||||
"keyword": paramsDto.EntCode,
|
||||
"pageSize": strconv.Itoa(pageSize),
|
||||
"pageNum": strconv.Itoa(pageNum),
|
||||
}
|
||||
|
||||
// 调用天眼查API - 经营异常
|
||||
response, err := deps.TianYanChaService.CallAPI(ctx, "AbnormalInfo", apiParams)
|
||||
if err != nil {
|
||||
if err.Error() == "数据源异常" {
|
||||
return nil, errors.Join(processors.ErrDatasource, err)
|
||||
} else {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
}
|
||||
|
||||
// 检查天眼查API调用是否成功
|
||||
if !response.Success {
|
||||
return nil, errors.Join(processors.ErrDatasource, errors.New(response.Message))
|
||||
}
|
||||
|
||||
// 返回天眼查响应数据
|
||||
respBytes, err := json.Marshal(response.Data)
|
||||
if err != nil {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
|
||||
return respBytes, nil
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package qygl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"tyapi-server/internal/domains/api/dto"
|
||||
"tyapi-server/internal/domains/api/services/processors"
|
||||
)
|
||||
|
||||
// ProcessQYGL8B4DRequest QYGL8B4D API处理方法 - 融资历史
|
||||
func ProcessQYGL8B4DRequest(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
|
||||
var paramsDto dto.QYGL8B4DReq
|
||||
if err := json.Unmarshal(params, ¶msDto); err != nil {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
|
||||
if err := deps.Validator.ValidateStruct(paramsDto); err != nil {
|
||||
return nil, errors.Join(processors.ErrInvalidParam, err)
|
||||
}
|
||||
|
||||
// 设置默认值
|
||||
pageSize := paramsDto.PageSize
|
||||
if pageSize == 0 {
|
||||
pageSize = 20
|
||||
}
|
||||
pageNum := paramsDto.PageNum
|
||||
if pageNum == 0 {
|
||||
pageNum = 1
|
||||
}
|
||||
|
||||
// 构建API调用参数
|
||||
apiParams := map[string]string{
|
||||
"keyword": paramsDto.EntCode,
|
||||
"pageSize": strconv.Itoa(pageSize),
|
||||
"pageNum": strconv.Itoa(pageNum),
|
||||
}
|
||||
|
||||
// 调用天眼查API - 融资历史
|
||||
response, err := deps.TianYanChaService.CallAPI(ctx, "FinancingHistory", apiParams)
|
||||
if err != nil {
|
||||
if err.Error() == "数据源异常" {
|
||||
return nil, errors.Join(processors.ErrDatasource, err)
|
||||
} else {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
}
|
||||
|
||||
// 检查天眼查API调用是否成功
|
||||
if !response.Success {
|
||||
return nil, errors.Join(processors.ErrDatasource, errors.New(response.Message))
|
||||
}
|
||||
|
||||
// 返回天眼查响应数据
|
||||
respBytes, err := json.Marshal(response.Data)
|
||||
if err != nil {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
|
||||
return respBytes, nil
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package qygl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"tyapi-server/internal/domains/api/dto"
|
||||
"tyapi-server/internal/domains/api/services/processors"
|
||||
)
|
||||
|
||||
// ProcessQYGL9E2FRequest QYGL9E2F API处理方法 - 行政处罚
|
||||
func ProcessQYGL9E2FRequest(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
|
||||
var paramsDto dto.QYGL9E2FReq
|
||||
if err := json.Unmarshal(params, ¶msDto); err != nil {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
|
||||
if err := deps.Validator.ValidateStruct(paramsDto); err != nil {
|
||||
return nil, errors.Join(processors.ErrInvalidParam, err)
|
||||
}
|
||||
|
||||
// 设置默认值
|
||||
pageSize := paramsDto.PageSize
|
||||
if pageSize == 0 {
|
||||
pageSize = 20
|
||||
}
|
||||
pageNum := paramsDto.PageNum
|
||||
if pageNum == 0 {
|
||||
pageNum = 1
|
||||
}
|
||||
|
||||
// 构建API调用参数
|
||||
apiParams := map[string]string{
|
||||
"keyword": paramsDto.EntCode,
|
||||
"pageSize": strconv.Itoa(pageSize),
|
||||
"pageNum": strconv.Itoa(pageNum),
|
||||
}
|
||||
|
||||
// 调用天眼查API - 行政处罚
|
||||
response, err := deps.TianYanChaService.CallAPI(ctx, "PunishmentInfo", apiParams)
|
||||
if err != nil {
|
||||
if err.Error() == "数据源异常" {
|
||||
return nil, errors.Join(processors.ErrDatasource, err)
|
||||
} else {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
}
|
||||
|
||||
// 检查天眼查API调用是否成功
|
||||
if !response.Success {
|
||||
return nil, errors.Join(processors.ErrDatasource, errors.New(response.Message))
|
||||
}
|
||||
|
||||
// 返回天眼查响应数据
|
||||
respBytes, err := json.Marshal(response.Data)
|
||||
if err != nil {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
|
||||
return respBytes, nil
|
||||
}
|
||||
Reference in New Issue
Block a user