51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
"""
|
|
backend/app/api/admin/faq_candidates.py
|
|
|
|
用途:热点 FAQ 候选管理 API(薄路由层)。
|
|
依赖:admin.blueprint、services/admin/faq_service。
|
|
逻辑:/faq-candidates* 路由。
|
|
"""
|
|
from flask import jsonify, request
|
|
|
|
from app.api.admin.blueprint import admin_bp
|
|
from app.core.decorators import require_admin
|
|
from app.services.admin import faq_service
|
|
|
|
|
|
@admin_bp.route('/faq-candidates', methods=['GET'])
|
|
@require_admin
|
|
def list_faq_candidates():
|
|
"""列出 PostgreSQL 热点 FAQ 候选。"""
|
|
agent_id = request.args.get('agent_id', type=int)
|
|
return jsonify(faq_service.list_faq_candidates(agent_id=agent_id))
|
|
|
|
|
|
@admin_bp.route('/faq-candidates/refresh', methods=['POST'])
|
|
@require_admin
|
|
def refresh_faq_candidates():
|
|
"""手动触发离线热点聚合。"""
|
|
data = request.get_json(silent=True) or {}
|
|
agent_id = data.get('agent_id')
|
|
dry_run = bool(data.get('dry_run'))
|
|
if agent_id is not None:
|
|
agent_id = int(agent_id)
|
|
return jsonify(faq_service.refresh_faq_candidates(agent_id=agent_id, dry_run=dry_run))
|
|
|
|
|
|
@admin_bp.route('/faq-candidates/promote', methods=['POST'])
|
|
@require_admin
|
|
def promote_faq_candidate():
|
|
"""将热点候选晋升为 QuickQuestion。"""
|
|
data = request.get_json() or {}
|
|
return jsonify(faq_service.promote_faq_candidate(data))
|
|
|
|
|
|
@admin_bp.route('/faq-candidates/dismiss', methods=['POST'])
|
|
@require_admin
|
|
def dismiss_faq_candidate():
|
|
"""忽略热点 FAQ 候选。"""
|
|
data = request.get_json() or {}
|
|
agent_id = data.get('agent_id')
|
|
q_norm = str(data.get('q_norm') or '')
|
|
return jsonify(faq_service.dismiss_faq_candidate(agent_id=int(agent_id), q_norm=q_norm))
|