1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| import sys,json,collections
| from pathlib import Path
| sys.stdout.reconfigure(encoding='utf-8')
| sys.path.insert(0,str(Path('scripts/iqc-import-20261012/deps').resolve()))
| 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)
| out={}
| with c.cursor() as q:
| q.execute('SELECT id,username,nickname,dept_id,status,deleted FROM system_users');out['users']=q.fetchall()
| q.execute('SELECT id,name FROM system_dept');out['depts']=q.fetchall()
| for t in ['mes_qc_iqc','mes_qc_ipqc','mes_qc_oqc','mes_qc_rqc','mes_wm_product_sales','mes_wm_product_produce','mes_pro_feedback','mes_pro_task','mes_pro_work_order','mes_wm_arrival_notice','mes_wm_item_receipt','mes_wm_return_vendor','mes_wm_rt_sales']:
| q.execute('SHOW TABLES LIKE %s',(t,))
| if not q.fetchone():continue
| q.execute('SHOW FULL COLUMNS FROM '+t);columns=q.fetchall()
| q.execute('SELECT * FROM '+t+' WHERE deleted=0 ORDER BY id');rows=q.fetchall();out[t]={'columns':columns,'rows':rows}
| Path(__file__).with_name('audit.json').write_text(json.dumps(out,ensure_ascii=False,indent=2,default=str),encoding='utf8')
| summary={}
| for t,v in out.items():
| if t.startswith('mes_qc_'):
| summary[t]={'count':len(v['rows']),'missing_date':sum(x.get('inspect_date') is None for x in v['rows']),'missing_inspector':sum(not x.get('inspector_user_id') for x in v['rows']),'inspectors':dict(collections.Counter(str(x.get('inspector_user_id')) for x in v['rows'])),'sources':dict(collections.Counter(str(x.get('source_doc_type')) for x in v['rows'])),'missing_samples':[{'id':x['id'],'code':x['code'],'inspector':x.get('inspector_user_id'),'date':x.get('inspect_date'),'source_id':x.get('source_doc_id'),'source_type':x.get('source_doc_type'),'creator':x['creator'],'create_time':x['create_time']} for x in v['rows'] if not x.get('inspector_user_id') or x.get('inspect_date') is None][:10]}
| print(json.dumps({'summary':summary,'quality_users':[x for x in out['users'] if x['dept_id']==118]},ensure_ascii=False,default=str));c.close()
|
|