fix: require manual reply for constrained LF inquiries

This commit is contained in:
ZE-TH5-AR516 committed 2026-11-27 13:53:53 +08:00
1 parent 127d88e84e
commit 22b99eb53e
6 files changed
+94 -7

No files matched your search

+38 -5
View File
@@ -180,11 +180,25 @@ class CandidateUnavailableError(RuntimeError):
pass
LF_MANUAL_REVIEW_MESSAGE = "来福减速器后续需求需AR516核实,交期以人工答复为准"
def is_lf_model(model: str) -> bool:
match = MODEL_PATTERN.fullmatch(model)
return bool(match and match.group("bracket") == "(")
def lf_reducer_shortage_detected(model: str, details: dict[str, Any]) -> bool:
"""Return whether an LF model still needs production and AR836 reports reducer shortage."""
if not is_lf_model(model):
return False
available_inventory = details.get("available_inventory")
requested_quantity = details.get("requested_quantity")
if available_inventory is None or requested_quantity is None:
return False
return available_inventory < requested_quantity and bool(details.get("reducer_shortages"))
def lf_stock_gate_reason(model: str, details: dict[str, Any]) -> str | None:
"""Use the current AR836 response to gate generated LF candidates."""
if not is_lf_model(model):
@@ -199,7 +213,7 @@ def lf_stock_gate_reason(model: str, details: dict[str, Any]) -> str | None:
if details.get("shortage_data_available") is not True:
return "接口未返回可核验的缺料明细"
if details.get("reducer_shortages"):
if lf_reducer_shortage_detected(model, details):
return "整机库存未覆盖需求且AR836返回减速器供应约束"
return None
@@ -845,7 +859,12 @@ def lead_time_details(
def overall_judgment_lines(candidates: list[dict[str, Any]]) -> list[str]:
available = [candidate for candidate in candidates if candidate["details"]["has_lead_time"]]
available = [
candidate
for candidate in candidates
if candidate["details"]["has_lead_time"]
and not candidate.get("manual_lf_review")
]
if not available:
return [
"- 现货候选:无法判断",
@@ -880,10 +899,15 @@ def overall_judgment_lines(candidates: list[dict[str, Any]]) -> list[str]:
def candidate_report_lines(candidate: dict[str, Any], quantity: int) -> list[str]:
details = candidate["details"]
lead_time_lines = (
[f"- 原型号分析:{LF_MANUAL_REVIEW_MESSAGE}"]
if candidate.get("manual_lf_review")
else [f"- {details['prediction']}"]
)
return [
f"{candidate['index']}. {candidate['model']}({candidate['type']})",
f"- 需求数量:{quantity}台",
f"- {details['prediction']}",
*lead_time_lines,
f"- 可用库存/覆盖情况:{details['inventory']}",
f"- 主导因素:{details['main_factor']}",
f"- 推荐理由:{candidate['reason']}",
@@ -984,7 +1008,14 @@ def render_record(
details = candidate["details"]
inventory = details.get("available_inventory")
inventory_text = f"{inventory:g}台" if isinstance(inventory, (int, float)) else "—"
api_status = "✅ 现货" if details.get("full_coverage") is True else "✅ 返回"
manual_lf_review = candidate.get("manual_lf_review") is True
api_status = (
"⚠️ 人工复核"
if manual_lf_review
else "✅ 现货"
if details.get("full_coverage") is True
else "✅ 返回"
)
row = [
record_order,
record_time,
@@ -992,7 +1023,7 @@ def render_record(
candidate["type"],
candidate["difference"],
api_status,
details.get("prediction_value") or "—",
"人工答复" if manual_lf_review else details.get("prediction_value") or "—",
inventory_text,
details.get("main_factor") or "—",
]
@@ -1067,6 +1098,7 @@ def build_report(request: RequestInput, candidate_offset: int = 0) -> str:
f"原因:{baseline['unavailable_reason']}\n"
"处理建议:请按上述提示核对;如确认信息无误,请联系维护人员核查。"
)
manual_lf_review = lf_reducer_shortage_detected(request.model, baseline)
candidates.append(
{
"index": 1,
@@ -1074,6 +1106,7 @@ def build_report(request: RequestInput, candidate_offset: int = 0) -> str:
"model": request.model,
"type": "原型号,DZ" if "[" in request.model else "原型号,LF",
"details": baseline,
"manual_lf_review": manual_lf_review,
"reason": "原始需求基准,用于交期测算与候选比较。",
"difference": "无",
"confirmation": "无型号差异;需确认正式交付节点和承诺边界。",
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.