Dockerfile
This commit is contained in:
156
service/sync/platform_factory.go
Normal file
156
service/sync/platform_factory.go
Normal file
@@ -0,0 +1,156 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
consts "assets/consts/public"
|
||||
"assets/dao/sync"
|
||||
"context"
|
||||
)
|
||||
|
||||
// DefaultPlatformFactory 默认平台服务工厂实现
|
||||
type DefaultPlatformFactory struct{}
|
||||
|
||||
// NewPlatformServiceFactory 创建平台服务工厂
|
||||
func NewPlatformServiceFactory() PlatformFactory {
|
||||
return &DefaultPlatformFactory{}
|
||||
}
|
||||
|
||||
// CreateAssetService 创建资产平台服务
|
||||
func (f *DefaultPlatformFactory) CreateAssetService(platform consts.SyncPlatform) AssetPlatformService {
|
||||
config, err := dao.SyncConfig.GetByPlatform(context.Background(), platform)
|
||||
if err != nil || config == nil {
|
||||
// 如果没有配置,创建默认配置
|
||||
//config = &entity.SyncConfig{
|
||||
// Platform: platform,
|
||||
// IsEnabled: true,
|
||||
// APIEndpoint: f.getAPIEndpoint(platform),
|
||||
// SyncInterval: 300,
|
||||
// BatchSize: 100,
|
||||
// MaxRetries: 3,
|
||||
//}
|
||||
}
|
||||
|
||||
switch platform {
|
||||
case consts.SyncPlatformTaobao:
|
||||
return NewTaobaoAssetService(config)
|
||||
case consts.SyncPlatformJD:
|
||||
return NewJDAssetService(config)
|
||||
case consts.SyncPlatformDouyin:
|
||||
return NewDouyinAssetService(config)
|
||||
case consts.SyncPlatformKuaishou:
|
||||
return NewKuaishouAssetService(config)
|
||||
case consts.SyncPlatformXiaohongshu:
|
||||
return NewXiaohongshuAssetService(config)
|
||||
case consts.SyncPlatformPinduoduo:
|
||||
return NewPinduoduoAssetService(config)
|
||||
case consts.SyncPlatformXianyu:
|
||||
return NewXianyuAssetService(config)
|
||||
case consts.SyncPlatformBlockchain:
|
||||
return NewBlockchainAssetService(config)
|
||||
case consts.SyncPlatformInternal:
|
||||
return NewInternalAssetService(config)
|
||||
default:
|
||||
return NewDefaultAssetService(platform, config)
|
||||
}
|
||||
}
|
||||
|
||||
// CreateAssetSkuService 创建资产SKU平台服务
|
||||
func (f *DefaultPlatformFactory) CreateAssetSkuService(platform consts.SyncPlatform) AssetSkuPlatformService {
|
||||
config, err := dao.SyncConfig.GetByPlatform(context.Background(), platform)
|
||||
if err != nil || config == nil {
|
||||
//config = &entity.ChannelConfig{
|
||||
// Platform: platform,
|
||||
// IsEnabled: true,
|
||||
// APIEndpoint: f.getAPIEndpoint(platform),
|
||||
// SyncInterval: 300,
|
||||
// BatchSize: 100,
|
||||
// MaxRetries: 3,
|
||||
//}
|
||||
}
|
||||
|
||||
switch platform {
|
||||
case consts.SyncPlatformTaobao:
|
||||
return NewTaobaoAssetSkuService(config)
|
||||
case consts.SyncPlatformJD:
|
||||
return NewJDAssetSkuService(config)
|
||||
case consts.SyncPlatformDouyin:
|
||||
return NewDouyinAssetSkuService(config)
|
||||
case consts.SyncPlatformKuaishou:
|
||||
return NewKuaishouAssetSkuService(config)
|
||||
case consts.SyncPlatformXiaohongshu:
|
||||
return NewXiaohongshuAssetSkuService(config)
|
||||
case consts.SyncPlatformPinduoduo:
|
||||
return NewPinduoduoAssetSkuService(config)
|
||||
case consts.SyncPlatformXianyu:
|
||||
return NewXianyuAssetSkuService(config)
|
||||
case consts.SyncPlatformBlockchain:
|
||||
return NewBlockchainAssetSkuService(config)
|
||||
case consts.SyncPlatformInternal:
|
||||
return NewInternalAssetSkuService(config)
|
||||
default:
|
||||
return NewDefaultAssetSkuService(platform, config)
|
||||
}
|
||||
}
|
||||
|
||||
// CreateStockService 创建库存平台服务
|
||||
func (f *DefaultPlatformFactory) CreateStockService(platform consts.SyncPlatform) StockPlatformService {
|
||||
config, err := dao.SyncConfig.GetByPlatform(context.Background(), platform)
|
||||
if err != nil || config == nil {
|
||||
//config = &entity.SyncConfig{
|
||||
// Platform: platform,
|
||||
// IsEnabled: true,
|
||||
// APIEndpoint: f.getAPIEndpoint(platform),
|
||||
// SyncInterval: 300,
|
||||
// BatchSize: 100,
|
||||
// MaxRetries: 3,
|
||||
//}
|
||||
}
|
||||
|
||||
switch platform {
|
||||
case consts.SyncPlatformTaobao:
|
||||
return NewTaobaoStockService(config)
|
||||
case consts.SyncPlatformJD:
|
||||
return NewJDStockService(config)
|
||||
case consts.SyncPlatformDouyin:
|
||||
return NewDouyinStockService(config)
|
||||
case consts.SyncPlatformKuaishou:
|
||||
return NewKuaishouStockService(config)
|
||||
case consts.SyncPlatformXiaohongshu:
|
||||
return NewXiaohongshuStockService(config)
|
||||
case consts.SyncPlatformPinduoduo:
|
||||
return NewPinduoduoStockService(config)
|
||||
case consts.SyncPlatformXianyu:
|
||||
return NewXianyuStockService(config)
|
||||
case consts.SyncPlatformBlockchain:
|
||||
return NewBlockchainStockService(config)
|
||||
case consts.SyncPlatformInternal:
|
||||
return NewInternalStockService(config)
|
||||
default:
|
||||
return NewDefaultStockService(platform, config)
|
||||
}
|
||||
}
|
||||
|
||||
// getAPIEndpoint 根据平台获取API端点
|
||||
func (f *DefaultPlatformFactory) getAPIEndpoint(platform consts.SyncPlatform) string {
|
||||
switch platform {
|
||||
case consts.SyncPlatformTaobao:
|
||||
return "https://eco.taobao.com/router/rest"
|
||||
case consts.SyncPlatformJD:
|
||||
return "https://api.jd.com/routerjson"
|
||||
case consts.SyncPlatformDouyin:
|
||||
return "https://open.douyin.com/api"
|
||||
case consts.SyncPlatformKuaishou:
|
||||
return "https://open.kuaishou.com/api"
|
||||
case consts.SyncPlatformXiaohongshu:
|
||||
return "https://open.xiaohongshu.com/api"
|
||||
case consts.SyncPlatformPinduoduo:
|
||||
return "https://open.pinduoduo.com/api"
|
||||
case consts.SyncPlatformXianyu:
|
||||
return "https://api.xianyu.com/api"
|
||||
case consts.SyncPlatformBlockchain:
|
||||
return "https://api.blockchain.com/api"
|
||||
case consts.SyncPlatformInternal:
|
||||
return "http://localhost:3004/api"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user