38 lines
1.4 KiB
Python
Executable File
38 lines
1.4 KiB
Python
Executable File
import pandas as pd
|
|
|
|
kd = pd.read_excel('物料清单正查_.xlsx', sheet_name='树形单据体')
|
|
kd = kd[kd['子项物料编码'].notna()].copy()
|
|
kd['code'] = kd['子项物料编码'].astype(str).str.strip()
|
|
kd['level'] = kd['BOM层级'].astype(str).str.strip()
|
|
|
|
db = pd.read_csv('db_bom.csv', dtype={'ChildMaterialId': str, 'ParentMaterialId': str})
|
|
db['code'] = db['ChildMaterialId'].astype(str).str.strip()
|
|
db['parent'] = db['ParentMaterialId'].astype(str).str.strip()
|
|
|
|
kd_codes = set(kd['code'])
|
|
db_codes = set(db['code'])
|
|
only_db = sorted(db_codes - kd_codes)
|
|
|
|
print("=== 数据库独有编码的上下文(父级/层级/名称/规格) ===")
|
|
for c in only_db:
|
|
rows = db[db['code'] == c]
|
|
for _, r in rows.iterrows():
|
|
print(f" {c} | 父级={r['parent']} | 层级={r['Level']} | 用量={r['UsageQty']} | 名称={r['MaterialName']} | 规格={r['Spec']}")
|
|
|
|
# 尝试匹配:数据库独有编码 vs 金蝶编码(去掉版本后缀比较)
|
|
import re
|
|
def strip_suffix(code):
|
|
# 去掉末尾的 -XX 版本后缀
|
|
return re.sub(r'-[A-Z]\d+$', '', code)
|
|
|
|
print("\n=== 数据库独有编码 与 金蝶编码 去后缀后的匹配 ===")
|
|
kd_stripped = {}
|
|
for c in kd_codes:
|
|
s = strip_suffix(c)
|
|
kd_stripped.setdefault(s, []).append(c)
|
|
|
|
for c in only_db:
|
|
s = strip_suffix(c)
|
|
if s in kd_stripped:
|
|
print(f" {c} (数据库) 去后缀={s} -> 金蝶有: {kd_stripped[s]}")
|