Unify export-task matching to time tolerance only (≤40s)
去掉顺心/中通/韵达/安能(应到) 导出任务认领时的标题/模块名校验, 统一改为仅按提交时间容差 ≤40 秒匹配本批任务。 理由:单账号无并发,时间窗内的任务必为本批所建;而站点可能调整 任务标题名,写死标题会导致匹配失败、任务已创建却一直查不到。 同步清理因此变成死代码的局部变量与函数形参。 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -81,7 +81,6 @@ def yunda_smart_menu_click(page, menu_path):
|
||||
def yunda_expected_download(page):
|
||||
"""韵达:应到货物数据下载"""
|
||||
print("\n▶ 开始执行【韵达 - 应到货物数据下载】任务...")
|
||||
target_task_title = "进站主单表"
|
||||
|
||||
download_dir = DOWNLOAD_DIR
|
||||
if not os.path.exists(download_dir):
|
||||
@@ -245,9 +244,7 @@ def yunda_expected_download(page):
|
||||
try:
|
||||
confirm_link.wait_for(state="visible", timeout=6000)
|
||||
if export_frame.get_by_text("导出任务建立成功").is_visible():
|
||||
print(
|
||||
" ✅ 导出任务已建立成功。"
|
||||
)
|
||||
print(" ✅ 导出任务已建立成功。")
|
||||
confirm_link.click()
|
||||
inner_success = True
|
||||
break
|
||||
@@ -311,7 +308,6 @@ def yunda_expected_download(page):
|
||||
_yunda_poll_and_download_tasks(
|
||||
page,
|
||||
export_times,
|
||||
target_task_title,
|
||||
download_dir,
|
||||
"韵达-应到货物数据.xlsx",
|
||||
)
|
||||
@@ -324,7 +320,6 @@ def yunda_expected_download(page):
|
||||
def yunda_actual_download(page):
|
||||
"""韵达:实到货物数据下载"""
|
||||
print("\n▶ 开始执行【韵达 - 实到货物数据下载】任务...")
|
||||
target_task_title = "扫描记录数据"
|
||||
|
||||
download_dir = DOWNLOAD_DIR
|
||||
if not os.path.exists(download_dir):
|
||||
@@ -406,17 +401,13 @@ def yunda_actual_download(page):
|
||||
match_total = re.search(r"总共\s*(\d+)\s*条记录", info_text)
|
||||
if match_total and int(match_total.group(1)) > 0:
|
||||
has_records = True
|
||||
print(
|
||||
f" ✅ 实到数据已加载,总记录数: [{match_total.group(1)}] 条。"
|
||||
)
|
||||
print(f" ✅ 实到数据已加载,总记录数: [{match_total.group(1)}] 条。")
|
||||
|
||||
if not has_records:
|
||||
if ws_frame.locator(
|
||||
".no-records-found", has_text="没有找到匹配的记录"
|
||||
).first.is_visible():
|
||||
print(
|
||||
" ⚠️ 当前查询范围内为空数据,终止并关闭标签页。"
|
||||
)
|
||||
print(" ⚠️ 当前查询范围内为空数据,终止并关闭标签页。")
|
||||
page.locator(".tags-view-item", has_text="扫描记录查询").locator(
|
||||
".el-icon-close"
|
||||
).click()
|
||||
@@ -466,9 +457,7 @@ def yunda_actual_download(page):
|
||||
try:
|
||||
confirm_link.wait_for(state="visible", timeout=6000)
|
||||
if export_frame.get_by_text("导出任务建立成功").is_visible():
|
||||
print(
|
||||
" ✅ 导出任务已建立成功。"
|
||||
)
|
||||
print(" ✅ 导出任务已建立成功。")
|
||||
confirm_link.click()
|
||||
inner_success = True
|
||||
break
|
||||
@@ -486,9 +475,7 @@ def yunda_actual_download(page):
|
||||
export_frame.locator(".allRight").click()
|
||||
page.wait_for_timeout(500)
|
||||
else:
|
||||
print(
|
||||
" ⚠️ 字段列表异常消失,重新打开导出面板..."
|
||||
)
|
||||
print(" ⚠️ 字段列表异常消失,重新打开导出面板...")
|
||||
needs_reopen = True
|
||||
break
|
||||
else:
|
||||
@@ -531,7 +518,6 @@ def yunda_actual_download(page):
|
||||
_yunda_poll_and_download_tasks(
|
||||
page,
|
||||
export_times,
|
||||
target_task_title,
|
||||
download_dir,
|
||||
"韵达-实到货物数据.xlsx",
|
||||
)
|
||||
@@ -541,9 +527,7 @@ def yunda_actual_download(page):
|
||||
return False
|
||||
|
||||
|
||||
def _yunda_poll_and_download_tasks(
|
||||
page, export_times, target_task_title, download_dir, final_filename
|
||||
):
|
||||
def _yunda_poll_and_download_tasks(page, export_times, download_dir, final_filename):
|
||||
"""韵达离线任务的轮询与下载"""
|
||||
print("\n>> 正在前往【导出服务】界面...")
|
||||
yunda_smart_menu_click(page, ["基础数据", "导出服务"])
|
||||
@@ -567,29 +551,28 @@ def _yunda_poll_and_download_tasks(
|
||||
ready_indices = []
|
||||
processing_indices = []
|
||||
|
||||
# 单账号无并发:仅按创建时间容差(40s)认领本批任务,不再校验模块名称
|
||||
# (站点可能调整标题名,写死标题会导致匹配失败、任务一直查不到)。
|
||||
for idx in range(row_count):
|
||||
row = task_rows.nth(idx)
|
||||
module_name = row.locator("td[field='modueName']").inner_text().strip()
|
||||
status_name = row.locator("td[field='fileStatus']").inner_text().strip()
|
||||
create_time_str = (
|
||||
row.locator("td[field='createdTime']").inner_text().strip()
|
||||
)
|
||||
|
||||
if module_name == target_task_title:
|
||||
try:
|
||||
row_time = datetime.strptime(create_time_str, "%Y-%m-%d %H:%M:%S")
|
||||
matched = any(
|
||||
abs((row_time - et).total_seconds()) <= 60
|
||||
for et in export_times
|
||||
)
|
||||
try:
|
||||
row_time = datetime.strptime(create_time_str, "%Y-%m-%d %H:%M:%S")
|
||||
matched = any(
|
||||
abs((row_time - et).total_seconds()) <= 40 for et in export_times
|
||||
)
|
||||
|
||||
if matched:
|
||||
if status_name == "导出完成":
|
||||
ready_indices.append(idx)
|
||||
else:
|
||||
processing_indices.append(idx)
|
||||
except Exception:
|
||||
pass
|
||||
if matched:
|
||||
if status_name == "导出完成":
|
||||
ready_indices.append(idx)
|
||||
else:
|
||||
processing_indices.append(idx)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
total_found = len(ready_indices) + len(processing_indices)
|
||||
print(
|
||||
|
||||
Reference in New Issue
Block a user