feat: resolve shortage names from Git-synced Kingdee material cache

This commit is contained in:
ar51
2026-10-09 10:18:34 +08:00
parent ad7c45d2d6
commit cf31549415
12 changed files with 7813 additions and 7 deletions

View File

@@ -22,6 +22,11 @@ truststore.inject_into_ssl()
import lark_oapi as lark
if __package__:
from .material_name_cache import MaterialNameCacheError, load_material_names
else:
from material_name_cache import MaterialNameCacheError, load_material_names
PROJECT_ROOT = Path(__file__).resolve().parents[2]
QUERY_SCRIPT = (
@@ -599,6 +604,8 @@ def shortage_material_names_line(shortages: list[Any]) -> str:
"""Show only names from shortage records, never codes or other raw fields."""
names: list[str] = []
missing_names = 0
cached_names: dict[str, str] | None = None
cache_error: str | None = None
for item in shortages:
name = None
if isinstance(item, dict):
@@ -607,6 +614,16 @@ def shortage_material_names_line(shortages: list[Any]) -> str:
if isinstance(value, str) and value.strip():
name = " ".join(value.split())
break
if name is None:
code = item.get("缺料物料")
if isinstance(code, str) and code.strip():
if cached_names is None and cache_error is None:
try:
cached_names = load_material_names()
except MaterialNameCacheError as exc:
cache_error = str(exc)
if cached_names is not None:
name = cached_names.get(code.strip())
if name is None:
missing_names += 1
elif name not in names:
@@ -614,7 +631,12 @@ def shortage_material_names_line(shortages: list[Any]) -> str:
text = ";".join(names)
if missing_names:
missing_text = f"{missing_names}项缺料记录未返回物料名称,需人工复核"
missing_text = f"{missing_names}项缺料记录未找到物料名称"
missing_text += (
f"({cache_error}),需补齐缓存后复核"
if cache_error is not None
else ",请核对物料编码并更新本地名称缓存后复核"
)
text = f"{text}(另有{missing_text})" if text else missing_text
return f"- 缺料物料明细:{text}"