feat: chat integration, tenant admin spec, backend chat service, miniprogram updates, DEMO moved to tmp, XCX-TEST removed, migrations & docs

This commit is contained in:
Neo
2026-03-20 09:02:10 +08:00
parent 3d2e5f8165
commit beb88d5bea
388 changed files with 6436 additions and 25458 deletions

View File

@@ -0,0 +1,48 @@
-- 迁移:给 cfg_area_category 加 sort_order 字段 + 创建 app.v_cfg_area_category 视图
-- 关联R3 修复(项目类型筛选接口重建)
-- 日期2026-03-20
-- 回滚:见文件末尾
-- ============================================================
-- 1. 给 cfg_area_category 加 sort_order 字段
-- ============================================================
ALTER TABLE dws.cfg_area_category
ADD COLUMN IF NOT EXISTS sort_order INTEGER DEFAULT 100 NOT NULL;
COMMENT ON COLUMN dws.cfg_area_category.sort_order
IS '前端筛选器显示排序(值越小越靠前)';
-- 按业务优先级设置排序值
UPDATE dws.cfg_area_category SET sort_order = 10 WHERE category_code = 'BILLIARD';
UPDATE dws.cfg_area_category SET sort_order = 20 WHERE category_code = 'SNOOKER';
UPDATE dws.cfg_area_category SET sort_order = 30 WHERE category_code = 'MAHJONG';
UPDATE dws.cfg_area_category SET sort_order = 40 WHERE category_code = 'KTV';
UPDATE dws.cfg_area_category SET sort_order = 900 WHERE category_code = 'SPECIAL';
UPDATE dws.cfg_area_category SET sort_order = 999 WHERE category_code = 'OTHER';
-- ============================================================
-- 2. 创建 app.v_cfg_area_category 视图
-- 去重到 category 级别,排除 SPECIAL/OTHER不在前端筛选器显示
-- ============================================================
CREATE OR REPLACE VIEW app.v_cfg_area_category AS
SELECT DISTINCT
category_code,
category_name,
display_name,
short_name,
sort_order
FROM dws.cfg_area_category
WHERE is_active = TRUE
AND category_code NOT IN ('SPECIAL', 'OTHER')
ORDER BY sort_order;
GRANT SELECT ON app.v_cfg_area_category TO app_reader;
COMMENT ON VIEW app.v_cfg_area_category
IS '项目类型筛选器配置视图(去重到 category 级别,排除 SPECIAL/OTHER';
-- ============================================================
-- 回滚
-- ============================================================
-- DROP VIEW IF EXISTS app.v_cfg_area_category;
-- ALTER TABLE dws.cfg_area_category DROP COLUMN IF EXISTS sort_order;

View File

@@ -0,0 +1,58 @@
-- =============================================================================
-- 迁移:移除废弃的 dws_member_recall_index 表及 RLS 视图
-- 日期: 2026-03-20
-- 原因: RecallIndexTask 已于 2026-02-13 被 WBI+NCI 替代,但表和视图的 DDL
-- 在 2026-02-19 schema 重命名billiards_dws → dws时残留至今。
-- 表中无有效数据ETL 任务已删除),属于孤儿对象。
-- 影响: 无下游消费者依赖此表数据(后端 recall 维度已改用 v_dws_member_winback_index
-- 回滚: 从 git 历史恢复 DDL 定义并重建表和视图
-- =============================================================================
BEGIN;
-- 1. 删除 RLS 视图
DROP VIEW IF EXISTS app.v_dws_member_recall_index;
-- 2. 删除索引
DROP INDEX IF EXISTS dws.idx_dws_recall_display;
-- 3. 删除表CASCADE 会自动清理约束)
DROP TABLE IF EXISTS dws.dws_member_recall_index CASCADE;
-- 4. 删除序列
DROP SEQUENCE IF EXISTS dws.dws_member_recall_index_recall_id_seq;
COMMIT;
-- =============================================================================
-- 验证
-- =============================================================================
DO $$
DECLARE
tbl_exists BOOLEAN;
view_exists BOOLEAN;
seq_exists BOOLEAN;
BEGIN
SELECT EXISTS(
SELECT 1 FROM information_schema.tables
WHERE table_schema = 'dws' AND table_name = 'dws_member_recall_index'
) INTO tbl_exists;
SELECT EXISTS(
SELECT 1 FROM information_schema.views
WHERE table_schema = 'app' AND table_name = 'v_dws_member_recall_index'
) INTO view_exists;
SELECT EXISTS(
SELECT 1 FROM information_schema.sequences
WHERE sequence_schema = 'dws' AND sequence_name = 'dws_member_recall_index_recall_id_seq'
) INTO seq_exists;
RAISE NOTICE '表存在: % (应为 false)', tbl_exists;
RAISE NOTICE '视图存在: % (应为 false)', view_exists;
RAISE NOTICE '序列存在: % (应为 false)', seq_exists;
IF tbl_exists OR view_exists OR seq_exists THEN
RAISE EXCEPTION '清理不完整,仍有残留对象';
END IF;
END $$;

View File

@@ -0,0 +1,89 @@
-- =============================================================================
-- 迁移:扩展 biz.ai_conversations 和 biz.ai_messages 支持 CHAT 模块
-- 日期2026-03-20
-- 关联 SPECrns1-chat-integrationRNS1.4 CHAT 对齐与联调收尾)
-- 需求R2.3, R3.8, R3.10, R4.3, R7.5
-- 说明:
-- 1. ai_conversations 新增 context_type/context_id多入口对话复用
-- title/last_message/last_message_at历史列表展示与排序
-- 2. ai_messages 新增 reference_card引用卡片 JSON
-- 3. 两个索引:上下文对话查找 + 历史列表排序
-- =============================================================================
-- ---------------------------------------------------------------------------
-- 1. 扩展 ai_conversations新增 5 个字段
-- ---------------------------------------------------------------------------
ALTER TABLE biz.ai_conversations
ADD COLUMN IF NOT EXISTS context_type varchar(20),
ADD COLUMN IF NOT EXISTS context_id varchar(50),
ADD COLUMN IF NOT EXISTS title varchar(200),
ADD COLUMN IF NOT EXISTS last_message text,
ADD COLUMN IF NOT EXISTS last_message_at timestamptz;
COMMENT ON COLUMN biz.ai_conversations.context_type
IS '对话关联上下文类型task任务/ customer客户/ coach助教/ general通用';
COMMENT ON COLUMN biz.ai_conversations.context_id
IS '关联上下文 IDtask 入口为 taskIdcustomer 入口为 customerIdcoach 入口为 coachIdgeneral 为 NULL';
COMMENT ON COLUMN biz.ai_conversations.title
IS '对话标题:自定义 > 上下文名称 > 首条消息前20字';
COMMENT ON COLUMN biz.ai_conversations.last_message
IS '最后一条消息内容摘要截断至100字';
COMMENT ON COLUMN biz.ai_conversations.last_message_at
IS '最后消息时间,用于历史列表排序和对话复用时限判断';
-- ---------------------------------------------------------------------------
-- 2. 扩展 ai_messages新增 reference_card 字段
-- ---------------------------------------------------------------------------
ALTER TABLE biz.ai_messages
ADD COLUMN IF NOT EXISTS reference_card jsonb;
COMMENT ON COLUMN biz.ai_messages.reference_card
IS 'referenceCard JSON{type, title, summary, data}';
-- ---------------------------------------------------------------------------
-- 3. 索引:上下文对话查找(按 context_type + context_id 查找可复用对话)
-- ---------------------------------------------------------------------------
CREATE INDEX IF NOT EXISTS idx_ai_conv_context
ON biz.ai_conversations (user_id, site_id, context_type, context_id, last_message_at DESC NULLS LAST)
WHERE context_type IS NOT NULL;
-- ---------------------------------------------------------------------------
-- 4. 索引历史列表排序优化CHAT-1: 按 last_message_at 倒序)
-- ---------------------------------------------------------------------------
CREATE INDEX IF NOT EXISTS idx_ai_conv_last_msg
ON biz.ai_conversations (user_id, site_id, last_message_at DESC NULLS LAST);
-- =============================================================================
-- 回滚
-- =============================================================================
-- DROP INDEX IF EXISTS biz.idx_ai_conv_context;
-- DROP INDEX IF EXISTS biz.idx_ai_conv_last_msg;
-- ALTER TABLE biz.ai_messages DROP COLUMN IF EXISTS reference_card;
-- ALTER TABLE biz.ai_conversations DROP COLUMN IF EXISTS last_message_at;
-- ALTER TABLE biz.ai_conversations DROP COLUMN IF EXISTS last_message;
-- ALTER TABLE biz.ai_conversations DROP COLUMN IF EXISTS title;
-- ALTER TABLE biz.ai_conversations DROP COLUMN IF EXISTS context_id;
-- ALTER TABLE biz.ai_conversations DROP COLUMN IF EXISTS context_type;
-- =============================================================================
-- 验证
-- =============================================================================
-- 1) ai_conversations 新字段存在性
-- SELECT column_name, data_type, character_maximum_length
-- FROM information_schema.columns
-- WHERE table_schema = 'biz' AND table_name = 'ai_conversations'
-- AND column_name IN ('context_type','context_id','title','last_message','last_message_at');
-- 预期5 行
-- 2) ai_messages 新字段存在性
-- SELECT column_name, data_type
-- FROM information_schema.columns
-- WHERE table_schema = 'biz' AND table_name = 'ai_messages'
-- AND column_name = 'reference_card';
-- 预期1 行jsonb
-- 3) 索引存在性
-- SELECT indexname FROM pg_indexes
-- WHERE schemaname = 'biz' AND tablename = 'ai_conversations'
-- AND indexname IN ('idx_ai_conv_context','idx_ai_conv_last_msg');
-- 预期2 行