fix(order-service): 回填未提交工单的最新资料配置

This commit is contained in:
yml2213
2026-11-04 12:02:46 +08:00
parent d576e8a2b1
commit b83741cbf7
6 changed files with 81 additions and 3 deletions
@@ -202,6 +202,41 @@ export async function setOrderServiceProfileCurrentVersion(
)
}
export async function backfillPendingOrderServiceSnapshotsForCategory(
client: PoolClient,
input: { categoryId: number; profileId: number; versionId: number },
): Promise<number> {
const result = await client.query(
`
UPDATE work_orders wo
SET service_profile_id = $2,
service_profile_version_id = $3,
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 p.id = $2
AND p.category_id = $1
AND v.id = $3
AND wo.category_id = p.category_id
AND wo.status = 'pending_material'
AND wo.assigned_worker_id IS NULL
AND wo.service_profile_snapshot_json IS NULL
`,
[input.categoryId, input.profileId, input.versionId],
)
return Number(result.rowCount || 0)
}
export async function getOrderServiceProfileVersion(
versionId: number | string,
client?: Pick<PoolClient, 'query'>,