From f66e6dd39e29747b7b75d8c64b0b11322a03baf5 Mon Sep 17 00:00:00 2001 From: Misaka_Company Date: Fri, 31 Jul 2026 14:44:50 +0800 Subject: [PATCH] fix(yunda): invert handover number filter to keep empty rows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous filter kept rows with non-empty handover numbers (派件/签收 scans), which were duplicate rows. The correct logic is to keep rows with empty handover numbers (到/接件 scans). - store.py: change != "" to == "" in ingest filter - compare.py: add same filter before comparison (previously missing) Co-Authored-By: Claude --- inbound_verify/compare.py | 6 ++++++ inbound_verify/store.py | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/inbound_verify/compare.py b/inbound_verify/compare.py index 9629826..e55bdd6 100644 --- a/inbound_verify/compare.py +++ b/inbound_verify/compare.py @@ -75,6 +75,12 @@ def process(name): df_exp = pd.read_excel(exp_path, dtype=str).fillna("") df_act = pd.read_excel(act_path, dtype=str).fillna("") + if name == "韵达": + # 韵达实到数据有重复行(同子单号出现两次),保留交接单号为空的(到/接件扫描), + # 丢弃交接单号不为空的(派件/签收等),再按子单号去重。 + df_act = df_act[df_act["交接单号"].astype(str).str.strip() == ""] + df_act = df_act.drop_duplicates(subset=["子单号"], keep="last") + # 同一运单可能有多条交接记录,按运单号去重、保留首条 dup = int(df_exp[cfg["exp_wb"]].duplicated().sum()) df_exp = df_exp.drop_duplicates(subset=[cfg["exp_wb"]], keep="first") diff --git a/inbound_verify/store.py b/inbound_verify/store.py index 508978c..e69a00f 100644 --- a/inbound_verify/store.py +++ b/inbound_verify/store.py @@ -314,9 +314,10 @@ def _ingest_actual(cur, site): cm = ACTUAL_COLMAP[site] df = pd.read_excel(path, dtype=str).fillna("") if site == "韵达": - # 韵达业务清洗:抛弃「交接单号」为空的行(派件/签收等其他扫描无交接单号), + # 韵达业务清洗:保留「交接单号」为空的行(到/接件扫描), + # 抛弃「交接单号」不为空的行(派件/签收等,属重复数据)。 # 再按子单号去重(一件多扫只留一条;清洗后子单号已天然唯一,drop 为保险)。 - df = df[df["交接单号"].astype(str).str.strip() != ""] + df = df[df["交接单号"].astype(str).str.strip() == ""] df = df.drop_duplicates(subset=[cm["piece"]], keep="last") rows = [] for r in df.to_dict("records"):