微信小程序页面迁移校验之前 P5任务处理之前

This commit is contained in:
Neo
2026-03-09 01:19:21 +08:00
parent 263bf96035
commit 6e20987d2f
1112 changed files with 153824 additions and 219694 deletions

View File

@@ -1,6 +1,6 @@
-- =============================================================================
-- etl_feiqiu / appRLS 视图层)
-- 生成日期2026-02-25
-- 生成日期2026-02-27
-- 来源:测试库(通过脚本自动导出)
-- =============================================================================
@@ -322,6 +322,9 @@ SELECT recharge_order_id,
WHERE (site_id = (current_setting('app.current_site_id'::text))::bigint);
;
-- ⚠️ consume_money 透传自 DWD 层存在三种历史口径A/B/CAPI 消费端不应直接展示或参与计算。
-- 应使用 items_sum = table_charge_money + goods_money + assistant_pd_money + assistant_cx_money + electricity_money
-- settle_type 枚举1=台桌结账, 3=商城订单, 6=退货订单, 7=退款订单(本表无 is_delete 字段)
CREATE OR REPLACE VIEW app.v_dwd_settlement_head AS
SELECT order_settle_id,
tenant_id,
@@ -683,7 +686,7 @@ SELECT id,
platform_fee_amount,
recharge_cash_inflow,
card_consume_total,
cash_card_consume,
recharge_card_consume,
gift_card_consume,
cash_outflow_total,
cash_balance_change,
@@ -992,7 +995,8 @@ SELECT id,
total_discount,
actual_pay,
cash_pay,
cash_card_pay,
balance_pay,
recharge_card_pay,
gift_card_pay,
groupbuy_pay,
table_duration_min,

View File

@@ -1,6 +1,6 @@
-- =============================================================================
-- etl_feiqiu / core跨门店标准化维度/事实)
-- 生成日期2026-02-25
-- 生成日期2026-02-27
-- 来源:测试库(通过脚本自动导出)
-- =============================================================================

View File

@@ -1,6 +1,6 @@
-- =============================================================================
-- etl_feiqiu / dwd明细数据层
-- 生成日期2026-02-25
-- 生成日期2026-02-27
-- 来源:测试库(通过脚本自动导出)
-- =============================================================================
@@ -616,27 +616,6 @@ CREATE TABLE dwd.dwd_assistant_service_log_ex (
operator_name text
);
CREATE TABLE dwd.dwd_assistant_trash_event (
assistant_trash_event_id bigint NOT NULL,
site_id bigint,
table_id bigint,
table_area_id bigint,
assistant_no character varying(32),
assistant_name character varying(64),
charge_minutes_raw integer,
abolish_amount numeric(18,2),
trash_reason character varying(255),
create_time timestamp with time zone,
tenant_id bigint
);
CREATE TABLE dwd.dwd_assistant_trash_event_ex (
assistant_trash_event_id bigint NOT NULL,
table_name character varying(64),
table_area_name character varying(64),
assistant_no_int integer
);
CREATE TABLE dwd.dwd_goods_stock_movement (
site_goods_stock_id bigint NOT NULL,
tenant_id bigint,
@@ -1170,8 +1149,6 @@ ALTER TABLE dwd.dim_tenant_goods ADD CONSTRAINT dim_tenant_goods_pkey PRIMARY KE
ALTER TABLE dwd.dim_tenant_goods_ex ADD CONSTRAINT dim_tenant_goods_ex_pkey PRIMARY KEY (tenant_goods_id, scd2_start_time);
ALTER TABLE dwd.dwd_assistant_service_log ADD CONSTRAINT dwd_assistant_service_log_pkey PRIMARY KEY (assistant_service_id);
ALTER TABLE dwd.dwd_assistant_service_log_ex ADD CONSTRAINT dwd_assistant_service_log_ex_pkey PRIMARY KEY (assistant_service_id);
ALTER TABLE dwd.dwd_assistant_trash_event ADD CONSTRAINT dwd_assistant_trash_event_pkey PRIMARY KEY (assistant_trash_event_id);
ALTER TABLE dwd.dwd_assistant_trash_event_ex ADD CONSTRAINT dwd_assistant_trash_event_ex_pkey PRIMARY KEY (assistant_trash_event_id);
ALTER TABLE dwd.dwd_goods_stock_movement ADD CONSTRAINT dwd_goods_stock_movement_pkey PRIMARY KEY (site_goods_stock_id);
ALTER TABLE dwd.dwd_goods_stock_summary ADD CONSTRAINT dwd_goods_stock_summary_pkey PRIMARY KEY (site_goods_id, fetched_at);
ALTER TABLE dwd.dwd_groupbuy_redemption ADD CONSTRAINT dwd_groupbuy_redemption_pkey PRIMARY KEY (redemption_id);
@@ -1262,8 +1239,6 @@ CREATE INDEX idx_dwd_assistant_service_log_time_create_time ON dwd.dwd_assistant
CREATE INDEX idx_dwd_assistant_service_log_time_pk_118fd0d3 ON dwd.dwd_assistant_service_log USING btree (create_time, assistant_service_id);
CREATE INDEX idx_dwd_assistant_service_log_time_pk_3fb2dede ON dwd.dwd_assistant_service_log USING btree (start_use_time, assistant_service_id);
CREATE INDEX idx_dwd_assistant_service_log_time_start_use_time ON dwd.dwd_assistant_service_log USING btree (start_use_time);
CREATE INDEX idx_dwd_assistant_trash_event_time_create_time ON dwd.dwd_assistant_trash_event USING btree (create_time);
CREATE INDEX idx_dwd_assistant_trash_event_time_pk_0b64af2a ON dwd.dwd_assistant_trash_event USING btree (create_time, assistant_trash_event_id);
CREATE INDEX idx_dwd_groupbuy_redemption_time_create_time ON dwd.dwd_groupbuy_redemption USING btree (create_time);
CREATE INDEX idx_dwd_groupbuy_redemption_time_pk_create_time_redemption_id ON dwd.dwd_groupbuy_redemption USING btree (create_time, redemption_id);
CREATE INDEX idx_dwd_payment_time_create_time ON dwd.dwd_payment USING btree (create_time);

View File

@@ -1,6 +1,6 @@
-- =============================================================================
-- etl_feiqiu / dws汇总数据层
-- 生成日期2026-02-25
-- 生成日期2026-02-27
-- 来源:测试库(通过脚本自动导出)
-- =============================================================================
@@ -42,8 +42,11 @@ CREATE SEQUENCE IF NOT EXISTS dws.dws_platform_settlement_id_seq AS bigint;
CREATE TABLE dws.cfg_area_category (
category_id integer DEFAULT nextval('dws.cfg_area_category_category_id_seq'::regclass) NOT NULL,
source_area_name character varying(100) NOT NULL,
source_table_name character varying(100) DEFAULT NULL,
category_code character varying(20) NOT NULL,
category_name character varying(50) NOT NULL,
display_name character varying(50) DEFAULT NULL,
short_name character varying(20) DEFAULT NULL,
match_type character varying(10) DEFAULT 'EXACT'::character varying NOT NULL,
match_priority integer DEFAULT 100 NOT NULL,
is_active boolean DEFAULT true NOT NULL,
@@ -51,6 +54,9 @@ CREATE TABLE dws.cfg_area_category (
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL
);
-- 唯一约束:(source_area_name, source_table_name) 支持同一台区下按台桌细分
CREATE UNIQUE INDEX uk_cfg_area_category
ON dws.cfg_area_category (source_area_name, COALESCE(source_table_name, ''));
CREATE TABLE dws.cfg_assistant_level_price (
price_id integer DEFAULT nextval('dws.cfg_assistant_level_price_price_id_seq'::regclass) NOT NULL,
@@ -102,7 +108,7 @@ CREATE TABLE dws.cfg_performance_tier (
min_hours numeric(10,2) NOT NULL,
max_hours numeric(10,2),
base_deduction numeric(10,2) DEFAULT 0 NOT NULL,
bonus_deduction_ratio numeric(5,4) DEFAULT 0 NOT NULL,
bonus_deduction_ratio numeric(7,4) DEFAULT 0 NOT NULL,
vacation_days integer DEFAULT 0 NOT NULL,
vacation_unlimited boolean DEFAULT false NOT NULL,
is_new_hire_tier boolean DEFAULT false NOT NULL,
@@ -215,7 +221,7 @@ CREATE TABLE dws.dws_assistant_finance_analysis (
revenue_room numeric(14,2) DEFAULT 0 NOT NULL,
cost_daily numeric(14,2) DEFAULT 0 NOT NULL,
gross_profit numeric(14,2) DEFAULT 0 NOT NULL,
gross_margin numeric(5,4) DEFAULT 0 NOT NULL,
gross_margin numeric(7,4) DEFAULT 0 NOT NULL,
service_count integer DEFAULT 0 NOT NULL,
service_hours numeric(10,2) DEFAULT 0 NOT NULL,
room_service_count integer DEFAULT 0 NOT NULL,
@@ -265,8 +271,8 @@ CREATE TABLE dws.dws_assistant_monthly_summary (
CREATE TABLE dws.dws_assistant_order_contribution (
contribution_id bigint DEFAULT nextval('dws.dws_assistant_order_contribution_contribution_id_seq'::regclass) NOT NULL,
site_id integer NOT NULL,
tenant_id integer NOT NULL,
site_id bigint NOT NULL,
tenant_id bigint NOT NULL,
assistant_id bigint NOT NULL,
assistant_nickname character varying(100),
stat_date date NOT NULL,
@@ -291,7 +297,7 @@ CREATE TABLE dws.dws_assistant_recharge_commission (
recharge_order_no character varying(50),
recharge_amount numeric(12,2) DEFAULT 0 NOT NULL,
commission_amount numeric(12,2) DEFAULT 0 NOT NULL,
commission_ratio numeric(5,4),
commission_ratio numeric(7,4),
import_batch_no character varying(50),
import_file_name character varying(200),
import_time timestamp with time zone,
@@ -323,7 +329,7 @@ CREATE TABLE dws.dws_assistant_salary_calc (
base_course_price numeric(10,2) DEFAULT 0 NOT NULL,
bonus_course_price numeric(10,2) DEFAULT 0 NOT NULL,
base_deduction numeric(10,2) DEFAULT 0 NOT NULL,
bonus_deduction_ratio numeric(5,4) DEFAULT 0 NOT NULL,
bonus_deduction_ratio numeric(7,4) DEFAULT 0 NOT NULL,
base_income numeric(12,2) DEFAULT 0 NOT NULL,
bonus_income numeric(12,2) DEFAULT 0 NOT NULL,
room_income numeric(12,2) DEFAULT 0 NOT NULL,
@@ -366,7 +372,7 @@ CREATE TABLE dws.dws_finance_daily_summary (
platform_fee_amount numeric(14,2) DEFAULT 0 NOT NULL,
recharge_cash_inflow numeric(14,2) DEFAULT 0 NOT NULL,
card_consume_total numeric(14,2) DEFAULT 0 NOT NULL,
cash_card_consume numeric(14,2) DEFAULT 0 NOT NULL,
recharge_card_consume numeric(14,2) DEFAULT 0 NOT NULL,
gift_card_consume numeric(14,2) DEFAULT 0 NOT NULL,
cash_outflow_total numeric(14,2) DEFAULT 0 NOT NULL,
cash_balance_change numeric(14,2) DEFAULT 0 NOT NULL,
@@ -394,7 +400,7 @@ CREATE TABLE dws.dws_finance_discount_detail (
discount_type_code character varying(30) NOT NULL,
discount_type_name character varying(50) NOT NULL,
discount_amount numeric(14,2) DEFAULT 0 NOT NULL,
discount_ratio numeric(5,4) DEFAULT 0 NOT NULL,
discount_ratio numeric(7,4) DEFAULT 0 NOT NULL,
usage_count integer DEFAULT 0 NOT NULL,
affected_orders integer DEFAULT 0 NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
@@ -429,7 +435,7 @@ CREATE TABLE dws.dws_finance_income_structure (
category_code character varying(30) NOT NULL,
category_name character varying(50) NOT NULL,
income_amount numeric(14,2) DEFAULT 0 NOT NULL,
income_ratio numeric(5,4) DEFAULT 0 NOT NULL,
income_ratio numeric(7,4) DEFAULT 0 NOT NULL,
order_count integer DEFAULT 0 NOT NULL,
duration_minutes integer DEFAULT 0 NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
@@ -564,7 +570,7 @@ CREATE TABLE dws.dws_member_assistant_intimacy (
score_recency numeric(10,4),
score_recharge numeric(10,4),
score_duration numeric(10,4),
burst_multiplier numeric(6,4),
burst_multiplier numeric(7,4),
raw_score numeric(14,6),
display_score numeric(4,2),
calc_time timestamp with time zone DEFAULT now() NOT NULL,
@@ -720,7 +726,7 @@ CREATE TABLE dws.dws_member_recall_index (
CREATE TABLE dws.dws_member_spending_power_index (
spi_id bigint DEFAULT nextval('dws.dws_member_spending_power_index_spi_id_seq'::regclass) NOT NULL,
site_id integer NOT NULL,
site_id bigint NOT NULL,
member_id bigint NOT NULL,
spend_30 numeric(14,2) DEFAULT 0,
spend_90 numeric(14,2) DEFAULT 0,
@@ -767,7 +773,8 @@ CREATE TABLE dws.dws_member_visit_detail (
total_discount numeric(12,2) DEFAULT 0 NOT NULL,
actual_pay numeric(12,2) DEFAULT 0 NOT NULL,
cash_pay numeric(12,2) DEFAULT 0 NOT NULL,
cash_card_pay numeric(12,2) DEFAULT 0 NOT NULL,
balance_pay numeric(12,2) DEFAULT 0 NOT NULL,
recharge_card_pay numeric(12,2) DEFAULT 0 NOT NULL,
gift_card_pay numeric(12,2) DEFAULT 0 NOT NULL,
groupbuy_pay numeric(12,2) DEFAULT 0 NOT NULL,
table_duration_min integer DEFAULT 0 NOT NULL,
@@ -1310,7 +1317,7 @@ SELECT id,
platform_fee_amount,
recharge_cash_inflow,
card_consume_total,
cash_card_consume,
recharge_card_consume,
gift_card_consume,
cash_outflow_total,
cash_balance_change,
@@ -1357,7 +1364,7 @@ SELECT id,
platform_fee_amount,
recharge_cash_inflow,
card_consume_total,
cash_card_consume,
recharge_card_consume,
gift_card_consume,
cash_outflow_total,
cash_balance_change,
@@ -1404,7 +1411,7 @@ SELECT id,
platform_fee_amount,
recharge_cash_inflow,
card_consume_total,
cash_card_consume,
recharge_card_consume,
gift_card_consume,
cash_outflow_total,
cash_balance_change,
@@ -1451,7 +1458,7 @@ SELECT id,
platform_fee_amount,
recharge_cash_inflow,
card_consume_total,
cash_card_consume,
recharge_card_consume,
gift_card_consume,
cash_outflow_total,
cash_balance_change,
@@ -1483,3 +1490,69 @@ CREATE INDEX idx_mv_finance_daily_l2 ON dws.mv_dws_finance_daily_summary_l2 USIN
CREATE INDEX idx_mv_finance_daily_l3 ON dws.mv_dws_finance_daily_summary_l3 USING btree (site_id, stat_date);
CREATE INDEX idx_mv_finance_daily_l4 ON dws.mv_dws_finance_daily_summary_l4 USING btree (site_id, stat_date);
-- =============================================================================
-- 项目标签表2026-03-07 新增)
-- =============================================================================
CREATE SEQUENCE IF NOT EXISTS dws.dws_assistant_project_tag_id_seq AS bigint;
CREATE SEQUENCE IF NOT EXISTS dws.dws_member_project_tag_id_seq AS bigint;
CREATE TABLE dws.dws_assistant_project_tag (
id BIGSERIAL NOT NULL,
site_id BIGINT NOT NULL,
tenant_id BIGINT NOT NULL,
assistant_id BIGINT NOT NULL,
time_window VARCHAR(40) NOT NULL,
category_code VARCHAR(30) NOT NULL,
category_name VARCHAR(50) NOT NULL,
short_name VARCHAR(10) NOT NULL,
duration_seconds BIGINT NOT NULL DEFAULT 0,
total_seconds BIGINT NOT NULL DEFAULT 0,
percentage NUMERIC(5,4) NOT NULL DEFAULT 0,
is_tagged BOOLEAN NOT NULL DEFAULT FALSE,
computed_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT pk_dws_assistant_project_tag PRIMARY KEY (id),
CONSTRAINT uk_dws_assistant_project_tag
UNIQUE (site_id, assistant_id, time_window, category_code)
);
COMMENT ON TABLE dws.dws_assistant_project_tag IS '助教项目标签按时间窗口计算各项目时长占比≥25%分配标签';
COMMENT ON COLUMN dws.dws_assistant_project_tag.time_window IS '时间窗口THIS_MONTH/THIS_QUARTER/LAST_MONTH/LAST_3_MONTHS_EXCL_CURRENT/LAST_QUARTER/LAST_6_MONTHS';
COMMENT ON COLUMN dws.dws_assistant_project_tag.is_tagged IS '占比≥0.25时为TRUE表示该助教拥有此项目标签';
CREATE TABLE dws.dws_member_project_tag (
id BIGSERIAL NOT NULL,
site_id BIGINT NOT NULL,
tenant_id BIGINT NOT NULL,
member_id BIGINT NOT NULL,
time_window VARCHAR(40) NOT NULL,
category_code VARCHAR(30) NOT NULL,
category_name VARCHAR(50) NOT NULL,
short_name VARCHAR(10) NOT NULL,
duration_seconds BIGINT NOT NULL DEFAULT 0,
total_seconds BIGINT NOT NULL DEFAULT 0,
percentage NUMERIC(5,4) NOT NULL DEFAULT 0,
is_tagged BOOLEAN NOT NULL DEFAULT FALSE,
computed_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT pk_dws_member_project_tag PRIMARY KEY (id),
CONSTRAINT uk_dws_member_project_tag
UNIQUE (site_id, member_id, time_window, category_code)
);
COMMENT ON TABLE dws.dws_member_project_tag IS '客户项目标签按时间窗口计算各项目消费时长占比≥25%分配标签';
COMMENT ON COLUMN dws.dws_member_project_tag.time_window IS '时间窗口LAST_30_DAYS/LAST_60_DAYS';
COMMENT ON COLUMN dws.dws_member_project_tag.is_tagged IS '占比≥0.25时为TRUE表示该客户拥有此项目标签';
-- 部分索引(加速看板查询)
CREATE INDEX idx_apt_site_window_tagged
ON dws.dws_assistant_project_tag (site_id, time_window)
WHERE is_tagged = TRUE;
CREATE INDEX idx_mpt_site_window_tagged
ON dws.dws_member_project_tag (site_id, time_window)
WHERE is_tagged = TRUE;

View File

@@ -1,6 +1,6 @@
-- =============================================================================
-- etl_feiqiu / metaETL 调度元数据)
-- 生成日期2026-02-25
-- 生成日期2026-02-27
-- 来源:测试库(通过脚本自动导出)
-- =============================================================================

View File

@@ -1,6 +1,6 @@
-- =============================================================================
-- etl_feiqiu / ods原始数据层
-- 生成日期2026-02-25
-- 生成日期2026-02-27
-- 来源:测试库(通过脚本自动导出)
-- =============================================================================
@@ -77,28 +77,6 @@ CREATE TABLE ods.assistant_accounts_master (
payload jsonb NOT NULL
);
CREATE TABLE ods.assistant_cancellation_records (
id bigint NOT NULL,
siteid bigint,
siteprofile jsonb,
assistantname text,
assistantabolishamount numeric(18,2),
assistanton integer,
pdchargeminutes integer,
tableareaid bigint,
tablearea text,
tableid bigint,
tablename text,
trashreason text,
createtime timestamp without time zone,
tenant_id bigint,
content_hash text NOT NULL,
source_file text,
source_endpoint text,
fetched_at timestamp with time zone DEFAULT now(),
payload jsonb NOT NULL
);
CREATE TABLE ods.assistant_service_records (
id bigint NOT NULL,
tenant_id bigint,
@@ -215,6 +193,7 @@ CREATE TABLE ods.goods_stock_summary (
rangesalemoney numeric(18,2),
rangeinventory numeric(18,4),
currentstock numeric(18,4),
siteid bigint,
content_hash text NOT NULL,
source_file text,
source_endpoint text,
@@ -1066,7 +1045,6 @@ CREATE TABLE ods.tenant_goods_master (
-- 约束(主键 / 唯一 / 外键)
ALTER TABLE ods.assistant_accounts_master ADD CONSTRAINT assistant_accounts_master_pkey PRIMARY KEY (id, content_hash);
ALTER TABLE ods.assistant_cancellation_records ADD CONSTRAINT assistant_cancellation_records_pkey PRIMARY KEY (id, content_hash);
ALTER TABLE ods.assistant_service_records ADD CONSTRAINT assistant_service_records_pkey PRIMARY KEY (id, content_hash);
ALTER TABLE ods.goods_stock_movements ADD CONSTRAINT goods_stock_movements_pkey PRIMARY KEY (sitegoodsstockid, content_hash);
ALTER TABLE ods.goods_stock_summary ADD CONSTRAINT goods_stock_summary_pkey PRIMARY KEY (sitegoodsid, content_hash);
@@ -1091,8 +1069,6 @@ ALTER TABLE ods.tenant_goods_master ADD CONSTRAINT tenant_goods_master_pkey PRIM
-- 索引
CREATE INDEX idx_assistant_accounts_master_fetched_at_fetched_at ON ods.assistant_accounts_master USING btree (fetched_at);
CREATE INDEX idx_assistant_accounts_master_fetched_pk_d986993f ON ods.assistant_accounts_master USING btree (fetched_at, id, content_hash);
CREATE INDEX idx_assistant_cancellation_records_fetched_at_fetched_at ON ods.assistant_cancellation_records USING btree (fetched_at);
CREATE INDEX idx_assistant_cancellation_records_fetched_pk_258b411c ON ods.assistant_cancellation_records USING btree (fetched_at, id, content_hash);
CREATE INDEX idx_assistant_service_records_fetched_at_fetched_at ON ods.assistant_service_records USING btree (fetched_at);
CREATE INDEX idx_assistant_service_records_fetched_pk_e200787c ON ods.assistant_service_records USING btree (fetched_at, id, content_hash);
CREATE INDEX idx_goods_stock_movements_fetched_at_fetched_at ON ods.goods_stock_movements USING btree (fetched_at);

View File

@@ -1,6 +1,6 @@
-- =============================================================================
-- FDW 跨库映射(在 zqyy_app 中执行)
-- 生成日期2026-02-25
-- 生成日期2026-02-27
-- 来源db/fdw/setup_fdw.sql
-- =============================================================================

View File

@@ -1,6 +1,6 @@
-- =============================================================================
-- zqyy_app / auth用户认证与权限
-- 生成日期2026-02-25
-- 生成日期2026-02-27
-- 来源:测试库(通过脚本自动导出)
-- =============================================================================
@@ -42,7 +42,7 @@ CREATE TABLE auth.site_code_mapping (
site_code character varying(10) NOT NULL,
site_id bigint NOT NULL,
site_name character varying(200),
tenant_id integer,
tenant_id bigint,
created_at timestamp with time zone DEFAULT now() NOT NULL
);
@@ -86,7 +86,7 @@ CREATE TABLE auth.users (
wx_avatar_url text,
nickname character varying(100),
phone character varying(20),
status character varying(20) DEFAULT 'pending'::character varying NOT NULL,
status character varying(20) DEFAULT 'new'::character varying NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL
);

View File

@@ -0,0 +1,89 @@
-- =============================================================================
-- zqyy_app / biz核心业务表任务/备注/触发器))
-- 生成日期2026-02-27
-- 来源:测试库(通过脚本自动导出)
-- =============================================================================
CREATE SCHEMA IF NOT EXISTS biz;
-- 序列
CREATE SEQUENCE IF NOT EXISTS biz.coach_task_history_id_seq AS bigint;
CREATE SEQUENCE IF NOT EXISTS biz.coach_tasks_id_seq AS bigint;
CREATE SEQUENCE IF NOT EXISTS biz.notes_id_seq AS bigint;
CREATE SEQUENCE IF NOT EXISTS biz.trigger_jobs_id_seq AS integer;
-- 表
CREATE TABLE biz.coach_task_history (
id bigint DEFAULT nextval('biz.coach_task_history_id_seq'::regclass) NOT NULL,
task_id bigint NOT NULL,
action character varying(50) NOT NULL,
old_status character varying(20),
new_status character varying(20),
old_task_type character varying(50),
new_task_type character varying(50),
detail jsonb,
created_at timestamp with time zone DEFAULT now()
);
CREATE TABLE biz.coach_tasks (
id bigint DEFAULT nextval('biz.coach_tasks_id_seq'::regclass) NOT NULL,
site_id bigint NOT NULL,
assistant_id bigint NOT NULL,
member_id bigint NOT NULL,
task_type character varying(50) NOT NULL,
status character varying(20) DEFAULT 'active'::character varying NOT NULL,
priority_score numeric(5,2),
expires_at timestamp with time zone,
is_pinned boolean DEFAULT false,
abandon_reason text,
completed_at timestamp with time zone,
completed_task_type character varying(50),
parent_task_id bigint,
created_at timestamp with time zone DEFAULT now(),
updated_at timestamp with time zone DEFAULT now()
);
CREATE TABLE biz.notes (
id bigint DEFAULT nextval('biz.notes_id_seq'::regclass) NOT NULL,
site_id bigint NOT NULL,
user_id integer NOT NULL,
target_type character varying(50) NOT NULL,
target_id bigint NOT NULL,
type character varying(20) DEFAULT 'normal'::character varying NOT NULL,
content text NOT NULL,
rating_service_willingness smallint,
rating_revisit_likelihood smallint,
task_id bigint,
ai_score smallint,
ai_analysis text,
created_at timestamp with time zone DEFAULT now(),
updated_at timestamp with time zone DEFAULT now()
);
CREATE TABLE biz.trigger_jobs (
id integer DEFAULT nextval('biz.trigger_jobs_id_seq'::regclass) NOT NULL,
job_type character varying(100) NOT NULL,
job_name character varying(100) NOT NULL,
trigger_condition character varying(20) NOT NULL,
trigger_config jsonb NOT NULL,
last_run_at timestamp with time zone,
next_run_at timestamp with time zone,
status character varying(20) DEFAULT 'enabled'::character varying NOT NULL,
created_at timestamp with time zone DEFAULT now()
);
-- 约束(主键 / 唯一 / 外键)
ALTER TABLE biz.coach_task_history ADD CONSTRAINT coach_task_history_task_id_fkey FOREIGN KEY (task_id) REFERENCES biz.coach_tasks(id);
ALTER TABLE biz.coach_task_history ADD CONSTRAINT coach_task_history_pkey PRIMARY KEY (id);
ALTER TABLE biz.coach_tasks ADD CONSTRAINT coach_tasks_parent_task_id_fkey FOREIGN KEY (parent_task_id) REFERENCES biz.coach_tasks(id);
ALTER TABLE biz.coach_tasks ADD CONSTRAINT coach_tasks_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.trigger_jobs ADD CONSTRAINT trigger_jobs_pkey PRIMARY KEY (id);
ALTER TABLE biz.trigger_jobs ADD CONSTRAINT trigger_jobs_job_name_key UNIQUE (job_name);
-- 索引
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_notes_target ON biz.notes USING btree (site_id, target_type, target_id);

View File

@@ -1,6 +1,6 @@
-- =============================================================================
-- zqyy_app / public小程序业务表
-- 生成日期2026-02-25
-- 生成日期2026-02-27
-- 来源:测试库(通过脚本自动导出)
-- =============================================================================
@@ -9,7 +9,7 @@ CREATE SCHEMA IF NOT EXISTS public;
-- 序列
CREATE SEQUENCE IF NOT EXISTS public.admin_users_id_seq AS integer;
CREATE SEQUENCE IF NOT EXISTS public.approvals_id_seq AS bigint;
CREATE SEQUENCE IF NOT EXISTS public.member_birthday_manual_id_seq AS bigint;
CREATE SEQUENCE IF NOT EXISTS public.member_retention_clue_id_seq AS bigint;
CREATE SEQUENCE IF NOT EXISTS public.permissions_id_seq AS integer;
CREATE SEQUENCE IF NOT EXISTS public.roles_id_seq AS integer;
CREATE SEQUENCE IF NOT EXISTS public.tasks_id_seq AS bigint;
@@ -37,15 +37,17 @@ CREATE TABLE public.approvals (
created_at timestamp with time zone DEFAULT now()
);
CREATE TABLE public.member_birthday_manual (
id bigint DEFAULT nextval('member_birthday_manual_id_seq'::regclass) NOT NULL,
CREATE TABLE public.member_retention_clue (
id bigint DEFAULT nextval('member_retention_clue_id_seq'::regclass) NOT NULL,
member_id bigint NOT NULL,
birthday_value date NOT NULL,
category character varying(20) NOT NULL,
summary character varying(200) NOT NULL,
detail text,
recorded_by_assistant_id bigint,
recorded_by_name character varying(50),
recorded_at timestamp with time zone DEFAULT now() NOT NULL,
source character varying(20) DEFAULT 'assistant'::character varying,
site_id bigint NOT NULL
site_id bigint NOT NULL,
source character varying(20) DEFAULT 'manual'::character varying NOT NULL
);
CREATE TABLE public.permissions (
@@ -149,8 +151,10 @@ ALTER TABLE admin_users ADD CONSTRAINT admin_users_username_key UNIQUE (username
ALTER TABLE approvals ADD CONSTRAINT approvals_approver_id_fkey FOREIGN KEY (approver_id) REFERENCES users(id);
ALTER TABLE approvals ADD CONSTRAINT approvals_task_id_fkey FOREIGN KEY (task_id) REFERENCES tasks(id) ON DELETE CASCADE;
ALTER TABLE approvals ADD CONSTRAINT approvals_pkey PRIMARY KEY (id);
ALTER TABLE member_birthday_manual ADD CONSTRAINT member_birthday_manual_pkey PRIMARY KEY (id);
ALTER TABLE member_birthday_manual ADD CONSTRAINT uk_member_birthday_manual UNIQUE (member_id, recorded_by_assistant_id);
ALTER TABLE member_retention_clue ADD CONSTRAINT member_retention_clue_pkey PRIMARY KEY (id);
ALTER TABLE member_retention_clue ADD CONSTRAINT chk_retention_clue_category CHECK (
category IN ('客户基础', '消费习惯', '玩法偏好', '促销偏好', '社交关系', '重要反馈')
);
ALTER TABLE permissions ADD CONSTRAINT permissions_pkey PRIMARY KEY (id);
ALTER TABLE permissions ADD CONSTRAINT permissions_resource_action_key UNIQUE (resource, action);
ALTER TABLE role_permissions ADD CONSTRAINT role_permissions_permission_id_fkey FOREIGN KEY (permission_id) REFERENCES permissions(id) ON DELETE CASCADE;
@@ -175,8 +179,9 @@ ALTER TABLE users ADD CONSTRAINT users_wx_openid_key UNIQUE (wx_openid);
CREATE INDEX idx_admin_users_site ON public.admin_users USING btree (site_id);
CREATE INDEX idx_approvals_site_id ON public.approvals USING btree (site_id);
CREATE INDEX idx_approvals_task_id ON public.approvals USING btree (task_id);
CREATE INDEX idx_mbd_member ON public.member_birthday_manual USING btree (member_id);
CREATE INDEX idx_mbd_site_id ON public.member_birthday_manual USING btree (site_id);
CREATE INDEX idx_retention_clue_category ON public.member_retention_clue USING btree (member_id, category);
CREATE INDEX idx_retention_clue_member ON public.member_retention_clue USING btree (member_id);
CREATE INDEX idx_retention_clue_site ON public.member_retention_clue USING btree (site_id);
CREATE INDEX idx_roles_site_id ON public.roles USING btree (site_id);
CREATE INDEX idx_scheduled_tasks_next_run ON public.scheduled_tasks USING btree (next_run_at) WHERE (enabled = true);
CREATE INDEX idx_scheduled_tasks_site ON public.scheduled_tasks USING btree (site_id);