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