InspectLobsterMenusAll.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import java.io.*;
  2. import java.sql.*;
  3. public class InspectLobsterMenusAll {
  4. static final String HOST = "cq-cdb-8fjmemkb.sql.tencentcdb.com:27220";
  5. static final String USER = "root";
  6. static final String PASS = "Ylrz_1q2w3e4r5t6y";
  7. public static void main(String[] args) throws Exception {
  8. Class.forName("com.mysql.cj.jdbc.Driver");
  9. new File("output").mkdirs();
  10. try (PrintWriter out = new PrintWriter(new OutputStreamWriter(
  11. new FileOutputStream("output/inspect-lobster-menus-all.txt"), "UTF-8"))) {
  12. inspect(open("fs_tenant_cs1"), out, "TENANT fs_tenant_cs1");
  13. inspect(open("ylrz_saas"), out, "MASTER ylrz_saas");
  14. }
  15. System.out.println("Wrote output/inspect-lobster-menus-all.txt");
  16. }
  17. static void inspect(Connection c, PrintWriter out, String label) throws Exception {
  18. out.println("\n######## " + label + " ########");
  19. dumpTable(c, out, "sys_menu", true);
  20. dumpTable(c, out, "company_menu", true);
  21. dumpTable(c, out, "tenant_sys_menu", false);
  22. dumpTable(c, out, "tenant_company_menu", false);
  23. }
  24. static void dumpTable(Connection c, PrintWriter out, String table, boolean countDistinct) throws Exception {
  25. if (!tableExists(c, table)) {
  26. out.println("-- " + table + " (not exists)");
  27. return;
  28. }
  29. out.println("\n=== " + table + " lobster tree ===");
  30. String sql = "SELECT menu_id, menu_name, parent_id, order_num, path, component, visible, HEX(menu_name) hx "
  31. + "FROM " + table + " WHERE menu_id = 29900 OR parent_id = 29900 OR parent_id = 29901 "
  32. + "OR menu_id = 2951 OR parent_id = 2951 "
  33. + "OR path = '/lobster' OR component LIKE 'lobster/%' OR component LIKE 'company/workflowLobster/%' "
  34. + "ORDER BY parent_id, order_num, menu_id";
  35. int n = 0;
  36. try (Statement st = c.createStatement(); ResultSet rs = st.executeQuery(sql)) {
  37. while (rs.next()) {
  38. n++;
  39. out.printf("[%d] %s | parent=%d order=%d path=%s comp=%s visible=%s hx=%s%n",
  40. rs.getLong("menu_id"), rs.getString("menu_name"), rs.getLong("parent_id"),
  41. rs.getInt("order_num"), rs.getString("path"), rs.getString("component"),
  42. rs.getString("visible"), rs.getString("hx"));
  43. }
  44. }
  45. out.println("row_count=" + n);
  46. if (countDistinct && "company_menu".equals(table)) {
  47. try (Statement st = c.createStatement();
  48. ResultSet rs = st.executeQuery(
  49. "SELECT COUNT(DISTINCT menu_id) FROM company_menu "
  50. + "WHERE menu_id=29900 OR parent_id=29900 OR parent_id=29901")) {
  51. rs.next();
  52. out.println("distinct_menu_id=" + rs.getInt(1));
  53. }
  54. }
  55. if ("sys_menu".equals(table) || "tenant_sys_menu".equals(table)) {
  56. try (Statement st = c.createStatement();
  57. ResultSet rs = st.executeQuery(
  58. "SELECT COUNT(*) FROM " + table + " WHERE menu_id=29900 OR parent_id=29900 OR parent_id=29901")) {
  59. rs.next();
  60. out.println("tree_count=" + rs.getInt(1));
  61. }
  62. }
  63. }
  64. static boolean tableExists(Connection c, String table) throws SQLException {
  65. try (PreparedStatement ps = c.prepareStatement(
  66. "SELECT 1 FROM information_schema.tables WHERE table_schema=DATABASE() AND table_name=? LIMIT 1")) {
  67. ps.setString(1, table);
  68. try (ResultSet rs = ps.executeQuery()) {
  69. return rs.next();
  70. }
  71. }
  72. }
  73. static Connection open(String db) throws SQLException {
  74. return DriverManager.getConnection(
  75. "jdbc:mysql://" + HOST + "/" + db + "?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8",
  76. USER, PASS);
  77. }
  78. }