refactor: 重构项目结构并优化类型定义
- 移除extension模块,将功能迁移至node-agent - 修复类型导出问题,使用export type明确类型导出 - 统一数据库连接方式,从直接导入改为使用config/database - 更新文档中的项目结构描述 - 添加多个服务的实用方法,如getForecast、getBalances等 - 修复类型错误和TS1205警告 - 优化RedisService调用方式 - 添加新的实体类型定义 - 更新审计日志格式,统一字段命名
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
> **模块**: 01_Architecture - TypeScript 编译零错误规约体系
|
||||
> **更新日期**: 2026-03-20
|
||||
> **适用范围**: 全项目(dashboard、server、extension、node-agent)
|
||||
> **适用范围**: 全项目(dashboard、server、node-agent)
|
||||
|
||||
---
|
||||
|
||||
@@ -399,7 +399,7 @@ jobs:
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
module: [dashboard, server, extension, node-agent]
|
||||
module: [dashboard, server, node-agent]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
> **模块**: 01_Architecture - 代码质量与 ESLint 规范
|
||||
> **更新日期**: 2026-03-20
|
||||
> **适用范围**: 全项目(dashboard、server、extension、node-agent)
|
||||
> **适用范围**: 全项目(dashboard、server、node-agent)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
> **模块**: 01_Architecture - Schema 驱动开发与数据验证
|
||||
> **更新日期**: 2026-03-20
|
||||
> **适用范围**: 全项目(dashboard、server、extension、node-agent)
|
||||
> **适用范围**: 全项目(dashboard、server、node-agent)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
> **模块**: 01_Architecture - 统一类型管理与语义中心
|
||||
> **更新日期**: 2026-03-20
|
||||
> **版本**: 1.0.0
|
||||
> **适用范围**: 全项目(dashboard、server、extension)
|
||||
> **适用范围**: 全项目(dashboard、server、node-agent)
|
||||
|
||||
---
|
||||
|
||||
@@ -84,7 +84,7 @@ dashboard/src/types/
|
||||
├── dataSourceMap.ts # DataSource 类型映射
|
||||
└── index.ts # 重新导出 server 类型
|
||||
|
||||
extension/src/types/
|
||||
node-agent/src/types/
|
||||
└── index.ts # 重新导出 server 类型
|
||||
```
|
||||
|
||||
@@ -278,12 +278,12 @@ import { User, CreateUserDTO } from '@shared/types';
|
||||
import { User } from '@/types';
|
||||
```
|
||||
|
||||
### 5.3 插件端导入
|
||||
### 5.3 Node Agent导入
|
||||
|
||||
```typescript
|
||||
// extension/src/background/MessageHandler.ts
|
||||
import { BaseMessage, MessageResponse } from '../../server/src/shared/types';
|
||||
import { BaseMessageSchema } from '../../server/src/shared/schemas';
|
||||
// node-agent/src/index.ts
|
||||
import { NodeTask } from '../../server/src/shared/types';
|
||||
import { NodeTaskSchema } from '../../server/src/shared/schemas';
|
||||
```
|
||||
|
||||
---
|
||||
@@ -413,19 +413,19 @@ export const MessageResponseSchema = z.object({
|
||||
});
|
||||
```
|
||||
|
||||
### 8.2 插件端使用
|
||||
### 8.2 Node Agent使用
|
||||
|
||||
```typescript
|
||||
// extension/src/background/MessageHandler.ts
|
||||
import { BaseMessage, MessageResponse } from '../../server/src/shared/types';
|
||||
// node-agent/src/index.ts
|
||||
import { NodeTask } from '../../server/src/shared/types';
|
||||
|
||||
export class MessageHandler {
|
||||
async handle(message: BaseMessage, sender: chrome.runtime.MessageSender): Promise<MessageResponse> {
|
||||
const traceId = message.traceId || this.generateTraceId();
|
||||
export class NodeAgent {
|
||||
async executeTask(task: NodeTask): Promise<void> {
|
||||
const traceId = task.traceId || this.generateTraceId();
|
||||
|
||||
switch (message.type) {
|
||||
switch (task.type) {
|
||||
case 'COLLECT_ORDERS':
|
||||
return this.orderCollector.collectOrders(message.payload, traceId);
|
||||
return this.collectOrders(task.payload, traceId);
|
||||
// ...
|
||||
}
|
||||
}
|
||||
@@ -545,7 +545,7 @@ jobs:
|
||||
run: |
|
||||
cd server && npx tsc --noEmit --skipLibCheck
|
||||
cd ../dashboard && npx tsc --noEmit --skipLibCheck
|
||||
cd ../extension && npx tsc --noEmit --skipLibCheck
|
||||
cd ../node-agent && npx tsc --noEmit --skipLibCheck
|
||||
```
|
||||
|
||||
### 12.2 Schema 验证
|
||||
|
||||
371
docs/01_Architecture/17_Frontend_Backend_Plugin_ClosedLoop.md
Normal file
371
docs/01_Architecture/17_Frontend_Backend_Plugin_ClosedLoop.md
Normal file
@@ -0,0 +1,371 @@
|
||||
# 前后端插件闭环架构方案
|
||||
|
||||
> **创建日期**: 2026-03-20
|
||||
> **状态**: 设计中
|
||||
> **优先级**: 最高
|
||||
|
||||
---
|
||||
|
||||
## 1. 系统架构总览
|
||||
|
||||
### 1.1 三端闭环架构
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||
│ Crawlful Hub Platform │
|
||||
├─────────────────────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
|
||||
│ │ Dashboard │ │ Server │ │ Node Agent │ │
|
||||
│ │ (前端控制台) │◄───►│ (后端服务) │◄───►│ (插件代理) │ │
|
||||
│ │ │ │ │ │ │ │
|
||||
│ │ - 操作入口 │ │ - 业务逻辑 │ │ - 平台采集 │ │
|
||||
│ │ - 状态展示 │ │ - 数据存储 │ │ - 自动化操作 │ │
|
||||
│ │ - 多店铺管理 │ │ - AI策略 │ │ - 反检测 │ │
|
||||
│ │ - 数据可视化 │ │ - 报表系统 │ │ - 多实例并发 │ │
|
||||
│ └────────┬────────┘ └────────┬────────┘ └────────┬────────┘ │
|
||||
│ │ │ │ │
|
||||
│ └───────────────────────┼───────────────────────┘ │
|
||||
│ │ │
|
||||
│ ▼ │
|
||||
│ ┌──────────────────────────────┐ │
|
||||
│ │ Shared Type Center │ │
|
||||
│ │ (统一类型定义中心) │ │
|
||||
│ │ │ │
|
||||
│ │ - messaging.ts (消息类型) │ │
|
||||
│ │ - domain.ts (领域类型) │ │
|
||||
│ │ - api.ts (API类型) │ │
|
||||
│ │ - plugin.ts (插件类型) │ │
|
||||
│ └──────────────────────────────┘ │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
### 1.2 数据流向
|
||||
|
||||
```
|
||||
用户操作 → Dashboard → Server API → Service层 → 数据库
|
||||
↓
|
||||
Node Agent → 平台采集 → 数据回传
|
||||
↓
|
||||
Server处理 → Dashboard展示
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. 前端闭环 (Dashboard)
|
||||
|
||||
### 2.1 页面模块
|
||||
|
||||
| 模块 | 页面 | 功能 | 对应后端服务 |
|
||||
|------|------|------|-------------|
|
||||
| **商品管理** | ProductList, ProductDetail, ProductPublishForm | 商品CRUD、刊登、定价 | ProductService |
|
||||
| **订单管理** | OrderList, OrderDetail, ExceptionOrder | 订单处理、异常处理 | OrderService |
|
||||
| **营销管理** | AdPlanPage, AdDelivery, ROIAnalysis | 广告计划、投放、ROI分析 | MarketingService |
|
||||
| **财务管理** | Transactions, Reconciliation | 交易记录、对账 | FinanceService |
|
||||
| **库存管理** | InventoryForecast, Warehouses | 库存预测、仓库管理 | InventoryService |
|
||||
| **物流管理** | LogisticsTrack, FreightCalc | 物流跟踪、运费计算 | LogisticsService |
|
||||
| **B2B贸易** | EnterpriseQuote, BatchOrder, ContractManage | 企业报价、批量订单、合同管理 | B2BTradeService |
|
||||
| **合规管理** | CertificateManage, ComplianceCheck | 证书管理、合规检查 | ComplianceService |
|
||||
| **多商户** | MerchantManage, MerchantSettlementManage | 商户管理、结算 | MerchantService |
|
||||
| **系统设置** | UserManagement, TenantSettings, SystemSettings | 用户、租户、系统设置 | SettingsService |
|
||||
|
||||
### 2.2 DataSource层设计
|
||||
|
||||
```typescript
|
||||
// 前端数据源抽象层
|
||||
export interface DataSource<T> {
|
||||
list(params?: QueryParams): Promise<T[]>;
|
||||
get(id: string): Promise<T | null>;
|
||||
create(data: Partial<T>): Promise<T>;
|
||||
update(id: string, data: Partial<T>): Promise<T>;
|
||||
delete(id: string): Promise<void>;
|
||||
}
|
||||
|
||||
// 实现示例
|
||||
export class ProductDataSource implements DataSource<Product> {
|
||||
async list(params?: ProductQueryParams): Promise<Product[]> {
|
||||
const response = await http.get('/api/products', { params });
|
||||
return response.data;
|
||||
}
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
### 2.3 状态管理
|
||||
|
||||
```typescript
|
||||
// Umi Model 设计
|
||||
export interface ModelState<T> {
|
||||
data: T[];
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
pagination: {
|
||||
current: number;
|
||||
pageSize: number;
|
||||
total: number;
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. 后端闭环 (Server)
|
||||
|
||||
### 3.1 服务分层架构
|
||||
|
||||
```
|
||||
Controller层 (请求处理)
|
||||
│
|
||||
├── 参数验证 (Zod Schema)
|
||||
├── 权限校验 (RBAC Middleware)
|
||||
└── 调用Service层
|
||||
│
|
||||
Service层 (业务逻辑) ← 核心层
|
||||
│
|
||||
├── 业务编排
|
||||
├── 状态流转 (State Machine)
|
||||
├── 事务管理
|
||||
└── 调用Repository层
|
||||
│
|
||||
Repository层 (数据访问)
|
||||
│
|
||||
├── 数据库CRUD (Knex.js)
|
||||
├── 缓存操作 (Redis)
|
||||
└── 外部API调用
|
||||
```
|
||||
|
||||
### 3.2 核心服务清单
|
||||
|
||||
| 领域 | 服务 | 职责 |
|
||||
|------|------|------|
|
||||
| **商品** | ProductService | 商品管理、SKU管理、定价 |
|
||||
| **订单** | OrderService | 订单处理、履约、售后 |
|
||||
| **营销** | MarketingService | 广告计划、投放优化 |
|
||||
| **财务** | FinanceService | 对账、结算、利润核算 |
|
||||
| **库存** | InventoryService | 库存管理、预测、补货 |
|
||||
| **物流** | LogisticsService | 物流渠道、运费计算 |
|
||||
| **B2B** | B2BTradeService | 企业贸易、批量订单 |
|
||||
| **合规** | ComplianceService | 证书管理、合规检查 |
|
||||
| **商户** | MerchantService | 多商户管理、结算 |
|
||||
| **AI** | AIService | AI决策、自动化 |
|
||||
| **Agent** | OperationAgentService | Agent任务调度 |
|
||||
|
||||
### 3.3 状态机设计
|
||||
|
||||
```typescript
|
||||
// 订单状态机
|
||||
export const OrderStateMachine = {
|
||||
states: {
|
||||
PENDING: { transitions: ['CONFIRMED', 'CANCELLED'] },
|
||||
CONFIRMED: { transitions: ['PROCESSING', 'CANCELLED'] },
|
||||
PROCESSING: { transitions: ['SHIPPED', 'EXCEPTION'] },
|
||||
SHIPPED: { transitions: ['DELIVERED', 'RETURNED'] },
|
||||
DELIVERED: { transitions: ['COMPLETED', 'RETURNED'] },
|
||||
COMPLETED: { transitions: [] },
|
||||
CANCELLED: { transitions: [] },
|
||||
RETURNED: { transitions: ['REFUNDED'] },
|
||||
REFUNDED: { transitions: [] },
|
||||
EXCEPTION: { transitions: ['PROCESSING', 'CANCELLED'] }
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. 插件闭环 (Node Agent)
|
||||
|
||||
### 4.1 Agent架构
|
||||
|
||||
```
|
||||
Node Agent (Playwright)
|
||||
│
|
||||
├── 任务调度器
|
||||
│ ├── 任务轮询
|
||||
│ ├── 任务执行
|
||||
│ └── 结果上报
|
||||
│
|
||||
├── 平台适配器
|
||||
│ ├── TikTokAdapter
|
||||
│ ├── TemuAdapter
|
||||
│ ├── AliExpressAdapter
|
||||
│ ├── AmazonAdapter
|
||||
│ └── ShopeeAdapter
|
||||
│
|
||||
└── 反检测系统
|
||||
├── 指纹隔离
|
||||
├── 代理IP
|
||||
└── 行为模拟
|
||||
```
|
||||
|
||||
### 4.2 任务类型
|
||||
|
||||
```typescript
|
||||
export enum TaskType {
|
||||
COLLECT_PRODUCT = 'COLLECT_PRODUCT', // 商品采集
|
||||
COLLECT_ORDER = 'COLLECT_ORDER', // 订单采集
|
||||
PUBLISH_PRODUCT = 'PUBLISH_PRODUCT', // 商品刊登
|
||||
PROCESS_ORDER = 'PROCESS_ORDER', // 订单处理
|
||||
SYNC_INVENTORY = 'SYNC_INVENTORY', // 库存同步
|
||||
MANAGE_AD = 'MANAGE_AD', // 广告管理
|
||||
PRICE_ADJUST = 'PRICE_ADJUST', // 价格调整
|
||||
RETURN_PROCESS = 'RETURN_PROCESS', // 退货处理
|
||||
}
|
||||
```
|
||||
|
||||
### 4.3 通信协议
|
||||
|
||||
```typescript
|
||||
// 任务请求
|
||||
interface TaskRequest {
|
||||
taskId: string;
|
||||
traceId: string;
|
||||
tenantId: string;
|
||||
shopId: string;
|
||||
type: TaskType;
|
||||
platform: string;
|
||||
params: Record<string, any>;
|
||||
priority: 'HIGH' | 'MEDIUM' | 'LOW';
|
||||
timeout: number;
|
||||
}
|
||||
|
||||
// 任务结果
|
||||
interface TaskResult {
|
||||
taskId: string;
|
||||
traceId: string;
|
||||
status: 'SUCCESS' | 'FAILED' | 'TIMEOUT';
|
||||
data?: any;
|
||||
error?: string;
|
||||
duration: number;
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. 类型对齐方案
|
||||
|
||||
### 5.1 统一类型中心
|
||||
|
||||
```
|
||||
server/src/shared/types/
|
||||
├── index.ts # 统一导出
|
||||
├── domain.ts # 领域类型
|
||||
├── api.ts # API类型
|
||||
├── messaging.ts # 消息类型
|
||||
├── plugin.ts # 插件类型
|
||||
├── enums.ts # 枚举定义
|
||||
└── dto/ # DTO类型
|
||||
├── product.dto.ts
|
||||
├── order.dto.ts
|
||||
└── ...
|
||||
```
|
||||
|
||||
### 5.2 Schema驱动开发
|
||||
|
||||
```typescript
|
||||
// 使用Zod定义Schema,自动推导类型
|
||||
import { z } from 'zod';
|
||||
|
||||
export const ProductSchema = z.object({
|
||||
id: z.string(),
|
||||
title: z.string(),
|
||||
price: z.number(),
|
||||
status: z.enum(['DRAFT', 'PENDING', 'APPROVED', 'REJECTED']),
|
||||
// ...
|
||||
});
|
||||
|
||||
export type Product = z.infer<typeof ProductSchema>;
|
||||
```
|
||||
|
||||
### 5.3 前后端类型同步
|
||||
|
||||
```typescript
|
||||
// 前端从后端导入类型
|
||||
import type { Product, Order, Customer } from '@shared/types';
|
||||
|
||||
// 或者通过API文档生成
|
||||
// openapi-typescript生成前端类型
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 6. 业务闭环清单
|
||||
|
||||
### 6.1 核心业务闭环
|
||||
|
||||
| 闭环 | 前端 | 后端 | 插件 | 状态 |
|
||||
|------|------|------|------|------|
|
||||
| 商品采集刊登 | ProductList, ProductPublishForm | ProductService, AutoListingService | Node Agent采集 | ✅ |
|
||||
| 订单履约 | OrderList, OrderDetail | OrderService, UnifiedFulfillmentService | Node Agent订单处理 | ✅ |
|
||||
| 广告营销 | AdPlanPage, ROIAnalysis | MarketingService, AdOpsService | Node Agent广告管理 | ✅ |
|
||||
| 库存管理 | InventoryForecast, Warehouses | InventoryService, InventoryForecastService | Node Agent库存同步 | ✅ |
|
||||
| 财务对账 | Transactions, Reconciliation | FinanceService, ReconciliationService | - | ✅ |
|
||||
| B2B贸易 | EnterpriseQuote, BatchOrder | B2BTradeService | - | ✅ |
|
||||
| 合规管理 | CertificateManage | ComplianceService, CertificateDatabaseService | - | ✅ |
|
||||
| 多商户 | MerchantManage | MerchantService, MerchantSettlementService | - | ✅ |
|
||||
|
||||
### 6.2 AI自动化闭环
|
||||
|
||||
| 闭环 | 功能 | 服务 | 状态 |
|
||||
|------|------|------|------|
|
||||
| 自动选品 | AI评分、自动筛选 | ProductSelectionService, AIService | ✅ |
|
||||
| 自动定价 | 动态定价、利润计算 | PricingService, DynamicPricingAGIService | ✅ |
|
||||
| 自动上架 | 批量刊登、模板化 | AutoListingService | ✅ |
|
||||
| 智能客服 | 自动回复、意图识别 | ChatBotService, CustomerService | ✅ |
|
||||
| 异常检测 | 风险识别、自动告警 | ExceptionMonitor, IntelligentExceptionHandler | ✅ |
|
||||
|
||||
### 6.3 治理闭环
|
||||
|
||||
| 闭环 | 功能 | 服务 | 状态 |
|
||||
|------|------|------|------|
|
||||
| 权限管理 | RBAC、层级隔离 | RBACEngine, PermissionService | ✅ |
|
||||
| 审批流程 | 工作流、审批链 | ApprovalService, WorkflowEngineService | ✅ |
|
||||
| 审计日志 | 操作记录、追溯 | AuditService, AgentTraceAuditService | ✅ |
|
||||
| 配额管理 | 资源限制、熔断 | QuotaGovernanceService, QuotaCircuitBreakerService | ✅ |
|
||||
|
||||
---
|
||||
|
||||
## 7. 实现优先级
|
||||
|
||||
### P0 - 核心闭环 (立即完成)
|
||||
|
||||
1. **商品采集刊登闭环**
|
||||
- 前端: ProductList, ProductPublishForm
|
||||
- 后端: ProductService, AutoListingService
|
||||
- 插件: Node Agent采集任务
|
||||
|
||||
2. **订单履约闭环**
|
||||
- 前端: OrderList, OrderDetail
|
||||
- 后端: OrderService, UnifiedFulfillmentService
|
||||
- 插件: Node Agent订单处理
|
||||
|
||||
3. **财务对账闭环**
|
||||
- 前端: Transactions, Reconciliation
|
||||
- 后端: FinanceService, ReconciliationService
|
||||
|
||||
### P1 - 重要闭环 (近期完成)
|
||||
|
||||
4. **广告营销闭环**
|
||||
5. **库存管理闭环**
|
||||
6. **B2B贸易闭环**
|
||||
7. **合规管理闭环**
|
||||
|
||||
### P2 - 增强闭环 (后续完成)
|
||||
|
||||
8. **多商户闭环**
|
||||
9. **AI自动化闭环**
|
||||
10. **治理闭环**
|
||||
|
||||
---
|
||||
|
||||
## 8. 相关文档
|
||||
|
||||
- [业务闭环总览](../00_Business/Business_ClosedLoops.md)
|
||||
- [服务编排总图](../01_Architecture/04_Service_Map.md)
|
||||
- [Node Agent设计](../04_Plugin/01_NodeAgent_Design.md)
|
||||
- [统一类型管理](../01_Architecture/16_Unified_Type_Management.md)
|
||||
- [状态机定义](../01_Architecture/06_State_Machine.md)
|
||||
|
||||
---
|
||||
|
||||
*最后更新: 2026-03-20*
|
||||
410
docs/01_Architecture/18_Global_Features_Plan.md
Normal file
410
docs/01_Architecture/18_Global_Features_Plan.md
Normal file
@@ -0,0 +1,410 @@
|
||||
# 全局功能方案
|
||||
|
||||
> **创建日期**: 2026-03-20
|
||||
> **状态**: 设计中
|
||||
> **优先级**: 最高
|
||||
|
||||
---
|
||||
|
||||
## 1. 全局功能架构
|
||||
|
||||
### 1.1 功能模块总览
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||
│ Crawlful Hub 功能架构 │
|
||||
├─────────────────────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ ┌─────────────────────────────────────────────────────────────────────┐ │
|
||||
│ │ 业务功能层 (Business Layer) │ │
|
||||
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
|
||||
│ │ │ 商品管理 │ │ 订单管理 │ │ 营销管理 │ │ 财务管理 │ │ 库存管理 │ │ │
|
||||
│ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │
|
||||
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
|
||||
│ │ │ 物流管理 │ │ B2B贸易 │ │ 合规管理 │ │ 多商户 │ │ 客户服务 │ │ │
|
||||
│ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │
|
||||
│ └─────────────────────────────────────────────────────────────────────┘ │
|
||||
│ │
|
||||
│ ┌─────────────────────────────────────────────────────────────────────┐ │
|
||||
│ │ AI自动化层 (AI Layer) │ │
|
||||
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
|
||||
│ │ │ 自动选品 │ │ 自动定价 │ │ 自动上架 │ │ 智能客服 │ │ 异常检测 │ │ │
|
||||
│ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │
|
||||
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
|
||||
│ │ │ 跨境套利 │ │ 广告优化 │ │ 库存预测 │ │ 风险预警 │ │ 策略市场 │ │ │
|
||||
│ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │
|
||||
│ └─────────────────────────────────────────────────────────────────────┘ │
|
||||
│ │
|
||||
│ ┌─────────────────────────────────────────────────────────────────────┐ │
|
||||
│ │ Agent执行层 (Agent Layer) │ │
|
||||
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
|
||||
│ │ │ 平台采集 │ │ 自动刊登 │ │ 订单处理 │ │ 广告投放 │ │ 库存同步 │ │ │
|
||||
│ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │
|
||||
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
|
||||
│ │ │ 价格调整 │ │ 退货处理 │ │ 客服回复 │ │ 数据同步 │ │ 健康监控 │ │ │
|
||||
│ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │
|
||||
│ └─────────────────────────────────────────────────────────────────────┘ │
|
||||
│ │
|
||||
│ ┌─────────────────────────────────────────────────────────────────────┐ │
|
||||
│ │ 后台管理层 (Admin Layer) │ │
|
||||
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
|
||||
│ │ │ 用户管理 │ │ 租户管理 │ │ 权限管理 │ │ 审批流程 │ │ 审计日志 │ │ │
|
||||
│ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │
|
||||
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
|
||||
│ │ │ 配额管理 │ │ 系统配置 │ │ 监控告警 │ │ 数据分析 │ │ 报表中心 │ │ │
|
||||
│ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │
|
||||
│ └─────────────────────────────────────────────────────────────────────┘ │
|
||||
│ │
|
||||
│ ┌─────────────────────────────────────────────────────────────────────┐ │
|
||||
│ │ 基础设施层 (Infrastructure Layer) │ │
|
||||
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
|
||||
│ │ │ 数据库 │ │ 缓存 │ │ 消息队列 │ │ 任务调度 │ │ 日志系统 │ │ │
|
||||
│ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │
|
||||
│ └─────────────────────────────────────────────────────────────────────┘ │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. 业务功能模块
|
||||
|
||||
### 2.1 商品管理模块
|
||||
|
||||
| 功能 | 描述 | 前端页面 | 后端服务 |
|
||||
|------|------|----------|----------|
|
||||
| 商品采集 | 多平台商品数据采集 | ProductList | ProductService, Node Agent |
|
||||
| 商品编辑 | 商品信息编辑、SKU管理 | ProductDetail | ProductService |
|
||||
| 商品刊登 | 多平台一键刊登 | ProductPublishForm | AutoListingService |
|
||||
| 商品定价 | 智能定价、利润计算 | AIPricing | PricingService |
|
||||
| 商品分析 | ROI分析、利润监控 | ROIAnalysis, ProfitMonitor | ArbitrageService |
|
||||
| 跨平台管理 | 多平台商品同步 | CrossPlatformManage | ProductService |
|
||||
|
||||
### 2.2 订单管理模块
|
||||
|
||||
| 功能 | 描述 | 前端页面 | 后端服务 |
|
||||
|------|------|----------|----------|
|
||||
| 订单列表 | 订单查询、筛选、导出 | OrderList | OrderService |
|
||||
| 订单详情 | 订单详细信息、操作 | OrderDetail | OrderService |
|
||||
| 异常订单 | 异常订单处理 | ExceptionOrder | OrderService |
|
||||
| 订单聚合 | 多店铺订单汇总 | OrderAggregation | OrderAggregationService |
|
||||
| 订单履约 | 发货、物流跟踪 | - | UnifiedFulfillmentService |
|
||||
|
||||
### 2.3 营销管理模块
|
||||
|
||||
| 功能 | 描述 | 前端页面 | 后端服务 |
|
||||
|------|------|----------|----------|
|
||||
| 广告计划 | 广告创建、管理 | AdPlanPage | MarketingService |
|
||||
| 广告投放 | 自动投放、优化 | AdDelivery | AdOpsService |
|
||||
| ROI分析 | 广告效果分析 | ROIAnalysis | MarketingService |
|
||||
| 竞品分析 | 竞品监控、分析 | Competitors | CompetitorService |
|
||||
| A/B测试 | 策略测试优化 | ABTestConfig, ABTestResults | ABTestService |
|
||||
|
||||
### 2.4 财务管理模块
|
||||
|
||||
| 功能 | 描述 | 前端页面 | 后端服务 |
|
||||
|------|------|----------|----------|
|
||||
| 交易记录 | 交易流水查询 | Transactions | FinanceService |
|
||||
| 资金对账 | 多平台对账 | Reconciliation | ReconciliationService |
|
||||
| 利润核算 | 利润计算、分析 | ProfitReport | OrderProfitService |
|
||||
| 结算管理 | 商户结算 | MerchantSettlementManage | SettlementService |
|
||||
|
||||
### 2.5 库存管理模块
|
||||
|
||||
| 功能 | 描述 | 前端页面 | 后端服务 |
|
||||
|------|------|----------|----------|
|
||||
| 库存查询 | 库存实时查询 | InventoryForecast | InventoryService |
|
||||
| 库存预测 | AI库存预测 | InventoryForecast | InventoryForecastService |
|
||||
| 仓库管理 | 多仓库管理 | Warehouses | WMSWaveService |
|
||||
| 补货建议 | 智能补货建议 | - | InventoryRLOptimizerService |
|
||||
|
||||
### 2.6 物流管理模块
|
||||
|
||||
| 功能 | 描述 | 前端页面 | 后端服务 |
|
||||
|------|------|----------|----------|
|
||||
| 物流跟踪 | 订单物流追踪 | LogisticsTrack | LogisticsTrackerService |
|
||||
| 运费计算 | 智能运费计算 | FreightCalc | DynamicShippingService |
|
||||
| 物流渠道 | 渠道选择管理 | LogisticsSelect | LogisticsService |
|
||||
|
||||
### 2.7 B2B贸易模块
|
||||
|
||||
| 功能 | 描述 | 前端页面 | 后端服务 |
|
||||
|------|------|----------|----------|
|
||||
| 企业报价 | B2B报价管理 | EnterpriseQuote | B2BTradeService |
|
||||
| 批量订单 | 批量订单处理 | BatchOrder | B2BTradeService |
|
||||
| 合同管理 | 合同创建、管理 | ContractManage | B2BTradeService |
|
||||
|
||||
### 2.8 合规管理模块
|
||||
|
||||
| 功能 | 描述 | 前端页面 | 后端服务 |
|
||||
|------|------|----------|----------|
|
||||
| 证书管理 | 合规证书管理 | CertificateManage | CertificateDatabaseService |
|
||||
| 合规检查 | 自动合规检查 | ComplianceCheck | ComplianceService |
|
||||
| 证书提醒 | 过期提醒 | CertificateExpiryReminder | CertificateDatabaseService |
|
||||
|
||||
### 2.9 多商户模块
|
||||
|
||||
| 功能 | 描述 | 前端页面 | 后端服务 |
|
||||
|------|------|----------|----------|
|
||||
| 商户管理 | 商户入驻、管理 | MerchantManage | MerchantService |
|
||||
| 商户订单 | 商户订单管理 | MerchantOrderManage | MerchantOrderService |
|
||||
| 商户店铺 | 商户店铺管理 | MerchantShopManage | MerchantShopService |
|
||||
| 商户结算 | 商户结算管理 | MerchantSettlementManage | MerchantSettlementService |
|
||||
|
||||
### 2.10 客户服务模块
|
||||
|
||||
| 功能 | 描述 | 前端页面 | 后端服务 |
|
||||
|------|------|----------|----------|
|
||||
| 客服中心 | 客服工单管理 | CustomerService | CustomerService |
|
||||
| 售后处理 | 退货、退款处理 | RefundProcess, ReturnApply | AfterSalesService |
|
||||
| 客户资产 | 会员、积分管理 | MemberLevel, PointsManage | UserAssetService |
|
||||
|
||||
---
|
||||
|
||||
## 3. AI自动化模块
|
||||
|
||||
### 3.1 自动选品
|
||||
|
||||
```typescript
|
||||
interface AutoSelectionConfig {
|
||||
platforms: string[];
|
||||
categories: string[];
|
||||
priceRange: { min: number; max: number };
|
||||
profitThreshold: number;
|
||||
scoreWeights: {
|
||||
profitRate: number;
|
||||
salesVolume: number;
|
||||
competition: number;
|
||||
trend: number;
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### 3.2 自动定价
|
||||
|
||||
```typescript
|
||||
interface AutoPricingConfig {
|
||||
strategy: 'MAX_PROFIT' | 'MAX_VOLUME' | 'BALANCED';
|
||||
minProfitRate: number;
|
||||
competitorTracking: boolean;
|
||||
dynamicAdjustment: boolean;
|
||||
adjustmentFrequency: 'HOURLY' | 'DAILY' | 'WEEKLY';
|
||||
}
|
||||
```
|
||||
|
||||
### 3.3 自动上架
|
||||
|
||||
```typescript
|
||||
interface AutoListingConfig {
|
||||
platforms: string[];
|
||||
auto_pricing: boolean;
|
||||
auto_description: boolean;
|
||||
auto_images: boolean;
|
||||
schedule: {
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
interval: number;
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### 3.4 智能客服
|
||||
|
||||
```typescript
|
||||
interface ChatBotConfig {
|
||||
enabled: boolean;
|
||||
autoReply: boolean;
|
||||
intentRecognition: boolean;
|
||||
escalationThreshold: number;
|
||||
supportedLanguages: string[];
|
||||
}
|
||||
```
|
||||
|
||||
### 3.5 异常检测
|
||||
|
||||
```typescript
|
||||
interface AnomalyDetectionConfig {
|
||||
metrics: string[];
|
||||
thresholds: Record<string, number>;
|
||||
alertChannels: ('EMAIL' | 'SMS' | 'WEBHOOK')[];
|
||||
autoRecovery: boolean;
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. Agent执行模块
|
||||
|
||||
### 4.1 平台采集Agent
|
||||
|
||||
| 平台 | 采集内容 | 适配器 |
|
||||
|------|----------|--------|
|
||||
| TikTok Shop | 商品、订单、广告 | TikTokAdapter |
|
||||
| Temu | 商品、订单 | TemuAdapter |
|
||||
| Amazon | 商品、订单、广告 | AmazonAdapter |
|
||||
| Shopee | 商品、订单 | ShopeeAdapter |
|
||||
| AliExpress | 商品、订单 | AliExpressAdapter |
|
||||
| 1688 | 商品、供应商 | Ali1688Adapter |
|
||||
|
||||
### 4.2 自动化操作Agent
|
||||
|
||||
| 操作 | 描述 | 触发方式 |
|
||||
|------|------|----------|
|
||||
| 商品刊登 | 自动刊登到目标平台 | 定时/手动 |
|
||||
| 价格调整 | 根据策略调整价格 | 定时/事件 |
|
||||
| 库存同步 | 多平台库存同步 | 定时/事件 |
|
||||
| 订单处理 | 自动确认、发货 | 事件驱动 |
|
||||
| 广告投放 | 自动创建、优化广告 | 定时/事件 |
|
||||
| 客服回复 | 自动回复客户消息 | 事件驱动 |
|
||||
|
||||
### 4.3 Agent任务调度
|
||||
|
||||
```typescript
|
||||
interface AgentTaskScheduler {
|
||||
// 任务优先级
|
||||
priority: 'HIGH' | 'MEDIUM' | 'LOW';
|
||||
|
||||
// 任务依赖
|
||||
dependencies: string[];
|
||||
|
||||
// 重试策略
|
||||
retry: {
|
||||
maxAttempts: number;
|
||||
backoff: 'LINEAR' | 'EXPONENTIAL';
|
||||
interval: number;
|
||||
};
|
||||
|
||||
// 超时设置
|
||||
timeout: number;
|
||||
|
||||
// 并发控制
|
||||
concurrency: {
|
||||
maxConcurrent: number;
|
||||
perShop: number;
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. 后台管理模块
|
||||
|
||||
### 5.1 用户管理
|
||||
|
||||
| 功能 | 描述 | 权限 |
|
||||
|------|------|------|
|
||||
| 用户列表 | 用户CRUD操作 | ADMIN |
|
||||
| 角色管理 | 角色定义、权限分配 | ADMIN |
|
||||
| 权限管理 | 细粒度权限控制 | ADMIN |
|
||||
| 登录日志 | 登录记录查询 | ADMIN, MANAGER |
|
||||
|
||||
### 5.2 租户管理
|
||||
|
||||
| 功能 | 描述 | 权限 |
|
||||
|------|------|------|
|
||||
| 租户列表 | 租户CRUD操作 | SUPER_ADMIN |
|
||||
| 租户配置 | 租户级配置管理 | ADMIN |
|
||||
| 租户隔离 | 数据隔离验证 | SYSTEM |
|
||||
| 配额管理 | 租户资源配额 | ADMIN |
|
||||
|
||||
### 5.3 审批流程
|
||||
|
||||
| 功能 | 描述 | 触发场景 |
|
||||
|------|------|----------|
|
||||
| 价格审批 | 价格变动审批 | 利润率低于阈值 |
|
||||
| 退款审批 | 退款申请审批 | 大额退款 |
|
||||
| 订单审批 | 特殊订单审批 | 异常订单 |
|
||||
| 合同审批 | B2B合同审批 | 新合同签订 |
|
||||
|
||||
### 5.4 审计日志
|
||||
|
||||
| 功能 | 描述 | 存储方式 |
|
||||
|------|------|----------|
|
||||
| 操作日志 | 用户操作记录 | 数据库 |
|
||||
| 系统日志 | 系统事件记录 | 文件 + 数据库 |
|
||||
| 审计追溯 | 操作链路追溯 | 数据库 |
|
||||
| 合规报告 | 合规性报告生成 | 定时生成 |
|
||||
|
||||
### 5.5 监控告警
|
||||
|
||||
| 功能 | 描述 | 通知方式 |
|
||||
|------|------|----------|
|
||||
| 系统监控 | 服务健康状态 | Dashboard + 邮件 |
|
||||
| 业务监控 | 业务指标监控 | Dashboard + 邮件 |
|
||||
| 异常告警 | 异常事件告警 | 邮件 + 短信 + Webhook |
|
||||
| 性能监控 | 性能指标监控 | Dashboard |
|
||||
|
||||
### 5.6 数据分析
|
||||
|
||||
| 功能 | 描述 | 输出方式 |
|
||||
|------|------|----------|
|
||||
| 业务报表 | 业务数据报表 | Dashboard + 导出 |
|
||||
| 趋势分析 | 数据趋势分析 | Dashboard |
|
||||
| 对比分析 | 多维度对比 | Dashboard |
|
||||
| 预测分析 | AI预测分析 | Dashboard |
|
||||
|
||||
---
|
||||
|
||||
## 6. 功能权限矩阵
|
||||
|
||||
| 角色 | 商品 | 订单 | 营销 | 财务 | 库存 | B2B | 合规 | 商户 | 系统 |
|
||||
|------|------|------|------|------|------|-----|------|------|------|
|
||||
| ADMIN | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||
| MANAGER | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
|
||||
| OPERATOR | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| FINANCE | ❌ | ❌ | ❌ | ✅ | ❌ | ✅ | ❌ | ✅ | ❌ |
|
||||
| SOURCING | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| LOGISTICS | ❌ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| ANALYST | 👁️ | 👁️ | 👁️ | 👁️ | 👁️ | 👁️ | 👁️ | 👁️ | ❌ |
|
||||
|
||||
---
|
||||
|
||||
## 7. 实现路线图
|
||||
|
||||
### Phase 1: 核心功能 (Week 1-2)
|
||||
|
||||
- [x] 商品管理闭环
|
||||
- [x] 订单管理闭环
|
||||
- [x] 财务管理闭环
|
||||
- [x] 用户权限管理
|
||||
|
||||
### Phase 2: 业务扩展 (Week 3-4)
|
||||
|
||||
- [x] 营销管理闭环
|
||||
- [x] 库存管理闭环
|
||||
- [x] 物流管理闭环
|
||||
- [x] B2B贸易闭环
|
||||
|
||||
### Phase 3: AI自动化 (Week 5-6)
|
||||
|
||||
- [x] 自动选品
|
||||
- [x] 自动定价
|
||||
- [x] 自动上架
|
||||
- [x] 智能客服
|
||||
|
||||
### Phase 4: Agent执行 (Week 7-8)
|
||||
|
||||
- [ ] Node Agent部署
|
||||
- [ ] 平台适配器完善
|
||||
- [ ] 任务调度优化
|
||||
- [ ] 反检测增强
|
||||
|
||||
### Phase 5: 后台管理 (Week 9-10)
|
||||
|
||||
- [x] 审批流程
|
||||
- [x] 审计日志
|
||||
- [x] 监控告警
|
||||
- [x] 数据分析
|
||||
|
||||
---
|
||||
|
||||
## 8. 相关文档
|
||||
|
||||
- [前后端插件闭环架构](./17_Frontend_Backend_Plugin_ClosedLoop.md)
|
||||
- [业务闭环总览](../00_Business/Business_ClosedLoops.md)
|
||||
- [服务编排总图](./04_Service_Map.md)
|
||||
- [Node Agent设计](../04_Plugin/01_NodeAgent_Design.md)
|
||||
|
||||
---
|
||||
|
||||
*最后更新: 2026-03-20*
|
||||
701
docs/01_Architecture/19_Agent_Features_Plan.md
Normal file
701
docs/01_Architecture/19_Agent_Features_Plan.md
Normal file
@@ -0,0 +1,701 @@
|
||||
# Agent功能方案
|
||||
|
||||
> **创建日期**: 2026-03-20
|
||||
> **状态**: 设计中
|
||||
> **优先级**: 最高
|
||||
|
||||
---
|
||||
|
||||
## 1. Agent架构总览
|
||||
|
||||
### 1.1 Agent类型
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||
│ Agent 功能架构 │
|
||||
├─────────────────────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ ┌─────────────────────────────────────────────────────────────────────┐ │
|
||||
│ │ Node Agent (Playwright) │ │
|
||||
│ │ ┌─────────────────────────────────────────────────────────────┐ │ │
|
||||
│ │ │ 平台采集 Agent │ │ │
|
||||
│ │ │ - TikTok Shop - Temu - Amazon - Shopee - AliExpress │ │ │
|
||||
│ │ └─────────────────────────────────────────────────────────────┘ │ │
|
||||
│ │ ┌─────────────────────────────────────────────────────────────┐ │ │
|
||||
│ │ │ 自动化操作 Agent │ │ │
|
||||
│ │ │ - 刊登 - 定价 - 订单处理 - 广告投放 - 库存同步 │ │ │
|
||||
│ │ └─────────────────────────────────────────────────────────────┘ │ │
|
||||
│ └─────────────────────────────────────────────────────────────────────┘ │
|
||||
│ │
|
||||
│ ┌─────────────────────────────────────────────────────────────────────┐ │
|
||||
│ │ AI Agent (智能决策) │ │
|
||||
│ │ ┌─────────────────────────────────────────────────────────────┐ │ │
|
||||
│ │ │ 决策 Agent │ │ │
|
||||
│ │ │ - 选品决策 - 定价决策 - 库存决策 - 营销决策 │ │ │
|
||||
│ │ └─────────────────────────────────────────────────────────────┘ │ │
|
||||
│ │ ┌─────────────────────────────────────────────────────────────┐ │ │
|
||||
│ │ │ 分析 Agent │ │ │
|
||||
│ │ │ - 趋势分析 - 竞品分析 - 利润分析 - 风险分析 │ │ │
|
||||
│ │ └─────────────────────────────────────────────────────────────┘ │ │
|
||||
│ └─────────────────────────────────────────────────────────────────────┘ │
|
||||
│ │
|
||||
│ ┌─────────────────────────────────────────────────────────────────────┐ │
|
||||
│ │ Operation Agent (运营代理) │ │
|
||||
│ │ ┌─────────────────────────────────────────────────────────────┐ │ │
|
||||
│ │ │ 任务编排 Agent │ │ │
|
||||
│ │ │ - 任务调度 - 依赖管理 - 失败重试 - 结果上报 │ │ │
|
||||
│ │ └─────────────────────────────────────────────────────────────┘ │ │
|
||||
│ │ ┌─────────────────────────────────────────────────────────────┐ │ │
|
||||
│ │ │ 监控 Agent │ │ │
|
||||
│ │ │ - 健康检查 - 性能监控 - 异常告警 - 自动恢复 │ │ │
|
||||
│ │ └─────────────────────────────────────────────────────────────┘ │ │
|
||||
│ └─────────────────────────────────────────────────────────────────────┘ │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. Node Agent (平台执行代理)
|
||||
|
||||
### 2.1 核心能力
|
||||
|
||||
| 能力 | 描述 | 技术实现 |
|
||||
|------|------|----------|
|
||||
| **无API平台采集** | TikTok Shop, Temu, 1688等无API平台 | Playwright浏览器自动化 |
|
||||
| **自动化操作** | 刊登、定价、订单处理、广告投放 | 平台适配器封装 |
|
||||
| **反检测** | 指纹隔离、代理IP、行为模拟 | 多浏览器上下文 |
|
||||
| **多实例并发** | 支持多店铺同时运行 | 任务队列 + 并发控制 |
|
||||
|
||||
### 2.2 任务类型定义
|
||||
|
||||
```typescript
|
||||
export enum TaskType {
|
||||
// 采集类任务
|
||||
COLLECT_PRODUCT = 'COLLECT_PRODUCT', // 商品采集
|
||||
COLLECT_ORDER = 'COLLECT_ORDER', // 订单采集
|
||||
COLLECT_AD = 'COLLECT_AD', // 广告数据采集
|
||||
COLLECT_INVENTORY = 'COLLECT_INVENTORY', // 库存数据采集
|
||||
|
||||
// 操作类任务
|
||||
PUBLISH_PRODUCT = 'PUBLISH_PRODUCT', // 商品刊登
|
||||
UPDATE_PRICE = 'UPDATE_PRICE', // 价格更新
|
||||
PROCESS_ORDER = 'PROCESS_ORDER', // 订单处理
|
||||
SYNC_INVENTORY = 'SYNC_INVENTORY', // 库存同步
|
||||
MANAGE_AD = 'MANAGE_AD', // 广告管理
|
||||
|
||||
// 客服类任务
|
||||
REPLY_MESSAGE = 'REPLY_MESSAGE', // 消息回复
|
||||
HANDLE_RETURN = 'HANDLE_RETURN', // 退货处理
|
||||
ISSUE_REFUND = 'ISSUE_REFUND', // 退款处理
|
||||
}
|
||||
|
||||
export interface NodeTask {
|
||||
taskId: string;
|
||||
traceId: string;
|
||||
tenantId: string;
|
||||
shopId: string;
|
||||
type: TaskType;
|
||||
platform: string;
|
||||
params: Record<string, any>;
|
||||
priority: 'HIGH' | 'MEDIUM' | 'LOW';
|
||||
timeout: number;
|
||||
retryCount: number;
|
||||
createdAt: number;
|
||||
}
|
||||
```
|
||||
|
||||
### 2.3 平台适配器
|
||||
|
||||
```typescript
|
||||
export interface IPlatformAdapter {
|
||||
platform: string;
|
||||
|
||||
// 采集方法
|
||||
collectProduct(params: CollectParams): Promise<ProductData[]>;
|
||||
collectOrder(params: CollectParams): Promise<OrderData[]>;
|
||||
collectInventory(params: CollectParams): Promise<InventoryData[]>;
|
||||
|
||||
// 操作方法
|
||||
publishProduct(product: ProductData): Promise<PublishResult>;
|
||||
updatePrice(productId: string, price: number): Promise<UpdateResult>;
|
||||
processOrder(orderId: string, action: OrderAction): Promise<ProcessResult>;
|
||||
|
||||
// 认证方法
|
||||
login(credentials: Credentials): Promise<LoginResult>;
|
||||
checkSession(): Promise<boolean>;
|
||||
logout(): Promise<void>;
|
||||
}
|
||||
|
||||
// 平台适配器工厂
|
||||
export class PlatformAdapterFactory {
|
||||
static create(platform: string): IPlatformAdapter {
|
||||
switch (platform) {
|
||||
case 'tiktok': return new TikTokAdapter();
|
||||
case 'temu': return new TemuAdapter();
|
||||
case 'amazon': return new AmazonAdapter();
|
||||
case 'shopee': return new ShopeeAdapter();
|
||||
case 'aliexpress': return new AliExpressAdapter();
|
||||
case '1688': return new Ali1688Adapter();
|
||||
default: throw new Error(`Unsupported platform: ${platform}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2.4 反检测策略
|
||||
|
||||
```typescript
|
||||
export interface AntiDetectionConfig {
|
||||
// 浏览器指纹
|
||||
fingerprint: {
|
||||
userAgent: string;
|
||||
viewport: { width: number; height: number };
|
||||
timezone: string;
|
||||
language: string;
|
||||
platform: string;
|
||||
webgl: { vendor: string; renderer: string };
|
||||
canvas: string;
|
||||
};
|
||||
|
||||
// 代理配置
|
||||
proxy: {
|
||||
server: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
};
|
||||
|
||||
// 行为模拟
|
||||
behavior: {
|
||||
mouseMovement: boolean;
|
||||
randomDelay: { min: number; max: number };
|
||||
scrollBehavior: 'smooth' | 'auto';
|
||||
typingSpeed: { min: number; max: number };
|
||||
};
|
||||
|
||||
// 会话隔离
|
||||
isolation: {
|
||||
profileDir: string;
|
||||
cookies: boolean;
|
||||
localStorage: boolean;
|
||||
sessionStorage: boolean;
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### 2.5 任务执行流程
|
||||
|
||||
```
|
||||
1. 任务接收
|
||||
└── 从Hub拉取任务 → 验证任务参数 → 加入执行队列
|
||||
|
||||
2. 环境准备
|
||||
└── 创建浏览器上下文 → 应用反检测配置 → 登录平台
|
||||
|
||||
3. 任务执行
|
||||
└── 获取平台适配器 → 执行具体操作 → 捕获结果/异常
|
||||
|
||||
4. 结果上报
|
||||
└── 生成执行报告 → 上报结果到Hub → 清理环境
|
||||
|
||||
5. 异常处理
|
||||
└── 捕获异常 → 判断是否重试 → 上报失败原因
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. AI Agent (智能决策代理)
|
||||
|
||||
### 3.1 决策Agent
|
||||
|
||||
#### 3.1.1 选品决策Agent
|
||||
|
||||
```typescript
|
||||
export class ProductSelectionAgent {
|
||||
/**
|
||||
* 执行选品决策
|
||||
*/
|
||||
async execute(params: {
|
||||
tenantId: string;
|
||||
platforms: string[];
|
||||
categories: string[];
|
||||
constraints: SelectionConstraints;
|
||||
}): Promise<SelectionResult> {
|
||||
// 1. 数据采集
|
||||
const products = await this.collectProducts(params);
|
||||
|
||||
// 2. 特征提取
|
||||
const features = await this.extractFeatures(products);
|
||||
|
||||
// 3. 评分计算
|
||||
const scores = await this.calculateScores(features);
|
||||
|
||||
// 4. 排序筛选
|
||||
const selected = this.rankAndFilter(scores, params.constraints);
|
||||
|
||||
// 5. 生成建议
|
||||
return this.generateRecommendations(selected);
|
||||
}
|
||||
|
||||
/**
|
||||
* 评分维度
|
||||
*/
|
||||
private scoringWeights = {
|
||||
profitRate: 0.3, // 利润率
|
||||
salesVolume: 0.2, // 销量
|
||||
competition: 0.15, // 竞争度
|
||||
trend: 0.15, // 趋势
|
||||
rating: 0.1, // 评分
|
||||
supplier: 0.1, // 供应商可靠性
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
#### 3.1.2 定价决策Agent
|
||||
|
||||
```typescript
|
||||
export class PricingDecisionAgent {
|
||||
/**
|
||||
* 执行定价决策
|
||||
*/
|
||||
async execute(params: {
|
||||
productId: string;
|
||||
platform: string;
|
||||
strategy: 'MAX_PROFIT' | 'MAX_VOLUME' | 'BALANCED';
|
||||
constraints: PricingConstraints;
|
||||
}): Promise<PricingResult> {
|
||||
// 1. 成本分析
|
||||
const costs = await this.analyzeCosts(params.productId);
|
||||
|
||||
// 2. 竞品分析
|
||||
const competitors = await this.analyzeCompetitors(params.productId, params.platform);
|
||||
|
||||
// 3. 需求预测
|
||||
const demand = await this.predictDemand(params.productId);
|
||||
|
||||
// 4. 价格优化
|
||||
const optimalPrice = await this.optimizePrice({
|
||||
costs,
|
||||
competitors,
|
||||
demand,
|
||||
strategy: params.strategy,
|
||||
constraints: params.constraints,
|
||||
});
|
||||
|
||||
// 5. 风险评估
|
||||
const risk = this.assessRisk(optimalPrice, costs);
|
||||
|
||||
return {
|
||||
recommendedPrice: optimalPrice.price,
|
||||
expectedProfit: optimalPrice.profit,
|
||||
expectedVolume: optimalPrice.volume,
|
||||
riskLevel: risk.level,
|
||||
confidence: optimalPrice.confidence,
|
||||
};
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 3.1.3 库存决策Agent
|
||||
|
||||
```typescript
|
||||
export class InventoryDecisionAgent {
|
||||
/**
|
||||
* 执行库存决策
|
||||
*/
|
||||
async execute(params: {
|
||||
tenantId: string;
|
||||
skuId: string;
|
||||
warehouseId: string;
|
||||
}): Promise<InventoryDecision> {
|
||||
// 1. 销量预测
|
||||
const forecast = await InventoryForecastService.getForecast(params.tenantId);
|
||||
|
||||
// 2. 安全库存计算
|
||||
const safetyStock = this.calculateSafetyStock(forecast);
|
||||
|
||||
// 3. 补货点计算
|
||||
const reorderPoint = this.calculateReorderPoint(forecast, safetyStock);
|
||||
|
||||
// 4. 补货量计算
|
||||
const reorderQuantity = this.calculateReorderQuantity(forecast);
|
||||
|
||||
// 5. 生成建议
|
||||
return {
|
||||
currentStock: await this.getCurrentStock(params.skuId),
|
||||
forecastedDemand: forecast,
|
||||
safetyStock,
|
||||
reorderPoint,
|
||||
reorderQuantity,
|
||||
recommendation: this.generateRecommendation({
|
||||
currentStock: await this.getCurrentStock(params.skuId),
|
||||
reorderPoint,
|
||||
reorderQuantity,
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3.2 分析Agent
|
||||
|
||||
#### 3.2.1 趋势分析Agent
|
||||
|
||||
```typescript
|
||||
export class TrendAnalysisAgent {
|
||||
/**
|
||||
* 分析市场趋势
|
||||
*/
|
||||
async analyze(params: {
|
||||
category: string;
|
||||
platform: string;
|
||||
timeRange: { start: Date; end: Date };
|
||||
}): Promise<TrendAnalysis> {
|
||||
// 1. 数据采集
|
||||
const data = await this.collectTrendData(params);
|
||||
|
||||
// 2. 时间序列分析
|
||||
const timeSeries = this.analyzeTimeSeries(data);
|
||||
|
||||
// 3. 趋势识别
|
||||
const trends = this.identifyTrends(timeSeries);
|
||||
|
||||
// 4. 预测
|
||||
const predictions = this.predictTrends(trends);
|
||||
|
||||
return {
|
||||
currentTrend: trends.current,
|
||||
predictedTrend: predictions,
|
||||
seasonality: timeSeries.seasonality,
|
||||
opportunities: this.identifyOpportunities(trends),
|
||||
risks: this.identifyRisks(trends),
|
||||
};
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 3.2.2 竞品分析Agent
|
||||
|
||||
```typescript
|
||||
export class CompetitorAnalysisAgent {
|
||||
/**
|
||||
* 分析竞争对手
|
||||
*/
|
||||
async analyze(params: {
|
||||
productId: string;
|
||||
platform: string;
|
||||
}): Promise<CompetitorAnalysis> {
|
||||
// 1. 识别竞品
|
||||
const competitors = await this.identifyCompetitors(params.productId);
|
||||
|
||||
// 2. 价格对比
|
||||
const priceComparison = this.comparePrices(params.productId, competitors);
|
||||
|
||||
// 3. 销量对比
|
||||
const salesComparison = await this.compareSales(params.productId, competitors);
|
||||
|
||||
// 4. 策略分析
|
||||
const strategies = this.analyzeStrategies(competitors);
|
||||
|
||||
return {
|
||||
competitors,
|
||||
priceComparison,
|
||||
salesComparison,
|
||||
strategies,
|
||||
recommendations: this.generateRecommendations({
|
||||
priceComparison,
|
||||
salesComparison,
|
||||
strategies,
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. Operation Agent (运营代理)
|
||||
|
||||
### 4.1 任务编排Agent
|
||||
|
||||
```typescript
|
||||
export class TaskOrchestrationAgent {
|
||||
private taskQueue: PriorityQueue<NodeTask>;
|
||||
private executor: TaskExecutor;
|
||||
|
||||
/**
|
||||
* 提交任务
|
||||
*/
|
||||
async submitTask(task: NodeTask): Promise<string> {
|
||||
// 1. 验证任务
|
||||
this.validateTask(task);
|
||||
|
||||
// 2. 检查依赖
|
||||
await this.checkDependencies(task);
|
||||
|
||||
// 3. 加入队列
|
||||
await this.taskQueue.enqueue(task);
|
||||
|
||||
// 4. 触发执行
|
||||
this.triggerExecution();
|
||||
|
||||
return task.taskId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行任务
|
||||
*/
|
||||
private async executeTask(task: NodeTask): Promise<TaskResult> {
|
||||
try {
|
||||
// 1. 预处理
|
||||
await this.preProcess(task);
|
||||
|
||||
// 2. 执行
|
||||
const result = await this.executor.execute(task);
|
||||
|
||||
// 3. 后处理
|
||||
await this.postProcess(task, result);
|
||||
|
||||
// 4. 上报结果
|
||||
await this.reportResult(task, result);
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
// 异常处理
|
||||
await this.handleError(task, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 4.2 监控Agent
|
||||
|
||||
```typescript
|
||||
export class MonitoringAgent {
|
||||
/**
|
||||
* 健康检查
|
||||
*/
|
||||
async healthCheck(): Promise<HealthStatus> {
|
||||
return {
|
||||
status: 'healthy',
|
||||
checks: {
|
||||
database: await this.checkDatabase(),
|
||||
redis: await this.checkRedis(),
|
||||
queue: await this.checkQueue(),
|
||||
agents: await this.checkAgents(),
|
||||
},
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 性能监控
|
||||
*/
|
||||
async monitorPerformance(): Promise<PerformanceMetrics> {
|
||||
return {
|
||||
cpu: await this.getCpuUsage(),
|
||||
memory: await this.getMemoryUsage(),
|
||||
network: await this.getNetworkStats(),
|
||||
tasks: await this.getTaskStats(),
|
||||
latency: await this.getLatencyStats(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 异常告警
|
||||
*/
|
||||
async alertAnomaly(anomaly: Anomaly): Promise<void> {
|
||||
// 1. 记录异常
|
||||
await this.recordAnomaly(anomaly);
|
||||
|
||||
// 2. 发送通知
|
||||
await this.sendNotification(anomaly);
|
||||
|
||||
// 3. 尝试自动恢复
|
||||
if (anomaly.autoRecoverable) {
|
||||
await this.attemptRecovery(anomaly);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. Agent协作模式
|
||||
|
||||
### 5.1 协作流程
|
||||
|
||||
```
|
||||
用户请求 → AI Agent (决策) → Operation Agent (编排) → Node Agent (执行)
|
||||
↓ ↓ ↓
|
||||
决策结果 任务调度 执行结果
|
||||
↓ ↓ ↓
|
||||
←────────────────── 结果反馈 ──────────────────
|
||||
```
|
||||
|
||||
### 5.2 消息协议
|
||||
|
||||
```typescript
|
||||
export interface AgentMessage {
|
||||
messageId: string;
|
||||
traceId: string;
|
||||
from: string;
|
||||
to: string;
|
||||
type: 'REQUEST' | 'RESPONSE' | 'NOTIFICATION' | 'ERROR';
|
||||
payload: any;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
export interface DecisionRequest {
|
||||
decisionType: 'SELECTION' | 'PRICING' | 'INVENTORY' | 'MARKETING';
|
||||
context: Record<string, any>;
|
||||
constraints: Record<string, any>;
|
||||
}
|
||||
|
||||
export interface ExecutionRequest {
|
||||
taskId: string;
|
||||
taskType: TaskType;
|
||||
platform: string;
|
||||
params: Record<string, any>;
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 6. Agent配置管理
|
||||
|
||||
### 6.1 全局配置
|
||||
|
||||
```typescript
|
||||
export interface AgentGlobalConfig {
|
||||
// Hub配置
|
||||
hub: {
|
||||
url: string;
|
||||
apiKey: string;
|
||||
timeout: number;
|
||||
};
|
||||
|
||||
// 并发配置
|
||||
concurrency: {
|
||||
maxConcurrent: number;
|
||||
perShop: number;
|
||||
perPlatform: number;
|
||||
};
|
||||
|
||||
// 重试配置
|
||||
retry: {
|
||||
maxAttempts: number;
|
||||
backoff: 'LINEAR' | 'EXPONENTIAL';
|
||||
baseInterval: number;
|
||||
};
|
||||
|
||||
// 超时配置
|
||||
timeout: {
|
||||
default: number;
|
||||
collect: number;
|
||||
publish: number;
|
||||
process: number;
|
||||
};
|
||||
|
||||
// 监控配置
|
||||
monitoring: {
|
||||
healthCheckInterval: number;
|
||||
metricsInterval: number;
|
||||
alertThresholds: Record<string, number>;
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### 6.2 店铺级配置
|
||||
|
||||
```typescript
|
||||
export interface ShopAgentConfig {
|
||||
shopId: string;
|
||||
platform: string;
|
||||
|
||||
// 代理配置
|
||||
proxy: {
|
||||
enabled: boolean;
|
||||
server: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
};
|
||||
|
||||
// 指纹配置
|
||||
fingerprint: {
|
||||
userAgent: string;
|
||||
viewport: { width: number; height: number };
|
||||
timezone: string;
|
||||
language: string;
|
||||
};
|
||||
|
||||
// 行为配置
|
||||
behavior: {
|
||||
randomDelay: { min: number; max: number };
|
||||
mouseMovement: boolean;
|
||||
typingSpeed: { min: number; max: number };
|
||||
};
|
||||
|
||||
// 任务配置
|
||||
tasks: {
|
||||
autoCollect: boolean;
|
||||
collectInterval: number;
|
||||
autoSync: boolean;
|
||||
syncInterval: number;
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 7. 实现优先级
|
||||
|
||||
### P0 - 核心Agent (立即完成)
|
||||
|
||||
1. **Node Agent基础框架**
|
||||
- 任务调度器
|
||||
- 平台适配器接口
|
||||
- 反检测基础能力
|
||||
|
||||
2. **AI决策Agent**
|
||||
- 选品决策
|
||||
- 定价决策
|
||||
- 库存决策
|
||||
|
||||
### P1 - 重要Agent (近期完成)
|
||||
|
||||
3. **平台适配器**
|
||||
- TikTok Shop适配器
|
||||
- Temu适配器
|
||||
- Amazon适配器
|
||||
|
||||
4. **分析Agent**
|
||||
- 趋势分析
|
||||
- 竞品分析
|
||||
- 利润分析
|
||||
|
||||
### P2 - 增强Agent (后续完成)
|
||||
|
||||
5. **监控Agent**
|
||||
- 健康检查
|
||||
- 性能监控
|
||||
- 异常告警
|
||||
|
||||
6. **高级功能**
|
||||
- 自动恢复
|
||||
- 智能调度
|
||||
- 策略优化
|
||||
|
||||
---
|
||||
|
||||
## 8. 相关文档
|
||||
|
||||
- [Node Agent设计](../04_Plugin/01_NodeAgent_Design.md)
|
||||
- [前后端插件闭环架构](./17_Frontend_Backend_Plugin_ClosedLoop.md)
|
||||
- [全局功能方案](./18_Global_Features_Plan.md)
|
||||
- [后台管理方案](./19_Admin_System_Plan.md)
|
||||
|
||||
---
|
||||
|
||||
*最后更新: 2026-03-20*
|
||||
1184
docs/01_Architecture/20_Admin_System_Plan.md
Normal file
1184
docs/01_Architecture/20_Admin_System_Plan.md
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user