feat(consignment): 自动匹配改为进入待抢单前一次性匹配
1) 配置改为开启自动匹配 + 匹配订单生效时间,移除内部匹配等待与定时轮询;2) 所有进入待抢单的路径统一先自动匹配一次,未命中进大厅;3) 手动匹配仅允许待抢单;4) 新增迁移 160 回填配置并迁移存量 internal_matching。
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
-- 160_consignment_auto_match_setting.sql
|
||||
--
|
||||
-- 匹配设置从「off / manual / auto 三态」收敛为「是否开启自动匹配」:
|
||||
-- 1. 旧 mode=auto 视为开启,其余视为关闭;
|
||||
-- 2. 新增匹配订单生效时间 orderEffectiveFrom,存量配置回填为迁移执行时间;
|
||||
-- 3. 取消内部匹配等待:历史 internal_matching 工单统一回到待抢单 open。
|
||||
--
|
||||
-- 全部语句幂等;不删除旧字段,方便回滚与旧客户端读取。
|
||||
|
||||
-- ===========================================================================
|
||||
-- 1. 配置草稿:补 autoMatchEnabled / orderEffectiveFrom
|
||||
-- ===========================================================================
|
||||
UPDATE consignment_profiles p
|
||||
SET config_json = jsonb_set(
|
||||
COALESCE(p.config_json, '{}'::jsonb),
|
||||
'{matching}',
|
||||
COALESCE(p.config_json -> 'matching', '{}'::jsonb)
|
||||
|| jsonb_build_object(
|
||||
'autoMatchEnabled',
|
||||
CASE
|
||||
WHEN p.config_json #> '{matching,autoMatchEnabled}' IS NOT NULL
|
||||
THEN p.config_json #> '{matching,autoMatchEnabled}'
|
||||
WHEN p.config_json #>> '{matching,mode}' = 'auto' THEN 'true'::jsonb
|
||||
ELSE 'false'::jsonb
|
||||
END,
|
||||
'orderEffectiveFrom',
|
||||
CASE
|
||||
WHEN COALESCE(p.config_json #>> '{matching,orderEffectiveFrom}', '') <> ''
|
||||
THEN to_jsonb(p.config_json #>> '{matching,orderEffectiveFrom}')
|
||||
ELSE to_jsonb(NOW())
|
||||
END
|
||||
),
|
||||
true
|
||||
)
|
||||
WHERE jsonb_typeof(COALESCE(p.config_json, '{}'::jsonb)) = 'object';
|
||||
|
||||
-- ===========================================================================
|
||||
-- 2. 已发布版本:同一口径回填,保证线上读取立即一致
|
||||
-- ===========================================================================
|
||||
UPDATE consignment_profile_versions v
|
||||
SET config_json = jsonb_set(
|
||||
COALESCE(v.config_json, '{}'::jsonb),
|
||||
'{matching}',
|
||||
COALESCE(v.config_json -> 'matching', '{}'::jsonb)
|
||||
|| jsonb_build_object(
|
||||
'autoMatchEnabled',
|
||||
CASE
|
||||
WHEN v.config_json #> '{matching,autoMatchEnabled}' IS NOT NULL
|
||||
THEN v.config_json #> '{matching,autoMatchEnabled}'
|
||||
WHEN v.config_json #>> '{matching,mode}' = 'auto' THEN 'true'::jsonb
|
||||
ELSE 'false'::jsonb
|
||||
END,
|
||||
'orderEffectiveFrom',
|
||||
CASE
|
||||
WHEN COALESCE(v.config_json #>> '{matching,orderEffectiveFrom}', '') <> ''
|
||||
THEN to_jsonb(v.config_json #>> '{matching,orderEffectiveFrom}')
|
||||
ELSE to_jsonb(NOW())
|
||||
END
|
||||
),
|
||||
true
|
||||
)
|
||||
WHERE jsonb_typeof(COALESCE(v.config_json, '{}'::jsonb)) = 'object';
|
||||
|
||||
-- ===========================================================================
|
||||
-- 3. 取消内部匹配等待:历史 internal_matching 工单回到待抢单
|
||||
-- ===========================================================================
|
||||
WITH migrated AS (
|
||||
UPDATE work_orders
|
||||
SET status = 'open',
|
||||
published_at = COALESCE(published_at, NOW()),
|
||||
hall_queued_at = COALESCE(hall_queued_at, NOW()),
|
||||
internal_match_deadline_at = NULL,
|
||||
hall_visible_at = NULL,
|
||||
updated_at = NOW()
|
||||
WHERE status = 'internal_matching'
|
||||
RETURNING id
|
||||
)
|
||||
INSERT INTO work_order_events (
|
||||
work_order_id, actor_type, actor_id, event_type, from_status, to_status,
|
||||
payload_json, created_at
|
||||
)
|
||||
SELECT
|
||||
id,
|
||||
'system',
|
||||
'consignment_migration',
|
||||
'consignment_internal_matching_migrated',
|
||||
'internal_matching',
|
||||
'open',
|
||||
'{"reason":"auto_match_setting_migration"}'::jsonb,
|
||||
NOW()
|
||||
FROM migrated;
|
||||
Reference in New Issue
Block a user