# -*- coding: utf-8 -*- """Analyze tenant_sys_menu issues for full organize.""" import pymysql from collections import defaultdict DB = dict(host='cq-cdb-8fjmemkb.sql.tencentcdb.com', port=27220, user='root', password='Ylrz_1q2w3e4r5t6y', database='ylrz_saas', charset='utf8mb4') conn = pymysql.connect(**DB) cur = conn.cursor(pymysql.cursors.DictCursor) cur.execute('SELECT * FROM tenant_sys_menu') rows = {r['menu_id']: r for r in cur.fetchall()} # path dup within parent (visible C/M only) dups = defaultdict(list) for r in rows.values(): if r['menu_type'] == 'F' or r['visible'] != '0': continue key = (r['parent_id'], r['path'] or '') dups[key].append(r['menu_id']) print('PATH_DUPS (visible):') for k, ids in sorted(dups.items()): if len(ids) > 1: print(k, ids) # empty visible M nodes print('\nEMPTY_VISIBLE_M:') for r in rows.values(): if r['menu_type'] != 'M' or r['visible'] != '0': continue children = [x for x in rows.values() if x['parent_id'] == r['menu_id'] and x['menu_type'] != 'F'] if not children: print(r['menu_id'], r['menu_name'], r['path'], 'parent', r['parent_id']) # platform components still visible print('\nBAD_VISIBLE:') for r in rows.values(): if r['visible'] != '0': continue comp = r.get('component') or '' if comp.startswith('admin/') or comp.startswith('proxy/') or comp.startswith('saas/'): print(r['menu_id'], comp) if (r.get('path') or '') in ('tool', 'tenant', 'monitor') and r['menu_type'] == 'C': print('path', r['menu_id'], r['path'], comp) cur.close() conn.close()