package public import "fmt" // SyncPlatform 同步渠道平台枚举 type SyncPlatform string const ( SyncPlatformTaobao SyncPlatform = "taobao" // 淘宝 SyncPlatformJD SyncPlatform = "jd" // 京东 SyncPlatformKuaishou SyncPlatform = "kuaishou" // 快手 SyncPlatformDouyin SyncPlatform = "douyin" // 抖音 SyncPlatformXiaohongshu SyncPlatform = "xiaohongshu" // 小红书 SyncPlatformPinduoduo SyncPlatform = "pinduoduo" // 拼多多 SyncPlatformXianyu SyncPlatform = "xianyu" // 闲鱼 SyncPlatformBlockchain SyncPlatform = "blockchain" // 区块链平台 SyncPlatformInternal SyncPlatform = "internal" // 内部平台 ) // SyncStatus 同步状态枚举 type SyncStatus string const ( SyncStatusPending SyncStatus = "pending" // 等待同步 SyncStatusSyncing SyncStatus = "syncing" // 同步中 SyncStatusSuccess SyncStatus = "success" // 同步成功 SyncStatusFailed SyncStatus = "failed" // 同步失败 ) // SyncType 同步类型 type SyncType string const ( SyncTypeIncremental SyncType = "incremental" // 增量同步 ) // PlatformSyncConfig 平台同步配置结构 type PlatformSyncConfig struct { Platform SyncPlatform // 平台名称 IsEnabled bool // 是否启用 SyncInterval int // 同步间隔(秒) BatchSize int // 批量同步数量 MaxRetries int // 最大重试次数 APIEndpoint string // API端点地址 Description string // 平台描述 } // GetPlatformSyncConfig 获取平台默认同步配置 func GetPlatformSyncConfig(platform SyncPlatform) (PlatformSyncConfig, error) { switch platform { case SyncPlatformTaobao: return PlatformSyncConfig{ Platform: SyncPlatformTaobao, IsEnabled: true, SyncInterval: 300, // 5分钟 BatchSize: 50, // 淘宝API限制较严 MaxRetries: 3, APIEndpoint: "https://eco.taobao.com/router/rest", Description: "淘宝电商平台,API限制严格", }, nil case SyncPlatformJD: return PlatformSyncConfig{ Platform: SyncPlatformJD, IsEnabled: true, SyncInterval: 240, // 4分钟 BatchSize: 100, // 京东API支持较大批次 MaxRetries: 3, APIEndpoint: "https://api.jd.com/routerjson", Description: "京东电商平台,API相对稳定", }, nil case SyncPlatformKuaishou: return PlatformSyncConfig{ Platform: SyncPlatformKuaishou, IsEnabled: true, SyncInterval: 180, // 3分钟,直播数据更新快 BatchSize: 80, MaxRetries: 2, // 快手API相对不稳定 APIEndpoint: "https://open.kuaishou.com/api", Description: "快手直播平台,数据更新频繁", }, nil case SyncPlatformDouyin: return PlatformSyncConfig{ Platform: SyncPlatformDouyin, IsEnabled: true, SyncInterval: 120, // 2分钟,内容更新非常频繁 BatchSize: 60, MaxRetries: 3, APIEndpoint: "https://open.douyin.com/api", Description: "抖音短视频平台,实时性要求高", }, nil case SyncPlatformXiaohongshu: return PlatformSyncConfig{ Platform: SyncPlatformXiaohongshu, IsEnabled: true, SyncInterval: 300, // 5分钟 BatchSize: 40, // 小红书API限制严格 MaxRetries: 2, APIEndpoint: "https://open.xiaohongshu.com/api", Description: "小红书内容平台,API调用频率限制严格", }, nil case SyncPlatformPinduoduo: return PlatformSyncConfig{ Platform: SyncPlatformPinduoduo, IsEnabled: true, SyncInterval: 360, // 6分钟,避免频率限制 BatchSize: 120, // 拼多多支持大批次 MaxRetries: 3, APIEndpoint: "https://open.pinduoduo.com/api", Description: "拼多多电商平台,需要控制调用频率", }, nil case SyncPlatformXianyu: return PlatformSyncConfig{ Platform: SyncPlatformXianyu, IsEnabled: false, // 默认关闭 SyncInterval: 600, // 10分钟,闲鱼更新较慢 BatchSize: 30, MaxRetries: 1, APIEndpoint: "https://api.xianyu.com/api", Description: "闲鱼二手平台,数据更新较慢,谨慎使用", }, nil case SyncPlatformBlockchain: return PlatformSyncConfig{ Platform: SyncPlatformBlockchain, IsEnabled: true, SyncInterval: 60, // 1分钟,需要高实时性 BatchSize: 20, // 区块链数据复杂,减小批次 MaxRetries: 5, // 区块链网络可能不稳定 APIEndpoint: "https://api.blockchain.com/api", Description: "区块链平台,数据需要高实时性和稳定性", }, nil case SyncPlatformInternal: return PlatformSyncConfig{ Platform: SyncPlatformInternal, IsEnabled: true, SyncInterval: 30, // 30秒,内部系统实时性高 BatchSize: 200, // 内部系统支持大批次 MaxRetries: 1, // 内部系统稳定 APIEndpoint: "http://localhost:3004/api", Description: "内部系统平台,高实时性和大批次处理能力", }, nil default: // 返回错误,未知平台 return PlatformSyncConfig{}, fmt.Errorf("unsupported sync platform: %s", platform) } }