analyze_menu_issues.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- coding: utf-8 -*-
  2. """Analyze tenant_sys_menu issues for full organize."""
  3. import pymysql
  4. from collections import defaultdict
  5. DB = dict(host='cq-cdb-8fjmemkb.sql.tencentcdb.com', port=27220,
  6. user='root', password='Ylrz_1q2w3e4r5t6y', database='ylrz_saas', charset='utf8mb4')
  7. conn = pymysql.connect(**DB)
  8. cur = conn.cursor(pymysql.cursors.DictCursor)
  9. cur.execute('SELECT * FROM tenant_sys_menu')
  10. rows = {r['menu_id']: r for r in cur.fetchall()}
  11. # path dup within parent (visible C/M only)
  12. dups = defaultdict(list)
  13. for r in rows.values():
  14. if r['menu_type'] == 'F' or r['visible'] != '0':
  15. continue
  16. key = (r['parent_id'], r['path'] or '')
  17. dups[key].append(r['menu_id'])
  18. print('PATH_DUPS (visible):')
  19. for k, ids in sorted(dups.items()):
  20. if len(ids) > 1:
  21. print(k, ids)
  22. # empty visible M nodes
  23. print('\nEMPTY_VISIBLE_M:')
  24. for r in rows.values():
  25. if r['menu_type'] != 'M' or r['visible'] != '0':
  26. continue
  27. children = [x for x in rows.values() if x['parent_id'] == r['menu_id'] and x['menu_type'] != 'F']
  28. if not children:
  29. print(r['menu_id'], r['menu_name'], r['path'], 'parent', r['parent_id'])
  30. # platform components still visible
  31. print('\nBAD_VISIBLE:')
  32. for r in rows.values():
  33. if r['visible'] != '0':
  34. continue
  35. comp = r.get('component') or ''
  36. if comp.startswith('admin/') or comp.startswith('proxy/') or comp.startswith('saas/'):
  37. print(r['menu_id'], comp)
  38. if (r.get('path') or '') in ('tool', 'tenant', 'monitor') and r['menu_type'] == 'C':
  39. print('path', r['menu_id'], r['path'], comp)
  40. cur.close()
  41. conn.close()