云
11 小时以前 1f6a660180d4e6fccd1ec83a27b79ea93a121817
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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("SHOW TABLES LIKE 'qc_report%'");report_tables=[list(x.values())[0] for x in q.fetchall()]
 for t in ['mes_qc_indicator','mes_qc_template','mes_qc_template_indicator','mes_qc_template_item','mes_qc_iqc','mes_qc_iqc_line','mes_qc_ipqc','mes_qc_ipqc_line','mes_qc_oqc','mes_qc_oqc_line','mes_qc_rqc','mes_qc_rqc_line','mes_qc_indicator_result','mes_qc_indicator_result_detail','mes_md_unit_measure']+report_tables:
  q.execute('SHOW FULL COLUMNS FROM `'+t+'`');cols=q.fetchall()
  q.execute('SELECT * FROM `'+t+'` ORDER BY id');rows=q.fetchall();out[t]={'columns':cols,'rows':rows}
 q.execute("SELECT * FROM system_dict_data WHERE dict_type IN ('mes_indicator_type','mes_qc_result_type') AND deleted=0");out['dicts']=q.fetchall()
Path(__file__).with_name('audit.json').write_text(json.dumps(out,ensure_ascii=False,indent=2,default=str),encoding='utf8')
active=lambda v:[x for x in v if x.get('deleted') not in (1,b'\x01')]
print(json.dumps({'counts':{t:len(active(v['rows'])) for t,v in out.items() if isinstance(v,dict)},'indicator_types':dict(collections.Counter(str(x['result_type']) for x in active(out['mes_qc_indicator']['rows']))),'indicators':[{'id':x['id'],'code':x['code'],'name':x['name'],'parent':x['parent_id'],'item_type':x['item_type'],'type':x['type'],'result_type':x['result_type'],'unit':x['unit_text']} for x in active(out['mes_qc_indicator']['rows'])],'dicts':out['dicts'],'report_columns':{t:[x['Field'] for x in out[t]['columns']] for t in report_tables}},ensure_ascii=False,default=str));c.close()