按站点指定下载日期偏移(0=今天…30)+ 修复启动陈旧登录态
偏移量功能(前端/API 可配,服务端持久化、多用户共享): - state_store:新增 site_config 表 + get_offset / set_offset(0..30 钳制) / get_all_offsets - server:新增 GET/PUT /config(百世锁定当天,不可配置) - 顺心/中通/韵达/安能(各 expected+actual):日期逻辑由 query_days 范围改为读 offset 算单日 target=今天-offset,起止同日;百世仍走当日 - config.example.yaml:query_days 标记为已废弃 修复启动时显示上一会话陈旧登录态: - state_store:新增 reset_login_states(登录态会话级,启动重置为 unknown;数据态会话无关、保留) - runtime.launch_and_prepare:启动时对各站重置登录态,心跳就绪后重新探测写真实值 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ from datetime import datetime, timedelta
|
||||
import pandas as pd
|
||||
|
||||
from paths import DOWNLOAD_DIR, CONFIG_PATH
|
||||
import state_store
|
||||
|
||||
|
||||
def with_retry(site_name, label, flow, reset, max_attempts=3):
|
||||
@@ -167,23 +168,14 @@ def yunda_expected_download_impl(page):
|
||||
ws_frame.locator("#startTime").wait_for(state="attached", timeout=15000)
|
||||
print("✅ 进站交接单查询页面就绪")
|
||||
|
||||
# 2. 从配置文件中解析并计算绝对日期跨度
|
||||
query_days = 1
|
||||
try:
|
||||
if os.path.exists(CONFIG_PATH):
|
||||
with open(CONFIG_PATH, "r", encoding="utf-8") as f:
|
||||
config = yaml.safe_load(f) or {}
|
||||
query_days = int(config.get("yunda", {}).get("query_days", 1))
|
||||
except Exception as e:
|
||||
print(f" ⚠️ 读取 config.yaml 失败,默认查询 1 天: {e}")
|
||||
|
||||
# 2. 读取服务端日期偏移(0=今天,1=昨天…),单日范围:起止同日
|
||||
offset = state_store.get_offset("韵达")
|
||||
today = datetime.now()
|
||||
start_date = today - timedelta(days=(query_days - 1))
|
||||
|
||||
today_ymd = f"{today.year}-{today.month}-{today.day}"
|
||||
start_date_ymd = f"{start_date.year}-{start_date.month}-{start_date.day}"
|
||||
|
||||
print(f">> 设置查询时间范围: [{start_date_ymd}] 至 [{today_ymd}]")
|
||||
target = today - timedelta(days=offset)
|
||||
target_ymd = f"{target.year}-{target.month}-{target.day}"
|
||||
start_date_ymd = target_ymd
|
||||
today_ymd = target_ymd
|
||||
print(f">> 设置查询日期: [{target_ymd}](偏移 {offset},0=今天)")
|
||||
|
||||
# 设定起始时间
|
||||
print(" >> 设置起始时间...")
|
||||
@@ -422,19 +414,15 @@ def yunda_actual_download_impl(page):
|
||||
).first.wait_for(state="visible", timeout=15000)
|
||||
print("✅ 扫描记录查询页面已初始化")
|
||||
|
||||
query_days = 1
|
||||
try:
|
||||
if os.path.exists(CONFIG_PATH):
|
||||
with open(CONFIG_PATH, "r", encoding="utf-8") as f:
|
||||
config = yaml.safe_load(f) or {}
|
||||
query_days = int(config.get("yunda", {}).get("query_days", 1))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
offset = state_store.get_offset("韵达")
|
||||
today = datetime.now()
|
||||
start_date = today - timedelta(days=(query_days - 1))
|
||||
|
||||
print(f">> 设置实到查询时间范围: [近 {query_days} 天]")
|
||||
target = today - timedelta(days=offset)
|
||||
start_date = target # 单日范围:起止同日
|
||||
today = target # 让下方"截止时间"选择器也指向 target
|
||||
print(
|
||||
f">> 设置实到查询日期: [{target.year}-{target.month}-{target.day}]"
|
||||
f"(偏移 {offset},0=今天)"
|
||||
)
|
||||
|
||||
print(" >> 正在设定起始时间...")
|
||||
ws_frame.locator("#startDate").click()
|
||||
|
||||
Reference in New Issue
Block a user