功能: - 文章内容库管理 - 待处理产品列表管理 - 自动处理流程 - 智能搜索和数据提取 - ParamHub API集成 - 定时任务调度 部署端口: 16043
68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
"""
|
|
系统管理 API
|
|
"""
|
|
from flask import Blueprint, request, jsonify
|
|
from models.database import db
|
|
|
|
bp = Blueprint('system', __name__, url_prefix='/api/system')
|
|
|
|
@bp.route('/config', methods=['GET'])
|
|
def get_config():
|
|
"""获取系统配置"""
|
|
configs = {
|
|
'auto_process_enabled': db.get_system_config('auto_process_enabled', 'true'),
|
|
'process_interval': db.get_system_config('process_interval', '300'),
|
|
'batch_size': db.get_system_config('batch_size', '5')
|
|
}
|
|
|
|
return jsonify({
|
|
'success': True,
|
|
'config': configs
|
|
})
|
|
|
|
@bp.route('/config', methods=['PUT'])
|
|
def update_config():
|
|
"""更新系统配置"""
|
|
data = request.get_json()
|
|
|
|
for key, value in data.items():
|
|
db.set_system_config(key, str(value))
|
|
|
|
return jsonify({
|
|
'success': True,
|
|
'message': '配置已更新'
|
|
})
|
|
|
|
@bp.route('/stats', methods=['GET'])
|
|
def get_stats():
|
|
"""获取系统统计信息"""
|
|
pending_count = db.get_pending_count()
|
|
processing_count = len(db.get_processing_products())
|
|
|
|
# 获取最近处理历史
|
|
recent_history = db.get_process_history(limit=10)
|
|
success_count = len([h for h in recent_history if h['status'] == 'submitted'])
|
|
failed_count = len([h for h in recent_history if h['status'] in ['failed', 'error']])
|
|
|
|
# 获取内容库统计
|
|
articles = db.get_all_articles(limit=1000)
|
|
|
|
return jsonify({
|
|
'success': True,
|
|
'stats': {
|
|
'pending_products': pending_count,
|
|
'processing_products': processing_count,
|
|
'recent_success': success_count,
|
|
'recent_failed': failed_count,
|
|
'total_articles': len(articles)
|
|
}
|
|
})
|
|
|
|
@bp.route('/health', methods=['GET'])
|
|
def health_check():
|
|
"""健康检查"""
|
|
return jsonify({
|
|
'success': True,
|
|
'status': 'healthy',
|
|
'message': '系统运行正常'
|
|
}) |