feat: dedup expected data by handover_no before export submit

- store.get_existing_handover_nos: query PG expected_record.handover_no

- inject dedup skip before submitting export in zto/yunda/anneng/shunxin

- shunxin reads RTS handover_no from waybill-list view (method 1)

- force-redownload switch threaded via task_spec -> dispatch -> impl

- schema: add idx_expected_handover index

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-07-29 10:57:07 +08:00
parent d74a35844f
commit f710622a3d
11 changed files with 663 additions and 28 deletions

View File

@@ -855,13 +855,15 @@ def _load_query_days():
return max(1, days)
def anneng_expected_download():
def anneng_expected_download(force=False):
"""安能:应到货物数据下载(内部含异常兜底重试,路由层无感)。"""
return with_retry("安能", "应到", anneng_expected_download_impl, anneng_reset)
return with_retry(
"安能", "应到", lambda: anneng_expected_download_impl(force=force), anneng_reset
)
def anneng_expected_download_impl():
def anneng_expected_download_impl(force=False):
"""安能:应到货物数据(运单信息)下载,完整流程(单次执行,无重试;供自动化测试用)。"""
print("\n▶ 开始执行【安能 - 应到货物数据下载】任务 ...")
download_dir = DOWNLOAD_DIR
@@ -880,6 +882,20 @@ def anneng_expected_download_impl():
main_cdp = find_main_page_cdp()
export_times = []
# 【去重】加载本站已落库交接单号force=True 或查询失败时 existing=空集(不去重)
if force:
existing = set()
print(">> [去重] 强制重下,跳过去重。")
else:
try:
from inbound_verify import store
existing = store.get_existing_handover_nos("安能")
except Exception as _e:
existing = set()
print(f">> [去重] 加载已落库交接单号失败,本次不去重: {_e}")
try:
# 1) 确认主页就绪并导航到“进站交接单查询”
wait_home_ready(main_cdp)
@@ -918,6 +934,10 @@ def anneng_expected_download_impl():
for i, ewbs_no in enumerate(target_ids, start=1):
print(f" ⏳ [{i}/{len(target_ids)}] 交接单号 {ewbs_no}")
# 【去重】已落库则跳过:不双击、不导出、不 append export_times
if ewbs_no in existing:
print(f" ⏭️ 交接单号 {ewbs_no} 已落库,跳过。")
continue
activate_tab(tab_cdp, "交接单信息")
time.sleep(0.3)
if not dblclick_jiaojie_dan_row(tab_cdp, ewbs_no):
@@ -936,6 +956,11 @@ def anneng_expected_download_impl():
close_tab_by_label(main_cdp, "进站交接单查询")
time.sleep(0.8)
# 【去重兜底】全部已落库/无数据 → 无导出任务,查询 tab 已关,跳过下载段
if not export_times:
print(">> 本次无新交接单需导出(全部已落库或无数据),结束。")
return True
# 5) 打开导出下载 tab轮询并下载
print(">> 打开【导出下载】tab ...")
export_cdp = ensure_tab_open(main_cdp, "导出下载", EXPORT_TAB_URL_HINT)
@@ -1233,7 +1258,7 @@ def _save_actual(rows, download_dir):
print("====================================================")
def anneng_actual_download():
def anneng_actual_download(force=False):
"""安能:实到数据下载(内部含异常兜底重试,路由层无感)。"""
return with_retry("安能", "实到", anneng_actual_download_impl, anneng_reset)