Files
ai_academy/migrations/versioned/000166_training_manual_push.up.sql
T
runny 61fb94744a
deploy-hxtesting / build-and-deploy (push) Successful in 1m19s
feat(公告推送):配置中心-推送管理中增加一个手动推送功能
目的:为和信智汇学院有重要通知时可随时向用户手动推送重要信息使用
推送内容:标题、内容、落地页(均可自定义配置),默认值标题为“和信智汇学院”、内容为“重要通知”、落地页默认系统登录页如果已登录默认登录后系统页面
推送人员:默认全员通知,可根据部门、职位、具体人员进行自定义人员
推送时间:可立即推送也可设定定时推送!
2026-11-29 13:41:05 +08:00

44 lines
2.3 KiB
SQL

-- Migration: 000166_training_manual_push
-- Manual push (手动推送) from the config center push-management tab
-- (2026-11 requirement: 和信智汇学院重要通知随时手动推送).
-- tr_push_tasks stores one push intent per row: custom title/content/landing
-- link, an audience selector (all / by dept / by post / explicit users) and a
-- send time (now or scheduled). The training scheduler claims due rows with a
-- compare-and-set (pending → sending → sent), resolves the audience at send
-- time (so "全员" covers accounts created after scheduling) and fans the task
-- out into tr_notifications rows (scene='manual_push', ref_id=task id) that
-- flow through the existing WeCom outbox and 推送记录 views. Cancelled tasks
-- never fan out.
DO $$ BEGIN RAISE NOTICE '[Migration 000166] Creating tr_push_tasks for manual push...'; END $$;
CREATE TABLE IF NOT EXISTS tr_push_tasks (
id VARCHAR(36) PRIMARY KEY,
tenant_id BIGINT NOT NULL,
title VARCHAR(255) NOT NULL DEFAULT '',
content TEXT NOT NULL DEFAULT '',
link_url VARCHAR(512) NOT NULL DEFAULT '',
audience_mode VARCHAR(16) NOT NULL DEFAULT 'all',
dept_ids JSONB NOT NULL DEFAULT '[]',
posts JSONB NOT NULL DEFAULT '[]',
user_ids JSONB NOT NULL DEFAULT '[]',
send_at TIMESTAMPTZ NOT NULL,
status VARCHAR(16) NOT NULL DEFAULT 'pending',
sent_count INT NOT NULL DEFAULT 0,
sent_at TIMESTAMPTZ,
created_by VARCHAR(36) NOT NULL DEFAULT '',
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMPTZ
);
CREATE INDEX IF NOT EXISTS idx_tr_push_tasks_tenant ON tr_push_tasks(tenant_id);
-- Due-task scan of the training scheduler tick (partial: pending rows only).
CREATE INDEX IF NOT EXISTS idx_tr_push_tasks_due
ON tr_push_tasks(send_at)
WHERE status = 'pending' AND deleted_at IS NULL;
COMMENT ON TABLE tr_push_tasks IS 'Manual push tasks (config center push management); scheduler fans due tasks out into tr_notifications';
COMMENT ON COLUMN tr_push_tasks.audience_mode IS 'Audience selector: all / dept / post / user';
COMMENT ON COLUMN tr_push_tasks.status IS 'pending (waiting or due) / sending (claimed) / sent / cancelled';