- libs: 新增 hr_sdk / hotel_report / dingtalk,更新 desktopauto - controlplane-next: SDK 管理模块(controller/entity/migrations)与前端视图 - electron-shell: 插件同步、注册表、runner 调整 - plugins: XQ0035/XQ0041/XQ0042/XQ0045_XQ0046/XQ0048/XQ0076/XQ0078 等版本更新 - tests/tools: 新增 SDK 兼容性检查与打包工具(sdk_pack.py、sdk_compat_check.py)
94 lines
3.1 KiB
Python
94 lines
3.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""下载任务与门店选择的纯逻辑(不依赖浏览器,便于离线自测)。
|
|
|
|
字段口径(抓包实测):
|
|
downloadTaskItemDTOList[] = {
|
|
fileName: 新版收益明细_2026-10-30~2026-10-31_团购_<taskId>.xlsx
|
|
taskId, createTime, downloadUrl, downloadStatus, downloadTaskTypeName
|
|
}
|
|
downloadStatus: 0=生成中,3=已完成(downloadUrl 非空)
|
|
"""
|
|
import re
|
|
from datetime import datetime
|
|
|
|
|
|
def throttle_seconds(msg):
|
|
"""平台限流文案「请 N 秒后再试」→ N。"""
|
|
m = re.search(r'(\d+)\s*秒', msg or '')
|
|
return int(m.group(1)) if m else 0
|
|
|
|
|
|
def age_minutes(create_time):
|
|
"""记录创建时间距今分钟数;解析失败按「很旧」处理(不复用)。"""
|
|
try:
|
|
dt = datetime.strptime(str(create_time).strip(), '%Y-%m-%d %H:%M:%S')
|
|
return (datetime.now() - dt).total_seconds() / 60.0
|
|
except Exception:
|
|
return 1e9
|
|
|
|
|
|
def is_ready(item):
|
|
return item.get('downloadStatus') == 3 and bool(item.get('downloadUrl'))
|
|
|
|
|
|
def pick_poi(pois, want_id=None, keyword='', default_id=None):
|
|
"""选门店:显式 poiId > 名称含关键字 > 只有一家时直接用 > 兜底 poiId。
|
|
|
|
pois: [(poiId:int, poiName:str)]
|
|
返回 (poiId, poiName);名称未知时 poiName 为空串。
|
|
"""
|
|
if want_id:
|
|
try:
|
|
want = int(str(want_id).strip())
|
|
except (TypeError, ValueError):
|
|
want = None
|
|
if want:
|
|
hit = [p for p in pois if p[0] == want]
|
|
return hit[0] if hit else (want, '')
|
|
if keyword:
|
|
hit = [p for p in pois if keyword in (p[1] or '')]
|
|
if hit:
|
|
return hit[0]
|
|
if len(pois) == 1:
|
|
return pois[0]
|
|
return default_id, ''
|
|
|
|
|
|
def find_reusable(items, day_from, day_to, max_age_min=30, type_name='收益明细'):
|
|
"""同区间、已完成、足够新的记录 → 直接复用(避免重复生成触发限流)。"""
|
|
key = f'{day_from.isoformat()}~{day_to.isoformat()}'
|
|
for it in items or []:
|
|
name = str(it.get('fileName') or '')
|
|
if key not in name:
|
|
continue
|
|
if it.get('downloadTaskTypeName') and it['downloadTaskTypeName'] != type_name:
|
|
continue
|
|
if not is_ready(it):
|
|
continue
|
|
if age_minutes(it.get('createTime')) > max_age_min:
|
|
continue
|
|
return it
|
|
return None
|
|
|
|
|
|
def find_task(items, task_id):
|
|
return next((it for it in (items or []) if str(it.get('taskId')) == str(task_id)), None)
|
|
|
|
|
|
def summary_has_data(summary_total_dto):
|
|
"""区间预检:收益汇总里有没有记录。
|
|
|
|
抓包实测字段:cnt / consumeCnt(记录数)、realPayed(实收)。任一非零即有数据;
|
|
三者都空/为 0(空区间)→ False,此时不必提交导出任务(平台会生成空表,还占限流名额)。
|
|
"""
|
|
dto = summary_total_dto or {}
|
|
|
|
def _num(v):
|
|
try:
|
|
return float(v or 0)
|
|
except (TypeError, ValueError):
|
|
return 0.0
|
|
|
|
return int(_num(dto.get('cnt'))) > 0 or int(_num(dto.get('consumeCnt'))) > 0 \
|
|
or _num(dto.get('realPayed')) != 0
|