重构数据引擎

This commit is contained in:
2026-05-29 18:39:32 +08:00
parent 3ced686cb5
commit 15db71b7ba
132 changed files with 2534 additions and 26198 deletions

View File

@@ -0,0 +1,92 @@
package sync
import (
"context"
svc "dataengine/service/sync"
"github.com/gogf/gf/v2/frame/g"
"github.com/sirupsen/logrus"
)
var PlatformSyncController = new(syncCtrl)
type syncCtrl struct{}
// TriggerSyncReq 触发同步请求
type TriggerSyncReq struct {
g.Meta `path:"/trigger" method:"post" tags:"平台同步" summary:"触发同步" dc:"根据平台编码和接口编码触发数据同步"`
PlatformCode string `json:"platformCode" v:"required" dc:"平台编码"`
InterfaceCode string `json:"interfaceCode" v:"required" dc:"接口编码"`
FullSync bool `json:"fullSync" dc:"是否全量同步true=全量 false=增量"`
}
// TriggerSyncRes 触发同步响应
type TriggerSyncRes struct {
Success bool `json:"success"`
TableName string `json:"tableName"`
TotalRows int `json:"totalRows"`
InsertedRows int `json:"insertedRows"`
Duration string `json:"duration"`
}
// TriggerSync 触发同步
func (c *syncCtrl) TriggerSync(ctx context.Context, req *TriggerSyncReq) (*TriggerSyncRes, error) {
logrus.Infof("触发同步: platform=%s, interface=%s, fullSync=%v", req.PlatformCode, req.InterfaceCode, req.FullSync)
result, err := svc.SyncByConfig(ctx, req.PlatformCode, req.InterfaceCode, req.FullSync)
if err != nil {
return nil, err
}
return &TriggerSyncRes{
Success: true, TableName: result.TableName,
TotalRows: result.TotalRows, InsertedRows: result.InsertedRows,
Duration: result.Duration,
}, nil
}
// QueryPlatformConfigReq 查询平台配置请求
type QueryPlatformConfigReq struct {
g.Meta `path:"/config" method:"get" tags:"平台同步" summary:"查询平台配置" dc:"查看平台和接口配置"`
PlatformCode string `json:"platformCode" v:"required" dc:"平台编码"`
}
// QueryPlatformConfigRes 查询平台配置响应
type QueryPlatformConfigRes struct {
PlatformName string `json:"platformName"`
PlatformCode string `json:"platformCode"`
ApiBaseUrl string `json:"apiBaseUrl"`
AuthType string `json:"authType"`
HasToken bool `json:"hasToken"`
InterfaceCount int `json:"interfaceCount"`
Interfaces []struct {
Code string `json:"code"`
Name string `json:"name"`
Url string `json:"url"`
HasTableDef bool `json:"hasTableDef"`
} `json:"interfaces"`
}
// QueryConfig 查询配置
func (c *syncCtrl) QueryConfig(ctx context.Context, req *QueryPlatformConfigReq) (*QueryPlatformConfigRes, error) {
pm := &svc.PlatformManager{}
platform, interfaces, err := pm.GetPlatformWithInterfaces(ctx, req.PlatformCode)
if err != nil {
return nil, err
}
res := &QueryPlatformConfigRes{
PlatformName: platform.PlatformName, PlatformCode: platform.PlatformCode,
ApiBaseUrl: platform.ApiBaseUrl, AuthType: platform.AuthType,
HasToken: platform.AccessToken != "", InterfaceCount: len(interfaces),
}
for _, iface := range interfaces {
res.Interfaces = append(res.Interfaces, struct {
Code string `json:"code"`
Name string `json:"name"`
Url string `json:"url"`
HasTableDef bool `json:"hasTableDef"`
}{
Code: iface.Code, Name: iface.Name, Url: iface.Url,
HasTableDef: iface.TableDefinition != nil && len(iface.TableDefinition) > 0,
})
}
return res, nil
}