refactor: expected_undelivered uses paths.DOWNLOAD_DIR/OUTPUT_DIR (Tier 2)

Remove the duplicate BASE/DOWNLOADS/OUTPUT self-anchor (the one that caused the Tier 1 hotfix bug when the file moved into the package). DOWNLOADS/OUTPUT now come from paths.py; OUTFILE derives from OUTPUT_DIR. Behavior identical.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-07-24 08:34:57 +08:00
parent 17293bee79
commit bd0df8909f

View File

@@ -40,12 +40,10 @@ from openpyxl.chart import BarChart, Reference
from openpyxl.worksheet.page import PageMargins from openpyxl.worksheet.page import PageMargins
from openpyxl.worksheet.properties import PageSetupProperties from openpyxl.worksheet.properties import PageSetupProperties
# 包内文件:上两级 = 项目根(与 paths.BASE_DIR 一致;站点下载落在 <root>/downloads from inbound_verify.paths import DOWNLOAD_DIR, OUTPUT_DIR
# 注:本模块自带锚点是 paths.py 的重复Tier 2 计划改为直接引用 paths.DOWNLOAD_DIR/OUTPUT_DIR。
BASE = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # 比对报表输出文件(路径锚定统一走 paths.py
DOWNLOADS = os.path.join(BASE, "downloads") OUTFILE = os.path.join(OUTPUT_DIR, "应到未到数据.xlsx")
OUTPUT = os.path.join(BASE, "output")
OUTFILE = os.path.join(OUTPUT, "应到未到数据.xlsx")
# 汇总报表覆盖的全部站点4 站在前、百世在末;汇总页图表只取 4 站) # 汇总报表覆盖的全部站点4 站在前、百世在末;汇总页图表只取 4 站)
ALL_REPORT_SITES = ["顺心", "中通", "韵达", "安能", "百世"] ALL_REPORT_SITES = ["顺心", "中通", "韵达", "安能", "百世"]
@@ -143,8 +141,8 @@ def process(name):
cfg = _site_cfg(name) cfg = _site_cfg(name)
if cfg is None: if cfg is None:
return None return None
exp_path = os.path.join(DOWNLOADS, cfg["exp"]) exp_path = os.path.join(DOWNLOAD_DIR, cfg["exp"])
act_path = os.path.join(DOWNLOADS, cfg["act"]) act_path = os.path.join(DOWNLOAD_DIR, cfg["act"])
if not os.path.exists(exp_path) or not os.path.exists(act_path): if not os.path.exists(exp_path) or not os.path.exists(act_path):
print(f"[跳过] {cfg['name']}downloads 下缺少 {cfg['exp']}{cfg['act']}") print(f"[跳过] {cfg['name']}downloads 下缺少 {cfg['exp']}{cfg['act']}")
return None return None
@@ -295,7 +293,7 @@ def write_station(ws, columns, rows):
def process_baishi(): def process_baishi():
"""百世:读站点直供的未到明细,返回 (columns, rows, stats);文件缺失返回 None。 """百世:读站点直供的未到明细,返回 (columns, rows, stats);文件缺失返回 None。
百世文件本身即未到结果(无应到/已到基数),统计只能给出未到件数。""" 百世文件本身即未到结果(无应到/已到基数),统计只能给出未到件数。"""
path = os.path.join(DOWNLOADS, BAISHI_FILE) path = os.path.join(DOWNLOAD_DIR, BAISHI_FILE)
if not os.path.exists(path): if not os.path.exists(path):
return None return None
df = pd.read_excel(path, dtype=str).fillna("") df = pd.read_excel(path, dtype=str).fillna("")
@@ -335,7 +333,7 @@ def process_baishi():
def write_site_file(name): def write_site_file(name):
"""4 站:把该站未到明细写到 downloads/<站>-未到数据.xlsx。 """4 站:把该站未到明细写到 downloads/<站>-未到数据.xlsx。
应到/实到缺process 返回 None→ 删旧文件、返回 False成功返回 True。""" 应到/实到缺process 返回 None→ 删旧文件、返回 False成功返回 True。"""
path = os.path.join(DOWNLOADS, SITE_UNDELIVERED_FILE.format(name=name)) path = os.path.join(DOWNLOAD_DIR, SITE_UNDELIVERED_FILE.format(name=name))
out = process(name) out = process(name)
if out is None: if out is None:
if os.path.exists(path): if os.path.exists(path):
@@ -371,7 +369,7 @@ def build_full_report(include, dates=None):
"""生成全站汇总报表 output/应到未到数据.xlsx。 """生成全站汇总报表 output/应到未到数据.xlsx。
include: 本次成功的站点集合;未成功站点在汇总里保留行、无数据(不影响他站)。 include: 本次成功的站点集合;未成功站点在汇总里保留行、无数据(不影响他站)。
返回 {站点: 未到件或None} 供日志。""" 返回 {站点: 未到件或None} 供日志。"""
os.makedirs(OUTPUT, exist_ok=True) os.makedirs(OUTPUT_DIR, exist_ok=True)
wb = Workbook() wb = Workbook()
wb.remove(wb.active) wb.remove(wb.active)
summary_ws = wb.create_sheet("汇总报表") # 首页占位 summary_ws = wb.create_sheet("汇总报表") # 首页占位
@@ -666,14 +664,14 @@ def main():
include = set() include = set()
for name in ALL_REPORT_SITES: for name in ALL_REPORT_SITES:
if name == "百世": if name == "百世":
if os.path.exists(os.path.join(DOWNLOADS, BAISHI_FILE)): if os.path.exists(os.path.join(DOWNLOAD_DIR, BAISHI_FILE)):
include.add(name) include.add(name)
else: else:
cfg = _site_cfg(name) cfg = _site_cfg(name)
if ( if (
cfg cfg
and os.path.exists(os.path.join(DOWNLOADS, cfg["exp"])) and os.path.exists(os.path.join(DOWNLOAD_DIR, cfg["exp"]))
and os.path.exists(os.path.join(DOWNLOADS, cfg["act"])) and os.path.exists(os.path.join(DOWNLOAD_DIR, cfg["act"]))
): ):
include.add(name) include.add(name)
if not include: if not include: