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:
@@ -109,18 +109,18 @@ def zto_smart_menu_click(page, menu_path):
|
||||
page.wait_for_timeout(1000)
|
||||
|
||||
|
||||
def zto_expected_download(page):
|
||||
def zto_expected_download(page, force=False):
|
||||
"""中通:应到货物数据下载(内部含异常兜底重试,路由层无感)。"""
|
||||
|
||||
return with_retry(
|
||||
"中通",
|
||||
"应到",
|
||||
lambda: zto_expected_download_impl(page),
|
||||
lambda: zto_expected_download_impl(page, force=force),
|
||||
lambda: zto_reset(page),
|
||||
)
|
||||
|
||||
|
||||
def zto_expected_download_impl(page):
|
||||
def zto_expected_download_impl(page, force=False):
|
||||
"""中通:应到货物数据下载(单次执行,无重试;供自动化测试探测原始结果用)。"""
|
||||
print("\n▶ 开始执行【中通 - 应到货物数据下载】任务...")
|
||||
|
||||
@@ -240,6 +240,19 @@ def zto_expected_download_impl(page):
|
||||
count = main_rows.count()
|
||||
print(f">> 共发现 {count} 个交接单需要导出。")
|
||||
|
||||
# 【去重】加载本站已落库交接单号;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}")
|
||||
|
||||
for i in range(count):
|
||||
print(f" ⏳ 正在处理第 {i+1}/{count} 个交接单...")
|
||||
row = ewb_frame.locator(
|
||||
@@ -251,6 +264,11 @@ def zto_expected_download_impl(page):
|
||||
handover_no = match.group(0) if match else raw_text.strip()
|
||||
print(f" -> 当前交接单号:{handover_no}")
|
||||
|
||||
# 【去重】已落库的交接单号不再提交导出任务(不双击、不 append export_times)
|
||||
if handover_no in existing:
|
||||
print(f" ⏭️ 交接单号 {handover_no} 已落库,跳过提交导出。")
|
||||
continue
|
||||
|
||||
row.dblclick()
|
||||
|
||||
ewb_frame.locator("#datagrid2").get_by_text("运单号").wait_for(
|
||||
@@ -316,6 +334,11 @@ def zto_expected_download_impl(page):
|
||||
except Exception as e:
|
||||
print(f" ⚠️ 关闭【进站交接单查询】标签页时出错: {e}")
|
||||
|
||||
# 【去重兜底】全部已落库/无数据 → 无导出任务,标签页已关,直接结束不进轮询
|
||||
if not export_times:
|
||||
print(">> 本次无新交接单需导出(全部已落库或无数据),结束。")
|
||||
return True
|
||||
|
||||
# 交由统一的轮询下载流程处理
|
||||
_zto_poll_and_download_tasks(
|
||||
page,
|
||||
@@ -330,7 +353,7 @@ def zto_expected_download_impl(page):
|
||||
return False
|
||||
|
||||
|
||||
def zto_actual_download(page):
|
||||
def zto_actual_download(page, force=False):
|
||||
"""中通:实到货物数据下载(内部含异常兜底重试,路由层无感)。"""
|
||||
|
||||
return with_retry(
|
||||
|
||||
Reference in New Issue
Block a user