gaoluyang
2 天以前 e71d71bf43c2307c89d3592adf08c1b32fcd0907
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import sys,json,collections
from pathlib import Path
P=Path(__file__).parent;P.mkdir(exist_ok=True)
sys.path.insert(0,str(P.parent/'iqc-import-20261012/deps'))
import pymysql,openpyxl
base=Path('D:/WechatRecord/xwechat_files/wxid_vmeut7wztkbp22_1546/temp/RWTemp/2026-10/c40afdcfa98e2b4561823e6babbefa33')
src={}
for kind,f in [('oqc','出货检验单导入-已填充.xlsx'),('ipqc','过程检验单导入-已填充.xlsx')]:
 w=openpyxl.load_workbook(base/f,data_only=True)
 r=list(w.active.values)
 src[kind]={'file':str(base/f),'sheet':w.active.title,'rows':[dict(zip(r[0],row),excel_row=i) for i,row in enumerate(r[1:],2) if any(row)]}
(P/'source.json').write_text(json.dumps(src,ensure_ascii=False,default=str,indent=2),encoding='utf8')
c=pymysql.connect(host='36.213.150.237',port=10000,user='root',password=sys.stdin.readline().strip(),database='mom-hm',charset='utf8mb4',connect_timeout=10,read_timeout=45,cursorclass=pymysql.cursors.DictCursor)
out={}
with c.cursor() as q:
 for t in ['mes_qc_oqc','mes_qc_oqc_line','mes_qc_ipqc','mes_qc_ipqc_line','mes_qc_template','mes_qc_template_indicator','mes_qc_template_item','mes_qc_indicator','mdm_item','mes_md_item','system_users','system_dict_data','crm_customer','mes_pro_work_order','mes_md_workstation','mes_pro_task','mes_wm_product_sales','mes_wm_product_sales_line']:
  q.execute('SELECT COUNT(*) n FROM information_schema.tables WHERE table_schema=DATABASE() AND table_name=%s',(t,))
  if q.fetchone()['n']==0:continue
  q.execute('SHOW CREATE TABLE `'+t+'`');out[t+'_schema']=q.fetchone()
  q.execute('SELECT * FROM `'+t+'` WHERE deleted=0');out[t]=q.fetchall()
c.close()
(P/'remote-snapshot.json').write_text(json.dumps(out,ensure_ascii=False,default=str,indent=2),encoding='utf8')
print('counts',{k:len(v) for k,v in out.items() if isinstance(v,list)})
print('template types',dict(collections.Counter(x['types'] for x in out['mes_qc_template'])))
for x in out['mes_qc_template']:
 if x['types']!='1':print(x['id'],x['name'],x['types'],x['status'])