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:
Neo
2026-05-04 02:30:19 +08:00
parent 2010034840
commit caf179a5da
130 changed files with 14543 additions and 2717 deletions

View File

@@ -1,6 +1,6 @@
-- =============================================================================
-- zqyy_app / biz核心业务表任务/备注/触发器))
-- 生成日期2026-04-06
-- 生成日期2026-05-02
-- 来源:测试库(通过脚本自动导出)
-- =============================================================================
@@ -16,11 +16,11 @@ CREATE SEQUENCE IF NOT EXISTS biz.cfg_task_generator_params_id_seq AS bigint;
CREATE SEQUENCE IF NOT EXISTS biz.coach_task_history_id_seq AS bigint;
CREATE SEQUENCE IF NOT EXISTS biz.coach_task_transfer_log_id_seq AS bigint;
CREATE SEQUENCE IF NOT EXISTS biz.coach_tasks_id_seq AS bigint;
CREATE SEQUENCE IF NOT EXISTS biz.recall_events_id_seq AS bigint;
CREATE SEQUENCE IF NOT EXISTS biz.connectors_id_seq AS integer;
CREATE SEQUENCE IF NOT EXISTS biz.dws_assistant_task_monthly_id_seq AS bigint;
CREATE SEQUENCE IF NOT EXISTS biz.excel_upload_log_id_seq AS bigint;
CREATE SEQUENCE IF NOT EXISTS biz.notes_id_seq AS bigint;
CREATE SEQUENCE IF NOT EXISTS biz.recall_events_id_seq AS bigint;
CREATE SEQUENCE IF NOT EXISTS biz.salary_adjustments_id_seq AS bigint;
CREATE SEQUENCE IF NOT EXISTS biz.site_code_history_id_seq AS integer;
CREATE SEQUENCE IF NOT EXISTS biz.sites_id_seq AS integer;
@@ -41,7 +41,9 @@ CREATE TABLE biz.ai_cache (
triggered_by character varying(100),
created_at timestamp with time zone DEFAULT now() NOT NULL,
expires_at timestamp with time zone,
status character varying(20) DEFAULT 'valid'::character varying
status character varying(20) DEFAULT 'valid'::character varying,
runtime_mode character varying(20) DEFAULT 'live'::character varying NOT NULL,
sandbox_instance_id character varying(64) DEFAULT 'live'::character varying NOT NULL
);
CREATE TABLE biz.ai_conversations (
@@ -86,7 +88,9 @@ CREATE TABLE biz.ai_run_logs (
session_id character varying(100),
created_at timestamp with time zone DEFAULT now() NOT NULL,
finished_at timestamp with time zone,
alert_status character varying(20) DEFAULT NULL::character varying
alert_status character varying(20) DEFAULT NULL::character varying,
runtime_mode character varying(20) DEFAULT 'live'::character varying NOT NULL,
sandbox_instance_id character varying(64) DEFAULT 'live'::character varying NOT NULL
);
CREATE TABLE biz.ai_trigger_jobs (
@@ -102,7 +106,9 @@ CREATE TABLE biz.ai_trigger_jobs (
started_at timestamp with time zone,
finished_at timestamp with time zone,
error_message text,
created_at timestamp with time zone DEFAULT now() NOT NULL
created_at timestamp with time zone DEFAULT now() NOT NULL,
runtime_mode character varying(20) DEFAULT 'live'::character varying NOT NULL,
sandbox_instance_id character varying(64) DEFAULT 'live'::character varying NOT NULL
);
CREATE TABLE biz.cfg_task_generator_params (
@@ -124,7 +130,9 @@ CREATE TABLE biz.coach_task_history (
old_task_type character varying(50),
new_task_type character varying(50),
detail jsonb,
created_at timestamp with time zone DEFAULT now()
created_at timestamp with time zone DEFAULT now(),
runtime_mode character varying(20) DEFAULT 'live'::character varying NOT NULL,
sandbox_instance_id character varying(64) DEFAULT 'live'::character varying NOT NULL
);
CREATE TABLE biz.coach_task_transfer_log (
@@ -138,7 +146,9 @@ CREATE TABLE biz.coach_task_transfer_log (
transfer_reason text,
guard_checks jsonb,
transfer_score numeric,
created_at timestamp with time zone DEFAULT now() NOT NULL
created_at timestamp with time zone DEFAULT now() NOT NULL,
runtime_mode character varying(20) DEFAULT 'live'::character varying NOT NULL,
sandbox_instance_id character varying(64) DEFAULT 'live'::character varying NOT NULL
);
CREATE TABLE biz.coach_tasks (
@@ -154,24 +164,15 @@ CREATE TABLE biz.coach_tasks (
abandon_reason text,
completed_at timestamp with time zone,
completed_task_type character varying(50),
completion_type character varying(10),
parent_task_id bigint,
created_at timestamp with time zone DEFAULT now(),
updated_at timestamp with time zone DEFAULT now(),
transfer_count integer DEFAULT 0 NOT NULL,
transferred_from bigint,
transferred_at timestamp with time zone
);
CREATE TABLE biz.recall_events (
id bigint DEFAULT nextval('biz.recall_events_id_seq'::regclass) NOT NULL,
site_id bigint NOT NULL,
assistant_id bigint NOT NULL,
member_id bigint NOT NULL,
pay_time timestamp with time zone NOT NULL,
task_id bigint,
task_type character varying(50),
created_at timestamp with time zone DEFAULT now()
transferred_at timestamp with time zone,
completion_type character varying(10),
runtime_mode character varying(20) DEFAULT 'live'::character varying NOT NULL,
sandbox_instance_id character varying(64) DEFAULT 'live'::character varying NOT NULL
);
CREATE TABLE biz.connectors (
@@ -232,6 +233,19 @@ CREATE TABLE biz.notes (
score smallint
);
CREATE TABLE biz.recall_events (
id bigint DEFAULT nextval('biz.recall_events_id_seq'::regclass) NOT NULL,
site_id bigint NOT NULL,
assistant_id bigint NOT NULL,
member_id bigint NOT NULL,
pay_time timestamp with time zone NOT NULL,
task_id bigint,
task_type character varying(50),
created_at timestamp with time zone DEFAULT now(),
runtime_mode character varying(20) DEFAULT 'live'::character varying NOT NULL,
sandbox_instance_id character varying(64) DEFAULT 'live'::character varying NOT NULL
);
CREATE TABLE biz.salary_adjustments (
id bigint DEFAULT nextval('biz.salary_adjustments_id_seq'::regclass) NOT NULL,
site_id bigint NOT NULL,
@@ -256,6 +270,19 @@ CREATE TABLE biz.site_code_history (
retired_at timestamp with time zone
);
CREATE TABLE biz.site_runtime_context (
site_id bigint NOT NULL,
mode character varying(20) DEFAULT 'live'::character varying NOT NULL,
sandbox_date date,
sandbox_instance_id character varying(64),
ai_mode character varying(20) DEFAULT 'live'::character varying NOT NULL,
status character varying(20) DEFAULT 'active'::character varying NOT NULL,
reason text,
updated_by bigint,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL
);
CREATE TABLE biz.sites (
id integer DEFAULT nextval('biz.sites_id_seq'::regclass) NOT NULL,
tenant_id integer NOT NULL,
@@ -354,12 +381,14 @@ ALTER TABLE biz.dws_assistant_task_monthly ADD CONSTRAINT dws_assistant_task_mon
ALTER TABLE biz.excel_upload_log ADD CONSTRAINT excel_upload_log_pkey PRIMARY KEY (id);
ALTER TABLE biz.notes ADD CONSTRAINT notes_task_id_fkey FOREIGN KEY (task_id) REFERENCES biz.coach_tasks(id);
ALTER TABLE biz.notes ADD CONSTRAINT notes_pkey PRIMARY KEY (id);
ALTER TABLE biz.recall_events ADD CONSTRAINT recall_events_pkey PRIMARY KEY (id);
ALTER TABLE biz.recall_events ADD CONSTRAINT recall_events_task_id_fkey FOREIGN KEY (task_id) REFERENCES biz.coach_tasks(id);
ALTER TABLE biz.recall_events ADD CONSTRAINT recall_events_pkey PRIMARY KEY (id);
ALTER TABLE biz.salary_adjustments ADD CONSTRAINT salary_adjustments_upload_batch_id_fkey FOREIGN KEY (upload_batch_id) REFERENCES biz.excel_upload_log(id);
ALTER TABLE biz.salary_adjustments ADD CONSTRAINT salary_adjustments_pkey PRIMARY KEY (id);
ALTER TABLE biz.site_code_history ADD CONSTRAINT site_code_history_pkey PRIMARY KEY (id);
ALTER TABLE biz.site_code_history ADD CONSTRAINT site_code_history_site_code_key UNIQUE (site_code);
ALTER TABLE biz.site_runtime_context ADD CONSTRAINT site_runtime_context_site_id_fkey FOREIGN KEY (site_id) REFERENCES biz.sites(site_id);
ALTER TABLE biz.site_runtime_context ADD CONSTRAINT site_runtime_context_pkey PRIMARY KEY (site_id);
ALTER TABLE biz.sites ADD CONSTRAINT sites_tenant_id_fkey FOREIGN KEY (tenant_id) REFERENCES biz.tenants(id);
ALTER TABLE biz.sites ADD CONSTRAINT sites_pkey PRIMARY KEY (id);
ALTER TABLE biz.sites ADD CONSTRAINT sites_site_code_key UNIQUE (site_code);
@@ -379,6 +408,7 @@ ALTER TABLE biz.trigger_jobs ADD CONSTRAINT trigger_jobs_job_name_key UNIQUE (jo
-- 索引
CREATE INDEX idx_ai_cache_cleanup ON biz.ai_cache USING btree (cache_type, site_id, target_id, created_at);
CREATE INDEX idx_ai_cache_lookup ON biz.ai_cache USING btree (cache_type, site_id, target_id, created_at DESC);
CREATE INDEX idx_ai_cache_runtime_lookup ON biz.ai_cache USING btree (cache_type, site_id, runtime_mode, sandbox_instance_id, target_id, created_at DESC);
CREATE INDEX idx_ai_conv_app_site ON biz.ai_conversations USING btree (app_id, site_id, created_at DESC);
CREATE INDEX idx_ai_conv_context ON biz.ai_conversations USING btree (user_id, site_id, context_type, context_id, last_message_at DESC NULLS LAST) WHERE (context_type IS NOT NULL);
CREATE INDEX idx_ai_conv_last_msg ON biz.ai_conversations USING btree (user_id, site_id, last_message_at DESC NULLS LAST);
@@ -390,18 +420,20 @@ CREATE INDEX idx_ai_run_logs_created_brin ON biz.ai_run_logs USING brin (created
CREATE INDEX idx_ai_run_logs_site_app ON biz.ai_run_logs USING btree (site_id, app_type);
CREATE INDEX idx_ai_run_logs_status ON biz.ai_run_logs USING btree (status);
CREATE INDEX idx_ai_trigger_jobs_dedup ON biz.ai_trigger_jobs USING btree (event_type, member_id, site_id, created_at) WHERE ((status)::text <> 'skipped_duplicate'::text);
CREATE INDEX idx_ai_trigger_jobs_runtime_site ON biz.ai_trigger_jobs USING btree (site_id, runtime_mode, sandbox_instance_id, event_type, status);
CREATE INDEX idx_ai_trigger_jobs_site ON biz.ai_trigger_jobs USING btree (site_id, event_type);
CREATE INDEX idx_ai_trigger_jobs_status ON biz.ai_trigger_jobs USING btree (status);
CREATE INDEX idx_transfer_log_member ON biz.coach_task_transfer_log USING btree (member_id, created_at DESC);
CREATE INDEX idx_transfer_log_site_created ON biz.coach_task_transfer_log USING btree (site_id, created_at DESC);
CREATE INDEX idx_coach_tasks_assistant_status ON biz.coach_tasks USING btree (site_id, assistant_id, status);
CREATE UNIQUE INDEX idx_coach_tasks_site_assistant_member_type ON biz.coach_tasks USING btree (site_id, assistant_id, member_id, task_type) WHERE ((status)::text = 'active'::text);
CREATE INDEX idx_coach_tasks_runtime_assistant_status ON biz.coach_tasks USING btree (site_id, runtime_mode, sandbox_instance_id, assistant_id, status);
CREATE UNIQUE INDEX idx_coach_tasks_runtime_unique_active ON biz.coach_tasks USING btree (site_id, assistant_id, member_id, task_type, runtime_mode, sandbox_instance_id) WHERE ((status)::text = 'active'::text);
CREATE INDEX idx_task_monthly_assistant ON biz.dws_assistant_task_monthly USING btree (assistant_id, stat_month DESC);
CREATE INDEX idx_task_monthly_site_month ON biz.dws_assistant_task_monthly USING btree (site_id, stat_month DESC);
CREATE INDEX idx_excel_log_site ON biz.excel_upload_log USING btree (site_id, created_at DESC);
CREATE INDEX idx_notes_target ON biz.notes USING btree (site_id, target_type, target_id);
CREATE INDEX idx_salary_adj_assistant_month ON biz.salary_adjustments USING btree (assistant_id, salary_month);
CREATE UNIQUE INDEX idx_recall_events_site_assistant_member_day ON biz.recall_events USING btree (site_id, assistant_id, member_id, (date_trunc('day', pay_time AT TIME ZONE 'Asia/Shanghai')));
CREATE INDEX idx_recall_events_assistant_pay ON biz.recall_events USING btree (site_id, assistant_id, pay_time);
CREATE UNIQUE INDEX idx_recall_events_runtime_site_assistant_member_day ON biz.recall_events USING btree (site_id, assistant_id, member_id, runtime_mode, sandbox_instance_id, date_trunc('day'::text, (pay_time AT TIME ZONE 'Asia/Shanghai'::text)));
CREATE INDEX idx_salary_adj_assistant_month ON biz.salary_adjustments USING btree (assistant_id, salary_month);
CREATE INDEX idx_salary_adj_site_month ON biz.salary_adjustments USING btree (site_id, salary_month);