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
27
28
29
30
31
32
| from pathlib import Path
| import sys,re,json
| from openpyxl import load_workbook
| sys.stdout.reconfigure(encoding='utf-8')
| sys.path.insert(0,str(Path('scripts/iqc-import-20261012/deps').resolve()))
| import pymysql
| P=Path(__file__).parent
| def connect():
| s=Path('yudao-server/src/main/resources/application-local.yaml').read_text(encoding='utf-8');x=s[s.index('jdbc:mysql://localhost:3306/'):]
| pw=re.search(r'password:\s*([^\r\n#]+)',x).group(1).strip().strip('\"\'')
| return pymysql.connect(host='127.0.0.1',port=3306,user='root',password=pw,database='mom-hm',charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor,autocommit=False)
| def dump(name,value): (P/name).write_text(json.dumps(value,ensure_ascii=False,indent=2,default=str),encoding='utf-8')
| if __name__=='__main__':
| w=load_workbook('C:/Users/云/Desktop/电商未缴库计划.xlsx2026.10.15xlsx.xlsx',data_only=True);source=[]
| for sheet in w:
| for row in sheet.iter_rows(min_row=3):
| v=[c.value for c in row]
| if isinstance(v[0],(int,float)) and v[1] and v[5]:source.append(dict(sheet=sheet.title,row=row[0].row,code=v[1],name=v[2],spec=v[3],unit=v[4],quantity=v[5],price=v[6],amount=v[7],due=v[8],note=v[9]))
| dump('source.json',source)
| tables=['mdm_item','mdm_unit_measure','mes_md_item','mes_md_unit_measure','mes_pro_route','mes_pro_route_product','mes_pro_route_process','mes_md_product_bom','mes_pro_route_product_bom','mes_md_workstation','mes_md_workstation_machine','mes_dv_machinery','mes_pd_process_param_template','mes_pd_process_param_template_detail','mes_cal_holiday','crm_customer','crm_business','crm_sale_quotation','crm_sale_quotation_product','crm_contract','crm_contract_product','crm_receivable_plan','crm_receivable','crm_permission','erp_sale_order','erp_sale_order_items','mes_pro_mps','mes_pro_work_order','mes_pro_work_order_process','mes_pro_work_order_bom','mes_pro_task','mes_pro_feedback','mes_pro_work_order_param_record','mes_pro_work_order_param_record_detail','mes_md_auto_code_rule','mes_md_auto_code_part','mes_md_auto_code_record','mes_pro_task_assignee']
| c=connect();data={};schema={}
| try:
| with c.cursor() as q:
| for t in tables:
| q.execute('show full columns from `'+t+'`');schema[t]=q.fetchall()
| q.execute('select * from `'+t+'` where deleted=0');data[t]=q.fetchall()
| q.execute('select id,nickname,dept_id,status from system_users where deleted=0');data['users']=q.fetchall()
| dump('audit.json',data);dump('schema.json',schema)
| print('Source rows:',len(source),'amount:',sum(r['amount'] for r in source))
| for x in data['mdm_item']:
| if x['name'] and (('90' in (x.get('specification') or '') and '枸杞' in x['name']) or ('500' in (x.get('specification') or '') and ('桑' in x['name'])) or (x['name']=='雪菊' and '50' in (x.get('specification') or ''))): print(json.dumps({k:x.get(k) for k in ['id','code','name','specification','unit_measure_id']},ensure_ascii=False))
| finally:c.rollback();c.close()
|
|