feat(ui): 目录树把手加竖轨连线、行垂直居中,并落实决策 321/316补十一 导出与勘察修复

This commit is contained in:
lianjianwei2024
2026-11-14 11:31:40 +08:00
parent 5d86c95402
commit b05b34ffbf
10 changed files with 522 additions and 137 deletions

View File

@@ -4078,6 +4078,10 @@ def _export_session(sc, sid, fmt="", progress=None):
# 决策 244 补记三:现算链故障的单位标记 _live_ok=False → 导出 0 量判定退老行为(不误删全部)
for plan in unit_plans.values():
plan["added_lme"] = []
# 决策 321:拆码登记簿提前装载(映射源注入的改印防重判定要在建计划期间用;
# 4286 处的正式装载不动,两处读同一份 s_settings)
_ri_early = _setting_get("session:%d" % sid, "recode_ident")
recode_ident_early = json.loads(_ri_early) if _ri_early else {}
for uw_id, uwkey in uwmap.items():
plan = unit_plans.get(uwkey)
if not plan:
@@ -4120,8 +4124,16 @@ def _export_session(sc, sid, fmt="", progress=None):
# 决策 288 补记二(导出指纹轮间漂移根因):set 迭代序随进程哈希种子逐轮变 →
# 映射源注入行 append 序漂 → 汇总再生区行序漂。固定按码升序(注入行源本无序,
# 只取确定序、不动行集);.sorted 保证跨进程稳定。
_refs = sorted({r[0] for r in sc.execute("""SELECT DISTINCT res_code FROM s_lme_res
WHERE session_id=? AND res_code IS NOT NULL""", (sid,))})
_refs = {r[0] for r in sc.execute("""SELECT DISTINCT res_code FROM s_lme_res
WHERE session_id=? AND res_code IS NOT NULL""", (sid,))}
# 决策 316 补记十一(2026-11-13 主人拍板「原地补全→导出放行」):**定额耗引用码一并纳入**
# ——补全/勘察补的源行引用地=定额耗(s_norm_res),此前只扫组成引用(s_lme_res)会漏;
# 注入判据照 186 不变(源文本没有该节点且库 uw/proj 有行→注入),无源的仍不造占位(304补七)。
_refs |= {r[0] for r in sc.execute(
"""SELECT DISTINCT nr.res_code FROM s_norm_res nr
JOIN s_norms n ON n.id=nr.norm_id JOIN s_bills b ON b.id=n.bill_id
WHERE b.session_id=? AND b.uw_id=? AND nr.res_code IS NOT NULL AND nr.res_code<>''""",
(sid, uw_id))}
_src_txt = _uw_src_text.get(uwkey)
if _lme_untouched:
_refs = () # 决策 274 补记四:无动作会话映射源不注入(源件缺失行保持缺失=源样)
@@ -4131,12 +4143,28 @@ def _export_session(sc, sid, fmt="", progress=None):
_u = sc.execute("""SELECT code, name, spec, unit, qty, taxrate, ntp, taxp, kind
FROM s_lme_uw WHERE session_id=? AND uw_id=? AND code=?""",
(sid, uw_id, rc)).fetchone()
_p = sc.execute("""SELECT code, name, spec, unit, qty, taxrate, ntp, taxp, kind
FROM s_lme_proj WHERE session_id=? AND code=?""", (sid, rc)).fetchone()
_src_has = (_src_txt is not None and
('<LabourMaterialsEquipmentsMachinesSummary Number="%s"' % rc) in _src_txt)
if not _src_has and (_u is not None or _p is not None):
plan["added_lme"].append(tuple(_u) if _u is not None else tuple(_p))
# 决策 321(2026-11-13 覆盖矩阵实测抓到):注入判据收窄=**本单位 uw 行存在**才注入。
# 旧兜底「项目级行有→也注入」会把 U1 独有链(如拌合机→油车,仅 U1 有汇总行)按全局
# 组成引用集渗漏进其他单位(UW2 被注入油车=源样量 3.0,显示 0→项目级聚合 3.6≠0.6,
# 违背 315 A案「项目级=单位级汇集」)。项目级独有行只在 Project.xml 骨架出场(台班戊
# 口径),不进单位文件;1009 补行场景不受影响(该行 uw 有行,_u 命中)。
if not _src_has and _u is not None:
# 决策 321(2026-11-13 主人令「异物三档都要考虑,不要人类去考虑」)拆码改印防重:
# rc 是 recode_ident 的改印**目标**且源文本还留着旧码节点(导出端 _ident_foreign_spans
# 会按名规单把它改印成 rc)→ 源节点即本行,不再注入第二条(否则导出件同码双行、
# 项目级聚合翻倍——321 覆盖矩阵实测抓到,装载机/重油/井水三码全中)。
_dupe = False
if _src_txt is not None and recode_ident_early:
for _oc, _idents in recode_ident_early.items():
if rc in (_idents or {}).values() and (
'<LabourMaterialsEquipmentsMachinesSummary Number="%s"' % _oc) in _src_txt:
_dupe = True
break
if _dupe:
continue
plan["added_lme"].append(tuple(_u))
# 决策 204/205:采纳新增行的子级组成(带子级整组照原生结构导出,子级码照映射、含量不动)
# + 三恒值回填映射(主人定:NoTaxOrgPrice / TaxOrgPrice / 税率 按原数据回填,
# 本单位→项目级回退;库中无 → 留空不编造)。added_children={码:[(子码,含量)]},added_org={码:(除税定额价,含税定额价,税率)}
@@ -4747,17 +4775,17 @@ def _lme_merge_groups(con, sid, sub=False):
def _key(r):
"""**组** = 名称|规格|单位相同(2026-11-04 主人定:合并的前提)——
组内成员再按「除数量外全字段」划分(见 _member_key)。"""
组内成员再按界面可见八元组划分(见 _member_key,决策 319)。"""
return ((r["name"] or "").strip(), (r["spec"] or "").strip(), (r["unit"] or "").strip())
def _member_key(r):
"""**成员** = 除数量外任一字段不同即独立成员(编码、名规单、类别、三价、六价扩展、flags)。
同字段组合的多行(不同单位工程)才是同一成员——数量在这里累计。"""
"""**成员** = 决策 319(2026-11-13 主人定):303 收窄贯彻到弹框——成员键=**界面可见
字段八元组**(编码/名规单/类别/三价),与 303 显示端、303 补记一导出端同一把尺;
原价四字段/flags 界面不显示、不再参与拆成员(可见全同=同成员,数量累计)。
(旧键「除数量外全字段」=2026-11-04 口径,被本决策取代。)"""
return ((r["code"] or "") if "code" in r.keys() else "",
(r["name"] or "").strip(), (r["spec"] or "").strip(), (r["unit"] or "").strip(),
_kval(r, "kind"), _kval(r, "ntp"), _kval(r, "taxrate"), _kval(r, "taxp"),
_kval(r, "ntp_org"), _kval(r, "ntp_expr"), _kval(r, "taxp_org"), _kval(r, "taxp_expr"),
_kval(r, "x_flags"))
_kval(r, "kind"), _kval(r, "ntp"), _kval(r, "taxrate"), _kval(r, "taxp"))
def _mid(ps):
# 升序中位(空价靠后):1条→它、2条→低、3条→居中(决策 108 单价规则同款)
ps = [p for p in ps]
@@ -4774,8 +4802,9 @@ def _lme_merge_groups(con, sid, sub=False):
# (折旧费 99450630)反而进组,测试勾选它合并后,引用它的台班子级全部变死引用(屏西 633 处)。
continue
groups.setdefault(k, []).append(("proj", r))
# 2026-11-04 主人定:**组** = 名规单;组内**成员** = 除数量外任一字段不同即独立成员
#(编码/名规单/类别/三价/六价/flags 全参与);同字段组合的多单位行聚成一个成员、数量累计。
# **组** = 名规单(2026-11-04 主人定);组内**成员** = 决策 319(2026-11-13 主人定):
# 键收窄为界面可见八元组(与 303 显示端/导出端同一把尺),原价/表达式/flags 不再拆成员;
# 可见全同的多单位行聚成一个成员、数量累计。
uw_agg = {}
for r in rows_u:
k = _key(r)
@@ -4851,14 +4880,10 @@ def _lme_merge_groups(con, sid, sub=False):
rows.sort(key=lambda x: (len(x["code"] or ""), 0 if x["lvl"] == "proj" else 1, x["id"]))
for i, x in enumerate(rows):
x["def"] = (i == 0)
# 组头数量=按码去重求和(同码不同价会出多行,现算数量只有一份,不能重复加)
_gq, _gseen = 0.0, set()
for x in rows:
_c = x["code"] or ""
if _c in _gseen:
continue
_gseen.add(_c)
_gq += (x["qty"] or 0)
# 组头数量=Σ成员量(决策 319:303 收窄贯彻到弹框后,成员量=各自归属的现算份额,
# 直接累计即该组总量;旧「按码去重」是为旧成员量错位(同码同价成员各拿全码量)
# 打的补丁(449d6d1),成员键收窄后错位不复存在,补丁随之取消)
_gq = sum((x["qty"] or 0) for x in rows)
out.append({"name": k[0], "spec": k[1], "unit": k[2],
"qty": _gq, "rows": rows})
out.sort(key=lambda g: (g["name"] or ""))
@@ -5079,6 +5104,18 @@ def api_lme_merge(sc, body):
hid += 1
if row and row[0] and row[0] != keep_code:
variants.append(row[0])
# 决策 316 补记七(269补四 force 在勾单位级分支的补漏,④c 六价断言实测暴露):
# 勾单位级聚合行时保留码的**全部单位行**三价+六价四列统一为保留行值——此前该分支只有
# hide 换码(不带三价/四列),三价靠回算自然统一、四列残留各单位原值(269补四 force
# 只落在勾项目级分支)。照 5015 同款:勾谁按谁,全量覆盖(没值清空)。
if keep_code and _g_ident and _g_ident[0]:
_xs_uw, _xa_uw = _px_extra(_sel_px6(sel), force=True)
sc.execute(("UPDATE s_lme_uw SET ntp=?, taxrate=?, taxp=?%s"
" WHERE session_id=? AND code=?"
" AND TRIM(COALESCE(name,''))=? AND TRIM(COALESCE(spec,''))=?"
" AND TRIM(COALESCE(unit,''))=?") % _xs_uw,
tuple(keep_px) + tuple(_xa_uw)
+ (sid, keep_code) + tuple(_g_ident))
# ③ 变体码收敛(决策 186 v3,2026-10-23 主人定「合并逻辑1」):
# 定额消耗量**精确码**换码(基础码不归并,防 D800 误伤)+ 子级整字段替换
# + 改码映射/子级替换数据持久化(导出件换码与子级重建,含单位级变体码);
@@ -5177,6 +5214,22 @@ def api_lme_merge(sc, body):
_merge_cleanup_tail(sc, sid, body) # 决策 288 补记七:合并收尾清场(消耗兜底+悬空清理+四留一删)
_inject_missing_refs(sc, sid) # 决策 186 第 5 条:Element 引用汇总行缺失→注入一次
_align_proj_summary(sc, sid) # 2026-11-13 A 案:项目级=单位级汇集(数量=Σ单位)
# 决策 316 补记七(甲案,2026-11-13 主人定「走甲」):合并收尾挂母行回算——被合并码
# 的价经保留值 force 覆盖后即「子价已变」,带子级母行按 288修/300 Σ 子级回算落库
# (与改价动作 lme_price 同口径,显示=库=导出三处一致)。逐级上溯由 _mothers_reprice 负责。
try:
_touched = set()
for g in (body.get("groups") if isinstance(body, dict) else None) or []:
_sel = g.get("sel") if isinstance(g.get("sel"), dict) else None
if _sel and _sel.get("code"):
_touched.add(str(_sel["code"]))
for _h in (g.get("hide") if isinstance(g.get("hide"), list) else []):
if isinstance(_h, dict) and _h.get("code"):
_touched.add(str(_h["code"]))
if _touched:
_mothers_reprice(sc, sid, sorted(_touched), as_children=True)
except Exception:
pass # 回算失败不挡合并本体(保留值已落库)
sess.dedupe_lme_uw(sc) # 决策 191:换码撞保留码双行收尾去重(幂等)
_consolidate_norm_res(sc, sid) # 决策 200:换码碰撞后同定额同码并一条(消耗量相加)
return {"ok": True, "sid": sid, "kept": kept, "hidden": hid}
@@ -5844,6 +5897,71 @@ def api_lme_price(sc, body):
"taxp0": (_a["x_taxp0"] if _a else None)}
def api_lme_fill(sc, body):
"""决策 316 补记十一(2026-11-13 主人拍板「原地补全」):缺源影子行原地补全——
工料机汇总里「有人用、没人供」的缺源耗码行(名称/规格/单位全空的影子行),操作员
点行弹填空小窗,一次填 名称/规格/单位/除税价/税率 保存即成真行:
INSERT 本单位 s_lme_uw + 项目级 s_lme_proj 汇集(_align_proj_summary 复用)
+ s_lme_lib 快照 INSERT OR IGNORE(三件套与勘察补源 297 补记三同款,值用操作员填的
——不造占位的延伸:处置权在操作员,软件不猜价);
补完重跑勘察(_chain_survey_repair):闭包缺源消失→chain_problems 清→导出闸放行。
补的名规单若与现有行三同 → 合并弹框自然成组,再合并归一(现有 294 功能,零新增)。
名称/单位必填(防半截行骗过导出闸);税没给按 除税/含税 反算(297 补三口径)。"""
sid = int(body.get("session_id", 0) or 0)
uw_id = int(body.get("uw_id", 0) or 0)
code = str(body.get("code") or "").strip()
name = str(body.get("name") or "").strip()
spec = str(body.get("spec") or "").strip()
unit = str(body.get("unit") or "").strip()
kind = int(body.get("kind", 2) or 2)
ntp = _num_or_none(body.get("ntp"))
taxp = _num_or_none(body.get("taxp"))
taxrate = _num_or_none(body.get("taxrate"))
if not (sid and code and name and unit):
return {"ok": False, "msg": "编码/名称/单位 必填(编码已由耗引用带出)"}
if not uw_id:
# 全单位视图(未选单位工程)→ 自动定位引用单位:取第一个引用该码的定额所在单位
_r = sc.execute("""SELECT b.uw_id FROM s_norm_res nr
JOIN s_norms n ON n.id=nr.norm_id JOIN s_bills b ON b.id=n.bill_id
WHERE b.session_id=? AND nr.res_code=? AND b.uw_id IS NOT NULL
ORDER BY b.uw_id LIMIT 1""", (sid, code)).fetchone()
if not _r:
return {"ok": False, "msg": "找不到引用该编码的定额(无需补全?)"}
uw_id = int(_r[0])
if taxrate is None and ntp is not None and taxp is not None and ntp:
taxrate = round((taxp / ntp - 1) * 100, 2) # 决策 297 补记三:税率反算
if taxp is None and ntp is not None and taxrate is not None:
taxp = round(ntp * (1 + taxrate / 100.0) + 1e-9, 2) # 决策 182:含税兜底
ex = sc.execute("SELECT id FROM s_lme_uw WHERE session_id=? AND uw_id=? AND code=?",
(sid, uw_id, code)).fetchone()
if ex:
sc.execute("""UPDATE s_lme_uw SET name=?, spec=?, unit=?, kind=?,
ntp=COALESCE(?,ntp), taxrate=COALESCE(?,taxrate), taxp=COALESCE(?,taxp)
WHERE id=?""", (name, spec, unit, kind, ntp, taxrate, taxp, ex["id"]))
else:
qty = sc.execute("""SELECT COALESCE(SUM(nr.qty),0) FROM s_norm_res nr
JOIN s_norms n ON n.id=nr.norm_id JOIN s_bills b ON b.id=n.bill_id
WHERE b.session_id=? AND b.uw_id=? AND nr.res_code=?
AND COALESCE(n.x_tdel,0)=0""", (sid, uw_id, code)).fetchone()[0]
sc.execute("""INSERT INTO s_lme_uw(session_id, uw_id, code, name, spec, unit, kind, qty,
ntp, taxrate, taxp, x_adopt_added)
VALUES(?,?,?,?,?,?,?,?,?,?,?,0)""",
(sid, uw_id, code, name, spec, unit, kind, qty, ntp, taxrate, taxp))
sc.execute("INSERT OR IGNORE INTO s_lme_lib(session_id, code, name, spec, unit, kind, ntp, taxp)"
" VALUES(?,?,?,?,?,?,?,?)",
(sid, code, name, spec, unit, kind, ntp, taxp))
try:
_align_proj_summary(sc, sid) # 315:项目级=单位级汇集(现成)
except Exception:
pass
try:
hc = conn()
_chain_survey_repair(sc, sid, hc) # 重跑勘察:缺源消失→登记清→闸放行
except Exception:
pass
return {"ok": True, "sid": sid, "code": code, "msg": "已补全(缺源清除,可重新导出)"}
def api_lme_field(sc, body):
"""项目级工料机汇总 名称/规格型号/单位 行内编辑(2026-10-22 主人定)。
口径:
@@ -9187,7 +9305,22 @@ class Handler(SimpleHTTPRequestHandler):
finally:
sc.close()
return self._json(r)
m = re.match(r"^/api/session/bill/(adopt|unadopt)$", u.path) # 批次B(决策 68):数据采纳/取消采纳
if u.path == "/api/session/lme/fill": # 决策 316 补记十一:缺源影子行原地补全
with WRITE_LOCK:
sc = sess.connect()
try:
r = api_lme_fill(sc, body)
sc.commit()
_sid = int(body.get("session_id") or 0) or 0
if r.get("ok") and _sid:
dyn_lme.qmap_drop(_sid) # 补行→量图失效(新源行进汇总)
except Exception as e:
sc.rollback()
r = {"ok": False, "msg": "补全失败:%s" % e}
finally:
sc.close()
return self._json(r)
m = re.match(r"^/api/session/bill/(adopt|unadopt)$", u.path) # 批次B(决策 68):数据采纳/取消采纳
if m:
with WRITE_LOCK: # 会话写库统一串行(决策 243:历史库也写附件事件,函数内自提交)
sc = sess.connect()