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

@@ -50,6 +50,7 @@ Expected:
- unavailable candidates remain in their original rule order and are recorded as `❌ 不可用` with unavailable result fields shown as `—`; lack of a result does not itself establish that the model does not exist; - unavailable candidates remain in their original rule order and are recorded as `❌ 不可用` with unavailable result fields shown as `—`; lack of a result does not itself establish that the model does not exist;
- generated LF candidates pass when finished-product available inventory covers demand, or when the readable AR836 shortage list contains no `20.30.*` reducer constraint after AR836's 95% yield, five-unit rounding and BOM calculation; - generated LF candidates pass when finished-product available inventory covers demand, or when the readable AR836 shortage list contains no `20.30.*` reducer constraint after AR836's 95% yield, five-unit rounding and BOM calculation;
- an LF candidate with insufficient finished-product inventory plus a `20.30.*` shortage, or with an unreadable shortage list, is absent from the report, fastest comparison, candidate counts and `不可用候选`; - an LF candidate with insufficient finished-product inventory plus a `20.30.*` shortage, or with an unreadable shortage list, is absent from the report, fastest comparison, candidate counts and `不可用候选`;
- an original LF inquiry remains visible, but when finished-product inventory is insufficient and AR836 returns a `20.30.*` shortage, its API lead time is suppressed and original-model analysis says `来福减速器后续需求需AR516核实,交期以人工答复为准`;
## Sample 1B | API Workdays And Final Delivery Date ## Sample 1B | API Workdays And Final Delivery Date
@@ -29,7 +29,9 @@ AR836 根据该排产量、BOM 用量、存量需求和当前供应判定减速
否则 -> AR836 未发现减速器供应约束,保留 否则 -> AR836 未发现减速器供应约束,保留
``` ```
被剔除的 LF 型号不出现在关节模组交期预估报告、不可用候选、最快交期比较、现货候选或候选统计中。原始输入型号仍作为基准展示,不按“生成候选”处理。 被剔除的生成 LF 候选不出现在关节模组交期预估报告、不可用候选、最快交期比较、现货候选或候选统计中。
原始询单型号本身为 LF 时也使用同一判断口径:整机库存已覆盖需求时正常答复交期;整机库存不足且 AR836 识别到 `20.30.*` 减速器缺料时,原型号仍展示,但不答复算法交期,并在原型号分析中写明“来福减速器后续需求需AR516核实,交期以人工答复为准”。
## 当前接口的边界 ## 当前接口的边界
@@ -234,4 +234,5 @@ data.采购信息.缺料明细[].缺料物料
- 整机库存不足,但 AR836 按 95% 合格率、5 台取整及 BOM 用量核算后未返回减速器供应约束:保留候选。 - 整机库存不足,但 AR836 按 95% 合格率、5 台取整及 BOM 用量核算后未返回减速器供应约束:保留候选。
- 缺料明细缺失或不可读:保守剔除。 - 缺料明细缺失或不可读:保守剔除。
- 被剔除型号不进入交期报告、最快交期比较或不可用候选清单。 - 被剔除型号不进入交期报告、最快交期比较或不可用候选清单。
- 原始询单型号为 LF 时,整机库存覆盖需求则正常答复;整机库存不足且识别到 `20.30.*` 减速器缺料时,不答复该原型号的算法交期,原型号分析固定提示“来福减速器后续需求需AR516核实,交期以人工答复为准”。
- 当前接口无法在减速器不缺料时单独展示匹配编码和确切库存,也无法实现销售订单待锁库/待预留二次扣减及逾期 30 天提醒。 - 当前接口无法在减速器不缺料时单独展示匹配编码和确切库存,也无法实现销售订单待锁库/待预留二次扣减及逾期 30 天提醒。
@@ -139,7 +139,7 @@ Do not use temporary curl, WebFetch, or any API method outside the controlled sc
- Otherwise reject when the shortage list is missing/unreadable or contains any material code beginning `20.30.`; retain when the readable list contains no such reducer constraint. - Otherwise reject when the shortage list is missing/unreadable or contains any material code beginning `20.30.`; retain when the readable list contains no such reducer constraint.
- Rejected LF candidates are omitted from the report, fastest comparison, candidate counts and `不可用候选`. - Rejected LF candidates are omitted from the report, fastest comparison, candidate counts and `不可用候选`.
- Do not claim that the current response proves the matched reducer code or exact reducer stock when no reducer shortage record is returned. - Do not claim that the current response proves the matched reducer code or exact reducer stock when no reducer shortage record is returned.
- The original input model remains the baseline; this generated-candidate gate does not hide the user's original model. - Apply the same evidence rule when the original input model is LF. If finished-product stock covers demand, reply normally. If stock is insufficient and AR836 returns a `20.30.*` reducer shortage, keep the original model visible but suppress its API lead time and show exactly `来福减速器后续需求需AR516核实,交期以人工答复为准` under original-model analysis.
## Unavailable Result Reasons ## Unavailable Result Reasons
+38 -5
View File
@@ -180,11 +180,25 @@ class CandidateUnavailableError(RuntimeError):
pass pass
LF_MANUAL_REVIEW_MESSAGE = "来福减速器后续需求需AR516核实,交期以人工答复为准"
def is_lf_model(model: str) -> bool: def is_lf_model(model: str) -> bool:
match = MODEL_PATTERN.fullmatch(model) match = MODEL_PATTERN.fullmatch(model)
return bool(match and match.group("bracket") == "(") 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: def lf_stock_gate_reason(model: str, details: dict[str, Any]) -> str | None:
"""Use the current AR836 response to gate generated LF candidates.""" """Use the current AR836 response to gate generated LF candidates."""
if not is_lf_model(model): 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: if details.get("shortage_data_available") is not True:
return "接口未返回可核验的缺料明细" return "接口未返回可核验的缺料明细"
if details.get("reducer_shortages"): if lf_reducer_shortage_detected(model, details):
return "整机库存未覆盖需求且AR836返回减速器供应约束" return "整机库存未覆盖需求且AR836返回减速器供应约束"
return None return None
@@ -845,7 +859,12 @@ def lead_time_details(
def overall_judgment_lines(candidates: list[dict[str, Any]]) -> list[str]: 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: if not available:
return [ 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]: def candidate_report_lines(candidate: dict[str, Any], quantity: int) -> list[str]:
details = candidate["details"] details = candidate["details"]
lead_time_lines = (
[f"- 原型号分析:{LF_MANUAL_REVIEW_MESSAGE}"]
if candidate.get("manual_lf_review")
else [f"- {details['prediction']}"]
)
return [ return [
f"{candidate['index']}. {candidate['model']}({candidate['type']})", f"{candidate['index']}. {candidate['model']}({candidate['type']})",
f"- 需求数量:{quantity}台", f"- 需求数量:{quantity}台",
f"- {details['prediction']}", *lead_time_lines,
f"- 可用库存/覆盖情况:{details['inventory']}", f"- 可用库存/覆盖情况:{details['inventory']}",
f"- 主导因素:{details['main_factor']}", f"- 主导因素:{details['main_factor']}",
f"- 推荐理由:{candidate['reason']}", f"- 推荐理由:{candidate['reason']}",
@@ -984,7 +1008,14 @@ def render_record(
details = candidate["details"] details = candidate["details"]
inventory = details.get("available_inventory") inventory = details.get("available_inventory")
inventory_text = f"{inventory:g}台" if isinstance(inventory, (int, float)) else "—" 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 = [ row = [
record_order, record_order,
record_time, record_time,
@@ -992,7 +1023,7 @@ def render_record(
candidate["type"], candidate["type"],
candidate["difference"], candidate["difference"],
api_status, api_status,
details.get("prediction_value") or "—", "人工答复" if manual_lf_review else details.get("prediction_value") or "—",
inventory_text, inventory_text,
details.get("main_factor") or "—", details.get("main_factor") or "—",
] ]
@@ -1067,6 +1098,7 @@ def build_report(request: RequestInput, candidate_offset: int = 0) -> str:
f"原因:{baseline['unavailable_reason']}\n" f"原因:{baseline['unavailable_reason']}\n"
"处理建议:请按上述提示核对;如确认信息无误,请联系维护人员核查。" "处理建议:请按上述提示核对;如确认信息无误,请联系维护人员核查。"
) )
manual_lf_review = lf_reducer_shortage_detected(request.model, baseline)
candidates.append( candidates.append(
{ {
"index": 1, "index": 1,
@@ -1074,6 +1106,7 @@ def build_report(request: RequestInput, candidate_offset: int = 0) -> str:
"model": request.model, "model": request.model,
"type": "原型号,DZ" if "[" in request.model else "原型号,LF", "type": "原型号,DZ" if "[" in request.model else "原型号,LF",
"details": baseline, "details": baseline,
"manual_lf_review": manual_lf_review,
"reason": "原始需求基准,用于交期测算与候选比较。", "reason": "原始需求基准,用于交期测算与候选比较。",
"difference": "无", "difference": "无",
"confirmation": "无型号差异;需确认正式交付节点和承诺边界。", "confirmation": "无型号差异;需确认正式交付节点和承诺边界。",
+50
View File
@@ -651,6 +651,56 @@ class LfStockGateTests(unittest.TestCase):
self.assertIn("整机可用库存3台(部分覆盖,仍需补齐7台)", report) self.assertIn("整机可用库存3台(部分覆盖,仍需补齐7台)", report)
self.assertNotIn("减速器实际可用量", report) self.assertNotIn("减速器实际可用量", report)
def test_original_lf_with_reducer_shortage_uses_manual_reply(self) -> None:
request = bridge.RequestInput(self.LF_MODEL, 10)
def query(query_request: bridge.RequestInput) -> dict[str, object]:
payload = successful_payload()
if query_request.model == request.model:
set_stock(payload, 3, query_request.quantity)
payload["data"]["采购信息"]["缺料明细"] = [
{"缺料物料": "20.30.00999", "物料名称": "来福减速器"}
]
return payload
with (
mock.patch.object(bridge, "run_controlled_query", side_effect=query),
mock.patch.object(bridge, "write_record") as record,
):
report = bridge.build_report(request)
original_section = report.split(f"1. {request.model}", 1)[1].split("\n\n", 1)[0]
self.assertIn(
"原型号分析:来福减速器后续需求需AR516核实,交期以人工答复为准",
original_section,
)
self.assertNotIn("AM516预测交期", original_section)
recorded_candidates = record.call_args.args[1]
self.assertTrue(recorded_candidates[0]["manual_lf_review"])
def test_original_lf_with_full_stock_keeps_api_lead_time(self) -> None:
payload = successful_payload()
set_stock(payload, 10, 10)
payload["data"]["采购信息"]["缺料明细"] = [
{"缺料物料": "20.30.00999", "物料名称": "来福减速器"}
]
details = bridge.lead_time_details(payload, 10)
candidate = {
"index": 1,
"model": self.LF_MODEL,
"type": "原型号,LF",
"details": details,
"manual_lf_review": bridge.lf_reducer_shortage_detected(self.LF_MODEL, details),
"reason": "原始需求基准",
"difference": "无",
"confirmation": "无",
}
report = "\n".join(bridge.candidate_report_lines(candidate, 10))
self.assertIn("AM516预测交期", report)
self.assertNotIn(bridge.LF_MANUAL_REVIEW_MESSAGE, report)
class CandidateBatchTests(unittest.TestCase): class CandidateBatchTests(unittest.TestCase):
def setUp(self) -> None: def setUp(self) -> None:
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.