# 采集域服务

> **入口**: [_index.md](_index.md)

---

## 服务列表

| 服务 | 文件 | 职责 |
|------|------|------|
| CollectionAdapterService | services/CollectionAdapterService.ts | 采集适配 |
| TikTokConnector | core/connectors/TikTokConnector.ts | TikTok采集 |
| TemuConnector | core/connectors/TemuConnector.ts | Temu采集 |
| ShopifyConnector | core/connectors/ShopifyConnector.ts | Shopify采集 |

---

## 核心流程

```
创建采集任务 → 选择连接器 → 执行采集 → 数据解析 → 存储入库
```

---

## CollectionAdapterService

### 方法列表

| 方法 | 说明 | 参数 | 返回 |
|------|------|------|------|
| createTask | 创建任务 | CreateRequest | CollectionTask |
| executeTask | 执行任务 | taskId | CollectionResult |
| getTaskStatus | 获取状态 | taskId | TaskStatus |
| cancelTask | 取消任务 | taskId | void |

---

## Connector接口

```typescript
interface IPlatformConnector {
  platformCode: string;
  capabilities: {
    hasApi: boolean;
    supportsPriceSync: boolean;
    supportsInventorySync: boolean;
    supportsOrderPull: boolean;
  };
  
  pullProducts(shopId: string): Promise<PlatformProduct[]>;
  pullOrders(shopId: string): Promise<PlatformOrder[]>;
  pushListing(product: Product): Promise<ListingResult>;
  updatePrice(listingId: string, price: number): Promise<void>;
  syncInventory(listingId: string, stock: number): Promise<void>;
}
```

---

## 已实现连接器

| 连接器 | 平台 | 能力 |
|--------|------|------|
| ShopifyConnector | Shopify | API全功能 |
| AmazonConnector | Amazon | API全功能 |
| TikTokConnector | TikTok Shop | API+采集 |
| TemuConnector | Temu | 采集 |
| ShopeeConnector | Shopee | API+采集 |

---

## 待实现连接器

| 连接器 | 平台 | 优先级 |
|--------|------|--------|
| Alibaba1688Connector | 1688 | P0 |
| TikTokAdsConnector | TikTok Ads | P0 |
| FacebookAdsConnector | Facebook Ads | P0 |
| GoogleAdsConnector | Google Ads | P0 |

---

## 状态机

```
PENDING → RUNNING → COMPLETED
              ↓
            FAILED
```

| 状态 | 说明 |
|------|------|
| PENDING | 待执行 |
| RUNNING | 执行中 |
| COMPLETED | 已完成 |
| FAILED | 失败 |

---

## API端点

| 端点 | 方法 | 服务方法 |
|------|------|----------|
| /api/v1/collection/tasks | POST | CollectionAdapterService.createTask |
| /api/v1/collection/tasks/:id | GET | CollectionAdapterService.getTaskStatus |
| /api/v1/collection/tasks/:id/execute | POST | CollectionAdapterService.executeTask |
| /api/v1/collection/tasks/:id/cancel | POST | CollectionAdapterService.cancelTask |

---

*最后更新: 2026-03-22*
