feat(consignment): 匹配成功短信通知并支持模板配置
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
-- 143_consignment_sms_logs.sql
|
||||
-- 寄卖匹配成功短信发送记录:用于幂等、审计与 Mock 联调验证。
|
||||
-- 同一工单 + 同一库存只允许一条记录,避免重试/重复调度重复发短信。
|
||||
CREATE TABLE IF NOT EXISTS consignment_sms_logs (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
work_order_id BIGINT REFERENCES work_orders(id) ON DELETE SET NULL,
|
||||
work_order_no TEXT NOT NULL DEFAULT '',
|
||||
inventory_id BIGINT REFERENCES consignment_inventories(id) ON DELETE SET NULL,
|
||||
inventory_no TEXT NOT NULL DEFAULT '',
|
||||
worker_id BIGINT REFERENCES worker_users(id) ON DELETE SET NULL,
|
||||
phone TEXT NOT NULL DEFAULT '',
|
||||
template_key TEXT NOT NULL DEFAULT 'consignment_matched',
|
||||
template_text TEXT NOT NULL DEFAULT '',
|
||||
content TEXT NOT NULL DEFAULT '',
|
||||
params_json JSONB NOT NULL DEFAULT '{}'::jsonb,
|
||||
provider TEXT NOT NULL DEFAULT 'mock',
|
||||
status TEXT NOT NULL DEFAULT 'sending'
|
||||
CHECK (status IN ('sending', 'sent', 'failed', 'skipped')),
|
||||
error_text TEXT NOT NULL DEFAULT '',
|
||||
match_type TEXT NOT NULL DEFAULT 'auto'
|
||||
CHECK (match_type IN ('auto', 'manual')),
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
sent_at TIMESTAMPTZ
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uq_consignment_sms_logs_work_order_inventory
|
||||
ON consignment_sms_logs (work_order_id, inventory_id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_consignment_sms_logs_created
|
||||
ON consignment_sms_logs (created_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_consignment_sms_logs_work_order
|
||||
ON consignment_sms_logs (work_order_id, created_at DESC);
|
||||
|
||||
COMMENT ON TABLE consignment_sms_logs IS '寄卖匹配成功短信发送记录(幂等键:工单 + 库存)';
|
||||
COMMENT ON COLUMN consignment_sms_logs.status IS 'sending/sent/failed/skipped';
|
||||
COMMENT ON COLUMN consignment_sms_logs.match_type IS 'auto/manual';
|
||||
COMMENT ON COLUMN consignment_sms_logs.template_key IS '短信场景键,寄卖匹配成功固定为 consignment_matched';
|
||||
Reference in New Issue
Block a user