gaoluyang
3 天以前 e40a608ef9bf51db294d8eefada6a8e2e80cebca
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import sys,json
from pathlib import Path
P=Path(__file__).parent
sys.stdout.reconfigure(encoding='utf8')
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={'tables':{}}
with c.cursor() as q:
 q.execute('SELECT NOW() now,DATABASE() db');s['state']=q.fetchone()
 q.execute("SELECT table_name FROM information_schema.tables WHERE table_schema=DATABASE() AND table_name LIKE 'mes_cal_%'");tabs=[x['TABLE_NAME'] for x in q.fetchall()]
 for t in tabs+['system_dept','system_users']:
  q.execute('SHOW CREATE TABLE '+t);ddl=q.fetchone()['Create Table']
  q.execute('SELECT * FROM '+t+' WHERE deleted=0 ORDER BY id');rows=q.fetchall();s['tables'][t]={'ddl':ddl,'rows':rows}
  if t.startswith('mes_cal_'):print(t,ddl,json.dumps(rows[:15],ensure_ascii=False,default=str))
  elif t=='system_dept':print('部门',json.dumps(rows,ensure_ascii=False,default=str))
 depts={r['id'] for r in s['tables']['system_dept']['rows'] if '生产' in r['name']}
 print('生产部门用户',json.dumps([{k:x[k] for k in ['id','username','nickname','dept_id','status']} for x in s['tables']['system_users']['rows'] if x['dept_id'] in depts],ensure_ascii=False))
(P/'production-schedule-before.json').write_text(json.dumps(s,ensure_ascii=False,default=str,indent=2),encoding='utf8')
c.close()