# -*- coding: utf-8 -*- # t11-users.py — A/B/C 用户部门实锤 + 项目角色字典值实锤(只读) import io, sys sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') import pymysql conn = pymysql.connect(host='8.129.84.155', port=3306, user='root', password='Itc@123456', database='crm', charset='utf8mb4') cur = conn.cursor() print('== 用户部门(sys_user / sys_user_dept)==') for sql in ( "SELECT id, real_name, primary_dept_id FROM sys_user WHERE id IN " "(739564171091247104, 744842565802524672, 744842566742048768, 744842318024015872)", ): try: cur.execute(sql) for r in cur.fetchall(): print(' ', r) except Exception as e: print(' ERR', e) print('== 用户-部门关联表 ==') try: cur.execute("SHOW TABLES LIKE '%user_dept%'") t = [r[0] for r in cur.fetchall()] print(' tables:', t) for tb in t: cur.execute('SELECT * FROM %s WHERE user_id IN ' '(744842565802524672, 744842566742048768, 744842318024015872)' % tb) for r in cur.fetchall(): print(' ', tb, r) except Exception as e: print(' ERR', e) print('== 部门名称 ==') try: cur.execute("SELECT id, dept_name, parent_id FROM sys_dept " "WHERE id IN (744841308564094976, 744841292483133440, 744841308677341184) " "OR parent_id IN (744841308564094976, 744841292483133440, 744841308677341184)") for r in cur.fetchall(): print(' ', r) except Exception as e: print(' ERR', e) print('== 项目角色字典 ==') try: cur.execute("SHOW TABLES LIKE '%dict%'") dt = [r[0] for r in cur.fetchall()] print(' tables:', dt) cur.execute("SELECT id, group_code, item_code, item_name, enabled FROM " "(SELECT * FROM sys_dict_item) di WHERE item_code LIKE 'project_role%' LIMIT 20") for r in cur.fetchall(): print(' ', r) except Exception as e: print(' ERR', e) conn.close() print('done')