去掉无用代码
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,13 +0,0 @@
|
||||
package app
|
||||
|
||||
// AppStatus 应用状态
|
||||
type AppStatus string
|
||||
|
||||
const (
|
||||
AppStatusActive AppStatus = "active" // 启用
|
||||
AppStatusInactive AppStatus = "inactive" // 停用
|
||||
)
|
||||
|
||||
func (s AppStatus) String() string {
|
||||
return string(s)
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package app
|
||||
|
||||
// AppType 应用类型
|
||||
type AppType string
|
||||
|
||||
const (
|
||||
AppTypeWeb AppType = "web" // Web应用
|
||||
AppTypeMobile AppType = "mobile" // 移动应用
|
||||
AppTypeMiniApp AppType = "mini_app" // 小程序
|
||||
AppTypeH5 AppType = "h5" // H5应用
|
||||
AppTypeDesktop AppType = "desktop" // 桌面应用
|
||||
AppTypeThirdParty AppType = "third_party" // 第三方应用
|
||||
)
|
||||
|
||||
func (s AppType) String() string {
|
||||
return string(s)
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package data
|
||||
|
||||
// ApiMethod 接口请求方法
|
||||
type ApiMethod string
|
||||
|
||||
const (
|
||||
ApiMethodGet ApiMethod = "GET" // GET请求
|
||||
ApiMethodPost ApiMethod = "POST" // POST请求
|
||||
ApiMethodPut ApiMethod = "PUT" // PUT请求
|
||||
ApiMethodDelete ApiMethod = "DELETE" // DELETE请求
|
||||
ApiMethodPatch ApiMethod = "PATCH" // PATCH请求
|
||||
ApiMethodHead ApiMethod = "HEAD" // HEAD请求
|
||||
ApiMethodOptions ApiMethod = "OPTIONS" // OPTIONS请求
|
||||
)
|
||||
|
||||
func (m ApiMethod) String() string {
|
||||
return string(m)
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package data
|
||||
|
||||
// FetchStatus 数据获取状态
|
||||
type FetchStatus string
|
||||
|
||||
const (
|
||||
FetchStatusPending FetchStatus = "pending" // 待执行
|
||||
FetchStatusRunning FetchStatus = "running" // 执行中
|
||||
FetchStatusSuccess FetchStatus = "success" // 成功
|
||||
FetchStatusFailed FetchStatus = "failed" // 失败
|
||||
FetchStatusRateLimit FetchStatus = "rate_limit" // 触发限流
|
||||
)
|
||||
|
||||
func (f FetchStatus) String() string {
|
||||
return string(f)
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package data
|
||||
|
||||
// LimitType 限流类型
|
||||
type LimitType string
|
||||
|
||||
const (
|
||||
LimitTypeApp LimitType = "app" // 应用维度限流
|
||||
LimitTypeTenant LimitType = "tenant" // 租户维度限流
|
||||
LimitTypeApi LimitType = "api" // 接口维度限流
|
||||
)
|
||||
|
||||
func (l LimitType) String() string {
|
||||
return string(l)
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package data
|
||||
|
||||
// PlatformStatus 平台状态
|
||||
type PlatformStatus string
|
||||
|
||||
const (
|
||||
PlatformStatusActive PlatformStatus = "active" // 启用
|
||||
PlatformStatusInactive PlatformStatus = "inactive" // 停用
|
||||
)
|
||||
|
||||
func (s PlatformStatus) String() string {
|
||||
return string(s)
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package data
|
||||
|
||||
// SyncPlatform 同步平台类型
|
||||
type SyncPlatform string
|
||||
|
||||
const (
|
||||
PlatformTaobao SyncPlatform = "taobao" // 淘宝
|
||||
PlatformJD SyncPlatform = "jd" // 京东
|
||||
PlatformKuaishou SyncPlatform = "kuaishou" // 快手
|
||||
PlatformDouyin SyncPlatform = "douyin" // 抖音
|
||||
PlatformXhs SyncPlatform = "xhs" // 小红书
|
||||
PlatformPdd SyncPlatform = "pdd" // 拼多多
|
||||
PlatformXianyu SyncPlatform = "xianyu" // 闲鱼
|
||||
PlatformTmall SyncPlatform = "tmall" // 天猫
|
||||
PlatformWechat SyncPlatform = "wechat" // 微信
|
||||
PlatformCustom SyncPlatform = "custom" // 自定义平台
|
||||
)
|
||||
|
||||
func (s SyncPlatform) String() string {
|
||||
return string(s)
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package mapping
|
||||
|
||||
// MappingStatus 映射状态
|
||||
type MappingStatus string
|
||||
|
||||
const (
|
||||
MappingStatusActive MappingStatus = "active" // 启用
|
||||
MappingStatusInactive MappingStatus = "inactive" // 停用
|
||||
)
|
||||
|
||||
func (s MappingStatus) String() string {
|
||||
return string(s)
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package mapping
|
||||
|
||||
// TransformType 转换类型
|
||||
type TransformType string
|
||||
|
||||
const (
|
||||
TransformTypeFixed TransformType = "fixed" // 固定值
|
||||
TransformTypeMapping TransformType = "mapping" // 值映射
|
||||
TransformTypeRegex TransformType = "regex" // 正则转换
|
||||
TransformTypeFunction TransformType = "function" // 函数转换
|
||||
TransformTypeScript TransformType = "script" // 脚本转换
|
||||
)
|
||||
|
||||
func (t TransformType) String() string {
|
||||
return string(t)
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
dto "cid/model/dto/app"
|
||||
service "cid/service/app"
|
||||
"context"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
type applicationController struct{}
|
||||
|
||||
// Application 应用控制器
|
||||
var Application = new(applicationController)
|
||||
|
||||
// CreateApplication 创建应用
|
||||
func (c *applicationController) CreateApplication(ctx context.Context, req *dto.CreateApplicationReq) (res *dto.CreateApplicationRes, err error) {
|
||||
return service.Application.Create(ctx, req)
|
||||
}
|
||||
|
||||
// ListApplication 获取应用列表
|
||||
func (c *applicationController) ListApplication(ctx context.Context, req *dto.ListApplicationReq) (res *dto.ListApplicationRes, err error) {
|
||||
return service.Application.List(ctx, req)
|
||||
}
|
||||
|
||||
// GetApplication 获取应用详情
|
||||
func (c *applicationController) GetApplication(ctx context.Context, req *dto.GetApplicationReq) (res *dto.GetApplicationRes, err error) {
|
||||
return service.Application.GetOne(ctx, req)
|
||||
}
|
||||
|
||||
// UpdateApplication 更新应用
|
||||
func (c *applicationController) UpdateApplication(ctx context.Context, req *dto.UpdateApplicationReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.Application.Update(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateApplicationStatus 更新应用状态
|
||||
func (c *applicationController) UpdateApplicationStatus(ctx context.Context, req *dto.UpdateApplicationStatusReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.Application.UpdateStatus(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteApplication 删除应用
|
||||
func (c *applicationController) DeleteApplication(ctx context.Context, req *dto.DeleteApplicationReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.Application.Delete(ctx, req)
|
||||
return
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
dto "cid/model/dto/data"
|
||||
service "cid/service/data"
|
||||
"context"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
type apiInterfaceController struct{}
|
||||
|
||||
// ApiInterface 接口控制器
|
||||
var ApiInterface = new(apiInterfaceController)
|
||||
|
||||
// CreateApiInterface 创建接口
|
||||
func (c *apiInterfaceController) CreateApiInterface(ctx context.Context, req *dto.CreateApiInterfaceReq) (res *dto.CreateApiInterfaceRes, err error) {
|
||||
return service.ApiInterface.Create(ctx, req)
|
||||
}
|
||||
|
||||
// ListApiInterface 获取接口列表
|
||||
func (c *apiInterfaceController) ListApiInterface(ctx context.Context, req *dto.ListApiInterfaceReq) (res *dto.ListApiInterfaceRes, err error) {
|
||||
return service.ApiInterface.List(ctx, req)
|
||||
}
|
||||
|
||||
// GetApiInterface 获取接口详情
|
||||
func (c *apiInterfaceController) GetApiInterface(ctx context.Context, req *dto.GetApiInterfaceReq) (res *dto.GetApiInterfaceRes, err error) {
|
||||
return service.ApiInterface.GetOne(ctx, req)
|
||||
}
|
||||
|
||||
// UpdateApiInterface 更新接口
|
||||
func (c *apiInterfaceController) UpdateApiInterface(ctx context.Context, req *dto.UpdateApiInterfaceReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.ApiInterface.Update(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateApiInterfaceStatus 更新接口状态
|
||||
func (c *apiInterfaceController) UpdateApiInterfaceStatus(ctx context.Context, req *dto.UpdateApiInterfaceStatusReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.ApiInterface.UpdateStatus(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteApiInterface 删除接口
|
||||
func (c *apiInterfaceController) DeleteApiInterface(ctx context.Context, req *dto.DeleteApiInterfaceReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.ApiInterface.Delete(ctx, req)
|
||||
return
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
dto "cid/model/dto/data"
|
||||
service "cid/service/data"
|
||||
"context"
|
||||
)
|
||||
|
||||
type dataFetchController struct{}
|
||||
|
||||
// DataFetch 数据获取控制器
|
||||
var DataFetch = new(dataFetchController)
|
||||
|
||||
// ExecuteDataFetch 执行数据获取
|
||||
func (c *dataFetchController) ExecuteDataFetch(ctx context.Context, req *dto.ExecuteDataFetchReq) (res *dto.ExecuteDataFetchRes, err error) {
|
||||
return service.DataFetch.Execute(ctx, req)
|
||||
}
|
||||
|
||||
// BatchExecuteDataFetch 批量执行数据获取
|
||||
func (c *dataFetchController) BatchExecuteDataFetch(ctx context.Context, req *dto.BatchExecuteDataFetchReq) (res *dto.BatchExecuteDataFetchRes, err error) {
|
||||
return service.DataFetch.BatchExecute(ctx, req)
|
||||
}
|
||||
|
||||
// ListDataFetchLog 获取数据获取日志列表
|
||||
func (c *dataFetchController) ListDataFetchLog(ctx context.Context, req *dto.ListDataFetchLogReq) (res *dto.ListDataFetchLogRes, err error) {
|
||||
return service.DataFetch.List(ctx, req)
|
||||
}
|
||||
|
||||
// GetDataFetchLog 获取数据获取日志详情
|
||||
func (c *dataFetchController) GetDataFetchLog(ctx context.Context, req *dto.GetDataFetchLogReq) (res *dto.GetDataFetchLogRes, err error) {
|
||||
return service.DataFetch.GetOne(ctx, req)
|
||||
}
|
||||
|
||||
// ReExecuteDataFetch 重新执行数据获取
|
||||
func (c *dataFetchController) ReExecuteDataFetch(ctx context.Context, req *dto.ReExecuteDataFetchReq) (res *dto.ReExecuteDataFetchRes, err error) {
|
||||
return service.DataFetch.ReExecute(ctx, req)
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
dto "cid/model/dto/data"
|
||||
service "cid/service/data"
|
||||
"context"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
type platformController struct{}
|
||||
|
||||
// Platform 平台控制器
|
||||
var Platform = new(platformController)
|
||||
|
||||
// CreatePlatform 创建平台
|
||||
func (c *platformController) CreatePlatform(ctx context.Context, req *dto.CreatePlatformReq) (res *dto.CreatePlatformRes, err error) {
|
||||
return service.Platform.Create(ctx, req)
|
||||
}
|
||||
|
||||
// ListPlatform 获取平台列表
|
||||
func (c *platformController) ListPlatform(ctx context.Context, req *dto.ListPlatformReq) (res *dto.ListPlatformRes, err error) {
|
||||
return service.Platform.List(ctx, req)
|
||||
}
|
||||
|
||||
// GetPlatform 获取平台详情
|
||||
func (c *platformController) GetPlatform(ctx context.Context, req *dto.GetPlatformReq) (res *dto.GetPlatformRes, err error) {
|
||||
return service.Platform.GetOne(ctx, req)
|
||||
}
|
||||
|
||||
// UpdatePlatform 更新平台
|
||||
func (c *platformController) UpdatePlatform(ctx context.Context, req *dto.UpdatePlatformReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.Platform.Update(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdatePlatformStatus 更新平台状态
|
||||
func (c *platformController) UpdatePlatformStatus(ctx context.Context, req *dto.UpdatePlatformStatusReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.Platform.UpdateStatus(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// DeletePlatform 删除平台
|
||||
func (c *platformController) DeletePlatform(ctx context.Context, req *dto.DeletePlatformReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.Platform.Delete(ctx, req)
|
||||
return
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package mapping
|
||||
|
||||
import (
|
||||
dto "cid/model/dto/mapping"
|
||||
service "cid/service/mapping"
|
||||
"context"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
type dataMappingController struct{}
|
||||
|
||||
// DataMapping 数据映射控制器
|
||||
var DataMapping = new(dataMappingController)
|
||||
|
||||
// CreateDataMapping 创建数据映射
|
||||
func (c *dataMappingController) CreateDataMapping(ctx context.Context, req *dto.CreateDataMappingReq) (res *dto.CreateDataMappingRes, err error) {
|
||||
return service.DataMapping.Create(ctx, req)
|
||||
}
|
||||
|
||||
// BatchCreateDataMappings 批量创建数据映射
|
||||
func (c *dataMappingController) BatchCreateDataMappings(ctx context.Context, req *dto.BatchCreateDataMappingReq) (res *dto.BatchCreateDataMappingRes, err error) {
|
||||
return service.DataMapping.BatchCreate(ctx, req)
|
||||
}
|
||||
|
||||
// ListDataMapping 获取数据映射列表
|
||||
func (c *dataMappingController) ListDataMapping(ctx context.Context, req *dto.ListDataMappingReq) (res *dto.ListDataMappingRes, err error) {
|
||||
return service.DataMapping.List(ctx, req)
|
||||
}
|
||||
|
||||
// GetDataMapping 获取数据映射详情
|
||||
func (c *dataMappingController) GetDataMapping(ctx context.Context, req *dto.GetDataMappingReq) (res *dto.GetDataMappingRes, err error) {
|
||||
return service.DataMapping.GetOne(ctx, req)
|
||||
}
|
||||
|
||||
// UpdateDataMapping 更新数据映射
|
||||
func (c *dataMappingController) UpdateDataMapping(ctx context.Context, req *dto.UpdateDataMappingReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.DataMapping.Update(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteDataMapping 删除数据映射
|
||||
func (c *dataMappingController) DeleteDataMapping(ctx context.Context, req *dto.DeleteDataMappingReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.DataMapping.Delete(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// ExecuteDataMapping 执行数据映射
|
||||
func (c *dataMappingController) ExecuteDataMapping(ctx context.Context, req *dto.ExecuteDataMappingReq) (res *dto.ExecuteDataMappingRes, err error) {
|
||||
return service.DataMapping.Execute(ctx, req)
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
consts "cid/consts/public"
|
||||
dto "cid/model/dto/app"
|
||||
entity "cid/model/entity/app"
|
||||
"context"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var Application = new(applicationDao)
|
||||
|
||||
type applicationDao struct{}
|
||||
|
||||
// Insert 插入应用
|
||||
func (d *applicationDao) Insert(ctx context.Context, req *dto.CreateApplicationReq) (id int64, err error) {
|
||||
var res *entity.Application
|
||||
if err = gconv.Struct(req, &res); err != nil {
|
||||
return
|
||||
}
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ApplicationTable).Data(&res).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// Update 更新应用
|
||||
func (d *applicationDao) Update(ctx context.Context, req *dto.UpdateApplicationReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ApplicationTable).Data(&req).OmitEmpty().Where(entity.ApplicationCols.Id, req.Id).Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// Delete 删除应用
|
||||
func (d *applicationDao) Delete(ctx context.Context, req *dto.DeleteApplicationReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ApplicationTable).Where(entity.ApplicationCols.Id, req.Id).Delete()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// GetOne 获取单个应用
|
||||
func (d *applicationDao) GetOne(ctx context.Context, req *dto.GetApplicationReq) (res *entity.Application, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ApplicationTable).Where(entity.ApplicationCols.Id, req.Id).One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// Count 获取应用数量
|
||||
func (d *applicationDao) Count(ctx context.Context, req *dto.ListApplicationReq) (count int, err error) {
|
||||
return d.buildListFilter(ctx, req).Count()
|
||||
}
|
||||
|
||||
// List 获取应用列表
|
||||
func (d *applicationDao) List(ctx context.Context, req *dto.ListApplicationReq) (res []entity.Application, total int, err error) {
|
||||
model := d.buildListFilter(ctx, req)
|
||||
model.OrderDesc(entity.ApplicationCols.CreatedAt)
|
||||
if req.Page != nil {
|
||||
model.Page(int(req.Page.PageNum), int(req.Page.PageSize))
|
||||
}
|
||||
r, total, err := model.AllAndCount(false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Structs(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// buildListFilter 构建列表查询的过滤条件
|
||||
func (d *applicationDao) buildListFilter(ctx context.Context, req *dto.ListApplicationReq) *gdb.Model {
|
||||
model := gfdb.DB(ctx).Model(ctx, consts.ApplicationTable).Model
|
||||
if !g.IsEmpty(req.Keyword) {
|
||||
model.WhereLike(entity.ApplicationCols.Name, "%"+req.Keyword+"%")
|
||||
model.WhereOrLike(entity.ApplicationCols.AppCode, "%"+req.Keyword+"%")
|
||||
}
|
||||
model.Where(entity.ApplicationCols.Name, req.Name)
|
||||
model.Where(entity.ApplicationCols.AppCode, req.AppCode)
|
||||
model.Where(entity.ApplicationCols.Type, req.Type)
|
||||
model.Where(entity.ApplicationCols.Status, req.Status)
|
||||
model.OmitEmptyWhere()
|
||||
return model
|
||||
}
|
||||
|
||||
// UpdateStatus 更新应用状态
|
||||
func (d *applicationDao) UpdateStatus(ctx context.Context, id int64, status string) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ApplicationTable).
|
||||
Data(map[string]interface{}{"status": status}).
|
||||
Where(entity.ApplicationCols.Id, id).
|
||||
Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// GetByAppCode 根据应用编码获取应用
|
||||
func (d *applicationDao) GetByAppCode(ctx context.Context, appCode string) (res *entity.Application, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ApplicationTable).
|
||||
Where(entity.ApplicationCols.AppCode, appCode).
|
||||
One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
consts "cid/consts/public"
|
||||
dto "cid/model/dto/data"
|
||||
entity "cid/model/entity/data"
|
||||
"context"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var ApiInterface = new(apiInterfaceDao)
|
||||
|
||||
type apiInterfaceDao struct{}
|
||||
|
||||
// Insert 插入接口
|
||||
func (d *apiInterfaceDao) Insert(ctx context.Context, req *dto.CreateApiInterfaceReq) (id int64, err error) {
|
||||
var res *entity.ApiInterface
|
||||
if err = gconv.Struct(req, &res); err != nil {
|
||||
return
|
||||
}
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).Data(&res).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// Update 更新接口
|
||||
func (d *apiInterfaceDao) Update(ctx context.Context, req *dto.UpdateApiInterfaceReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).Data(&req).OmitEmpty().Where(entity.ApiInterfaceCols.Id, req.Id).Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// Delete 删除接口
|
||||
func (d *apiInterfaceDao) Delete(ctx context.Context, req *dto.DeleteApiInterfaceReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).Where(entity.ApiInterfaceCols.Id, req.Id).Delete()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// GetOne 获取单个接口
|
||||
func (d *apiInterfaceDao) GetOne(ctx context.Context, req *dto.GetApiInterfaceReq) (res *entity.ApiInterface, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).Where(entity.ApiInterfaceCols.Id, req.Id).One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// Count 获取接口数量
|
||||
func (d *apiInterfaceDao) Count(ctx context.Context, req *dto.ListApiInterfaceReq) (count int, err error) {
|
||||
return d.buildListFilter(ctx, req).Count()
|
||||
}
|
||||
|
||||
// List 获取接口列表
|
||||
func (d *apiInterfaceDao) List(ctx context.Context, req *dto.ListApiInterfaceReq) (res []entity.ApiInterface, total int, err error) {
|
||||
model := d.buildListFilter(ctx, req)
|
||||
model.OrderDesc(entity.ApiInterfaceCols.CreatedAt)
|
||||
if req.Page != nil {
|
||||
model.Page(int(req.Page.PageNum), int(req.Page.PageSize))
|
||||
}
|
||||
r, total, err := model.AllAndCount(false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Structs(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// buildListFilter 构建列表查询的过滤条件
|
||||
func (d *apiInterfaceDao) buildListFilter(ctx context.Context, req *dto.ListApiInterfaceReq) *gdb.Model {
|
||||
model := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).Model
|
||||
if !g.IsEmpty(req.Keyword) {
|
||||
model.WhereLike(entity.ApiInterfaceCols.Name, "%"+req.Keyword+"%")
|
||||
model.WhereOrLike(entity.ApiInterfaceCols.Code, "%"+req.Keyword+"%")
|
||||
}
|
||||
model.Where(entity.ApiInterfaceCols.PlatformId, req.PlatformId)
|
||||
model.Where(entity.ApiInterfaceCols.Name, req.Name)
|
||||
model.Where(entity.ApiInterfaceCols.Code, req.Code)
|
||||
model.Where(entity.ApiInterfaceCols.Method, req.Method)
|
||||
model.Where(entity.ApiInterfaceCols.Status, req.Status)
|
||||
model.OmitEmptyWhere()
|
||||
return model
|
||||
}
|
||||
|
||||
// UpdateStatus 更新接口状态
|
||||
func (d *apiInterfaceDao) UpdateStatus(ctx context.Context, id int64, status string) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).
|
||||
Data(map[string]interface{}{"status": status}).
|
||||
Where(entity.ApiInterfaceCols.Id, id).
|
||||
Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// GetByIds 根据ID列表获取接口列表
|
||||
func (d *apiInterfaceDao) GetByIds(ctx context.Context, ids []int64) (res []entity.ApiInterface, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).
|
||||
WhereIn(entity.ApiInterfaceCols.Id, ids).
|
||||
All()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Structs(&res)
|
||||
return
|
||||
}
|
||||
@@ -1,135 +0,0 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
consts "cid/consts/public"
|
||||
dto "cid/model/dto/data"
|
||||
entity "cid/model/entity/data"
|
||||
"context"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
)
|
||||
|
||||
var DataFetchLog = new(dataFetchLogDao)
|
||||
|
||||
type dataFetchLogDao struct{}
|
||||
|
||||
// Insert 插入数据获取日志
|
||||
func (d *dataFetchLogDao) Insert(ctx context.Context, log *entity.DataFetchLog) (id int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.DataFetchLogTable).Data(&log).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// Update 更新数据获取日志
|
||||
func (d *dataFetchLogDao) Update(ctx context.Context, id int64, data map[string]interface{}) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.DataFetchLogTable).
|
||||
Data(data).
|
||||
OmitEmpty().
|
||||
Where(entity.DataFetchLogCols.Id, id).
|
||||
Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// GetOne 获取单个数据获取日志
|
||||
func (d *dataFetchLogDao) GetOne(ctx context.Context, req *dto.GetDataFetchLogReq) (res *entity.DataFetchLog, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.DataFetchLogTable).Where(entity.DataFetchLogCols.Id, req.Id).One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// Count 获取数据获取日志数量
|
||||
func (d *dataFetchLogDao) Count(ctx context.Context, req *dto.ListDataFetchLogReq) (count int, err error) {
|
||||
return d.buildListFilter(ctx, req).Count()
|
||||
}
|
||||
|
||||
// List 获取数据获取日志列表
|
||||
func (d *dataFetchLogDao) List(ctx context.Context, req *dto.ListDataFetchLogReq) (res []entity.DataFetchLog, total int, err error) {
|
||||
model := d.buildListFilter(ctx, req)
|
||||
model.OrderDesc(entity.DataFetchLogCols.CreatedAt)
|
||||
if req.Page != nil {
|
||||
model.Page(int(req.Page.PageNum), int(req.Page.PageSize))
|
||||
}
|
||||
r, total, err := model.AllAndCount(false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Structs(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// buildListFilter 构建列表查询的过滤条件
|
||||
func (d *dataFetchLogDao) buildListFilter(ctx context.Context, req *dto.ListDataFetchLogReq) *gdb.Model {
|
||||
model := gfdb.DB(ctx).Model(ctx, consts.DataFetchLogTable).Model
|
||||
model.Where(entity.DataFetchLogCols.PlatformId, req.PlatformId)
|
||||
model.Where(entity.DataFetchLogCols.InterfaceId, req.InterfaceId)
|
||||
model.Where(entity.DataFetchLogCols.RequestId, req.RequestId)
|
||||
model.Where(entity.DataFetchLogCols.Status, req.Status)
|
||||
if req.StartTime > 0 {
|
||||
model.WhereGTE(entity.DataFetchLogCols.StartTime, req.StartTime)
|
||||
}
|
||||
if req.EndTime > 0 {
|
||||
model.WhereLTE(entity.DataFetchLogCols.StartTime, req.EndTime)
|
||||
}
|
||||
model.OmitEmptyWhere()
|
||||
return model
|
||||
}
|
||||
|
||||
// GetByRequestId 根据请求ID获取日志
|
||||
func (d *dataFetchLogDao) GetByRequestId(ctx context.Context, requestId string) (res *entity.DataFetchLog, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.DataFetchLogTable).
|
||||
Where(entity.DataFetchLogCols.RequestId, requestId).
|
||||
One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateStatus 更新日志状态
|
||||
func (d *dataFetchLogDao) UpdateStatus(ctx context.Context, id int64, status string, endTime int64, duration int, responseData, errorMessage string) (rows int64, err error) {
|
||||
updateData := map[string]interface{}{
|
||||
"status": status,
|
||||
}
|
||||
if endTime > 0 {
|
||||
updateData["end_time"] = endTime
|
||||
}
|
||||
if duration > 0 {
|
||||
updateData["duration"] = duration
|
||||
}
|
||||
if responseData != "" {
|
||||
updateData["response_data"] = responseData
|
||||
}
|
||||
if errorMessage != "" {
|
||||
updateData["error_message"] = errorMessage
|
||||
}
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.DataFetchLogTable).
|
||||
Data(updateData).
|
||||
Where(entity.DataFetchLogCols.Id, id).
|
||||
Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// IncrementRetryCount 增加重试次数
|
||||
func (d *dataFetchLogDao) IncrementRetryCount(ctx context.Context, id int64) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.DataFetchLogTable).
|
||||
Where(entity.DataFetchLogCols.Id, id).
|
||||
Data(gdb.Raw(entity.DataFetchLogCols.RetryCount + " + 1")).
|
||||
Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
consts "cid/consts/public"
|
||||
dto "cid/model/dto/data"
|
||||
entity "cid/model/entity/data"
|
||||
"context"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var Platform = new(platformDao)
|
||||
|
||||
type platformDao struct{}
|
||||
|
||||
// Insert 插入平台
|
||||
func (d *platformDao) Insert(ctx context.Context, req *dto.CreatePlatformReq) (id int64, err error) {
|
||||
var res *entity.Platform
|
||||
if err = gconv.Struct(req, &res); err != nil {
|
||||
return
|
||||
}
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.PlatformTable).Data(&res).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// Update 更新平台
|
||||
func (d *platformDao) Update(ctx context.Context, req *dto.UpdatePlatformReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.PlatformTable).Data(&req).OmitEmpty().Where(entity.PlatformCols.Id, req.Id).Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// Delete 删除平台
|
||||
func (d *platformDao) Delete(ctx context.Context, req *dto.DeletePlatformReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.PlatformTable).Where(entity.PlatformCols.Id, req.Id).Delete()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// GetOne 获取单个平台
|
||||
func (d *platformDao) GetOne(ctx context.Context, req *dto.GetPlatformReq) (res *entity.Platform, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.PlatformTable).Where(entity.PlatformCols.Id, req.Id).One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// Count 获取平台数量
|
||||
func (d *platformDao) Count(ctx context.Context, req *dto.ListPlatformReq) (count int, err error) {
|
||||
return d.buildListFilter(ctx, req).Count()
|
||||
}
|
||||
|
||||
// List 获取平台列表
|
||||
func (d *platformDao) List(ctx context.Context, req *dto.ListPlatformReq) (res []entity.Platform, total int, err error) {
|
||||
model := d.buildListFilter(ctx, req)
|
||||
model.OrderDesc(entity.PlatformCols.CreatedAt)
|
||||
if req.Page != nil {
|
||||
model.Page(int(req.Page.PageNum), int(req.Page.PageSize))
|
||||
}
|
||||
r, total, err := model.AllAndCount(false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Structs(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// buildListFilter 构建列表查询的过滤条件
|
||||
func (d *platformDao) buildListFilter(ctx context.Context, req *dto.ListPlatformReq) *gdb.Model {
|
||||
model := gfdb.DB(ctx).Model(ctx, consts.PlatformTable).Model
|
||||
if !g.IsEmpty(req.Keyword) {
|
||||
model.WhereLike(entity.PlatformCols.Name, "%"+req.Keyword+"%")
|
||||
}
|
||||
model.Where(entity.PlatformCols.Name, req.Name)
|
||||
model.Where(entity.PlatformCols.Type, req.Type)
|
||||
model.Where(entity.PlatformCols.Status, req.Status)
|
||||
model.OmitEmptyWhere()
|
||||
return model
|
||||
}
|
||||
|
||||
// UpdateStatus 更新平台状态
|
||||
func (d *platformDao) UpdateStatus(ctx context.Context, id int64, status string) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.PlatformTable).
|
||||
Data(map[string]interface{}{"status": status}).
|
||||
Where(entity.PlatformCols.Id, id).
|
||||
Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// GetByType 根据类型获取平台
|
||||
func (d *platformDao) GetByType(ctx context.Context, platformType string) (res *entity.Platform, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.PlatformTable).
|
||||
Where(entity.PlatformCols.Type, platformType).
|
||||
One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
package mapping
|
||||
|
||||
import (
|
||||
consts "cid/consts/public"
|
||||
dto "cid/model/dto/mapping"
|
||||
entity "cid/model/entity/mapping"
|
||||
"context"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var DataMapping = new(dataMappingDao)
|
||||
|
||||
type dataMappingDao struct{}
|
||||
|
||||
// Insert 插入数据映射
|
||||
func (d *dataMappingDao) Insert(ctx context.Context, req *dto.CreateDataMappingReq) (id int64, err error) {
|
||||
var res *entity.DataMapping
|
||||
if err = gconv.Struct(req, &res); err != nil {
|
||||
return
|
||||
}
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.DataMappingTable).Data(&res).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// BatchInsert 批量插入数据映射
|
||||
func (d *dataMappingDao) BatchInsert(ctx context.Context, mappings []entity.DataMapping) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.DataMappingTable).Data(&mappings).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// Update 更新数据映射
|
||||
func (d *dataMappingDao) Update(ctx context.Context, req *dto.UpdateDataMappingReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.DataMappingTable).Data(&req).OmitEmpty().Where(entity.DataMappingCols.Id, req.Id).Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// Delete 删除数据映射
|
||||
func (d *dataMappingDao) Delete(ctx context.Context, req *dto.DeleteDataMappingReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.DataMappingTable).Where(entity.DataMappingCols.Id, req.Id).Delete()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// GetOne 获取单个数据映射
|
||||
func (d *dataMappingDao) GetOne(ctx context.Context, req *dto.GetDataMappingReq) (res *entity.DataMapping, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.DataMappingTable).Where(entity.DataMappingCols.Id, req.Id).One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// Count 获取数据映射数量
|
||||
func (d *dataMappingDao) Count(ctx context.Context, req *dto.ListDataMappingReq) (count int, err error) {
|
||||
return d.buildListFilter(ctx, req).Count()
|
||||
}
|
||||
|
||||
// List 获取数据映射列表
|
||||
func (d *dataMappingDao) List(ctx context.Context, req *dto.ListDataMappingReq) (res []entity.DataMapping, total int, err error) {
|
||||
model := d.buildListFilter(ctx, req)
|
||||
model.OrderAsc(entity.DataMappingCols.Priority)
|
||||
model.OrderDesc(entity.DataMappingCols.CreatedAt)
|
||||
if req.Page != nil {
|
||||
model.Page(int(req.Page.PageNum), int(req.Page.PageSize))
|
||||
}
|
||||
r, total, err := model.AllAndCount(false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Structs(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// buildListFilter 构建列表的过滤条件
|
||||
func (d *dataMappingDao) buildListFilter(ctx context.Context, req *dto.ListDataMappingReq) *gdb.Model {
|
||||
model := gfdb.DB(ctx).Model(ctx, consts.DataMappingTable).Model
|
||||
model.Where(entity.DataMappingCols.PlatformId, req.PlatformId)
|
||||
model.Where(entity.DataMappingCols.InterfaceId, req.InterfaceId)
|
||||
model.Where(entity.DataMappingCols.SourceField, req.SourceField)
|
||||
model.Where(entity.DataMappingCols.TargetField, req.TargetField)
|
||||
model.Where(entity.DataMappingCols.Status, req.Status)
|
||||
model.OmitEmptyWhere()
|
||||
return model
|
||||
}
|
||||
|
||||
// GetByInterfaceId 根据接口ID获取映射规则列表(按优先级排序)
|
||||
func (d *dataMappingDao) GetByInterfaceId(ctx context.Context, interfaceId int64) (res []entity.DataMapping, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.DataMappingTable).
|
||||
Where(entity.DataMappingCols.InterfaceId, interfaceId).
|
||||
Where("status", "active").
|
||||
OrderAsc(entity.DataMappingCols.Priority).
|
||||
All()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Structs(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// GetByInterfaceIdAndTargetField 根据接口ID和目标字段获取映射规则
|
||||
func (d *dataMappingDao) GetByInterfaceIdAndTargetField(ctx context.Context, interfaceId int64, targetField string) (res *entity.DataMapping, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.DataMappingTable).
|
||||
Where(entity.DataMappingCols.InterfaceId, interfaceId).
|
||||
Where(entity.DataMappingCols.TargetField, targetField).
|
||||
Where("status", "active").
|
||||
One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteByInterfaceId 根据接口ID删除所有映射规则
|
||||
func (d *dataMappingDao) DeleteByInterfaceId(ctx context.Context, interfaceId int64) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.DataMappingTable).
|
||||
Where(entity.DataMappingCols.InterfaceId, interfaceId).
|
||||
Delete()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
13
main.go
13
main.go
@@ -1,12 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"cid/controller/app"
|
||||
"cid/controller/data"
|
||||
"cid/controller/dataengine"
|
||||
"cid/controller/mapping"
|
||||
"cid/controller/yidun"
|
||||
controllerYidun "cid/controller/yidun"
|
||||
serviceDataengine "cid/service/dataengine"
|
||||
serviceYidun "cid/service/yidun"
|
||||
"context"
|
||||
@@ -55,13 +51,8 @@ func main() {
|
||||
|
||||
// 注册 API 路由并启动服务器
|
||||
http.RouteRegister([]interface{}{
|
||||
data.Platform,
|
||||
data.ApiInterface,
|
||||
data.DataFetch,
|
||||
mapping.DataMapping,
|
||||
app.Application,
|
||||
controllerYidun.YidunController,
|
||||
controllerYidun.YidunCallback,
|
||||
yidun.YidunController,
|
||||
yidun.YidunCallback,
|
||||
yidun.ContentCheck,
|
||||
dataengine.MaterialVerify,
|
||||
})
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"cid/consts/app"
|
||||
entity "cid/model/entity/app"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// CreateApplicationReq 创建应用请求
|
||||
type CreateApplicationReq struct {
|
||||
g.Meta `path:"/createApplication" method:"post" tags:"应用管理" summary:"创建应用" dc:"创建新的应用"`
|
||||
Name string `json:"name" v:"required" dc:"应用名称"`
|
||||
AppCode string `json:"appCode" v:"required" dc:"应用编码(唯一标识)"`
|
||||
Type app.AppType `json:"type" v:"required" dc:"应用类型"`
|
||||
Status app.AppStatus `json:"status" dc:"应用状态" d:"active"`
|
||||
Description string `json:"description" dc:"应用描述"`
|
||||
AccessConfig map[string]interface{} `json:"accessConfig" dc:"接入配置"`
|
||||
LimitConfig map[string]interface{} `json:"limitConfig" dc:"限流配置"`
|
||||
CallbackConfig map[string]interface{} `json:"callbackConfig" dc:"回调配置"`
|
||||
}
|
||||
|
||||
// CreateApplicationRes 创建应用响应
|
||||
type CreateApplicationRes struct {
|
||||
Id int64 `json:"id" dc:"应用ID"`
|
||||
}
|
||||
|
||||
// ListApplicationReq 获取应用列表请求
|
||||
type ListApplicationReq struct {
|
||||
g.Meta `path:"/listApplications" method:"get" tags:"应用管理" summary:"获取应用列表" dc:"分页查询应用列表"`
|
||||
*beans.Page
|
||||
Name string `json:"name" dc:"应用名称"`
|
||||
AppCode string `json:"appCode" dc:"应用编码"`
|
||||
Type app.AppType `json:"type" dc:"应用类型"`
|
||||
Status app.AppStatus `json:"status" dc:"应用状态"`
|
||||
Keyword string `json:"keyword" dc:"关键字(搜索应用名称或编码)"`
|
||||
}
|
||||
|
||||
// ListApplicationRes 获取应用列表响应
|
||||
type ListApplicationRes struct {
|
||||
List []ApplicationItem `json:"list" dc:"应用列表"`
|
||||
Total int `json:"total" dc:"总数"`
|
||||
}
|
||||
|
||||
type ApplicationItem struct {
|
||||
Id int64 `json:"id,string"`
|
||||
Name string `json:"name"`
|
||||
AppCode string `json:"appCode"`
|
||||
Type app.AppType `json:"type"`
|
||||
TypeName string `json:"typeName"`
|
||||
Status app.AppStatus `json:"status"`
|
||||
StatusName string `json:"statusName"`
|
||||
Description string `json:"description"`
|
||||
CreatedAt int64 `json:"createdAt"`
|
||||
UpdatedAt int64 `json:"updatedAt"`
|
||||
}
|
||||
|
||||
// GetApplicationReq 获取应用详情请求
|
||||
type GetApplicationReq struct {
|
||||
g.Meta `path:"/getApplication" method:"get" tags:"应用管理" summary:"获取应用详情" dc:"获取应用详情"`
|
||||
Id int64 `json:"id" v:"required" dc:"应用ID"`
|
||||
}
|
||||
|
||||
// GetApplicationRes 获取应用详情响应
|
||||
type GetApplicationRes struct {
|
||||
*entity.Application
|
||||
}
|
||||
|
||||
// UpdateApplicationReq 更新应用请求
|
||||
type UpdateApplicationReq struct {
|
||||
g.Meta `path:"/updateApplication" method:"put" tags:"应用管理" summary:"更新应用" dc:"更新应用信息"`
|
||||
Id int64 `json:"id" v:"required" dc:"应用ID"`
|
||||
Name string `json:"name" dc:"应用名称"`
|
||||
AppCode string `json:"appCode" dc:"应用编码"`
|
||||
Type app.AppType `json:"type" dc:"应用类型"`
|
||||
Status app.AppStatus `json:"status,omitempty" dc:"应用状态"`
|
||||
Description string `json:"description" dc:"应用描述"`
|
||||
AccessConfig map[string]interface{} `json:"accessConfig" dc:"接入配置"`
|
||||
LimitConfig map[string]interface{} `json:"limitConfig" dc:"限流配置"`
|
||||
CallbackConfig map[string]interface{} `json:"callbackConfig" dc:"回调配置"`
|
||||
}
|
||||
|
||||
// DeleteApplicationReq 删除应用请求
|
||||
type DeleteApplicationReq struct {
|
||||
g.Meta `path:"/deleteApplication" method:"delete" tags:"应用管理" summary:"删除应用" dc:"删除应用"`
|
||||
Id int64 `json:"id" v:"required" dc:"应用ID"`
|
||||
}
|
||||
|
||||
// UpdateApplicationStatusReq 更新应用状态请求
|
||||
type UpdateApplicationStatusReq struct {
|
||||
g.Meta `path:"/updateApplicationStatus" method:"put" tags:"应用管理" summary:"更新应用状态" dc:"更新应用状态"`
|
||||
Id int64 `json:"id" v:"required" dc:"应用ID"`
|
||||
Status app.AppStatus `json:"status" v:"required|in:active,inactive" dc:"状态:active启用/inactive停用"`
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"cid/consts/data"
|
||||
entity "cid/model/entity/data"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// CreateApiInterfaceReq 创建接口请求
|
||||
type CreateApiInterfaceReq struct {
|
||||
g.Meta `path:"/createApiInterface" method:"post" tags:"接口管理" summary:"创建接口" dc:"创建新的数据接口"`
|
||||
PlatformId int64 `json:"platformId" v:"required" dc:"所属平台ID"`
|
||||
Name string `json:"name" v:"required" dc:"接口名称"`
|
||||
Code string `json:"code" v:"required" dc:"接口编码"`
|
||||
Url string `json:"url" v:"required" dc:"接口地址"`
|
||||
Method data.ApiMethod `json:"method" v:"required" dc:"请求方法"`
|
||||
Status data.PlatformStatus `json:"status" dc:"接口状态" d:"active"`
|
||||
AuthType string `json:"authType" dc:"认证类型"`
|
||||
RequestConfig map[string]interface{} `json:"requestConfig" dc:"请求配置"`
|
||||
ResponseConfig map[string]interface{} `json:"responseConfig" dc:"响应配置"`
|
||||
LimitConfig map[string]interface{} `json:"limitConfig" dc:"接口独立限流配置"`
|
||||
}
|
||||
|
||||
// CreateApiInterfaceRes 创建接口响应
|
||||
type CreateApiInterfaceRes struct {
|
||||
Id int64 `json:"id" dc:"接口ID"`
|
||||
}
|
||||
|
||||
// ListApiInterfaceReq 获取接口列表请求
|
||||
type ListApiInterfaceReq struct {
|
||||
g.Meta `path:"/listApiInterfaces" method:"get" tags:"接口管理" summary:"获取接口列表" dc:"分页查询接口列表"`
|
||||
*beans.Page
|
||||
PlatformId int64 `json:"platformId" dc:"平台ID"`
|
||||
Name string `json:"name" dc:"接口名称"`
|
||||
Code string `json:"code" dc:"接口编码"`
|
||||
Method data.ApiMethod `json:"method" dc:"请求方法"`
|
||||
Status data.PlatformStatus `json:"status" dc:"接口状态"`
|
||||
Keyword string `json:"keyword" dc:"关键字(搜索名称或编码)"`
|
||||
}
|
||||
|
||||
// ListApiInterfaceRes 获取接口列表响应
|
||||
type ListApiInterfaceRes struct {
|
||||
List []ApiInterfaceItem `json:"list" dc:"接口列表"`
|
||||
Total int `json:"total" dc:"总数"`
|
||||
}
|
||||
|
||||
type ApiInterfaceItem struct {
|
||||
Id int64 `json:"id,string"`
|
||||
PlatformId int64 `json:"platformId"`
|
||||
PlatformName string `json:"platformName"`
|
||||
Name string `json:"name"`
|
||||
Code string `json:"code"`
|
||||
Url string `json:"url"`
|
||||
Method data.ApiMethod `json:"method"`
|
||||
Status data.PlatformStatus `json:"status"`
|
||||
StatusName string `json:"statusName"`
|
||||
CreatedAt int64 `json:"createdAt"`
|
||||
UpdatedAt int64 `json:"updatedAt"`
|
||||
}
|
||||
|
||||
// GetApiInterfaceReq 获取接口详情请求
|
||||
type GetApiInterfaceReq struct {
|
||||
g.Meta `path:"/getApiInterface" method:"get" tags:"接口管理" summary:"获取接口详情" dc:"获取接口详情"`
|
||||
Id int64 `json:"id" v:"required" dc:"接口ID"`
|
||||
}
|
||||
|
||||
// GetApiInterfaceRes 获取接口详情响应
|
||||
type GetApiInterfaceRes struct {
|
||||
*entity.ApiInterface
|
||||
PlatformName string `json:"platformName,omitempty"`
|
||||
}
|
||||
|
||||
// UpdateApiInterfaceReq 更新接口请求
|
||||
type UpdateApiInterfaceReq struct {
|
||||
g.Meta `path:"/updateApiInterface" method:"put" tags:"接口管理" summary:"更新接口" dc:"更新接口信息"`
|
||||
Id int64 `json:"id" v:"required" dc:"接口ID"`
|
||||
PlatformId int64 `json:"platformId" dc:"所属平台ID"`
|
||||
Name string `json:"name" dc:"接口名称"`
|
||||
Code string `json:"code" dc:"接口编码"`
|
||||
Url string `json:"url" dc:"接口地址"`
|
||||
Method data.ApiMethod `json:"method" dc:"请求方法"`
|
||||
Status data.PlatformStatus `json:"status,omitempty" dc:"接口状态"`
|
||||
AuthType string `json:"authType" dc:"认证类型"`
|
||||
RequestConfig map[string]interface{} `json:"requestConfig" dc:"请求配置"`
|
||||
ResponseConfig map[string]interface{} `json:"responseConfig" dc:"响应配置"`
|
||||
LimitConfig map[string]interface{} `json:"limitConfig" dc:"接口独立限流配置"`
|
||||
}
|
||||
|
||||
// DeleteApiInterfaceReq 删除接口请求
|
||||
type DeleteApiInterfaceReq struct {
|
||||
g.Meta `path:"/deleteApiInterface" method:"delete" tags:"接口管理" summary:"删除接口" dc:"删除接口"`
|
||||
Id int64 `json:"id" v:"required" dc:"接口ID"`
|
||||
}
|
||||
|
||||
// UpdateApiInterfaceStatusReq 更新接口状态请求
|
||||
type UpdateApiInterfaceStatusReq struct {
|
||||
g.Meta `path:"/updateApiInterfaceStatus" method:"put" tags:"接口管理" summary:"更新接口状态" dc:"更新接口状态"`
|
||||
Id int64 `json:"id" v:"required" dc:"接口ID"`
|
||||
Status data.PlatformStatus `json:"status" v:"required|in:active,inactive" dc:"状态:active启用/inactive停用"`
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"cid/consts/data"
|
||||
entity "cid/model/entity/data"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// ExecuteDataFetchReq 执行数据获取请求
|
||||
type ExecuteDataFetchReq struct {
|
||||
g.Meta `path:"/executeDataFetch" method:"post" tags:"数据获取" summary:"执行数据获取" dc:"执行接口数据获取"`
|
||||
PlatformId int64 `json:"platformId" v:"required" dc:"平台ID"`
|
||||
InterfaceId int64 `json:"interfaceId" v:"required" dc:"接口ID"`
|
||||
RequestParams map[string]interface{} `json:"requestParams" dc:"请求参数"`
|
||||
}
|
||||
|
||||
// ExecuteDataFetchRes 执行数据获取响应
|
||||
type ExecuteDataFetchRes struct {
|
||||
RequestId string `json:"requestId" dc:"请求ID"`
|
||||
Status string `json:"status" dc:"状态"`
|
||||
Message string `json:"message" dc:"消息"`
|
||||
}
|
||||
|
||||
// ListDataFetchLogReq 获取数据获取日志列表请求
|
||||
type ListDataFetchLogReq struct {
|
||||
g.Meta `path:"/listDataFetchLogs" method:"get" tags:"数据获取" summary:"获取数据获取日志" dc:"分页查询数据获取日志"`
|
||||
*beans.Page
|
||||
PlatformId int64 `json:"platformId" dc:"平台ID"`
|
||||
InterfaceId int64 `json:"interfaceId" dc:"接口ID"`
|
||||
RequestId string `json:"requestId" dc:"请求ID"`
|
||||
Status data.FetchStatus `json:"status" dc:"执行状态"`
|
||||
StartTime int64 `json:"startTime" dc:"开始时间(时间戳)"`
|
||||
EndTime int64 `json:"endTime" dc:"结束时间(时间戳)"`
|
||||
}
|
||||
|
||||
// ListDataFetchLogRes 获取数据获取日志列表响应
|
||||
type ListDataFetchLogRes struct {
|
||||
List []DataFetchLogItem `json:"list" dc:"日志列表"`
|
||||
Total int `json:"total" dc:"总数"`
|
||||
}
|
||||
|
||||
type DataFetchLogItem struct {
|
||||
Id int64 `json:"id,string"`
|
||||
PlatformId int64 `json:"platformId"`
|
||||
PlatformName string `json:"platformName"`
|
||||
InterfaceId int64 `json:"interfaceId"`
|
||||
InterfaceName string `json:"interfaceName"`
|
||||
RequestId string `json:"requestId"`
|
||||
Status data.FetchStatus `json:"status"`
|
||||
StatusName string `json:"statusName"`
|
||||
StartTime int64 `json:"startTime"`
|
||||
EndTime int64 `json:"endTime"`
|
||||
Duration int `json:"duration"`
|
||||
ErrorMessage string `json:"errorMessage"`
|
||||
RetryCount int `json:"retryCount"`
|
||||
CreatedAt int64 `json:"createdAt"`
|
||||
}
|
||||
|
||||
// GetDataFetchLogReq 获取数据获取日志详情请求
|
||||
type GetDataFetchLogReq struct {
|
||||
g.Meta `path:"/getDataFetchLog" method:"get" tags:"数据获取" summary:"获取数据获取日志详情" dc:"获取数据获取日志详情"`
|
||||
Id int64 `json:"id" v:"required" dc:"日志ID"`
|
||||
}
|
||||
|
||||
// GetDataFetchLogRes 获取数据获取日志详情响应
|
||||
type GetDataFetchLogRes struct {
|
||||
*entity.DataFetchLog
|
||||
PlatformName string `json:"platformName,omitempty"`
|
||||
InterfaceName string `json:"interfaceName,omitempty"`
|
||||
}
|
||||
|
||||
// BatchExecuteDataFetchReq 批量执行数据获取请求
|
||||
type BatchExecuteDataFetchReq struct {
|
||||
g.Meta `path:"/batchExecuteDataFetch" method:"post" tags:"数据获取" summary:"批量执行数据获取" dc:"批量执行接口数据获取"`
|
||||
InterfaceIds []int64 `json:"interfaceIds" v:"required" dc:"接口ID列表"`
|
||||
RequestParams map[string]interface{} `json:"requestParams" dc:"请求参数(所有接口共用)"`
|
||||
}
|
||||
|
||||
// BatchExecuteDataFetchRes 批量执行数据获取响应
|
||||
type BatchExecuteDataFetchRes struct {
|
||||
SuccessCount int `json:"successCount" dc:"成功数量"`
|
||||
FailedCount int `json:"failedCount" dc:"失败数量"`
|
||||
RequestIds []string `json:"requestIds" dc:"请求ID列表"`
|
||||
}
|
||||
|
||||
// ReExecuteDataFetchReq 重新执行数据获取请求
|
||||
type ReExecuteDataFetchReq struct {
|
||||
g.Meta `path:"/reExecuteDataFetch" method:"post" tags:"数据获取" summary:"重新执行数据获取" dc:"重新执行失败的数据获取"`
|
||||
LogId int64 `json:"logId" v:"required" dc:"日志ID"`
|
||||
}
|
||||
|
||||
// ReExecuteDataFetchRes 重新执行数据获取响应
|
||||
type ReExecuteDataFetchRes struct {
|
||||
RequestId string `json:"requestId" dc:"请求ID"`
|
||||
Status string `json:"status" dc:"状态"`
|
||||
Message string `json:"message" dc:"消息"`
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"cid/consts/data"
|
||||
entity "cid/model/entity/data"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// CreatePlatformReq 创建平台请求
|
||||
type CreatePlatformReq struct {
|
||||
g.Meta `path:"/createPlatform" method:"post" tags:"平台管理" summary:"创建平台" dc:"创建新的数据源平台"`
|
||||
Name string `json:"name" v:"required" dc:"平台名称"`
|
||||
Type data.SyncPlatform `json:"type" v:"required" dc:"平台类型"`
|
||||
Status data.PlatformStatus `json:"status" dc:"平台状态" d:"active"`
|
||||
Description string `json:"description" dc:"平台描述"`
|
||||
AuthConfig map[string]interface{} `json:"authConfig" dc:"认证配置"`
|
||||
LimitConfig map[string]interface{} `json:"limitConfig" dc:"限流配置"`
|
||||
PlatformConfig map[string]interface{} `json:"platformConfig" dc:"平台专用配置"`
|
||||
}
|
||||
|
||||
// CreatePlatformRes 创建平台响应
|
||||
type CreatePlatformRes struct {
|
||||
Id int64 `json:"id" dc:"平台ID"`
|
||||
}
|
||||
|
||||
// ListPlatformReq 获取平台列表请求
|
||||
type ListPlatformReq struct {
|
||||
g.Meta `path:"/listPlatforms" method:"get" tags:"平台管理" summary:"获取平台列表" dc:"分页查询平台列表"`
|
||||
*beans.Page
|
||||
Name string `json:"name" dc:"平台名称"`
|
||||
Type data.SyncPlatform `json:"type" dc:"平台类型"`
|
||||
Status data.PlatformStatus `json:"status" dc:"平台状态"`
|
||||
Keyword string `json:"keyword" dc:"关键字(搜索平台名称)"`
|
||||
}
|
||||
|
||||
// ListPlatformRes 获取平台列表响应
|
||||
type ListPlatformRes struct {
|
||||
List []PlatformItem `json:"list" dc:"平台列表"`
|
||||
Total int `json:"total" dc:"总数"`
|
||||
}
|
||||
|
||||
type PlatformItem struct {
|
||||
Id int64 `json:"id,string"`
|
||||
Name string `json:"name"`
|
||||
Type data.SyncPlatform `json:"type"`
|
||||
TypeName string `json:"typeName"`
|
||||
Status data.PlatformStatus `json:"status"`
|
||||
StatusName string `json:"statusName"`
|
||||
Description string `json:"description"`
|
||||
CreatedAt int64 `json:"createdAt"`
|
||||
UpdatedAt int64 `json:"updatedAt"`
|
||||
}
|
||||
|
||||
// GetPlatformReq 获取平台详情请求
|
||||
type GetPlatformReq struct {
|
||||
g.Meta `path:"/getPlatform" method:"get" tags:"平台管理" summary:"获取平台详情" dc:"获取平台详情"`
|
||||
Id int64 `json:"id" v:"required" dc:"平台ID"`
|
||||
}
|
||||
|
||||
// GetPlatformRes 获取平台详情响应
|
||||
type GetPlatformRes struct {
|
||||
*entity.Platform
|
||||
}
|
||||
|
||||
// UpdatePlatformReq 更新平台请求
|
||||
type UpdatePlatformReq struct {
|
||||
g.Meta `path:"/updatePlatform" method:"put" tags:"平台管理" summary:"更新平台" dc:"更新平台信息"`
|
||||
Id int64 `json:"id" v:"required" dc:"平台ID"`
|
||||
Name string `json:"name" dc:"平台名称"`
|
||||
Type data.SyncPlatform `json:"type" dc:"平台类型"`
|
||||
Status data.PlatformStatus `json:"status,omitempty" dc:"平台状态"`
|
||||
Description string `json:"description" dc:"平台描述"`
|
||||
AuthConfig map[string]interface{} `json:"authConfig" dc:"认证配置"`
|
||||
LimitConfig map[string]interface{} `json:"limitConfig" dc:"限流配置"`
|
||||
PlatformConfig map[string]interface{} `json:"platformConfig" dc:"平台专用配置"`
|
||||
}
|
||||
|
||||
// DeletePlatformReq 删除平台请求
|
||||
type DeletePlatformReq struct {
|
||||
g.Meta `path:"/deletePlatform" method:"delete" tags:"平台管理" summary:"删除平台" dc:"删除平台"`
|
||||
Id int64 `json:"id" v:"required" dc:"平台ID"`
|
||||
}
|
||||
|
||||
// UpdatePlatformStatusReq 更新平台状态请求
|
||||
type UpdatePlatformStatusReq struct {
|
||||
g.Meta `path:"/updatePlatformStatus" method:"put" tags:"平台管理" summary:"更新平台状态" dc:"更新平台状态"`
|
||||
Id int64 `json:"id" v:"required" dc:"平台ID"`
|
||||
Status data.PlatformStatus `json:"status" v:"required|in:active,inactive" dc:"状态:active启用/inactive停用"`
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
package mapping
|
||||
|
||||
import (
|
||||
"cid/consts/mapping"
|
||||
entity "cid/model/entity/mapping"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// CreateDataMappingReq 创建数据映射请求
|
||||
type CreateDataMappingReq struct {
|
||||
g.Meta `path:"/createDataMapping" method:"post" tags:"数据映射" summary:"创建数据映射" dc:"创建数据映射规则"`
|
||||
PlatformId int64 `json:"platformId" v:"required" dc:"平台ID"`
|
||||
InterfaceId int64 `json:"interfaceId" v:"required" dc:"接口ID"`
|
||||
SourceField string `json:"sourceField" v:"required" dc:"源字段"`
|
||||
TargetField string `json:"targetField" v:"required" dc:"目标字段"`
|
||||
FieldType string `json:"fieldType" v:"required" dc:"字段类型"`
|
||||
DefaultValue string `json:"defaultValue" dc:"默认值"`
|
||||
TransformRule map[string]interface{} `json:"transformRule" dc:"转换规则"`
|
||||
Priority int `json:"priority" dc:"优先级" d:"0"`
|
||||
Status mapping.MappingStatus `json:"status" dc:"状态" d:"active"`
|
||||
}
|
||||
|
||||
// CreateDataMappingRes 创建数据映射响应
|
||||
type CreateDataMappingRes struct {
|
||||
Id int64 `json:"id" dc:"映射ID"`
|
||||
}
|
||||
|
||||
// ListDataMappingReq 获取数据映射列表请求
|
||||
type ListDataMappingReq struct {
|
||||
g.Meta `path:"/listDataMappings" method:"get" tags:"数据映射" summary:"获取数据映射列表" dc:"分页查询数据映射列表"`
|
||||
*beans.Page
|
||||
PlatformId int64 `json:"platformId" dc:"平台ID"`
|
||||
InterfaceId int64 `json:"interfaceId" dc:"接口ID"`
|
||||
SourceField string `json:"sourceField" dc:"源字段"`
|
||||
TargetField string `json:"targetField" dc:"目标字段"`
|
||||
Status mapping.MappingStatus `json:"status" dc:"状态"`
|
||||
}
|
||||
|
||||
// ListDataMappingRes 获取数据映射列表响应
|
||||
type ListDataMappingRes struct {
|
||||
List []DataMappingItem `json:"list" dc:"映射列表"`
|
||||
Total int `json:"total" dc:"总数"`
|
||||
}
|
||||
|
||||
type DataMappingItem struct {
|
||||
Id int64 `json:"id,string"`
|
||||
PlatformId int64 `json:"platformId"`
|
||||
PlatformName string `json:"platformName"`
|
||||
InterfaceId int64 `json:"interfaceId"`
|
||||
InterfaceName string `json:"interfaceName"`
|
||||
SourceField string `json:"sourceField"`
|
||||
TargetField string `json:"targetField"`
|
||||
FieldType string `json:"fieldType"`
|
||||
DefaultValue string `json:"defaultValue"`
|
||||
TransformRule map[string]interface{} `json:"transformRule"`
|
||||
Priority int `json:"priority"`
|
||||
Status mapping.MappingStatus `json:"status"`
|
||||
StatusName string `json:"statusName"`
|
||||
CreatedAt int64 `json:"createdAt"`
|
||||
UpdatedAt int64 `json:"updatedAt"`
|
||||
}
|
||||
|
||||
// GetDataMappingReq 获取数据映射详情请求
|
||||
type GetDataMappingReq struct {
|
||||
g.Meta `path:"/getDataMapping" method:"get" tags:"数据映射" summary:"获取数据映射详情" dc:"获取数据映射详情"`
|
||||
Id int64 `json:"id" v:"required" dc:"映射ID"`
|
||||
}
|
||||
|
||||
// GetDataMappingRes 获取数据映射详情响应
|
||||
type GetDataMappingRes struct {
|
||||
*entity.DataMapping
|
||||
PlatformName string `json:"platformName,omitempty"`
|
||||
InterfaceName string `json:"interfaceName,omitempty"`
|
||||
}
|
||||
|
||||
// UpdateDataMappingReq 更新数据映射请求
|
||||
type UpdateDataMappingReq struct {
|
||||
g.Meta `path:"/updateDataMapping" method:"put" tags:"数据映射" summary:"更新数据映射" dc:"更新数据映射规则"`
|
||||
Id int64 `json:"id" v:"required" dc:"映射ID"`
|
||||
PlatformId int64 `json:"platformId" dc:"平台ID"`
|
||||
InterfaceId int64 `json:"interfaceId" dc:"接口ID"`
|
||||
SourceField string `json:"sourceField" dc:"源字段"`
|
||||
TargetField string `json:"targetField" dc:"目标字段"`
|
||||
FieldType string `json:"fieldType" dc:"字段类型"`
|
||||
DefaultValue string `json:"defaultValue" dc:"默认值"`
|
||||
TransformRule map[string]interface{} `json:"transformRule" dc:"转换规则"`
|
||||
Priority int `json:"priority" dc:"优先级"`
|
||||
Status mapping.MappingStatus `json:"status,omitempty" dc:"状态"`
|
||||
}
|
||||
|
||||
// DeleteDataMappingReq 删除数据映射请求
|
||||
type DeleteDataMappingReq struct {
|
||||
g.Meta `path:"/deleteDataMapping" method:"delete" tags:"数据映射" summary:"删除数据映射" dc:"删除数据映射"`
|
||||
Id int64 `json:"id" v:"required" dc:"映射ID"`
|
||||
}
|
||||
|
||||
// BatchCreateDataMappingReq 批量创建数据映射请求
|
||||
type BatchCreateDataMappingReq struct {
|
||||
g.Meta `path:"/batchCreateDataMappings" method:"post" tags:"数据映射" summary:"批量创建数据映射" dc:"批量创建数据映射规则"`
|
||||
PlatformId int64 `json:"platformId" v:"required" dc:"平台ID"`
|
||||
InterfaceId int64 `json:"interfaceId" v:"required" dc:"接口ID"`
|
||||
Mappings []CreateDataMappingReq `json:"mappings" v:"required" dc:"映射规则列表"`
|
||||
}
|
||||
|
||||
// BatchCreateDataMappingRes 批量创建数据映射响应
|
||||
type BatchCreateDataMappingRes struct {
|
||||
SuccessCount int `json:"successCount" dc:"成功数量"`
|
||||
FailedCount int `json:"failedCount" dc:"失败数量"`
|
||||
Ids []int64 `json:"ids" dc:"映射ID列表"`
|
||||
}
|
||||
|
||||
// ExecuteDataMappingReq 执行数据映射请求
|
||||
type ExecuteDataMappingReq struct {
|
||||
g.Meta `path:"/executeDataMapping" method:"post" tags:"数据映射" summary:"执行数据映射" dc:"执行数据字段映射"`
|
||||
InterfaceId int64 `json:"interfaceId" v:"required" dc:"接口ID"`
|
||||
SourceData map[string]interface{} `json:"sourceData" v:"required" dc:"源数据"`
|
||||
}
|
||||
|
||||
// ExecuteDataMappingRes 执行数据映射响应
|
||||
type ExecuteDataMappingRes struct {
|
||||
TargetData map[string]interface{} `json:"targetData" dc:"目标数据"`
|
||||
AppliedRules []string `json:"appliedRules" dc:"应用的映射规则"`
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
consts "cid/consts/app"
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
// Application 应用管理实体
|
||||
type Application struct {
|
||||
beans.SQLBaseDO `orm:",inherit"`
|
||||
// 基础信息
|
||||
Name string `orm:"name" json:"name" description:"应用名称"`
|
||||
AppCode string `orm:"app_code" json:"appCode" description:"应用编码(唯一标识)"`
|
||||
Type consts.AppType `orm:"type" json:"type" description:"应用类型"`
|
||||
Status consts.AppStatus `orm:"status" json:"status" description:"应用状态:active启用/inactive停用"`
|
||||
Description string `orm:"description" json:"description" description:"应用描述"`
|
||||
// 接入配置 (JSONB)
|
||||
AccessConfig map[string]interface{} `orm:"access_config" json:"accessConfig" description:"接入配置"`
|
||||
// 限流配置 (JSONB)
|
||||
LimitConfig map[string]interface{} `orm:"limit_config" json:"limitConfig" description:"限流配置"`
|
||||
// 回调配置 (JSONB)
|
||||
CallbackConfig map[string]interface{} `orm:"callback_config" json:"callbackConfig" description:"回调配置"`
|
||||
}
|
||||
|
||||
// ApplicationCol 应用表字段定义
|
||||
type ApplicationCol struct {
|
||||
beans.SQLBaseCol
|
||||
Name string
|
||||
AppCode string
|
||||
Type string
|
||||
Status string
|
||||
Description string
|
||||
AccessConfig string
|
||||
LimitConfig string
|
||||
CallbackConfig string
|
||||
}
|
||||
|
||||
// ApplicationCols 应用表字段常量
|
||||
var ApplicationCols = ApplicationCol{
|
||||
SQLBaseCol: beans.DefSQLBaseCol,
|
||||
Name: "name",
|
||||
AppCode: "app_code",
|
||||
Type: "type",
|
||||
Status: "status",
|
||||
Description: "description",
|
||||
AccessConfig: "access_config",
|
||||
LimitConfig: "limit_config",
|
||||
CallbackConfig: "callback_config",
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
consts "cid/consts/data"
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
// ApiInterface 接口管理实体
|
||||
type ApiInterface struct {
|
||||
beans.SQLBaseDO `orm:",inherit"`
|
||||
// 基础信息
|
||||
PlatformId int64 `orm:"platform_id" json:"platformId" description:"所属平台ID"`
|
||||
Name string `orm:"name" json:"name" description:"接口名称"`
|
||||
Code string `orm:"code" json:"code" description:"接口编码"`
|
||||
Url string `orm:"url" json:"url" description:"接口地址"`
|
||||
Method consts.ApiMethod `orm:"method" json:"method" description:"请求方法:GET/POST/PUT/DELETE等"`
|
||||
Status consts.PlatformStatus `orm:"status" json:"status" description:"接口状态:active启用/inactive停用"`
|
||||
// 认证类型
|
||||
AuthType string `orm:"auth_type" json:"authType" description:"认证类型:oauth2/apikey/basic等"`
|
||||
// 请求配置 (JSONB)
|
||||
RequestConfig map[string]interface{} `orm:"request_config" json:"requestConfig" description:"请求配置"`
|
||||
// 响应配置 (JSONB)
|
||||
ResponseConfig map[string]interface{} `orm:"response_config" json:"responseConfig" description:"响应配置"`
|
||||
// 独立限流配置 (JSONB)
|
||||
LimitConfig map[string]interface{} `orm:"limit_config" json:"limitConfig" description:"接口独立限流配置(可选,覆盖平台配置)"`
|
||||
}
|
||||
|
||||
// ApiInterfaceCol 接口表字段定义
|
||||
type ApiInterfaceCol struct {
|
||||
beans.SQLBaseCol
|
||||
PlatformId string
|
||||
Name string
|
||||
Code string
|
||||
Url string
|
||||
Method string
|
||||
Status string
|
||||
AuthType string
|
||||
RequestConfig string
|
||||
ResponseConfig string
|
||||
LimitConfig string
|
||||
}
|
||||
|
||||
// ApiInterfaceCols 接口表字段常量
|
||||
var ApiInterfaceCols = ApiInterfaceCol{
|
||||
SQLBaseCol: beans.DefSQLBaseCol,
|
||||
PlatformId: "platform_id",
|
||||
Name: "name",
|
||||
Code: "code",
|
||||
Url: "url",
|
||||
Method: "method",
|
||||
Status: "status",
|
||||
AuthType: "auth_type",
|
||||
RequestConfig: "request_config",
|
||||
ResponseConfig: "response_config",
|
||||
LimitConfig: "limit_config",
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
consts "cid/consts/data"
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
// DataFetchLog 数据获取日志实体
|
||||
type DataFetchLog struct {
|
||||
beans.SQLBaseDO `orm:",inherit"`
|
||||
// 关联信息
|
||||
PlatformId int64 `orm:"platform_id" json:"platformId" description:"平台ID"`
|
||||
InterfaceId int64 `orm:"interface_id" json:"interfaceId" description:"接口ID"`
|
||||
RequestId string `orm:"request_id" json:"requestId" description:"请求ID"`
|
||||
// 执行状态
|
||||
Status consts.FetchStatus `orm:"status" json:"status" description:"执行状态:pending/running/success/failed/rate_limit"`
|
||||
StartTime int64 `orm:"start_time" json:"startTime" description:"开始时间(时间戳)"`
|
||||
EndTime int64 `orm:"end_time" json:"endTime" description:"结束时间(时间戳)"`
|
||||
Duration int `orm:"duration" json:"duration" description:"执行时长(毫秒)"`
|
||||
// 请求响应数据
|
||||
RequestConfig map[string]interface{} `orm:"request_config" json:"requestConfig" description:"请求配置参数"`
|
||||
ResponseData string `orm:"response_data" json:"responseData" description:"响应数据(JSON)"`
|
||||
ErrorMessage string `orm:"error_message" json:"errorMessage" description:"错误信息"`
|
||||
// 重试信息
|
||||
RetryCount int `orm:"retry_count" json:"retryCount" description:"重试次数"`
|
||||
}
|
||||
|
||||
// DataFetchLogCol 数据获取日志表字段定义
|
||||
type DataFetchLogCol struct {
|
||||
beans.SQLBaseCol
|
||||
PlatformId string
|
||||
InterfaceId string
|
||||
RequestId string
|
||||
Status string
|
||||
StartTime string
|
||||
EndTime string
|
||||
Duration string
|
||||
RequestConfig string
|
||||
ResponseData string
|
||||
ErrorMessage string
|
||||
RetryCount string
|
||||
}
|
||||
|
||||
// DataFetchLogCols 数据获取日志表字段常量
|
||||
var DataFetchLogCols = DataFetchLogCol{
|
||||
SQLBaseCol: beans.DefSQLBaseCol,
|
||||
PlatformId: "platform_id",
|
||||
InterfaceId: "interface_id",
|
||||
RequestId: "request_id",
|
||||
Status: "status",
|
||||
StartTime: "start_time",
|
||||
EndTime: "end_time",
|
||||
Duration: "duration",
|
||||
RequestConfig: "request_config",
|
||||
ResponseData: "response_data",
|
||||
ErrorMessage: "error_message",
|
||||
RetryCount: "retry_count",
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
consts "cid/consts/data"
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
// Platform 平台管理实体
|
||||
type Platform struct {
|
||||
beans.SQLBaseDO `orm:",inherit"`
|
||||
// 基础信息
|
||||
Name string `orm:"name" json:"name" description:"平台名称"`
|
||||
Type consts.SyncPlatform `orm:"type" json:"type" description:"平台类型"`
|
||||
Status consts.PlatformStatus `orm:"status" json:"status" description:"平台状态:active启用/inactive停用"`
|
||||
Description string `orm:"description" json:"description" description:"平台描述"`
|
||||
// 认证配置 (JSONB)
|
||||
AuthConfig map[string]interface{} `orm:"auth_config" json:"authConfig" description:"认证配置"`
|
||||
// 限流配置 (JSONB)
|
||||
LimitConfig map[string]interface{} `orm:"limit_config" json:"limitConfig" description:"限流配置"`
|
||||
// 平台专用配置 (JSONB)
|
||||
PlatformConfig map[string]interface{} `orm:"platform_config" json:"platformConfig" description:"平台专用配置"`
|
||||
}
|
||||
|
||||
// PlatformCol 平台表字段定义
|
||||
type PlatformCol struct {
|
||||
beans.SQLBaseCol
|
||||
Name string
|
||||
Type string
|
||||
Status string
|
||||
Description string
|
||||
AuthConfig string
|
||||
LimitConfig string
|
||||
PlatformConfig string
|
||||
}
|
||||
|
||||
// PlatformCols 平台表字段常量
|
||||
var PlatformCols = PlatformCol{
|
||||
SQLBaseCol: beans.DefSQLBaseCol,
|
||||
Name: "name",
|
||||
Type: "type",
|
||||
Status: "status",
|
||||
Description: "description",
|
||||
AuthConfig: "auth_config",
|
||||
LimitConfig: "limit_config",
|
||||
PlatformConfig: "platform_config",
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package mapping
|
||||
|
||||
import (
|
||||
"cid/consts/mapping"
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
// DataMapping 数据映射实体
|
||||
type DataMapping struct {
|
||||
beans.SQLBaseDO `orm:",inherit"`
|
||||
// 关联信息
|
||||
PlatformId int64 `orm:"platform_id" json:"platformId" description:"平台ID"`
|
||||
InterfaceId int64 `orm:"interface_id" json:"interfaceId" description:"接口ID"`
|
||||
// 映射规则
|
||||
SourceField string `orm:"source_field" json:"sourceField" description:"源字段(接口返回字段)"`
|
||||
TargetField string `orm:"target_field" json:"targetField" description:"目标字段(本地表字段)"`
|
||||
FieldType string `orm:"field_type" json:"fieldType" description:"字段类型:string/int/float/bool/array/object"`
|
||||
DefaultValue string `orm:"default_value" json:"defaultValue" description:"默认值"`
|
||||
// 转换规则 (JSONB)
|
||||
TransformRule map[string]interface{} `orm:"transform_rule" json:"transformRule" description:"转换规则"`
|
||||
// 优先级和状态
|
||||
Priority int `orm:"priority" json:"priority" description:"优先级(数字越小优先级越高)"`
|
||||
Status mapping.MappingStatus `orm:"status" json:"status" description:"状态:active启用/inactive停用"`
|
||||
}
|
||||
|
||||
// DataMappingCol 数据映射表字段定义
|
||||
type DataMappingCol struct {
|
||||
beans.SQLBaseCol
|
||||
PlatformId string
|
||||
InterfaceId string
|
||||
SourceField string
|
||||
TargetField string
|
||||
FieldType string
|
||||
DefaultValue string
|
||||
TransformRule string
|
||||
Priority string
|
||||
Status string
|
||||
}
|
||||
|
||||
// DataMappingCols 数据映射表字段常量
|
||||
var DataMappingCols = DataMappingCol{
|
||||
SQLBaseCol: beans.DefSQLBaseCol,
|
||||
PlatformId: "platform_id",
|
||||
InterfaceId: "interface_id",
|
||||
SourceField: "source_field",
|
||||
TargetField: "target_field",
|
||||
FieldType: "field_type",
|
||||
DefaultValue: "default_value",
|
||||
TransformRule: "transform_rule",
|
||||
Priority: "priority",
|
||||
Status: "status",
|
||||
}
|
||||
@@ -1,178 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
consts "cid/consts/app"
|
||||
dao "cid/dao/app"
|
||||
dto "cid/model/dto/app"
|
||||
entity "cid/model/entity/app"
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
type applicationService struct{}
|
||||
|
||||
// Application 应用服务
|
||||
var Application = new(applicationService)
|
||||
|
||||
// Create 创建应用
|
||||
func (s *applicationService) Create(ctx context.Context, req *dto.CreateApplicationReq) (res *dto.CreateApplicationRes, err error) {
|
||||
// 检查应用名称是否重复
|
||||
count, err := dao.Application.Count(ctx, &dto.ListApplicationReq{Name: req.Name})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if count > 0 {
|
||||
return nil, errors.New("应用名称已存在")
|
||||
}
|
||||
|
||||
// 检查应用编码是否重复
|
||||
count, err = dao.Application.Count(ctx, &dto.ListApplicationReq{AppCode: req.AppCode})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if count > 0 {
|
||||
return nil, errors.New("应用编码已存在")
|
||||
}
|
||||
|
||||
// 插入数据库
|
||||
id, err := dao.Application.Insert(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
res = &dto.CreateApplicationRes{
|
||||
Id: id,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// List 获取应用列表
|
||||
func (s *applicationService) List(ctx context.Context, req *dto.ListApplicationReq) (res *dto.ListApplicationRes, err error) {
|
||||
applicationList, total, err := dao.Application.List(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 组装响应数据
|
||||
list := make([]dto.ApplicationItem, 0, len(applicationList))
|
||||
for _, item := range applicationList {
|
||||
list = append(list, dto.ApplicationItem{
|
||||
Id: item.Id,
|
||||
Name: item.Name,
|
||||
AppCode: item.AppCode,
|
||||
Type: item.Type,
|
||||
TypeName: s.getTypeName(item.Type),
|
||||
Status: item.Status,
|
||||
StatusName: s.getStatusName(item.Status),
|
||||
Description: item.Description,
|
||||
CreatedAt: item.CreatedAt.Unix(),
|
||||
UpdatedAt: item.UpdatedAt.Unix(),
|
||||
})
|
||||
}
|
||||
|
||||
res = &dto.ListApplicationRes{
|
||||
List: list,
|
||||
Total: total,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetOne 获取单个应用
|
||||
func (s *applicationService) GetOne(ctx context.Context, req *dto.GetApplicationReq) (res *dto.GetApplicationRes, err error) {
|
||||
application, err := dao.Application.GetOne(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var applicationEntity *entity.Application
|
||||
if err = gconv.Struct(application, &applicationEntity); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return &dto.GetApplicationRes{
|
||||
Application: applicationEntity,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Update 更新应用
|
||||
func (s *applicationService) Update(ctx context.Context, req *dto.UpdateApplicationReq) (err error) {
|
||||
// 检查应用是否存在
|
||||
exist, err := dao.Application.GetOne(ctx, &dto.GetApplicationReq{Id: req.Id})
|
||||
if err != nil || exist == nil {
|
||||
return errors.New("应用不存在")
|
||||
}
|
||||
|
||||
// 如果修改了名称,检查新名称是否重复
|
||||
if req.Name != "" && req.Name != exist.Name {
|
||||
count, err := dao.Application.Count(ctx, &dto.ListApplicationReq{Name: req.Name})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if count > 0 {
|
||||
return errors.New("应用名称已存在")
|
||||
}
|
||||
}
|
||||
|
||||
// 如果修改了应用编码,检查新编码是否重复
|
||||
if req.AppCode != "" && req.AppCode != exist.AppCode {
|
||||
count, err := dao.Application.Count(ctx, &dto.ListApplicationReq{AppCode: req.AppCode})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if count > 0 {
|
||||
return errors.New("应用编码已存在")
|
||||
}
|
||||
}
|
||||
|
||||
_, err = dao.Application.Update(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateStatus 更新应用状态
|
||||
func (s *applicationService) UpdateStatus(ctx context.Context, req *dto.UpdateApplicationStatusReq) (err error) {
|
||||
_, err = dao.Application.UpdateStatus(ctx, req.Id, req.Status.String())
|
||||
return
|
||||
}
|
||||
|
||||
// Delete 删除应用
|
||||
func (s *applicationService) Delete(ctx context.Context, req *dto.DeleteApplicationReq) (err error) {
|
||||
// TODO: 检查是否存在关联的数据,防止误删
|
||||
// 例如: 检查该应用是否有关联的广告活动等
|
||||
|
||||
_, err = dao.Application.Delete(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// GetByAppCode 根据应用编码获取应用
|
||||
func (s *applicationService) GetByAppCode(ctx context.Context, appCode string) (res *entity.Application, err error) {
|
||||
return dao.Application.GetByAppCode(ctx, appCode)
|
||||
}
|
||||
|
||||
// getTypeName 获取类型名称
|
||||
func (s *applicationService) getTypeName(appType consts.AppType) string {
|
||||
typeNames := map[consts.AppType]string{
|
||||
consts.AppTypeWeb: "Web应用",
|
||||
consts.AppTypeMobile: "移动应用",
|
||||
consts.AppTypeMiniApp: "小程序",
|
||||
consts.AppTypeH5: "H5应用",
|
||||
consts.AppTypeDesktop: "桌面应用",
|
||||
consts.AppTypeThirdParty: "第三方应用",
|
||||
}
|
||||
if name, ok := typeNames[appType]; ok {
|
||||
return name
|
||||
}
|
||||
return string(appType)
|
||||
}
|
||||
|
||||
// getStatusName 获取状态名称
|
||||
func (s *applicationService) getStatusName(status consts.AppStatus) string {
|
||||
statusNames := map[consts.AppStatus]string{
|
||||
consts.AppStatusActive: "启用",
|
||||
consts.AppStatusInactive: "停用",
|
||||
}
|
||||
if name, ok := statusNames[status]; ok {
|
||||
return name
|
||||
}
|
||||
return string(status)
|
||||
}
|
||||
@@ -1,191 +0,0 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
consts "cid/consts/data"
|
||||
dao "cid/dao/data"
|
||||
dto "cid/model/dto/data"
|
||||
entity "cid/model/entity/data"
|
||||
"context"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type apiInterfaceService struct{}
|
||||
|
||||
// ApiInterface 接口服务
|
||||
var ApiInterface = new(apiInterfaceService)
|
||||
|
||||
// Create 创建接口
|
||||
func (s *apiInterfaceService) Create(ctx context.Context, req *dto.CreateApiInterfaceReq) (res *dto.CreateApiInterfaceRes, err error) {
|
||||
// 检查平台是否存在
|
||||
_, err = dao.Platform.GetOne(ctx, &dto.GetPlatformReq{Id: req.PlatformId})
|
||||
if err != nil {
|
||||
return nil, errors.New("平台不存在")
|
||||
}
|
||||
|
||||
// 检查接口编码在同一平台下是否重复
|
||||
interfaces, _, err := dao.ApiInterface.List(ctx, &dto.ListApiInterfaceReq{
|
||||
PlatformId: req.PlatformId,
|
||||
Code: req.Code,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if len(interfaces) > 0 {
|
||||
return nil, errors.New("接口编码在该平台下已存在")
|
||||
}
|
||||
|
||||
// 插入数据库
|
||||
id, err := dao.ApiInterface.Insert(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
res = &dto.CreateApiInterfaceRes{
|
||||
Id: id,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// List 获取接口列表
|
||||
func (s *apiInterfaceService) List(ctx context.Context, req *dto.ListApiInterfaceReq) (res *dto.ListApiInterfaceRes, err error) {
|
||||
apiList, total, err := dao.ApiInterface.List(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 获取平台ID列表用于批量查询
|
||||
platformIds := make([]int64, 0)
|
||||
for _, item := range apiList {
|
||||
if item.PlatformId > 0 {
|
||||
platformIds = append(platformIds, item.PlatformId)
|
||||
}
|
||||
}
|
||||
|
||||
// 批量获取平台信息
|
||||
platformMap := make(map[int64]string)
|
||||
if len(platformIds) > 0 {
|
||||
platforms, _, err := dao.Platform.List(ctx, &dto.ListPlatformReq{})
|
||||
if err == nil {
|
||||
for _, p := range platforms {
|
||||
platformMap[p.Id] = p.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 组装响应数据
|
||||
list := make([]dto.ApiInterfaceItem, 0, len(apiList))
|
||||
for _, item := range apiList {
|
||||
platformName := ""
|
||||
if name, ok := platformMap[item.PlatformId]; ok {
|
||||
platformName = name
|
||||
}
|
||||
|
||||
list = append(list, dto.ApiInterfaceItem{
|
||||
Id: item.Id,
|
||||
PlatformId: item.PlatformId,
|
||||
PlatformName: platformName,
|
||||
Name: item.Name,
|
||||
Code: item.Code,
|
||||
Url: item.Url,
|
||||
Method: item.Method,
|
||||
Status: item.Status,
|
||||
StatusName: s.getStatusName(item.Status),
|
||||
CreatedAt: item.CreatedAt.Unix(),
|
||||
UpdatedAt: item.UpdatedAt.Unix(),
|
||||
})
|
||||
}
|
||||
|
||||
res = &dto.ListApiInterfaceRes{
|
||||
List: list,
|
||||
Total: total,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetOne 获取单个接口
|
||||
func (s *apiInterfaceService) GetOne(ctx context.Context, req *dto.GetApiInterfaceReq) (res *dto.GetApiInterfaceRes, err error) {
|
||||
apiInterface, err := dao.ApiInterface.GetOne(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 获取平台名称
|
||||
var platformName string
|
||||
if apiInterface.PlatformId > 0 {
|
||||
platform, _ := dao.Platform.GetOne(ctx, &dto.GetPlatformReq{Id: apiInterface.PlatformId})
|
||||
if platform != nil {
|
||||
platformName = platform.Name
|
||||
}
|
||||
}
|
||||
|
||||
return &dto.GetApiInterfaceRes{
|
||||
ApiInterface: apiInterface,
|
||||
PlatformName: platformName,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Update 更新接口
|
||||
func (s *apiInterfaceService) Update(ctx context.Context, req *dto.UpdateApiInterfaceReq) (err error) {
|
||||
// 检查接口是否存在
|
||||
exist, err := dao.ApiInterface.GetOne(ctx, &dto.GetApiInterfaceReq{Id: req.Id})
|
||||
if err != nil || exist == nil {
|
||||
return errors.New("接口不存在")
|
||||
}
|
||||
|
||||
// 如果修改了平台,检查平台是否存在
|
||||
if req.PlatformId > 0 && req.PlatformId != exist.PlatformId {
|
||||
_, err := dao.Platform.GetOne(ctx, &dto.GetPlatformReq{Id: req.PlatformId})
|
||||
if err != nil {
|
||||
return errors.New("平台不存在")
|
||||
}
|
||||
}
|
||||
|
||||
// 如果修改了编码,检查编码是否重复
|
||||
if req.Code != "" && req.Code != exist.Code {
|
||||
platformId := req.PlatformId
|
||||
if platformId == 0 {
|
||||
platformId = exist.PlatformId
|
||||
}
|
||||
interfaces, _, err := dao.ApiInterface.List(ctx, &dto.ListApiInterfaceReq{
|
||||
PlatformId: platformId,
|
||||
Code: req.Code,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(interfaces) > 0 {
|
||||
return errors.New("接口编码在该平台下已存在")
|
||||
}
|
||||
}
|
||||
|
||||
_, err = dao.ApiInterface.Update(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateStatus 更新接口状态
|
||||
func (s *apiInterfaceService) UpdateStatus(ctx context.Context, req *dto.UpdateApiInterfaceStatusReq) (err error) {
|
||||
_, err = dao.ApiInterface.UpdateStatus(ctx, req.Id, req.Status.String())
|
||||
return
|
||||
}
|
||||
|
||||
// Delete 删除接口
|
||||
func (s *apiInterfaceService) Delete(ctx context.Context, req *dto.DeleteApiInterfaceReq) (err error) {
|
||||
_, err = dao.ApiInterface.Delete(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// GetByIds 根据ID列表获取接口
|
||||
func (s *apiInterfaceService) GetByIds(ctx context.Context, ids []int64) (res []entity.ApiInterface, err error) {
|
||||
return dao.ApiInterface.GetByIds(ctx, ids)
|
||||
}
|
||||
|
||||
// getStatusName 获取状态名称
|
||||
func (s *apiInterfaceService) getStatusName(status consts.PlatformStatus) string {
|
||||
statusNames := map[consts.PlatformStatus]string{
|
||||
consts.PlatformStatusActive: "启用",
|
||||
consts.PlatformStatusInactive: "停用",
|
||||
}
|
||||
if name, ok := statusNames[status]; ok {
|
||||
return name
|
||||
}
|
||||
return string(status)
|
||||
}
|
||||
@@ -1,316 +0,0 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
consts "cid/consts/data"
|
||||
dao "cid/dao/data"
|
||||
dto "cid/model/dto/data"
|
||||
entity "cid/model/entity/data"
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/grpool"
|
||||
"github.com/gogf/gf/v2/util/guid"
|
||||
)
|
||||
|
||||
type dataFetchService struct{}
|
||||
|
||||
// DataFetch 数据获取服务
|
||||
var DataFetch = new(dataFetchService)
|
||||
|
||||
// FetchPool 数据获取协程池,限制并发数避免goroutine爆炸
|
||||
var FetchPool = grpool.New(10)
|
||||
|
||||
// Execute 执行数据获取
|
||||
func (s *dataFetchService) Execute(ctx context.Context, req *dto.ExecuteDataFetchReq) (res *dto.ExecuteDataFetchRes, err error) {
|
||||
// 检查接口是否存在
|
||||
apiInterface, err := dao.ApiInterface.GetOne(ctx, &dto.GetApiInterfaceReq{Id: req.InterfaceId})
|
||||
if err != nil || apiInterface == nil {
|
||||
return nil, fmt.Errorf("接口不存在")
|
||||
}
|
||||
|
||||
// 检查接口状态
|
||||
if apiInterface.Status != consts.PlatformStatusActive {
|
||||
return nil, fmt.Errorf("接口未启用")
|
||||
}
|
||||
|
||||
// 检查平台是否存在
|
||||
platform, err := dao.Platform.GetOne(ctx, &dto.GetPlatformReq{Id: apiInterface.PlatformId})
|
||||
if err != nil || platform == nil {
|
||||
return nil, fmt.Errorf("平台不存在")
|
||||
}
|
||||
|
||||
// 检查平台状态
|
||||
if platform.Status != consts.PlatformStatusActive {
|
||||
return nil, fmt.Errorf("平台未启用")
|
||||
}
|
||||
|
||||
// 生成请求ID
|
||||
requestId := guid.S()
|
||||
startTime := time.Now().UnixMilli()
|
||||
|
||||
// 创建数据获取日志
|
||||
fetchLog := &entity.DataFetchLog{
|
||||
PlatformId: req.PlatformId,
|
||||
InterfaceId: req.InterfaceId,
|
||||
RequestId: requestId,
|
||||
Status: consts.FetchStatusPending,
|
||||
StartTime: startTime,
|
||||
RequestConfig: req.RequestParams,
|
||||
RetryCount: 0,
|
||||
}
|
||||
|
||||
logId, err := dao.DataFetchLog.Insert(ctx, fetchLog)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("创建日志失败: %v", err)
|
||||
}
|
||||
|
||||
// 使用协程池异步执行数据获取
|
||||
asyncCtx := context.WithoutCancel(ctx)
|
||||
FetchPool.Add(asyncCtx, func(ctx context.Context) {
|
||||
s.executeFetch(ctx, logId, requestId, platform, apiInterface, req.RequestParams, startTime)
|
||||
})
|
||||
|
||||
return &dto.ExecuteDataFetchRes{
|
||||
RequestId: requestId,
|
||||
Status: string(consts.FetchStatusPending),
|
||||
Message: "任务已提交",
|
||||
}, nil
|
||||
}
|
||||
|
||||
// BatchExecute 批量执行数据获取
|
||||
func (s *dataFetchService) BatchExecute(ctx context.Context, req *dto.BatchExecuteDataFetchReq) (res *dto.BatchExecuteDataFetchRes, err error) {
|
||||
var requestIds []string
|
||||
successCount := 0
|
||||
failedCount := 0
|
||||
|
||||
for _, interfaceId := range req.InterfaceIds {
|
||||
executeReq := &dto.ExecuteDataFetchReq{
|
||||
PlatformId: 0, // 接口服务会自动获取
|
||||
InterfaceId: interfaceId,
|
||||
RequestParams: req.RequestParams,
|
||||
}
|
||||
|
||||
executeRes, err := s.Execute(ctx, executeReq)
|
||||
if err != nil {
|
||||
failedCount++
|
||||
g.Log().Error(ctx, "批量执行失败", g.Map{
|
||||
"interfaceId": interfaceId,
|
||||
"error": err.Error(),
|
||||
})
|
||||
} else {
|
||||
successCount++
|
||||
requestIds = append(requestIds, executeRes.RequestId)
|
||||
}
|
||||
}
|
||||
|
||||
return &dto.BatchExecuteDataFetchRes{
|
||||
SuccessCount: successCount,
|
||||
FailedCount: failedCount,
|
||||
RequestIds: requestIds,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// List 获取数据获取日志列表
|
||||
func (s *dataFetchService) List(ctx context.Context, req *dto.ListDataFetchLogReq) (res *dto.ListDataFetchLogRes, err error) {
|
||||
logList, total, err := dao.DataFetchLog.List(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 获取平台和接口ID列表
|
||||
platformIds := make([]int64, 0)
|
||||
interfaceIds := make([]int64, 0)
|
||||
for _, item := range logList {
|
||||
if item.PlatformId > 0 {
|
||||
platformIds = append(platformIds, item.PlatformId)
|
||||
}
|
||||
if item.InterfaceId > 0 {
|
||||
interfaceIds = append(interfaceIds, item.InterfaceId)
|
||||
}
|
||||
}
|
||||
|
||||
// 批量获取平台和接口信息
|
||||
platformMap := make(map[int64]string)
|
||||
interfaceMap := make(map[int64]string)
|
||||
if len(platformIds) > 0 {
|
||||
platforms, _, err := dao.Platform.List(ctx, &dto.ListPlatformReq{})
|
||||
if err == nil {
|
||||
for _, p := range platforms {
|
||||
platformMap[p.Id] = p.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(interfaceIds) > 0 {
|
||||
interfaces, _, err := dao.ApiInterface.List(ctx, &dto.ListApiInterfaceReq{})
|
||||
if err == nil {
|
||||
for _, i := range interfaces {
|
||||
interfaceMap[i.Id] = i.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 组装响应数据
|
||||
list := make([]dto.DataFetchLogItem, 0, len(logList))
|
||||
for _, item := range logList {
|
||||
platformName := ""
|
||||
if name, ok := platformMap[item.PlatformId]; ok {
|
||||
platformName = name
|
||||
}
|
||||
interfaceName := ""
|
||||
if name, ok := interfaceMap[item.InterfaceId]; ok {
|
||||
interfaceName = name
|
||||
}
|
||||
|
||||
list = append(list, dto.DataFetchLogItem{
|
||||
Id: item.Id,
|
||||
PlatformId: item.PlatformId,
|
||||
PlatformName: platformName,
|
||||
InterfaceId: item.InterfaceId,
|
||||
InterfaceName: interfaceName,
|
||||
RequestId: item.RequestId,
|
||||
Status: item.Status,
|
||||
StatusName: s.getStatusName(item.Status),
|
||||
StartTime: item.StartTime,
|
||||
EndTime: item.EndTime,
|
||||
Duration: item.Duration,
|
||||
ErrorMessage: item.ErrorMessage,
|
||||
RetryCount: item.RetryCount,
|
||||
CreatedAt: item.CreatedAt.Unix(),
|
||||
})
|
||||
}
|
||||
|
||||
res = &dto.ListDataFetchLogRes{
|
||||
List: list,
|
||||
Total: total,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetOne 获取单个数据获取日志
|
||||
func (s *dataFetchService) GetOne(ctx context.Context, req *dto.GetDataFetchLogReq) (res *dto.GetDataFetchLogRes, err error) {
|
||||
fetchLog, err := dao.DataFetchLog.GetOne(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 获取平台和接口名称
|
||||
var platformName, interfaceName string
|
||||
if fetchLog.PlatformId > 0 {
|
||||
platform, _ := dao.Platform.GetOne(ctx, &dto.GetPlatformReq{Id: fetchLog.PlatformId})
|
||||
if platform != nil {
|
||||
platformName = platform.Name
|
||||
}
|
||||
}
|
||||
if fetchLog.InterfaceId > 0 {
|
||||
apiInterface, _ := dao.ApiInterface.GetOne(ctx, &dto.GetApiInterfaceReq{Id: fetchLog.InterfaceId})
|
||||
if apiInterface != nil {
|
||||
interfaceName = apiInterface.Name
|
||||
}
|
||||
}
|
||||
|
||||
return &dto.GetDataFetchLogRes{
|
||||
DataFetchLog: fetchLog,
|
||||
PlatformName: platformName,
|
||||
InterfaceName: interfaceName,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ReExecute 重新执行数据获取
|
||||
func (s *dataFetchService) ReExecute(ctx context.Context, req *dto.ReExecuteDataFetchReq) (res *dto.ReExecuteDataFetchRes, err error) {
|
||||
// 获取原日志
|
||||
oldLog, err := dao.DataFetchLog.GetOne(ctx, &dto.GetDataFetchLogReq{Id: req.LogId})
|
||||
if err != nil || oldLog == nil {
|
||||
return nil, fmt.Errorf("日志不存在")
|
||||
}
|
||||
|
||||
// 检查接口是否存在
|
||||
apiInterface, err := dao.ApiInterface.GetOne(ctx, &dto.GetApiInterfaceReq{Id: oldLog.InterfaceId})
|
||||
if err != nil || apiInterface == nil {
|
||||
return nil, fmt.Errorf("接口不存在")
|
||||
}
|
||||
|
||||
// 检查平台是否存在
|
||||
platform, err := dao.Platform.GetOne(ctx, &dto.GetPlatformReq{Id: apiInterface.PlatformId})
|
||||
if err != nil || platform == nil {
|
||||
return nil, fmt.Errorf("平台不存在")
|
||||
}
|
||||
|
||||
// 生成新的请求ID
|
||||
requestId := guid.S()
|
||||
startTime := time.Now().UnixMilli()
|
||||
|
||||
// 创建新的数据获取日志
|
||||
fetchLog := &entity.DataFetchLog{
|
||||
PlatformId: oldLog.PlatformId,
|
||||
InterfaceId: oldLog.InterfaceId,
|
||||
RequestId: requestId,
|
||||
Status: consts.FetchStatusPending,
|
||||
StartTime: startTime,
|
||||
RequestConfig: oldLog.RequestConfig,
|
||||
RetryCount: oldLog.RetryCount + 1,
|
||||
}
|
||||
|
||||
logId, err := dao.DataFetchLog.Insert(ctx, fetchLog)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("创建日志失败: %v", err)
|
||||
}
|
||||
|
||||
// 使用协程池异步执行数据获取
|
||||
asyncCtx := context.WithoutCancel(ctx)
|
||||
FetchPool.Add(asyncCtx, func(ctx context.Context) {
|
||||
s.executeFetch(ctx, logId, requestId, platform, apiInterface, oldLog.RequestConfig, startTime)
|
||||
})
|
||||
|
||||
return &dto.ReExecuteDataFetchRes{
|
||||
RequestId: requestId,
|
||||
Status: string(consts.FetchStatusPending),
|
||||
Message: "任务已重新提交",
|
||||
}, nil
|
||||
}
|
||||
|
||||
// executeFetch 执行实际的数据获取(在协程池中运行)
|
||||
func (s *dataFetchService) executeFetch(ctx context.Context, logId int64, requestId string, platform *entity.Platform, apiInterface *entity.ApiInterface, requestParams map[string]interface{}, startTime int64) {
|
||||
// 更新状态为执行中
|
||||
dao.DataFetchLog.UpdateStatus(ctx, logId, string(consts.FetchStatusRunning), 0, 0, "", "")
|
||||
|
||||
// TODO: 根据平台和接口配置执行HTTP请求
|
||||
// 这里需要根据平台的限流配置进行限流控制
|
||||
// 根据接口的请求配置组装请求参数
|
||||
// 调用接口获取数据
|
||||
|
||||
// 模拟接口调用
|
||||
time.Sleep(time.Second * 2)
|
||||
|
||||
// 模拟成功响应
|
||||
responseData := `{"code": 0, "message": "success", "data": {"items": []}}`
|
||||
endTime := time.Now().UnixMilli()
|
||||
duration := int(endTime - startTime)
|
||||
|
||||
// 更新状态为成功
|
||||
dao.DataFetchLog.UpdateStatus(ctx, logId, string(consts.FetchStatusSuccess), endTime, duration, responseData, "")
|
||||
|
||||
g.Log().Info(ctx, "数据获取成功", g.Map{
|
||||
"logId": logId,
|
||||
"requestId": requestId,
|
||||
"platform": platform.Name,
|
||||
"interface": apiInterface.Name,
|
||||
"duration": duration,
|
||||
})
|
||||
}
|
||||
|
||||
// getStatusName 获取状态名称
|
||||
func (s *dataFetchService) getStatusName(status consts.FetchStatus) string {
|
||||
statusNames := map[consts.FetchStatus]string{
|
||||
consts.FetchStatusPending: "待执行",
|
||||
consts.FetchStatusRunning: "执行中",
|
||||
consts.FetchStatusSuccess: "成功",
|
||||
consts.FetchStatusFailed: "失败",
|
||||
consts.FetchStatusRateLimit: "触发限流",
|
||||
}
|
||||
if name, ok := statusNames[status]; ok {
|
||||
return name
|
||||
}
|
||||
return string(status)
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
consts "cid/consts/data"
|
||||
dao "cid/dao/data"
|
||||
dto "cid/model/dto/data"
|
||||
entity "cid/model/entity/data"
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
type platformService struct{}
|
||||
|
||||
// Platform 平台服务
|
||||
var Platform = new(platformService)
|
||||
|
||||
// Create 创建平台
|
||||
func (s *platformService) Create(ctx context.Context, req *dto.CreatePlatformReq) (res *dto.CreatePlatformRes, err error) {
|
||||
// 检查平台名称是否重复
|
||||
count, err := dao.Platform.Count(ctx, &dto.ListPlatformReq{Name: req.Name})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if count > 0 {
|
||||
return nil, errors.New("平台名称已存在")
|
||||
}
|
||||
|
||||
// 检查平台类型是否重复
|
||||
count, err = dao.Platform.Count(ctx, &dto.ListPlatformReq{Type: req.Type})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if count > 0 {
|
||||
return nil, errors.New("该类型平台已存在")
|
||||
}
|
||||
|
||||
// 插入数据库
|
||||
id, err := dao.Platform.Insert(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
res = &dto.CreatePlatformRes{
|
||||
Id: id,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// List 获取平台列表
|
||||
func (s *platformService) List(ctx context.Context, req *dto.ListPlatformReq) (res *dto.ListPlatformRes, err error) {
|
||||
platformList, total, err := dao.Platform.List(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 组装响应数据
|
||||
list := make([]dto.PlatformItem, 0, len(platformList))
|
||||
for _, item := range platformList {
|
||||
list = append(list, dto.PlatformItem{
|
||||
Id: item.Id,
|
||||
Name: item.Name,
|
||||
Type: item.Type,
|
||||
TypeName: s.getTypeName(item.Type),
|
||||
Status: item.Status,
|
||||
StatusName: s.getStatusName(item.Status),
|
||||
Description: item.Description,
|
||||
CreatedAt: item.CreatedAt.Unix(),
|
||||
UpdatedAt: item.UpdatedAt.Unix(),
|
||||
})
|
||||
}
|
||||
|
||||
res = &dto.ListPlatformRes{
|
||||
List: list,
|
||||
Total: total,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetOne 获取单个平台
|
||||
func (s *platformService) GetOne(ctx context.Context, req *dto.GetPlatformReq) (res *dto.GetPlatformRes, err error) {
|
||||
platform, err := dao.Platform.GetOne(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var platformEntity *entity.Platform
|
||||
if err = gconv.Struct(platform, &platformEntity); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return &dto.GetPlatformRes{
|
||||
Platform: platformEntity,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Update 更新平台
|
||||
func (s *platformService) Update(ctx context.Context, req *dto.UpdatePlatformReq) (err error) {
|
||||
// 检查平台是否存在
|
||||
exist, err := dao.Platform.GetOne(ctx, &dto.GetPlatformReq{Id: req.Id})
|
||||
if err != nil || exist == nil {
|
||||
return errors.New("平台不存在")
|
||||
}
|
||||
|
||||
// 如果修改了名称,检查新名称是否重复
|
||||
if req.Name != "" && req.Name != exist.Name {
|
||||
count, err := dao.Platform.Count(ctx, &dto.ListPlatformReq{Name: req.Name})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if count > 0 {
|
||||
return errors.New("平台名称已存在")
|
||||
}
|
||||
}
|
||||
|
||||
// 如果修改了类型,检查新类型是否重复
|
||||
if req.Type != "" && req.Type != exist.Type {
|
||||
count, err := dao.Platform.Count(ctx, &dto.ListPlatformReq{Type: req.Type})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if count > 0 {
|
||||
return errors.New("该类型平台已存在")
|
||||
}
|
||||
}
|
||||
|
||||
_, err = dao.Platform.Update(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateStatus 更新平台状态
|
||||
func (s *platformService) UpdateStatus(ctx context.Context, req *dto.UpdatePlatformStatusReq) (err error) {
|
||||
_, err = dao.Platform.UpdateStatus(ctx, req.Id, req.Status.String())
|
||||
return
|
||||
}
|
||||
|
||||
// Delete 删除平台
|
||||
func (s *platformService) Delete(ctx context.Context, req *dto.DeletePlatformReq) (err error) {
|
||||
// 检查是否存在关联的接口
|
||||
interfaces, _, err := dao.ApiInterface.List(ctx, &dto.ListApiInterfaceReq{
|
||||
PlatformId: req.Id,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(interfaces) > 0 {
|
||||
return errors.New("该平台下存在接口,无法删除")
|
||||
}
|
||||
|
||||
_, err = dao.Platform.Delete(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// GetByType 根据类型获取平台
|
||||
func (s *platformService) GetByType(ctx context.Context, platformType consts.SyncPlatform) (res *entity.Platform, err error) {
|
||||
return dao.Platform.GetByType(ctx, platformType.String())
|
||||
}
|
||||
|
||||
// getTypeName 获取类型名称
|
||||
func (s *platformService) getTypeName(platformType consts.SyncPlatform) string {
|
||||
typeNames := map[consts.SyncPlatform]string{
|
||||
consts.PlatformTaobao: "淘宝",
|
||||
consts.PlatformJD: "京东",
|
||||
consts.PlatformKuaishou: "快手",
|
||||
consts.PlatformDouyin: "抖音",
|
||||
consts.PlatformXhs: "小红书",
|
||||
consts.PlatformPdd: "拼多多",
|
||||
consts.PlatformXianyu: "闲鱼",
|
||||
consts.PlatformTmall: "天猫",
|
||||
consts.PlatformWechat: "微信",
|
||||
consts.PlatformCustom: "自定义",
|
||||
}
|
||||
if name, ok := typeNames[platformType]; ok {
|
||||
return name
|
||||
}
|
||||
return string(platformType)
|
||||
}
|
||||
|
||||
// getStatusName 获取状态名称
|
||||
func (s *platformService) getStatusName(status consts.PlatformStatus) string {
|
||||
statusNames := map[consts.PlatformStatus]string{
|
||||
consts.PlatformStatusActive: "启用",
|
||||
consts.PlatformStatusInactive: "停用",
|
||||
}
|
||||
if name, ok := statusNames[status]; ok {
|
||||
return name
|
||||
}
|
||||
return string(status)
|
||||
}
|
||||
@@ -1,306 +0,0 @@
|
||||
package mapping
|
||||
|
||||
import (
|
||||
consts "cid/consts/mapping"
|
||||
dao "cid/dao/mapping"
|
||||
dto "cid/model/dto/mapping"
|
||||
entity "cid/model/entity/mapping"
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
type dataMappingService struct{}
|
||||
|
||||
// DataMapping 数据映射服务
|
||||
var DataMapping = new(dataMappingService)
|
||||
|
||||
// Create 创建数据映射
|
||||
func (s *dataMappingService) Create(ctx context.Context, req *dto.CreateDataMappingReq) (res *dto.CreateDataMappingRes, err error) {
|
||||
// 检查接口是否存在
|
||||
// TODO: 这里需要调用data层的ApiInterface服务,暂时跳过
|
||||
|
||||
// 检查同一接口下目标字段是否重复
|
||||
existing, err := dao.DataMapping.GetByInterfaceIdAndTargetField(ctx, req.InterfaceId, req.TargetField)
|
||||
if err == nil && existing != nil {
|
||||
return nil, errors.New("该接口下目标字段已存在")
|
||||
}
|
||||
|
||||
// 插入数据库
|
||||
id, err := dao.DataMapping.Insert(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
res = &dto.CreateDataMappingRes{
|
||||
Id: id,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BatchCreate 批量创建数据映射
|
||||
func (s *dataMappingService) BatchCreate(ctx context.Context, req *dto.BatchCreateDataMappingReq) (res *dto.BatchCreateDataMappingRes, err error) {
|
||||
var ids []int64
|
||||
successCount := 0
|
||||
failedCount := 0
|
||||
|
||||
for _, mappingReq := range req.Mappings {
|
||||
// 设置平台和接口ID
|
||||
mappingReq.PlatformId = req.PlatformId
|
||||
mappingReq.InterfaceId = req.InterfaceId
|
||||
|
||||
createRes, err := s.Create(ctx, &mappingReq)
|
||||
if err != nil {
|
||||
failedCount++
|
||||
g.Log().Error(ctx, "批量创建映射失败", g.Map{
|
||||
"sourceField": mappingReq.SourceField,
|
||||
"targetField": mappingReq.TargetField,
|
||||
"error": err.Error(),
|
||||
})
|
||||
} else {
|
||||
successCount++
|
||||
ids = append(ids, createRes.Id)
|
||||
}
|
||||
}
|
||||
|
||||
return &dto.BatchCreateDataMappingRes{
|
||||
SuccessCount: successCount,
|
||||
FailedCount: failedCount,
|
||||
Ids: ids,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// List 获取数据映射列表
|
||||
func (s *dataMappingService) List(ctx context.Context, req *dto.ListDataMappingReq) (res *dto.ListDataMappingRes, err error) {
|
||||
mappingList, total, err := dao.DataMapping.List(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 获取平台和接口ID列表
|
||||
platformIds := make([]int64, 0)
|
||||
interfaceIds := make([]int64, 0)
|
||||
for _, item := range mappingList {
|
||||
if item.PlatformId > 0 {
|
||||
platformIds = append(platformIds, item.PlatformId)
|
||||
}
|
||||
if item.InterfaceId > 0 {
|
||||
interfaceIds = append(interfaceIds, item.InterfaceId)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: 批量获取平台和接口信息(需要调用data层服务)
|
||||
platformMap := make(map[int64]string)
|
||||
interfaceMap := make(map[int64]string)
|
||||
|
||||
// 组装响应数据
|
||||
list := make([]dto.DataMappingItem, 0, len(mappingList))
|
||||
for _, item := range mappingList {
|
||||
platformName := ""
|
||||
if name, ok := platformMap[item.PlatformId]; ok {
|
||||
platformName = name
|
||||
}
|
||||
interfaceName := ""
|
||||
if name, ok := interfaceMap[item.InterfaceId]; ok {
|
||||
interfaceName = name
|
||||
}
|
||||
|
||||
list = append(list, dto.DataMappingItem{
|
||||
Id: item.Id,
|
||||
PlatformId: item.PlatformId,
|
||||
PlatformName: platformName,
|
||||
InterfaceId: item.InterfaceId,
|
||||
InterfaceName: interfaceName,
|
||||
SourceField: item.SourceField,
|
||||
TargetField: item.TargetField,
|
||||
FieldType: item.FieldType,
|
||||
DefaultValue: item.DefaultValue,
|
||||
TransformRule: item.TransformRule,
|
||||
Priority: item.Priority,
|
||||
Status: item.Status,
|
||||
StatusName: s.getStatusName(item.Status),
|
||||
CreatedAt: item.CreatedAt.Unix(),
|
||||
UpdatedAt: item.UpdatedAt.Unix(),
|
||||
})
|
||||
}
|
||||
|
||||
res = &dto.ListDataMappingRes{
|
||||
List: list,
|
||||
Total: total,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetOne 获取单个数据映射
|
||||
func (s *dataMappingService) GetOne(ctx context.Context, req *dto.GetDataMappingReq) (res *dto.GetDataMappingRes, err error) {
|
||||
mapping, err := dao.DataMapping.GetOne(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: 获取平台和接口名称
|
||||
platformName := ""
|
||||
interfaceName := ""
|
||||
|
||||
return &dto.GetDataMappingRes{
|
||||
DataMapping: mapping,
|
||||
PlatformName: platformName,
|
||||
InterfaceName: interfaceName,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Update 更新数据映射
|
||||
func (s *dataMappingService) Update(ctx context.Context, req *dto.UpdateDataMappingReq) (err error) {
|
||||
// 检查映射是否存在
|
||||
exist, err := dao.DataMapping.GetOne(ctx, &dto.GetDataMappingReq{Id: req.Id})
|
||||
if err != nil || exist == nil {
|
||||
return errors.New("映射不存在")
|
||||
}
|
||||
|
||||
// 如果修改了目标字段,检查是否重复
|
||||
if req.TargetField != "" && req.TargetField != exist.TargetField {
|
||||
interfaceId := req.InterfaceId
|
||||
if interfaceId == 0 {
|
||||
interfaceId = exist.InterfaceId
|
||||
}
|
||||
existing, err := dao.DataMapping.GetByInterfaceIdAndTargetField(ctx, interfaceId, req.TargetField)
|
||||
if err == nil && existing != nil && existing.Id != req.Id {
|
||||
return errors.New("该接口下目标字段已存在")
|
||||
}
|
||||
}
|
||||
|
||||
_, err = dao.DataMapping.Update(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// Delete 删除数据映射
|
||||
func (s *dataMappingService) Delete(ctx context.Context, req *dto.DeleteDataMappingReq) (err error) {
|
||||
_, err = dao.DataMapping.Delete(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// Execute 执行数据映射
|
||||
func (s *dataMappingService) Execute(ctx context.Context, req *dto.ExecuteDataMappingReq) (res *dto.ExecuteDataMappingRes, err error) {
|
||||
// 获取接口的所有映射规则
|
||||
mappings, err := dao.DataMapping.GetByInterfaceId(ctx, req.InterfaceId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(mappings) == 0 {
|
||||
return &dto.ExecuteDataMappingRes{
|
||||
TargetData: map[string]interface{}{},
|
||||
AppliedRules: []string{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// 初始化目标数据
|
||||
targetData := make(map[string]interface{})
|
||||
appliedRules := make([]string, 0)
|
||||
|
||||
// 遍历映射规则进行转换
|
||||
for _, mapping := range mappings {
|
||||
if mapping.Status != consts.MappingStatusActive {
|
||||
continue
|
||||
}
|
||||
|
||||
// 获取源数据值
|
||||
sourceValue, exists := req.SourceData[mapping.SourceField]
|
||||
|
||||
// 应用转换规则
|
||||
targetValue := s.applyTransformRule(ctx, sourceValue, exists, mapping)
|
||||
|
||||
// 设置目标数据
|
||||
targetData[mapping.TargetField] = targetValue
|
||||
|
||||
appliedRules = append(appliedRules, gconv.String(mapping.SourceField)+" -> "+gconv.String(mapping.TargetField))
|
||||
}
|
||||
|
||||
return &dto.ExecuteDataMappingRes{
|
||||
TargetData: targetData,
|
||||
AppliedRules: appliedRules,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// applyTransformRule 应用转换规则
|
||||
func (s *dataMappingService) applyTransformRule(ctx context.Context, sourceValue interface{}, exists bool, mapping entity.DataMapping) interface{} {
|
||||
// 如果源字段不存在,使用默认值
|
||||
if !exists {
|
||||
if mapping.DefaultValue != "" {
|
||||
return mapping.DefaultValue
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 如果没有转换规则,直接返回源值
|
||||
if mapping.TransformRule == nil || len(mapping.TransformRule) == 0 {
|
||||
return sourceValue
|
||||
}
|
||||
|
||||
// 获取转换类型
|
||||
transformType := ""
|
||||
if t, ok := mapping.TransformRule["type"].(string); ok {
|
||||
transformType = t
|
||||
}
|
||||
|
||||
// 根据转换类型应用不同的转换逻辑
|
||||
switch consts.TransformType(transformType) {
|
||||
case consts.TransformTypeFixed:
|
||||
// 固定值
|
||||
if v, ok := mapping.TransformRule["rule"].(string); ok {
|
||||
return v
|
||||
}
|
||||
case consts.TransformTypeMapping:
|
||||
// 值映射
|
||||
if mappingMap, ok := mapping.TransformRule["mappingMap"].(map[string]interface{}); ok {
|
||||
if sourceKey := gconv.String(sourceValue); sourceKey != "" {
|
||||
if v, ok := mappingMap[sourceKey]; ok {
|
||||
return v
|
||||
}
|
||||
}
|
||||
}
|
||||
case consts.TransformTypeRegex:
|
||||
// 正则转换
|
||||
if regex, ok := mapping.TransformRule["regex"].(string); ok {
|
||||
// TODO: 实现正则替换逻辑
|
||||
g.Log().Warning(ctx, "正则转换暂未实现", g.Map{
|
||||
"regex": regex,
|
||||
"sourceValue": sourceValue,
|
||||
})
|
||||
}
|
||||
case consts.TransformTypeFunction:
|
||||
// 函数转换
|
||||
if functionName, ok := mapping.TransformRule["functionName"].(string); ok {
|
||||
// TODO: 实现函数调用逻辑
|
||||
g.Log().Warning(ctx, "函数转换暂未实现", g.Map{
|
||||
"function": functionName,
|
||||
"sourceValue": sourceValue,
|
||||
})
|
||||
}
|
||||
case consts.TransformTypeScript:
|
||||
// 脚本转换
|
||||
if script, ok := mapping.TransformRule["script"].(string); ok {
|
||||
// TODO: 实现脚本执行逻辑
|
||||
g.Log().Warning(ctx, "脚本转换暂未实现", g.Map{
|
||||
"script": script,
|
||||
"sourceValue": sourceValue,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 默认返回源值
|
||||
return sourceValue
|
||||
}
|
||||
|
||||
// getStatusName 获取状态名称
|
||||
func (s *dataMappingService) getStatusName(status consts.MappingStatus) string {
|
||||
statusNames := map[consts.MappingStatus]string{
|
||||
consts.MappingStatusActive: "启用",
|
||||
consts.MappingStatusInactive: "停用",
|
||||
}
|
||||
if name, ok := statusNames[status]; ok {
|
||||
return name
|
||||
}
|
||||
return string(status)
|
||||
}
|
||||
129
update.sql
129
update.sql
@@ -1,129 +0,0 @@
|
||||
-- CID数据库表结构
|
||||
|
||||
-- 应用管理表
|
||||
CREATE TABLE IF NOT EXISTS cid_application (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
tenant_id VARCHAR(64) DEFAULT '',
|
||||
name VARCHAR(255) NOT NULL COMMENT '应用名称',
|
||||
app_code VARCHAR(100) NOT NULL COMMENT '应用编码(唯一标识)',
|
||||
type VARCHAR(50) NOT NULL COMMENT '应用类型',
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'active' COMMENT '应用状态:active启用/inactive停用',
|
||||
description TEXT COMMENT '应用描述',
|
||||
access_config JSONB COMMENT '接入配置',
|
||||
limit_config JSONB COMMENT '限流配置',
|
||||
callback_config JSONB COMMENT '回调配置',
|
||||
created_at BIGINT NOT NULL,
|
||||
updated_at BIGINT NOT NULL,
|
||||
deleted_at BIGINT DEFAULT 0,
|
||||
CONSTRAINT uk_cid_application_app_code UNIQUE (app_code, deleted_at)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_cid_application_tenant ON cid_application(tenant_id);
|
||||
CREATE INDEX idx_cid_application_type ON cid_application(type);
|
||||
CREATE INDEX idx_cid_application_status ON cid_application(status);
|
||||
CREATE INDEX idx_cid_application_name ON cid_application(name);
|
||||
CREATE INDEX idx_cid_application_app_code ON cid_application(app_code);
|
||||
|
||||
-- 平台管理表
|
||||
CREATE TABLE IF NOT EXISTS cid_platform (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
tenant_id VARCHAR(64) DEFAULT '',
|
||||
name VARCHAR(255) NOT NULL COMMENT '平台名称',
|
||||
type VARCHAR(50) NOT NULL COMMENT '平台类型',
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'active' COMMENT '平台状态:active启用/inactive停用',
|
||||
description TEXT COMMENT '平台描述',
|
||||
auth_config JSONB COMMENT '认证配置',
|
||||
limit_config JSONB COMMENT '限流配置',
|
||||
platform_config JSONB COMMENT '平台专用配置',
|
||||
created_at BIGINT NOT NULL,
|
||||
updated_at BIGINT NOT NULL,
|
||||
deleted_at BIGINT DEFAULT 0
|
||||
);
|
||||
|
||||
CREATE INDEX idx_cid_platform_tenant ON cid_platform(tenant_id);
|
||||
CREATE INDEX idx_cid_platform_type ON cid_platform(type);
|
||||
CREATE INDEX idx_cid_platform_status ON cid_platform(status);
|
||||
CREATE INDEX idx_cid_platform_name ON cid_platform(name);
|
||||
|
||||
-- 接口管理表
|
||||
CREATE TABLE IF NOT EXISTS cid_api_interface (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
tenant_id VARCHAR(64) DEFAULT '',
|
||||
platform_id BIGINT NOT NULL COMMENT '所属平台ID',
|
||||
name VARCHAR(255) NOT NULL COMMENT '接口名称',
|
||||
code VARCHAR(100) NOT NULL COMMENT '接口编码',
|
||||
url VARCHAR(500) NOT NULL COMMENT '接口地址',
|
||||
method VARCHAR(10) NOT NULL COMMENT '请求方法:GET/POST/PUT/DELETE等',
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'active' COMMENT '接口状态:active启用/inactive停用',
|
||||
auth_type VARCHAR(50) COMMENT '认证类型:oauth2/apikey/basic等',
|
||||
request_config JSONB COMMENT '请求配置',
|
||||
response_config JSONB COMMENT '响应配置',
|
||||
limit_config JSONB COMMENT '接口独立限流配置(可选,覆盖平台配置)',
|
||||
created_at BIGINT NOT NULL,
|
||||
updated_at BIGINT NOT NULL,
|
||||
deleted_at BIGINT DEFAULT 0,
|
||||
CONSTRAINT fk_cid_api_interface_platform FOREIGN KEY (platform_id) REFERENCES cid_platform(id)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_cid_api_interface_tenant ON cid_api_interface(tenant_id);
|
||||
CREATE INDEX idx_cid_api_interface_platform ON cid_api_interface(platform_id);
|
||||
CREATE INDEX idx_cid_api_interface_code ON cid_api_interface(code);
|
||||
CREATE INDEX idx_cid_api_interface_status ON cid_api_interface(status);
|
||||
CREATE INDEX idx_cid_api_interface_name ON cid_api_interface(name);
|
||||
|
||||
-- 数据获取日志表
|
||||
CREATE TABLE IF NOT EXISTS cid_data_fetch_log (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
tenant_id VARCHAR(64) DEFAULT '',
|
||||
platform_id BIGINT NOT NULL COMMENT '平台ID',
|
||||
interface_id BIGINT NOT NULL COMMENT '接口ID',
|
||||
request_id VARCHAR(100) NOT NULL COMMENT '请求ID',
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'pending' COMMENT '执行状态:pending/running/success/failed/rate_limit',
|
||||
start_time BIGINT NOT NULL COMMENT '开始时间(时间戳)',
|
||||
end_time BIGINT DEFAULT 0 COMMENT '结束时间(时间戳)',
|
||||
duration INT DEFAULT 0 COMMENT '执行时长(毫秒)',
|
||||
request_config JSONB COMMENT '请求配置参数',
|
||||
response_data TEXT COMMENT '响应数据(JSON)',
|
||||
error_message TEXT COMMENT '错误信息',
|
||||
retry_count INT DEFAULT 0 COMMENT '重试次数',
|
||||
created_at BIGINT NOT NULL,
|
||||
updated_at BIGINT NOT NULL,
|
||||
deleted_at BIGINT DEFAULT 0,
|
||||
CONSTRAINT fk_cid_data_fetch_log_platform FOREIGN KEY (platform_id) REFERENCES cid_platform(id),
|
||||
CONSTRAINT fk_cid_data_fetch_log_interface FOREIGN KEY (interface_id) REFERENCES cid_api_interface(id)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_cid_data_fetch_log_tenant ON cid_data_fetch_log(tenant_id);
|
||||
CREATE INDEX idx_cid_data_fetch_log_platform ON cid_data_fetch_log(platform_id);
|
||||
CREATE INDEX idx_cid_data_fetch_log_interface ON cid_data_fetch_log(interface_id);
|
||||
CREATE INDEX idx_cid_data_fetch_log_request_id ON cid_data_fetch_log(request_id);
|
||||
CREATE INDEX idx_cid_data_fetch_log_status ON cid_data_fetch_log(status);
|
||||
CREATE INDEX idx_cid_data_fetch_log_start_time ON cid_data_fetch_log(start_time);
|
||||
|
||||
-- 数据映射表
|
||||
CREATE TABLE IF NOT EXISTS cid_data_mapping (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
tenant_id VARCHAR(64) DEFAULT '',
|
||||
platform_id BIGINT NOT NULL COMMENT '平台ID',
|
||||
interface_id BIGINT NOT NULL COMMENT '接口ID',
|
||||
source_field VARCHAR(255) NOT NULL COMMENT '源字段(接口返回字段)',
|
||||
target_field VARCHAR(255) NOT NULL COMMENT '目标字段(本地表字段)',
|
||||
field_type VARCHAR(50) NOT NULL COMMENT '字段类型:string/int/float/bool/array/object',
|
||||
default_value VARCHAR(500) COMMENT '默认值',
|
||||
transform_rule JSONB COMMENT '转换规则',
|
||||
priority INT DEFAULT 0 COMMENT '优先级(数字越小优先级越高)',
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'active' COMMENT '状态:active启用/inactive停用',
|
||||
created_at BIGINT NOT NULL,
|
||||
updated_at BIGINT NOT NULL,
|
||||
deleted_at BIGINT DEFAULT 0,
|
||||
CONSTRAINT fk_cid_data_mapping_platform FOREIGN KEY (platform_id) REFERENCES cid_platform(id),
|
||||
CONSTRAINT fk_cid_data_mapping_interface FOREIGN KEY (interface_id) REFERENCES cid_api_interface(id),
|
||||
CONSTRAINT uk_cid_data_mapping_interface_target UNIQUE (interface_id, target_field, deleted_at)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_cid_data_mapping_tenant ON cid_data_mapping(tenant_id);
|
||||
CREATE INDEX idx_cid_data_mapping_platform ON cid_data_mapping(platform_id);
|
||||
CREATE INDEX idx_cid_data_mapping_interface ON cid_data_mapping(interface_id);
|
||||
CREATE INDEX idx_cid_data_mapping_source_field ON cid_data_mapping(source_field);
|
||||
CREATE INDEX idx_cid_data_mapping_status ON cid_data_mapping(status);
|
||||
CREATE INDEX idx_cid_data_mapping_priority ON cid_data_mapping(priority);
|
||||
Reference in New Issue
Block a user