|
@@ -794,9 +794,10 @@ def fetch_process(case_id, version=None):
|
|
|
return _proc_payload(case_id, version, rows)
|
|
return _proc_payload(case_id, version, rows)
|
|
|
|
|
|
|
|
|
|
|
|
|
-def fetch_all_process(case_ids=None):
|
|
|
|
|
|
|
+def fetch_all_process(case_ids=None, lite=False):
|
|
|
"""批量取多帖工序解构(每帖取最新真实版,link_ 排后),一次查询拍平。
|
|
"""批量取多帖工序解构(每帖取最新真实版,link_ 排后),一次查询拍平。
|
|
|
- case_ids:选填 case_id 列表;None=全表所有有解构的帖,[]=空(直接返回空)。
|
|
- case_ids:选填 case_id 列表;None=全表所有有解构的帖,[]=空(直接返回空)。
|
|
|
|
|
+ - lite:True 走精简投影(丢大字段 + 截断 value),供工序库平铺表快速首屏。
|
|
|
返回 {case_id: _proc_payload(...)};无解构记录的 case_id 不出现在结果里。"""
|
|
返回 {case_id: _proc_payload(...)};无解构记录的 case_id 不出现在结果里。"""
|
|
|
if case_ids is not None and not case_ids:
|
|
if case_ids is not None and not case_ids:
|
|
|
return {}
|
|
return {}
|
|
@@ -821,7 +822,7 @@ def fetch_all_process(case_ids=None):
|
|
|
ver = best["version"]
|
|
ver = best["version"]
|
|
|
vrows = sorted((r for r in crows if r["version"] == ver),
|
|
vrows = sorted((r for r in crows if r["version"] == ver),
|
|
|
key=lambda r: (r["seq"] if r["seq"] is not None else 0, r["id"]))
|
|
key=lambda r: (r["seq"] if r["seq"] is not None else 0, r["id"]))
|
|
|
- out[cid] = _proc_payload(cid, ver, vrows)
|
|
|
|
|
|
|
+ out[cid] = _proc_payload(cid, ver, vrows, lite=lite)
|
|
|
return out
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
@@ -941,10 +942,49 @@ def fetch_categorized_cases(case_ids, mode="process"):
|
|
|
return _categorized_from_rows(rows)
|
|
return _categorized_from_rows(rows)
|
|
|
|
|
|
|
|
|
|
|
|
|
-def _proc_payload(case_id, version, rows):
|
|
|
|
|
- """mode_process 行集 → {case_id, version, …, procedures:[...]}。无行返回 None。"""
|
|
|
|
|
|
|
+_LITE_VALUE_LIMIT = 300 # lite 模式 输入/输出 value 截断字节上限
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _trunc(s, limit=_LITE_VALUE_LIMIT):
|
|
|
|
|
+ """按 UTF-8 字节截断长文本(不切坏多字节字符),超限追加省略号。非字符串原样返回。"""
|
|
|
|
|
+ if not isinstance(s, str):
|
|
|
|
|
+ return s
|
|
|
|
|
+ b = s.encode("utf-8")
|
|
|
|
|
+ if len(b) <= limit:
|
|
|
|
|
+ return s
|
|
|
|
|
+ return b[:limit].decode("utf-8", "ignore") + "…"
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _lite_steps(steps):
|
|
|
|
|
+ """lite 模式:仅截断每步 inputs/outputs 的 value(其余字段供平铺表/分组用,保留)。"""
|
|
|
|
|
+ if not isinstance(steps, list):
|
|
|
|
|
+ return steps
|
|
|
|
|
+ for st in steps:
|
|
|
|
|
+ if not isinstance(st, dict):
|
|
|
|
|
+ continue
|
|
|
|
|
+ for io_key in ("inputs", "outputs"):
|
|
|
|
|
+ ios = st.get(io_key)
|
|
|
|
|
+ if isinstance(ios, list):
|
|
|
|
|
+ for io in ios:
|
|
|
|
|
+ if isinstance(io, dict) and "value" in io:
|
|
|
|
|
+ io["value"] = _trunc(io.get("value"))
|
|
|
|
|
+ return steps
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _proc_payload(case_id, version, rows, lite=False):
|
|
|
|
|
+ """mode_process 行集 → {case_id, version, …, procedures:[...]}。无行返回 None。
|
|
|
|
|
+ lite=True:工序库平铺表只需 procedures[].{id,name,steps},丢弃大字段
|
|
|
|
|
+ (source/declarations/type_registry/tools_used)并截断输入/输出 value;
|
|
|
|
|
+ 完整值由前端展开时按 case 调 /api/process 懒加载。"""
|
|
|
if not rows:
|
|
if not rows:
|
|
|
return None
|
|
return None
|
|
|
|
|
+ if lite:
|
|
|
|
|
+ procedures = [{
|
|
|
|
|
+ "id": r["procedure_id"], "name": r["name"],
|
|
|
|
|
+ "steps": _lite_steps(_loads(r["steps"], [])),
|
|
|
|
|
+ } for r in rows]
|
|
|
|
|
+ return {"case_id": case_id, "version": version,
|
|
|
|
|
+ "title": rows[0]["post_title"], "procedures": procedures}
|
|
|
procedures = [{
|
|
procedures = [{
|
|
|
"id": r["procedure_id"], "name": r["name"], "purpose": r["purpose"],
|
|
"id": r["procedure_id"], "name": r["name"], "purpose": r["purpose"],
|
|
|
"category": r["category"], "declarations": _loads(r["declarations"]),
|
|
"category": r["category"], "declarations": _loads(r["declarations"]),
|