feat: 2026-04-15~05-02 累积变更基线 — AI 重构 + Runtime Context + DWS 修复
涵盖(每条对应已存的审计记录): - AI 模块拆分:apps/backend/app/ai/apps -> prompts/(8 个 APP + app2a 派生) audit: 2026-04-20__ai-module-complete.md - admin-web AI 管理套件:AIDashboard / AIOperations / AIRunLogs / AITriggers / TriggerManager audit: 2026-04-21__admin-web-ai-management-suite.md - App2 财务洞察 prompt v3 -> v5.1 + 小程序 AI 接入(chat / board-finance) audit: 2026-04-22__app2_prompt_v5_1_and_miniprogram_ai_insight.md - App2 prewarm 全过滤器 + AI 触发器 cron reschedule audit: 2026-04-21__app2-finance-prewarm-all-filters.md migration: 20260420_ai_trigger_jobs_and_app2_prewarm.sql / 20260421_app2_prewarm_cron_reschedule.sql - AppType 联合类型对齐 + adminAiAppTypes.test.ts audit: 2026-04-30__admin_web_ai_app_type_alignment.md - DashScope tokens_used 提取修复 audit: 2026-04-30__backend_dashscope_tokens_used_extraction.md - App3 线索完整详情 prompt audit: 2026-05-01__backend_app3_full_detail_prompt.md - Runtime Context 沙箱(5-1~5-2 主线): - 后端 schema/service + admin_runtime_context / xcx_runtime_clock 两个 router - admin-web RuntimeContext.tsx + miniprogram runtime-clock.ts - migration: 20260501__runtime_context_sandbox.sql - tools/db/verify_admin_web_sandbox.py + verify_sandbox_end_to_end.py - database/changes: 7 份 sandbox_* 验证报告 - 飞球 DWS 修复:finance_area_daily 区域汇总 + task_engine 调整 + RLS 视图业务日上界(migration 20260502 + scripts/ops/gen_rls_business_date_migration.py) 合规: - .gitignore 启用 tmp/ 排除 - 不入仓:apps/etl/connectors/feiqiu/.env(API_TOKEN secret,本地修改保留) 待验证清单: - docs/audit/changes/2026-05-04__cumulative_baseline_pending_verification.md 每个主题的功能完整性 / 上线验证几乎都未收口,按优先级 P0~P3 逐一处理
This commit is contained in:
@@ -195,6 +195,7 @@ from typing import Any
|
||||
from fastapi import HTTPException
|
||||
|
||||
from app.services import fdw_queries
|
||||
from app.services.runtime_context import get_runtime_context, task_runtime_filter
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -260,7 +261,8 @@ async def get_coach_board(
|
||||
detail="最近6个月不支持客源储值排序",
|
||||
)
|
||||
|
||||
start_date, end_date = _calc_date_range(time)
|
||||
runtime_ctx = get_runtime_context(site_id)
|
||||
start_date, end_date = _calc_date_range(time, ref_date=runtime_ctx.business_date)
|
||||
start_str = str(start_date)
|
||||
end_str = str(end_date)
|
||||
|
||||
@@ -415,20 +417,22 @@ def _query_coach_tasks(
|
||||
|
||||
result: dict[int, dict] = {}
|
||||
try:
|
||||
runtime_clause, runtime_params = task_runtime_filter(site_id, conn=conn)
|
||||
with conn.cursor() as cur:
|
||||
# 狭义召回+回访完成数:均从 coach_tasks 统计,status='completed' 表示助教亲自完成
|
||||
cur.execute(
|
||||
"""
|
||||
f"""
|
||||
SELECT assistant_id, task_type, COUNT(*) AS cnt
|
||||
FROM biz.coach_tasks
|
||||
WHERE assistant_id = ANY(%s)
|
||||
AND site_id = %s
|
||||
{runtime_clause}
|
||||
AND completed_at >= %s::date
|
||||
AND completed_at < (%s::date + INTERVAL '1 day')::timestamptz
|
||||
AND status = 'completed'
|
||||
GROUP BY assistant_id, task_type
|
||||
""",
|
||||
(assistant_ids, site_id, start_date, end_date),
|
||||
[assistant_ids, site_id, *runtime_params, start_date, end_date],
|
||||
)
|
||||
for row in cur.fetchall():
|
||||
aid, task_type, cnt = row[0], row[1], row[2] or 0
|
||||
@@ -470,13 +474,27 @@ def _batch_ideal_days(conn: Any, site_id: int, member_ids: list[int]) -> dict[in
|
||||
return result
|
||||
|
||||
|
||||
def _batch_coach_details(conn: Any, site_id: int, member_ids: list[int]) -> dict[int, list[dict]]:
|
||||
"""批量查询客户-助教服务明细(loyal 维度 coachDetails 用)。每个客户前 5 个。"""
|
||||
def _batch_coach_details(
|
||||
conn: Any,
|
||||
site_id: int,
|
||||
member_ids: list[int],
|
||||
*,
|
||||
ref_date: date | None = None,
|
||||
) -> dict[int, list[dict]]:
|
||||
"""批量查询客户-助教服务明细(loyal 维度 coachDetails 用)。每个客户前 5 个。
|
||||
|
||||
ref_date 默认从 RuntimeContext 取业务日,用于把 60 天消费窗口的上界落到 ``ref_date`` 上,
|
||||
避免 sandbox 模式下读到 sandbox_date 之后的真实消费。
|
||||
"""
|
||||
from app.services.fdw_queries import _fdw_context
|
||||
from app.services.runtime_context import as_runtime_today_param
|
||||
|
||||
ref = ref_date or as_runtime_today_param(site_id, conn=conn)
|
||||
result: dict[int, list[dict]] = {mid: [] for mid in member_ids}
|
||||
try:
|
||||
with _fdw_context(conn, site_id) as cur:
|
||||
# CHANGE 2026-03-29 | coach_spend 改为从 dwd_assistant_service_log 聚合 60 天消费
|
||||
# CHANGE 2026-05-02 | 用 ref_date(业务日)替代 CURRENT_DATE,沙箱不读「未来」
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT ri.member_id,
|
||||
@@ -493,7 +511,8 @@ def _batch_coach_details(conn: Any, site_id: int, member_ids: list[int]) -> dict
|
||||
SUM(ledger_amount) AS spend_60d
|
||||
FROM app.v_dwd_assistant_service_log
|
||||
WHERE is_delete = 0
|
||||
AND create_time >= CURRENT_DATE - INTERVAL '60 days'
|
||||
AND create_time >= (%s::date - INTERVAL '60 days')
|
||||
AND create_time < (%s::date + INTERVAL '1 day')
|
||||
AND tenant_member_id = ANY(%s)
|
||||
GROUP BY tenant_member_id, site_assistant_id
|
||||
) s60 ON ri.member_id = s60.tenant_member_id
|
||||
@@ -502,7 +521,7 @@ def _batch_coach_details(conn: Any, site_id: int, member_ids: list[int]) -> dict
|
||||
AND (da.leave_status IS NULL OR da.leave_status = 0)
|
||||
ORDER BY ri.member_id, ri.rs_display DESC
|
||||
""",
|
||||
(member_ids, member_ids),
|
||||
(ref, ref, member_ids, member_ids),
|
||||
)
|
||||
for row in cur.fetchall():
|
||||
mid = row[0]
|
||||
@@ -690,7 +709,8 @@ async def get_finance_board(
|
||||
- area≠all 时 overview 覆盖逻辑保留
|
||||
- compare=1 时对上期执行同样缓存/日粒度逻辑
|
||||
"""
|
||||
start_date, end_date = _calc_date_range(time)
|
||||
runtime_ctx = get_runtime_context(site_id)
|
||||
start_date, end_date = _calc_date_range(time, ref_date=runtime_ctx.business_date)
|
||||
start_str = str(start_date)
|
||||
end_str = str(end_date)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user