fix(shipping-notice): 修复订单解析签名与库存 RPA 导出流程
- 修正订单提取运行与模板签名处理 - 优化库存 RPA 归档及报表导出逻辑 - 补充库存参数、归档、运行与签名测试 - 更新 Shipping Notice 技术文档
This commit is contained in:
1 parent
dabf140e41
commit
2bb7822247
10 files changed
+300
-43
No files matched your search
@@ -13,7 +13,7 @@ from __future__ import annotations
|
||||
import json
|
||||
import re
|
||||
import zipfile
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
@@ -23,6 +23,7 @@ from app import db
|
||||
from app.core.errors import NotFoundError
|
||||
from app.models import ScheduleRun, ShippingInventoryFile
|
||||
from app.services.schedule.shipping_inventory_rpa_finalize import is_shipping_inventory_rpa_task
|
||||
from app.services.schedule.timezone_util import resolve_schedule_tzinfo
|
||||
|
||||
_RAW_ZIP_NOT_FOUND_MESSAGE = "原始库存包不存在,请重新执行或联系管理员"
|
||||
|
||||
@@ -52,26 +53,38 @@ def get_inventory_archive_dir() -> str:
|
||||
|
||||
def _attachment_when_from_run(run: ScheduleRun) -> datetime:
|
||||
"""
|
||||
推导企微/下载展示名中的时刻。
|
||||
推导企微/下载展示名中的当地时刻。
|
||||
|
||||
核心逻辑:优先 started_at → created_at → finished_at;再尝试解析 RUN{yyyyMMddHHmmss}*;
|
||||
最后回退 utcnow。完整 run_no 仍留在卡片与磁盘归档键,不塞进展示名。
|
||||
核心逻辑:started_at → created_at → finished_at → 解析 RUN{yyyyMMddHHmmss}* → utcnow;
|
||||
上述时刻在库内均为 UTC naive(含 run_no 时间戳),格式化前转到任务
|
||||
schedule_timezone(缺省 Asia/Shanghai)。完整 run_no 仍留在卡片与磁盘归档键。
|
||||
"""
|
||||
when_utc: datetime | None = None
|
||||
for value in (run.started_at, run.created_at, run.finished_at):
|
||||
if isinstance(value, datetime):
|
||||
return value
|
||||
match = re.match(r"^RUN(\d{14})", str(run.run_no or "").strip())
|
||||
if match:
|
||||
try:
|
||||
return datetime.strptime(match.group(1), "%Y%m%d%H%M%S")
|
||||
except ValueError:
|
||||
pass
|
||||
return datetime.utcnow()
|
||||
when_utc = value
|
||||
break
|
||||
if when_utc is None:
|
||||
match = re.match(r"^RUN(\d{14})", str(run.run_no or "").strip())
|
||||
if match:
|
||||
try:
|
||||
when_utc = datetime.strptime(match.group(1), "%Y%m%d%H%M%S")
|
||||
except ValueError:
|
||||
when_utc = None
|
||||
if when_utc is None:
|
||||
when_utc = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
|
||||
task = getattr(run, "task", None)
|
||||
tz_name = getattr(task, "schedule_timezone", None) if task is not None else None
|
||||
tz = resolve_schedule_tzinfo(tz_name)
|
||||
if when_utc.tzinfo is None:
|
||||
when_utc = when_utc.replace(tzinfo=timezone.utc)
|
||||
return when_utc.astimezone(tz)
|
||||
|
||||
|
||||
def inventory_rpa_attachment_stem(run: ScheduleRun) -> str:
|
||||
"""
|
||||
库存 RPA 企微附件共用前缀:库存RPA-{yyyyMMdd}-{HHmm}。
|
||||
库存 RPA 企微附件共用前缀:库存RPA-{yyyyMMdd}-{HHmm}(业务时区当地时间)。
|
||||
|
||||
Args:
|
||||
run: 排程执行记录。
|
||||
|
||||
Reference in new issue
Block a user