qc_work_order_conclusion.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. """质检工单级结论:由下属任务 conclusion 派生(合格/不合格)。"""
  2. from __future__ import annotations
  3. from typing import Any, Dict, Iterable, List, Optional
  4. _WORK_ORDER_QC_CONCLUSION_LABELS = {
  5. "tg": "合格",
  6. "btg": "不合格",
  7. }
  8. def derive_work_order_qc_conclusion(task_conclusions: Iterable[Optional[str]]) -> str:
  9. """与短信模块规则一致:任一 btg → btg;全部 tg → tg;否则空。"""
  10. conclusions = [(c or "").strip() for c in task_conclusions]
  11. if not conclusions:
  12. return ""
  13. if any(c == "btg" for c in conclusions):
  14. return "btg"
  15. if all(c == "tg" for c in conclusions):
  16. return "tg"
  17. return ""
  18. def work_order_qc_conclusion_label(code: Optional[str]) -> str:
  19. return _WORK_ORDER_QC_CONCLUSION_LABELS.get((code or "").strip(), "")
  20. def build_qc_conclusion_fields(
  21. task_conclusions: Iterable[Optional[str]],
  22. ) -> Dict[str, str]:
  23. code = derive_work_order_qc_conclusion(task_conclusions)
  24. return {
  25. "qcConclusion": code,
  26. "qcConclusionLabel": work_order_qc_conclusion_label(code),
  27. }