新增产品状态检查功能
- 处理前检查产品是否已存在(已发布/待审核) - 避免重复处理已有产品 - 新增 check_product_exists API 方法 - 更新 README 文档
This commit is contained in:
@@ -15,6 +15,10 @@
|
||||
- 可随时查看任务进度和状态
|
||||
- 支持手动停止正在运行的任务
|
||||
- 自动记录成功/失败/保存数量
|
||||
- 🛡️ **产品状态检查**:处理前自动检查产品是否已存在
|
||||
- 检查已发布产品(模型/GPU/CPU)
|
||||
- 检查待审核产品
|
||||
- 已存在则自动跳过,避免重复处理
|
||||
|
||||
## 系统架构
|
||||
|
||||
@@ -262,13 +266,18 @@ GET /api/system/health
|
||||
## 处理流程
|
||||
|
||||
1. **添加待处理产品**:手动添加或系统自动发现新产品
|
||||
2. **自动/手动触发处理**:
|
||||
2. **产品状态检查**:
|
||||
- 检查产品是否已在 ParamHub 系统中
|
||||
- 检查已发布产品(模型/GPU/CPU)
|
||||
- 检查待审核列表
|
||||
- 如已存在则跳过后续处理
|
||||
3. **自动/手动触发处理**:
|
||||
- 从内容库搜索相关文章
|
||||
- 从互联网搜索最新数据
|
||||
- 提取产品具体内容
|
||||
- 根据类别字段填充数据
|
||||
- 提交到ParamHub待审核区
|
||||
3. **发现新产品**:处理过程中自动发现并添加相关产品
|
||||
4. **发现新产品**:处理过程中自动发现并添加相关产品
|
||||
|
||||
## 数据库表结构
|
||||
|
||||
@@ -313,6 +322,12 @@ BATCH_SIZE = 5 # 批量处理数量
|
||||
|
||||
## 版本历史
|
||||
|
||||
- v1.2.0 (2026-07-16): 产品状态检查
|
||||
- 新增产品状态检查功能
|
||||
- 处理前检查产品是否已存在(已发布/待审核)
|
||||
- 避免重复处理已有产品
|
||||
- 新增 check_product_exists API 方法
|
||||
|
||||
- v1.1.0 (2026-07-14): 后台任务系统
|
||||
- 新增后台任务API(/api/tasks)
|
||||
- 抓取任务在后台独立运行,不受页面刷新影响
|
||||
|
||||
@@ -127,6 +127,114 @@ class ParamHubClient:
|
||||
except Exception as e:
|
||||
print(f"发送通知失败: {str(e)}")
|
||||
return False
|
||||
|
||||
def check_product_exists(self, product_name):
|
||||
"""
|
||||
检查产品是否已存在于系统中(已发布或待审核)
|
||||
|
||||
Args:
|
||||
product_name: 产品名称
|
||||
|
||||
Returns:
|
||||
{
|
||||
'exists': bool,
|
||||
'status': str ('published'/'pending'/None),
|
||||
'message': str
|
||||
}
|
||||
"""
|
||||
try:
|
||||
if not self.session:
|
||||
self.login()
|
||||
|
||||
# 1. 检查已发布的产品(通过搜索API)
|
||||
response = self.session.get(
|
||||
f'{self.base_url}/api/search',
|
||||
params={'q': product_name}
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
|
||||
# 检查是否匹配(精确匹配或包含匹配)
|
||||
product_name_lower = product_name.lower().strip()
|
||||
|
||||
# 检查已发布的模型
|
||||
for model in result.get('models', []):
|
||||
name = model.get('name', '').lower().strip()
|
||||
if product_name_lower == name or product_name_lower in name or name in product_name_lower:
|
||||
return {
|
||||
'exists': True,
|
||||
'status': 'published',
|
||||
'message': f'产品 "{product_name}" 已在已发布的模型中',
|
||||
'category': 'ai-models',
|
||||
'data': model
|
||||
}
|
||||
|
||||
# 检查已发布的GPU
|
||||
for gpu in result.get('gpus', []):
|
||||
name = gpu.get('name', '').lower().strip()
|
||||
if product_name_lower == name or product_name_lower in name or name in product_name_lower:
|
||||
return {
|
||||
'exists': True,
|
||||
'status': 'published',
|
||||
'message': f'产品 "{product_name}" 已在已发布的GPU中',
|
||||
'category': 'gpus',
|
||||
'data': gpu
|
||||
}
|
||||
|
||||
# 检查已发布的CPU
|
||||
for cpu in result.get('cpus', []):
|
||||
name = cpu.get('name', '').lower().strip()
|
||||
if product_name_lower == name or product_name_lower in name or name in product_name_lower:
|
||||
return {
|
||||
'exists': True,
|
||||
'status': 'published',
|
||||
'message': f'产品 "{product_name}" 已在已发布的CPU中',
|
||||
'category': 'cpus',
|
||||
'data': cpu
|
||||
}
|
||||
|
||||
|
||||
# 2. 检查待审核列表
|
||||
response = self.session.get(
|
||||
f'{self.base_url}/api/reviews',
|
||||
params={'status': 'pending'}
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
reviews = response.json()
|
||||
product_name_lower = product_name.lower().strip()
|
||||
|
||||
for review in reviews:
|
||||
review_data = review.get('data', {})
|
||||
review_name = review_data.get('name', '').lower().strip()
|
||||
|
||||
if product_name_lower == review_name or product_name_lower in review_name or review_name in product_name_lower:
|
||||
return {
|
||||
'exists': True,
|
||||
'status': 'pending',
|
||||
'message': f'产品 "{product_name}" 已在待审核列表中',
|
||||
'review_id': review.get('id'),
|
||||
'category': review.get('category_id'),
|
||||
'data': review
|
||||
}
|
||||
|
||||
|
||||
# 产品不存在
|
||||
return {
|
||||
'exists': False,
|
||||
'status': None,
|
||||
'message': f'产品 "{product_name}" 未在系统中找到'
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
print(f"检查产品是否存在失败: {str(e)}")
|
||||
# 出错时返回不存在,允许后续处理
|
||||
return {
|
||||
'exists': False,
|
||||
'status': None,
|
||||
'message': f'检查失败: {str(e)}'
|
||||
}
|
||||
|
||||
# 全局客户端实例
|
||||
paramhub_client = ParamHubClient()
|
||||
@@ -44,6 +44,37 @@ class DataProcessService:
|
||||
}
|
||||
|
||||
try:
|
||||
# 0. 【新增】检查产品是否已存在于系统中(已发布或待审核)
|
||||
print(f"[检查] 检查产品是否已存在: {product_name}")
|
||||
exists_check = paramhub_client.check_product_exists(product_name)
|
||||
|
||||
if exists_check['exists']:
|
||||
# 产品已存在,不进行后续处理
|
||||
status_text = {
|
||||
'published': '已发布',
|
||||
'pending': '待审核'
|
||||
}.get(exists_check['status'], '未知状态')
|
||||
|
||||
result['message'] = f"产品 '{product_name}' 已在系统中{status_text},跳过处理"
|
||||
print(f"[跳过] {result['message']}")
|
||||
|
||||
# 记录处理历史
|
||||
db.add_process_history(
|
||||
product_name=product_name,
|
||||
category=category,
|
||||
subcategory=subcategory,
|
||||
status='skipped',
|
||||
details={
|
||||
'reason': 'product_exists',
|
||||
'existing_status': exists_check['status'],
|
||||
'existing_data': exists_check.get('data')
|
||||
}
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
print(f"[检查] 产品未找到,继续处理流程")
|
||||
|
||||
# 1. 从内容库和互联网搜索原始数据
|
||||
print(f"[处理] 开始处理产品: {product_name}")
|
||||
search_results = search_service.search_all(
|
||||
|
||||
Reference in New Issue
Block a user