-- 可选:将仍有 task.current_assignee_user_id 且无步骤负责人的旧任务回填到全部步骤 -- -- 注意:MySQL 5.7 在 INSERT...SELECT 中 UUID() 可能整批只计算一次,导致主键重复。 -- 此处用 SHA2(step_id) 生成确定性主键,每步唯一,且可重复执行(已存在则跳过)。 INSERT INTO `biz_production_task_step_assignee` ( `id`, `step_id`, `user_id`, `tenant_no`, `order_num`, `create_by`, `create_dept_id`, `create_time`, `update_by`, `update_time`, `del_flag` ) SELECT LOWER(SHA2(CONCAT('step-assignee-backfill:', s.id), 256)), s.id, t.current_assignee_user_id, s.tenant_no, 0, t.create_by, IFNULL(t.create_dept_id, ''), NOW(), t.update_by, NOW(), 0 FROM `biz_production_task` t JOIN `biz_production_task_step` s ON s.task_id = t.id AND s.del_flag = 0 WHERE t.del_flag = 0 AND t.current_assignee_user_id IS NOT NULL AND TRIM(t.current_assignee_user_id) <> '' AND NOT EXISTS ( SELECT 1 FROM `biz_production_task_step_assignee` a WHERE a.step_id = s.id AND a.del_flag = 0 );