INSERT INTO t_base_role_resource_ref (refID, roleID, resID, orgID, belongTo)
SELECT uuid() AS refID, t1.roleID, t1.resID, '1' AS orgID, 'school' AS belongTo
FROM t_base_role_resource_ref t1
WHERE t1.belongTo = 'school-default'
AND NOT EXISTS (
SELECT 1
FROM t_base_role_resource_ref t2
WHERE t2.roleID = t1.roleID
AND t1.resID = t2.resID
AND t2.orgID = #{schoolID}
);
UPDATE t_base_role_resource_ref
SET refID = replace(refID, '-', '')
WHERE orgID = #{schoolID};
注意:第一个select时不能直接用replace语句进行替换,否则生成的是同样的UUID,必须先插入后更新。
生成的UUID非常接近,乍一看是一样的。