import sys,json from pathlib import Path P=Path(__file__).parent sys.path.insert(0,str(P.parent/'iqc-import-20261012/deps')) import pymysql c=pymysql.connect(host='36.213.150.237',port=10000,user='root',password=sys.stdin.readline().strip(),database='mom-hm',charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor) s={} with c.cursor() as q: q.execute("SELECT type,sub_type,COUNT(*) n FROM system_operate_log WHERE deleted=0 GROUP BY type,sub_type ORDER BY type,sub_type");s['groups']=q.fetchall() q.execute("SELECT * FROM system_operate_log WHERE deleted=0 AND type LIKE 'MDM%%' AND (type LIKE '%%物料%%' OR sub_type LIKE '%%物料%%') ORDER BY id");s['mdm_material_logs']=q.fetchall() q.execute("SELECT table_name FROM information_schema.tables WHERE table_schema=DATABASE() AND (table_name LIKE 'mdm%%item%%' OR table_name LIKE 'mdm%%material%%')");s['candidate_tables']=q.fetchall() (P/'before-mdm-material-logs.json').write_text(json.dumps(s,ensure_ascii=False,default=str,indent=2),encoding='utf8') print(json.dumps({'groups':s['groups'],'mdm_material_logs':[{k:r[k] for k in ['id','type','sub_type','user_id','biz_id','action','create_time','trace_id']} for r in s['mdm_material_logs']],'candidate_tables':s['candidate_tables']},ensure_ascii=False,default=str)) c.close()