fix(order-service): 回填未提交工单的最新资料配置
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
-- 132_backfill_pending_order_service_snapshots.sql
|
||||
--
|
||||
-- 旧工单创建于“配置快照”上线之前,打开 /o 时会回退到旧的 requirement_json。
|
||||
-- 对本分类仍待客户提交资料、且未指派打手的工单,回填当前发布版本快照。
|
||||
|
||||
UPDATE work_orders wo
|
||||
SET service_profile_id = p.id,
|
||||
service_profile_version_id = v.id,
|
||||
service_profile_snapshot_json = jsonb_build_object(
|
||||
'profileId', p.id,
|
||||
'categoryId', p.category_id,
|
||||
'versionId', v.id,
|
||||
'versionNo', v.version_no,
|
||||
'config', v.config_json
|
||||
),
|
||||
requirement_json = jsonb_build_object(
|
||||
'fields', COALESCE(v.config_json -> 'fields', '[]'::jsonb)
|
||||
),
|
||||
updated_at = NOW()
|
||||
FROM order_service_profiles p
|
||||
JOIN order_service_profile_versions v ON v.id = p.current_version_id
|
||||
WHERE wo.category_id = p.category_id
|
||||
AND p.status <> 'archived'
|
||||
AND wo.status = 'pending_material'
|
||||
AND wo.assigned_worker_id IS NULL
|
||||
AND wo.service_profile_snapshot_json IS NULL;
|
||||
Reference in New Issue
Block a user