fix(contract): 合同付款预警bug修复

This commit is contained in:
sophie committed 2026-09-23 14:34:08 +08:00
1 parent 5330e08281
commit 161666c0e7
26 files changed
+1599 -117

No files matched your search

@@ -5,6 +5,7 @@ services/contract_payment/oa_client.py
依赖:requests、lxml、Flask 配置;由 sync_service 负责将本客户端的标准化结果落库。
逻辑:同一登录会话顺序扫描待办和已办归档列表并翻页;满页大小以 OA 实际返回行数为准(泛微默认 10 条/页),
不得用配置页大小把首页短页误判为到底;首次全量翻到短页为止,增量触顶页上限时标记截断供同步层不推进断点。
合同原文被临时文件清理删掉后,可按流程 ID 与附件 ID 重新打开详情并下载。
"""
from __future__ import annotations
@@ -340,6 +341,49 @@ class ContractOaClient:
content_type = (response.headers.get("content-type") or "application/octet-stream").split(";", 1)[0].strip().lower()
return data, content_type, _filename_from_disposition(response.headers.get("content-disposition"))
def download_attachment_by_id(self, *, process_id: str, attachment_id: str) -> tuple[bytes, str, str | None]:
"""
按 OA 流程和附件 ID 重新下载合同原文。
用途:合同附件曾按临时 FileAsset 落库,清理任务删除对象后,详情页下载和重解析用本方法找回字节。
核心逻辑:打开 ViewRequest.jsp,在详情解析出的附件里匹配 attachment_id,再走 download_attachment。
Args:
process_id: OA requestid,对应合同台账 oa_record_id。
attachment_id: 详情页附件 ID,对应附件 source_key 去掉 `oa:` 前缀后的值。
Returns:
文件字节、MIME 类型和响应头文件名。
Raises:
ValueError: 流程 ID 或附件 ID 为空。
RuntimeError: OA 未配置、详情打不开,或详情中没有该附件。
requests.RequestException: 登录失效或 OA 下载失败。
"""
process_id = str(process_id or "").strip()
attachment_id = str(attachment_id or "").strip()
if not process_id or not attachment_id:
raise ValueError("缺少 OA 流程或附件 ID")
if not self.is_configured():
raise RuntimeError("OA 未配置,无法重新下载合同附件")
session = self._session()
detail = self._fetch_detail(session, {
"process_id": process_id,
"detail_url": f"/workflow/request/ViewRequest.jsp?requestid={process_id}",
})
if not detail:
raise RuntimeError("无法打开 OA 合同详情")
match = next(
(
item for item in (detail.get("attachments") or [])
if str(item.get("attachment_id") or "").strip() == attachment_id
),
None,
)
if match is None:
raise RuntimeError("OA 详情中找不到原合同附件")
return self.download_attachment(match)
def _session(self, *, refresh: bool = False) -> requests.Session:
"""复用 20 分钟 OA 登录会话;登录字段通过环境变量覆盖以适配不同 OA 部署。"""
with _SESSION_LOCK: