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 DATABASE() db,NOW() now');s['state']=q.fetchone();assert s['state']['db']=='mom-hm' q.execute('SELECT id,username,nickname,status,dept_id FROM system_users WHERE deleted=0');s['users']=q.fetchall() for t in ['crm_customer','mdm_item','mdm_item_unit','mes_md_item','mes_md_unit_measure','erp_product','erp_product_unit','erp_account','crm_sale_quotation','crm_sale_quotation_product','crm_contract','crm_contract_product','erp_sale_order','erp_sale_order_items','crm_invoice','crm_receivable','crm_receivable_plan','crm_permission','crm_contract_config']: q.execute('SELECT COUNT(*) n FROM information_schema.tables WHERE table_schema=DATABASE() AND table_name=%s',(t,)) if not q.fetchone()['n']:continue q.execute('SHOW CREATE TABLE `'+t+'`');schema=q.fetchone() q.execute('SELECT * FROM `'+t+'` WHERE deleted=0 ORDER BY id');rows=q.fetchall() s[t]={'schema':schema,'rows':rows} print(t,len(rows)) if t not in ['crm_customer','mdm_item','mes_md_item','crm_permission','erp_product']:print(schema['Create Table']) q.execute("SELECT dict_type,label,value FROM system_dict_data WHERE deleted=0 AND (dict_type LIKE '%%invoice%%' OR dict_type LIKE '%%receivable%%' OR dict_type LIKE '%%quotation%%' OR dict_type LIKE '%%audit%%') ORDER BY dict_type,sort");s['dicts']=q.fetchall() print('dicts',json.dumps(s['dicts'],ensure_ascii=False,default=str)) (P/'before-ledger-database.json').write_text(json.dumps(s,ensure_ascii=False,default=str,indent=2),encoding='utf8') c.close()