feat(shipping-notice): 增强订单抽取功能,添加进度事件和诊断运行管理,优化数据模型和访问控制
This commit is contained in:
1 parent
ce26d6d0c4
commit
c4095b08da
175 files changed
+13064
-1814
No files matched your search
@@ -13,6 +13,7 @@ from typing import Any
|
||||
from app import db
|
||||
from app.core.errors import NotFoundError, ValidationError
|
||||
from app.models import Agent, KbDocument, QuickQuestion
|
||||
from app.services.agent_user_access import is_user_application, require_user_application
|
||||
|
||||
|
||||
def parse_aliases(raw_aliases) -> list[str]:
|
||||
@@ -82,6 +83,7 @@ def apply_quick_question_payload(qq: QuickQuestion, data: dict, *, require_answe
|
||||
if 'question' in data:
|
||||
qq.question = str(data['question']).strip()
|
||||
if 'agent_id' in data:
|
||||
require_user_application(db.session.get(Agent, data['agent_id']))
|
||||
qq.agent_id = data['agent_id']
|
||||
if 'sort_order' in data:
|
||||
qq.sort_order = data.get('sort_order', 0)
|
||||
@@ -122,6 +124,8 @@ def list_quick_questions(*, stale_only: bool = False) -> list[dict]:
|
||||
rows = []
|
||||
for q in query.all():
|
||||
agent = db.session.get(Agent, q.agent_id)
|
||||
if not is_user_application(agent):
|
||||
continue
|
||||
stale_doc = db.session.get(KbDocument, q.stale_kb_document_id) if q.stale_kb_document_id else None
|
||||
rows.append(serialize_quick_question(q, agent.name if agent else 'Unknown', stale_doc))
|
||||
return rows
|
||||
@@ -164,6 +168,8 @@ def list_faq_candidates(*, agent_id: int | None = None) -> dict:
|
||||
from app.services.hot_faq_aggregator import HotFaqAggregator
|
||||
from app.services.hot_faq_candidate_store import HotFaqCandidateStore
|
||||
|
||||
if agent_id is not None:
|
||||
require_user_application(db.session.get(Agent, agent_id))
|
||||
items = HotFaqCandidateStore.list_candidates(agent_id)
|
||||
return {
|
||||
'items': items,
|
||||
@@ -176,6 +182,8 @@ def refresh_faq_candidates(*, agent_id: int | None, dry_run: bool) -> dict:
|
||||
"""手动触发离线热点聚合。"""
|
||||
from app.services.hot_faq_aggregator import HotFaqAggregator
|
||||
|
||||
if agent_id is not None:
|
||||
require_user_application(db.session.get(Agent, agent_id))
|
||||
return HotFaqAggregator.aggregate_hot_faq_candidates(agent_id=agent_id, dry_run=dry_run)
|
||||
|
||||
|
||||
@@ -189,6 +197,7 @@ def promote_faq_candidate(data: dict[str, Any]) -> dict:
|
||||
q_norm = normalize_faq_query(str(data.get('q_norm') or ''))
|
||||
if not agent_id or not q_norm:
|
||||
raise ValidationError('agent_id and q_norm are required')
|
||||
require_user_application(db.session.get(Agent, agent_id))
|
||||
|
||||
candidate = HotFaqCandidateStore.get_candidate(int(agent_id), q_norm)
|
||||
if not candidate:
|
||||
@@ -233,5 +242,6 @@ def dismiss_faq_candidate(*, agent_id: int, q_norm: str) -> dict:
|
||||
normalized = normalize_faq_query(q_norm)
|
||||
if not agent_id or not normalized:
|
||||
raise ValidationError('agent_id and q_norm are required')
|
||||
require_user_application(db.session.get(Agent, agent_id))
|
||||
HotFaqCandidateStore.dismiss(int(agent_id), normalized)
|
||||
return {'status': 'ok'}
|
||||
Reference in new issue
Block a user