SELECT id,NAME,url,description,CASE WHEN @parent = m.parentid THEN @intlevel WHEN @parent < m.parentid THEN @intlevel := @intlevel + 1 ELSE @intlevel:=0 END AS LEVEL,FALSE AS EXPANDED,CASE WHEN m.parentid=0 then 0 ELSE 1 END AS ISLEAF FROM system_menu m ,(SELECT @intlevel := 0,@parent := 0) c $condition AND permissionid IN ($permissionIds)
最后变成的sql 是SELECT id,NAME,url,description,CASE WHEN NULL = m.parentid THEN NULL WHEN NULL < m.parentid THEN NULL := NULL + 1 ELSE NULL:=0 END AS LEVEL,FALSE AS EXPANDED,CASE WHEN m.parentid=0 then 0 ELSE 1 END AS ISLEAF FROM system_menu m ,(SELECT NULL := 0,NULL := 0) c WHERE 1=1 AND permissionid IN (01,2,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,2015,2016,101,117,118,119,120,121,122,123,124,125,1014,1801,1802,1803,1804,1805,1901,1902,1903,1904)'