Files
param-auto-manager/README.md
T
hz4th_coder 6534c3315b feat: 新增后台任务系统,支持抓取任务在后台持续运行
- 新增后台任务API (/api/tasks)
- 抓取任务在后台独立运行,不受页面刷新影响
- 支持任务状态查询和手动停止
- 新增后台任务管理界面
- 数据库新增 background_tasks 表
- 前端使用轮询方式更新任务进度
2026-07-14 10:59:18 +08:00

327 lines
6.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Param Auto Manager - 参数数据自动化管理系统
自动管理参数数据网站的系统,支持从内容库和互联网搜索数据,自动处理产品并提交到后台管理待审核区。
## 功能特性
- 📚 **内容库管理**:存储和管理搜索获取的相关文章内容
- 🔄 **自动处理流程**:自动从待处理列表中提取产品并处理
- 🔍 **智能搜索**:从内容库和互联网搜索相关数据
- 📝 **数据提取**:根据产品类别提取和填充字段
-**审核提交**:自动提交到ParamHub后台管理待审核区
- 🕐 **定时任务**:支持定时自动处理产品
- 🔧 **后台任务系统**:抓取任务在后台持续运行,不受页面刷新影响
- 一键抓取触发后,任务在后台独立运行
- 可随时查看任务进度和状态
- 支持手动停止正在运行的任务
- 自动记录成功/失败/保存数量
## 系统架构
```
param-auto-manager/
├── app.py # 主应用入口
├── config.py # 配置文件
├── requirements.txt # Python依赖
├── models/
│ └── database.py # 数据库模型
├── routes/
│ ├── articles.py # 文章内容库API
│ ├── products.py # 产品处理API
│ └── system.py # 系统管理API
├── services/
│ ├── search_service.py # 搜索服务
│ ├── process_service.py # 数据处理服务
│ └── paramhub_client.py # ParamHub API客户端
├── utils/
│ └── scheduler.py # 定时任务调度器
├── data/ # 数据库文件目录
└── logs/ # 日志文件目录
```
## 安装依赖
```bash
cd works/param-auto-manager
pip install -r requirements.txt
```
## 启动服务
```bash
# 方式1: 使用启动脚本
chmod +x start.sh
./start.sh
# 方式2: 直接运行
python3 app.py
```
服务将在端口 **16043** 启动。
## API 文档
### 文章内容库 API (`/api/articles`)
#### 获取文章列表
```
GET /api/articles?limit=100&offset=0
```
#### 搜索文章
```
GET /api/articles/search?q=关键词&category=分类
```
#### 获取文章详情
```
GET /api/articles/{article_id}
```
#### 创建文章
```
POST /api/articles
Content-Type: application/json
{
"product_names": ["产品A", "产品B"],
"category": "AI模型",
"keywords": ["关键词1", "关键词2"],
"summary": "文章摘要",
"content": "文章内容",
"source": "来源",
"url": "原文链接"
}
```
#### 从URL抓取文章
```
POST /api/articles/fetch
Content-Type: application/json
{
"url": "https://example.com/article",
"product_names": ["产品A"],
"category": "分类"
}
```
#### 删除文章
```
DELETE /api/articles/{article_id}
```
### 产品处理 API (`/api/products`)
#### 获取待处理产品列表
```
GET /api/products/pending?limit=20&order_by=priority
```
#### 添加待处理产品
```
POST /api/products/pending
Content-Type: application/json
{
"product_name": "产品名称",
"category": "分类",
"subcategory": "子分类",
"priority": 10,
"source": "manual"
}
```
#### 批量添加待处理产品
```
POST /api/products/pending
Content-Type: application/json
[
{"product_name": "产品1", "category": "分类"},
{"product_name": "产品2", "category": "分类"}
]
```
#### 移除待处理产品
```
DELETE /api/products/pending/{product_name}
```
#### 获取处理中的产品
```
GET /api/products/processing
```
#### 获取处理历史
```
GET /api/products/history?limit=100
```
#### 获取指定产品的处理历史
```
GET /api/products/history/{product_name}
```
#### 处理单个产品
```
POST /api/products/process
Content-Type: application/json
{
"product_name": "产品名称",
"category": "分类",
"subcategory": "子分类"
}
```
#### 批量处理产品
```
POST /api/products/process/batch
Content-Type: application/json
{
"limit": 5
}
```
### 后台任务 API (`/api/tasks`)
#### 启动后台抓取任务
```
POST /api/tasks/start
Content-Type: application/json
{
"results": [{"title": "标题", "url": "https://..."}],
"auto_save": true,
"category": "分类",
"keywords": ["关键词"]
}
```
#### 获取任务状态
```
GET /api/tasks/{task_id}/status
```
#### 停止任务
```
POST /api/tasks/{task_id}/stop
```
#### 获取活动任务列表
```
GET /api/tasks/active
```
#### 获取最近任务
```
GET /api/tasks/recent?limit=20
```
#### 删除任务记录
```
DELETE /api/tasks/{task_id}
```
#### 清理已完成任务
```
POST /api/tasks/clear
```
### 系统管理 API (`/api/system`)
#### 获取系统配置
```
GET /api/system/config
```
#### 更新系统配置
```
PUT /api/system/config
Content-Type: application/json
{
"auto_process_enabled": "true",
"process_interval": "300",
"batch_size": "5"
}
```
#### 获取系统统计
```
GET /api/system/stats
```
#### 健康检查
```
GET /api/system/health
```
## 处理流程
1. **添加待处理产品**:手动添加或系统自动发现新产品
2. **自动/手动触发处理**
- 从内容库搜索相关文章
- 从互联网搜索最新数据
- 提取产品具体内容
- 根据类别字段填充数据
- 提交到ParamHub待审核区
3. **发现新产品**:处理过程中自动发现并添加相关产品
## 数据库表结构
### articles (文章内容库)
- id, product_names, category, keywords, summary, content, source, url, fetch_date
### pending_products (待处理产品列表)
- id, product_name, category, subcategory, priority, source
### processing_products (处理中产品)
- id, product_name, category, subcategory, status, started_at
### process_history (处理历史)
- id, product_name, category, subcategory, status, review_id, details
## 配置说明
编辑 `config.py` 文件:
```python
PORT = 16043 # 服务端口
PARAMHUB_BASE_URL = 'http://localhost:16041' # ParamHub API地址
PARAMHUB_PASSWORD = 'admin123' # ParamHub管理员密码
SEARCH_MAX_RESULTS = 10 # 搜索最大结果数
PROCESS_INTERVAL = 300 # 自动处理间隔(秒)
BATCH_SIZE = 5 # 批量处理数量
```
## 注意事项
1. 确保 ParamHub 服务(端口16041)正常运行
2. 首次运行会自动创建数据库和表结构
3. 定时任务默认每5分钟执行一次自动处理
4. 可通过系统配置API调整自动处理参数
## 日志
日志文件位于 `logs/app.log`,包含:
- 系统启动信息
- 处理过程记录
- 错误和异常信息
## 版本历史
- v1.1.0 (2026-07-14): 后台任务系统
- 新增后台任务API/api/tasks
- 抓取任务在后台独立运行,不受页面刷新影响
- 支持任务状态查询和手动停止
- 新增后台任务管理界面
- 数据库新增 background_tasks 表
- v1.0.0 (2026-07-12): 初始版本
- 内容库管理
- 产品处理流程
- 定时任务调度
- ParamHub API集成