fix(order-service): 修复 Mock 工单未绑定自动发布配置
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
-- 136_backfill_mock_order_service_snapshots.sql
|
||||
-- 修复历史 Mock 工单未绑定订单服务版本,导致资料提交后无法自动发布的问题。
|
||||
|
||||
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 wo.service_profile_snapshot_json IS NULL
|
||||
AND wo.status IN ('pending_material', 'unassigned')
|
||||
AND wo.assigned_worker_id IS NULL
|
||||
AND wo.material_json -> 'source' ->> 'mock' = 'true'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM work_order_shares share
|
||||
WHERE share.work_order_id = wo.id
|
||||
AND share.status <> 'cancelled'
|
||||
);
|
||||
|
||||
INSERT INTO order_service_auto_publish_jobs (work_order_id, max_attempts)
|
||||
SELECT
|
||||
wo.id,
|
||||
GREATEST(
|
||||
1,
|
||||
COALESCE(
|
||||
NULLIF(wo.service_profile_snapshot_json -> 'config' -> 'autoPublish' ->> 'retryMax', '')::int,
|
||||
3
|
||||
) + 1
|
||||
)
|
||||
FROM work_orders wo
|
||||
WHERE wo.material_json -> 'source' ->> 'mock' = 'true'
|
||||
AND wo.status = 'unassigned'
|
||||
AND wo.assigned_worker_id IS NULL
|
||||
AND wo.material_json -> 'collect' ->> 'complete' = 'true'
|
||||
AND wo.service_profile_snapshot_json -> 'config' -> 'autoPublish' ->> 'enabled' = 'true'
|
||||
ON CONFLICT DO NOTHING;
|
||||
Reference in New Issue
Block a user