Files
pricing_review/CostReview/_patch_ehsnap.py

143 lines
7.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
# 决策 218 补二:编辑历史改版——按清单快照(时间|工程量|单价|合价),只记清单,本次不出现
import io
p = r'D:\PricingReview\CostReview\app\server\api_server.py'
with io.open(p, encoding='utf-8') as f:
t = f.read()
def rep(old, new, tag):
global t
assert t.count(old) == 1, tag + ' count=' + str(t.count(old))
t = t.replace(old, new)
# 1) 清单快照函数(_edit_log 前)
rep('def _edit_log(sc, ekbase, fields, cols, row):',
'''def _bill_snap_log(sc, brow):
"""清单编辑快照(决策 218 补二,2026-10-26 主人定):清单被编辑/采纳覆盖**前**的三值快照
(工程量|单价|合价)——编辑历史浮层按 时间|工程量|单价|合价 展示;记的是改前值,
本次(最新)状态就在格子上看,天然不重复出现。只记清单,定额不再记。"""
import json as _json
o = _json.dumps({"q": brow["Quantity"], "p": brow["Price"], "t": brow["Total"]},
ensure_ascii=False)
sc.execute("INSERT INTO s_edit_log(ekbase, f, o, n) VALUES(?,?,?,'')",
(_bill_ekbase(sc, brow), "SNAP", o))
def _edit_log(sc, ekbase, fields, cols, row):''', 'snap函数')
# 2) 清单行内编辑:改前快照替代逐字段日志
rep(''' cur_row = sc.execute("SELECT * FROM s_bills WHERE id=?", (bid,)).fetchone()
vals.append(bid)
sc.execute("UPDATE s_bills SET %s WHERE id=?" % ",".join(sets), vals)
_edit_log(sc, _bill_ekbase(sc, cur_row), ef, _BILL_EDIT_FIELDS, cur_row)''',
''' cur_row = sc.execute("SELECT * FROM s_bills WHERE id=?", (bid,)).fetchone()
_bill_snap_log(sc, cur_row) # 决策 218 补二:改前快照(时间|工程量|单价|合价),只记清单
vals.append(bid)
sc.execute("UPDATE s_bills SET %s WHERE id=?" % ",".join(sets), vals)''', 'bill edit')
# 3) 定额编辑不再记日志
rep(''' sc.execute("UPDATE s_norms SET %s WHERE id=?" % ",".join(sets), vals)
_edit_log(sc, _norm_ekbase(sc, cur_row),
{k: fields[k] for k in ("Name", "Quantity") if k in fields},
{"Name": "Name", "Quantity": "Quantity"}, cur_row)''',
''' sc.execute("UPDATE s_norms SET %s WHERE id=?" % ",".join(sets), vals)
# 决策 218 补二:定额编辑不再记日志(编辑历史只记清单快照)''', 'norm edit')
# 4) 采纳覆盖也记改前快照(在 9.3 单价覆盖 UPDATE 前抓 sb——sb 已在函数头取过,补快照)
rep(''' new_price = bb["Price"]
src_qty = f_(bb["Quantity"])''',
''' new_price = bb["Price"]
_bill_snap_log(sc, sb) # 决策 218 补二:采纳覆盖前快照(采纳也是一次变更)
src_qty = f_(bb["Quantity"])''', 'adopt snap')
# 5) api_edit_log:下发快照(清单键=ekbase 本身);旧字段级行不再下发(口径换,铁律6)
rep(''' bases = set(m.values())
log = []
for r in sc.execute("SELECT ekbase, f, o, n, at FROM s_edit_log ORDER BY id DESC").fetchall():
if r["ekbase"] in bases:
log.append({"k": r["ekbase"] + ":" + r["f"], "o": r["o"], "n": r["n"], "at": r["at"]})''',
''' bases = set(m.values())
log = []
# 决策 218 补二:只下发清单快照行(f=SNAP,o=json{q,p,t});字段级旧行不再下发
import json as _json
for r in sc.execute("SELECT ekbase, f, o, n, at FROM s_edit_log WHERE f='SNAP' ORDER BY id DESC").fetchall():
if r["ekbase"] in bases:
try:
s = _json.loads(r["o"] or "{}")
except Exception:
s = {}
log.append({"k": r["ekbase"], "at": r["at"],
"q": s.get("q"), "p": s.get("p"), "t": s.get("t")})''', 'api_edit_log')
with io.open(p, 'w', encoding='utf-8', newline='\n') as f:
f.write(t)
print('后端五处已改')
# ---------- 前端 common.js ----------
p = r'D:\PricingReview\CostReview\app\ui\common.js'
with io.open(p, encoding='utf-8') as f:
t = f.read()
# 1) 映射简化:只挂清单行工程量格(组表 idx8 / 原数据 idx7);定额映射弃
rep("""const EH_FIELDS_BILL = { Name: 5, Attr: 6, Unit: 7, Quantity: 8, src_remark: 12 }; // 组表列位
const EH_FIELDS_BILL_RAW = { Name: 4, Attr: 5, Quantity: 7 }; // 决策 218 补:原数据行列位(0把手1序号2编码3类型4名称5特征7工程量)
const EH_FIELDS_NORM = { Name: 5, Quantity: 8 };""",
"""/* 决策 218 补二:编辑历史只挂**清单行工程量格**(组表 idx8 / 原数据 idx7);键=清单 ekbase;
浮层按 时间|工程量|单价|合价 展示改前快照。定额不再有编辑历史。 */
const EH_QTY_IDX = { grp: 8, raw: 7 };""", '映射简化')
# 2) markGroupEH:只挂清单行、键=ekbase
rep(""" const mark = (tr, fields, rid) => {
const base = EH_M[String(rid)]; // 稳定键基(重解析不丢,服务端下发)
if (!base) return;
for (const f in fields) {
const k = base + ':' + f;
if (EH_LOG[k] && EH_LOG[k].length) {
const td = tr.children[fields[f]];
if (td) { td.classList.add('eh'); td.dataset.ehk = k; }
}
}
};
const billMap = (tb.id === 'rawbody') ? EH_FIELDS_BILL_RAW : EH_FIELDS_BILL;
tb.querySelectorAll('tr[data-bid]').forEach(tr => mark(tr, billMap, tr.dataset.bid));
tb.querySelectorAll('tr.sub[data-nid]').forEach(tr => mark(tr, EH_FIELDS_NORM, tr.dataset.nid));""",
""" const mark = (tr, qtyIdx, rid) => {
const k = EH_M[String(rid)]; // 决策 218 补二:键=清单 ekbase(快照聚合)
if (k && EH_LOG[k] && EH_LOG[k].length) {
const td = tr.children[qtyIdx];
if (td) { td.classList.add('eh'); td.dataset.ehk = k; }
}
};
const isRaw = (tb.id === 'rawbody');
tb.querySelectorAll('tr[data-bid]').forEach(tr => mark(tr, EH_QTY_IDX[isRaw ? 'raw' : 'grp'], tr.dataset.bid));""", 'markGroupEH')
# 3) loadEditLog 解析(键不再拼字段)
rep(""" EH_M = d.m || {}; EH_LOG = {};
(d.log || []).forEach(r => {
(EH_LOG[r.k] = EH_LOG[r.k] || []).push({ at: r.at, o: r.o, n: r.n });
});""",
""" EH_M = d.m || {}; EH_LOG = {};
(d.log || []).forEach(r => { // 决策 218 补二:快照行 {k,at,q,p,t},k=清单键
(EH_LOG[r.k] = EH_LOG[r.k] || []).push({ at: r.at, q: r.q, p: r.p, t: r.t });
});""", 'loadEditLog')
# 4) 浮层:四列表
rep(""" pop.innerHTML = '<div class="eh-hd">编辑历史</div><table>'
+ list.map((r, i) => '<tr><td class="n">' + (i + 1) + '</td><td class="at">' + esc(r.at || '')
+ '</td><td class="c">' + esc((r.o ? r.o + ' → ' : '') + (r.n == null ? '' : r.n))
+ '</td></tr>').join('')
+ '</table>';""",
""" // 决策 218 补二:编辑时间|工程量|单价|合价(改前快照,新→旧;本次=格子现值不在此列)
const f3 = v => (v == null || v === '') ? '—' : v;
pop.innerHTML = '<div class="eh-hd">编辑历史</div><table>'
+ '<tr class="eh-th"><td>编辑时间</td><td>工程量</td><td>单价</td><td>合价</td></tr>'
+ list.map(r => '<tr><td class="at">' + esc(r.at || '') + '</td><td class="c">' + esc(f3(r.q))
+ '</td><td class="c">' + esc(f3(r.p)) + '</td><td class="c">' + esc(f3(r.t))
+ '</td></tr>').join('')
+ '</table>';""", '浮层四列')
with io.open(p, 'w', encoding='utf-8', newline='\n') as f:
f.write(t)
print('前端四处已改')