fix(costreview): 历史清单定额展开支持重导后按批次+哈希重定位,并后台预升级过期批次

This commit is contained in:
lianjianwei2024
2026-11-15 10:26:48 +08:00
parent 0e5785f1dc
commit 4b54ee1cfa
5 changed files with 95 additions and 13 deletions

View File

@@ -8616,17 +8616,32 @@ def _bill_norms(con, T, bill_id):
return {"rows": out}
def api_bill_norms(bill_id):
"""批次内:一条清单下挂的定额(批次库)"""
def api_bill_norms(bill_id, bhash=None, batch=None):
"""批次内:一条清单下挂的定额(批次库)。
决策 341(2026-11-15 主人拍板「修下」):279 按需重导会把 bills/norms 的 id 全部换新——
对比框/检索行手里攥的旧 id 展开「定额/耗」会空。前端随 ± 把手带 bhash+batch,旧 id
查不到清单行时按 **批次+内容哈希** 重定位(279 延伸同款),用新 id 取数;响应带重定位后的 bill_id。"""
c = conn()
try:
d = _bill_norms(c, TBL["batch"], bill_id)
_b = c.execute("SELECT batch_id FROM bills WHERE id=?", (bill_id,)).fetchone()
if _b is None and bhash and batch:
try:
batch = int(batch)
except (TypeError, ValueError):
batch = 0
_nb = c.execute("""SELECT id, batch_id FROM bills WHERE batch_id=? AND x_hash_exact=?
ORDER BY id DESC LIMIT 1""", (batch, bhash)).fetchone()
if _nb is not None:
bill_id = _nb["id"]
d = _bill_norms(c, TBL["batch"], bill_id)
_b = _nb
# 决策 289 补三(2026-11-09 主人定「显示哪条,耗就开他来源的工料机」):入库历史行
# 耗浮层的**子级组成**要按批次取(/api/admin/lme/res?batch_id=)——响应带上本清单
# 所属批次号,前端沿 tgHist→耗钮→浮层→± 传递,检索行/定额行本身都不用改。
_b = c.execute("SELECT batch_id FROM bills WHERE id=?", (bill_id,)).fetchone()
if _b is not None:
d["batch_id"] = _b[0]
d["bill_id"] = bill_id # 决策 341:重定位后的新 id
return d
finally:
c.close()
@@ -9255,7 +9270,7 @@ class Handler(SimpleHTTPRequestHandler):
return self._json(_norm_res(_shared_ro("hist"), TBL["batch"], int(m.group(1))))
m = re.match(r"^/api/admin/bill/(\d+)/norms$", p)
if m:
return self._json(api_bill_norms(int(m.group(1))))
return self._json(api_bill_norms(int(m.group(1)), one.get("bhash"), one.get("batch")))
except Exception as e:
import traceback as _tb
_tb.print_exc() # 决策 288:500 带栈落日志(排查基建,不再静默)
@@ -9865,6 +9880,7 @@ def run():
print("serving on http://127.0.0.1:%d (db=%s) (PID=%d)" % (PORT, DB, os.getpid()), flush=True)
# 决策 126:端口已 listening,先让启动器/窗口走;清理回收在后台跑,慢也不再挡住开窗。
threading.Thread(target=_startup_selfheal_bg, name="startup-selfheal", daemon=True).start()
adopt_api.upgrade_stale_batches_bg() # 决策 341(主人拍板「修下」):后台逐批预升级过期批次——把采纳时的一次性重导卡顿集中到启动后台消化
srv.serve_forever()