import java.sql.*; import java.util.ArrayList; import java.util.List; public class InspectLobsterMenuTree { static final String URL = "jdbc:mysql://cq-cdb-8fjmemkb.sql.tencentcdb.com:27220/fs_tenant_cs1?useSSL=false&serverTimezone=GMT%2B8"; static final String USER = "root"; static final String PASS = "Ylrz_1q2w3e4r5t6y"; public static void main(String[] args) throws Exception { Class.forName("com.mysql.cj.jdbc.Driver"); try (Connection c = DriverManager.getConnection(URL, USER, PASS)) { for (long rootId : new long[]{2951L, 29900L}) { System.out.println("\n=== subtree root=" + rootId + " ==="); dumpTree(c, rootId, 0); } System.out.println("\n=== sys_role_menu refs under 2951 ==="); try (Statement st = c.createStatement(); ResultSet rs = st.executeQuery( "SELECT rm.role_id, rm.menu_id, m.menu_name FROM sys_role_menu rm " + "JOIN sys_menu m ON m.menu_id = rm.menu_id " + "WHERE rm.menu_id IN (SELECT menu_id FROM sys_menu WHERE menu_id=2951 OR parent_id=2951 " + "UNION SELECT menu_id FROM sys_menu WHERE parent_id IN " + "(SELECT menu_id FROM sys_menu WHERE parent_id=2951)) " + "OR rm.menu_id = 2951 LIMIT 50")) { int n = 0; while (rs.next()) { n++; System.out.printf("role=%d menu=%d %s%n", rs.getLong(1), rs.getLong(2), rs.getString(3)); } if (n == 0) System.out.println("(none)"); } } } static void dumpTree(Connection c, long parentId, int depth) throws SQLException { String sql = "SELECT menu_id, menu_name, path, component, menu_type, visible " + "FROM sys_menu WHERE parent_id = ? ORDER BY order_num, menu_id"; try (PreparedStatement ps = c.prepareStatement(sql)) { ps.setLong(1, parentId); try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { String indent = " ".repeat(depth); System.out.printf("%s[%s] id=%d name=%s path=%s comp=%s vis=%s%n", indent, rs.getString(5), rs.getLong(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(6)); dumpTree(c, rs.getLong(1), depth + 1); } } } if (depth == 0) { try (PreparedStatement ps = c.prepareStatement( "SELECT menu_id, menu_name, path, component, menu_type, visible FROM sys_menu WHERE menu_id = ?")) { ps.setLong(1, parentId); try (ResultSet rs = ps.executeQuery()) { if (rs.next()) { System.out.printf("[ROOT %s] id=%d name=%s path=%s comp=%s vis=%s%n", rs.getString(5), rs.getLong(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(6)); } } } } } }