Centralize paths in paths.py and harden waybill-number handling
- Add paths.py: BASE_DIR/DOWNLOAD_DIR/CONFIG_PATH anchored on __file__ so paths resolve regardless of the launch cwd - Route main_router and all site modules through DOWNLOAD_DIR/CONFIG_PATH, replacing os.getcwd()-based download dirs and the "config.yaml" literal - main_router compare engine: read Excel as str with keep_default_na, strip/normalize 运单号, drop blanks, and isin against a set so int/float-vs-str mismatches no longer produce false "undelivered" - Shunxin: give downloaded files unique microsecond temp names and read Excel as str to preserve long-waybill precision - Normalize bare except: to except Exception: across affected files Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,8 @@ import yaml
|
||||
import pandas as pd
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
from paths import DOWNLOAD_DIR, CONFIG_PATH
|
||||
|
||||
# 导入抽离出去的各个网点模块
|
||||
import site_shunxin
|
||||
import site_baishi
|
||||
@@ -34,7 +36,7 @@ def task_process_undelivered_data(site_name="顺心"):
|
||||
"""全局模块:应到未到异常件比对引擎 (支持动态网点前缀)"""
|
||||
print(f"\n▶ 开始执行【{site_name} - 应到未到数据处理】任务...")
|
||||
|
||||
download_dir = os.path.join(os.getcwd(), "downloads")
|
||||
download_dir = DOWNLOAD_DIR
|
||||
expected_path = os.path.join(download_dir, f"{site_name}-应到货物数据.xlsx")
|
||||
actual_path = os.path.join(download_dir, f"{site_name}-实到货物数据.xlsx")
|
||||
output_path = os.path.join(download_dir, f"{site_name}-应到未到货物数据.xlsx")
|
||||
@@ -49,8 +51,9 @@ def task_process_undelivered_data(site_name="顺心"):
|
||||
|
||||
try:
|
||||
print(">> 正在载入本地 Excel 文档...")
|
||||
df_expected = pd.read_excel(expected_path)
|
||||
df_actual = pd.read_excel(actual_path)
|
||||
# 全部按字符串读取并保留空串:避免 18 位运单号被当成浮点数丢精度,也避免空单元格变成 NaN。
|
||||
df_expected = pd.read_excel(expected_path, dtype=str, keep_default_na=False)
|
||||
df_actual = pd.read_excel(actual_path, dtype=str, keep_default_na=False)
|
||||
|
||||
if "运单号" not in df_expected.columns or "运单号" not in df_actual.columns:
|
||||
print("❌ 核心资产校验失败:数据源中缺失【运单号】字段,请检查导出配置。")
|
||||
@@ -58,8 +61,16 @@ def task_process_undelivered_data(site_name="顺心"):
|
||||
|
||||
print(">> 正在启动多维数据集比对引擎...")
|
||||
|
||||
# 统一运单号为去空白字符串,消除 int/float 与 str 混读导致 isin 永不命中的隐患
|
||||
df_expected["运单号"] = df_expected["运单号"].astype(str).str.strip()
|
||||
df_actual["运单号"] = df_actual["运单号"].astype(str).str.strip()
|
||||
|
||||
# 剔除空白运单号,避免空值被误判为“应到未到”
|
||||
df_expected = df_expected[df_expected["运单号"] != ""]
|
||||
actual_set = set(df_actual["运单号"]) - {""}
|
||||
|
||||
# Left Anti-Join:在应到中找出不存在于实到里的运单号
|
||||
df_undelivered = df_expected[~df_expected["运单号"].isin(df_actual["运单号"])]
|
||||
df_undelivered = df_expected[~df_expected["运单号"].isin(actual_set)]
|
||||
|
||||
target_columns = ["班次号", "交接单号", "运单号"]
|
||||
available_columns = [
|
||||
@@ -86,8 +97,8 @@ def run_multi_site_daemon():
|
||||
debug_mode = False
|
||||
debug_target = ""
|
||||
try:
|
||||
if os.path.exists("config.yaml"):
|
||||
with open("config.yaml", "r", encoding="utf-8") as f:
|
||||
if os.path.exists(CONFIG_PATH):
|
||||
with open(CONFIG_PATH, "r", encoding="utf-8") as f:
|
||||
config = yaml.safe_load(f)
|
||||
debug_mode = config.get("debug", {}).get("enabled", False)
|
||||
debug_target = config.get("debug", {}).get("target_site", "")
|
||||
@@ -191,7 +202,7 @@ def run_multi_site_daemon():
|
||||
if read_btns.nth(i).is_visible(timeout=500):
|
||||
read_btns.nth(i).click()
|
||||
handled_any = True
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
if bs_page.locator("button:has-text('关 闭')").is_visible(
|
||||
@@ -199,7 +210,7 @@ def run_multi_site_daemon():
|
||||
):
|
||||
bs_page.locator("button:has-text('关 闭')").click()
|
||||
handled_any = True
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
if not handled_any:
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user