feat(costreview): 新增清单库与项目目录管理并修复采纳定额单价回填及换行实体转义
This commit is contained in:
51
_analysis/定额单价专题/patch_273_exp.py
Normal file
51
_analysis/定额单价专题/patch_273_exp.py
Normal file
@@ -0,0 +1,51 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""决策 273 导出端:采纳定额(x_side 有值)的单价行 Total 按 x_side 回填——
|
||||
一致=外部值/不一致=空串;无 x_side 维持清零现状(106 口径不动)。"""
|
||||
import io
|
||||
p = r"D:\PricingReview\CostReview\app\core\export_cos.py"
|
||||
s = io.open(p, encoding="utf-8").read()
|
||||
|
||||
# ---- ① _norm_xml 里 pre/post 清零后按 x_side 回填单价行 Total ----
|
||||
old = ''' pre, post = _zero_results(pre), _zero_results(post)
|
||||
pre = re.sub(r'<ExpressElement\\b[^>]*/>', '', pre)
|
||||
post = re.sub(r'<ExpressElement\\b[^>]*/>', '', post)'''
|
||||
new = ''' pre, post = _zero_results(pre), _zero_results(post)
|
||||
pre = re.sub(r'<ExpressElement\\b[^>]*/>', '', pre)
|
||||
post = re.sub(r'<ExpressElement\\b[^>]*/>', '', post)
|
||||
# 决策 273(2026-11-04 主人定):采纳定额的单价行 Total 按 Name 匹配外部——
|
||||
# x_side(采纳时构造:同区模板行组+Total 按 Name 匹配外部,一致=外部值/不一致留空)
|
||||
# 有值时回填 Total 覆盖清零;无 x_side 维持清零现状(106 口径不动)。
|
||||
_sm = {}
|
||||
if n.get("x_side"):
|
||||
try:
|
||||
for _rec in json.loads(n["x_side"]):
|
||||
if _rec.get("tag") == "UnitPriceCalculationOfItem":
|
||||
_a = _rec.get("attrs") or {}
|
||||
_sm[(_a.get("Name") or "").strip()] = _a.get("Total")
|
||||
except Exception:
|
||||
_sm = {}
|
||||
if _sm:
|
||||
pre = _adopt_totals(pre, _sm)
|
||||
post = _adopt_totals(post, _sm)'''
|
||||
assert old in s, "zero block NOT FOUND"
|
||||
s = s.replace(old, new)
|
||||
|
||||
# ---- ② _adopt_totals 函数(挂在 _zero_results 后面) ----
|
||||
old2 = '''def _zero_results(frag):'''
|
||||
new2 = '''def _adopt_totals(frag, sm):
|
||||
"""决策 273:单价行 Total 按 Name 匹配回填——一致=外部该行 Total;不一致=空串(留空)。
|
||||
只动骨架已有的 UnitPriceCalculationOfItem 自闭合行(卡槽在才写)。"""
|
||||
def _f(m):
|
||||
a = dict(re.findall(r'(\\w+)="([^"]*)"', m.group(1)))
|
||||
nm = (a.get("Name") or "").strip()
|
||||
v = sm.get(nm)
|
||||
return _attr_set(m.group(0), "Total", "" if v is None else v)
|
||||
return re.sub(r'<UnitPriceCalculationOfItem\\b([^>]*?)/>', _f, frag)
|
||||
|
||||
|
||||
def _zero_results(frag):'''
|
||||
assert old2 in s, "_zero_results anchor NOT FOUND"
|
||||
s = s.replace(old2, new2)
|
||||
|
||||
io.open(p, "w", encoding="utf-8").write(s)
|
||||
print("export side done")
|
||||
Reference in New Issue
Block a user