1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| 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,connect_timeout=10,read_timeout=60)
| s={}
| with c.cursor() as q:
| q.execute('SELECT DATABASE() db');assert q.fetchone()['db']=='mom-hm'
| q.execute('SHOW CREATE TABLE system_operate_log');s['log_schema']=q.fetchone()
| q.execute('SELECT COUNT(*) n FROM system_operate_log WHERE deleted=0');s['log_count']=q.fetchone()['n']
| q.execute('SELECT * FROM system_operate_log WHERE deleted=0 ORDER BY id DESC LIMIT 30');s['existing_logs']=q.fetchall()
| q.execute('SELECT id,username,nickname,status,dept_id FROM system_users WHERE deleted=0');s['users']=q.fetchall()
| for t in ['crm_contract','erp_sale_order','mes_pro_mps','mes_pro_route','mes_pro_process','mes_md_workstation','mes_pd_process_param','mes_pd_process_param_template','mes_md_item','mes_qc_iqc','mes_qc_oqc','mes_md_product_bom']:
| 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 COLUMNS FROM '+t);cols=[x['Field'] for x in q.fetchall()]
| wanted=[x for x in ['id','code','no','name','param_name','template_name','status','creator','create_time','updater','update_time','remark','sale_order_id','sale_order_no','sale_order_item_id','product_id','item_id','count','quantity','production_status','process_id','workshop_id'] if x in cols]
| q.execute('SELECT '+','.join('`'+x+'`' for x in wanted)+' FROM '+t+' WHERE deleted=0 ORDER BY id');s[t]=q.fetchall()
| c.close()
| (P/'before-log-sources.json').write_text(json.dumps(s,ensure_ascii=False,indent=2,default=str),encoding='utf8')
| print(s['log_schema']['Create Table']);print('existing_log_count',s['log_count']);print('existing_examples',json.dumps(s['existing_logs'][:3],ensure_ascii=False,default=str));print('source_counts',json.dumps({k:len(v) for k,v in s.items() if isinstance(v,list)},ensure_ascii=False));print('source_creators',sorted({str(r.get('creator')) for k,v in s.items() if isinstance(v,list) and k not in ['existing_logs','users'] for r in v}));print('users',json.dumps([u for u in s['users'] if u['id'] in [1,244,291]],ensure_ascii=False))
|
|