feat(全链): 落实决策322-333——采纳落价Σ合价÷量、编制价三件套归一、块进块出、导出通用化只改导入、母随子动回算、台账分层留存

This commit is contained in:
lianjianwei2024
2026-11-14 23:40:41 +08:00
parent b05b34ffbf
commit b400454f74
12 changed files with 1572 additions and 384 deletions

View File

@@ -533,25 +533,58 @@ def qmap_mtime_of(sc):
return _qpath_mt(sc)[1]
def _propagate(base, kids):
def _propagate(base, kids, remap=None):
"""母子传导唯一实现:子量 = 母量 × 子含量,从直接消耗量快照出发只传一层
(决策 268补三 2026-11-04 主人定口径;子级自己带子级不二次传导)。"""
(决策 268补三 2026-11-04 主人定口径;子级自己带子级不二次传导)。
remap={旧码: 新码}(2026-11-14 决策 304 缺口修复):同码异物拆码迁移后,源件组成边
(uw_id=NULL 全项目一份)仍指向旧码——迁移桶里旧码已无行、行已迁新码,本桶传导目标
按 remap 重定向,消除「原码幽灵量」(显示端项目级=按行所在单位取量会漏它)。
无拆码项目 remap=None,行为与历史完全一致。"""
out = dict(base)
for mcode, mq in base.items():
if mq is None:
continue
for c, q, _nm in kids.get(mcode) or ():
tgt = (remap or {}).get(c, c)
try:
out[c] = out.get(c, 0.0) + float(mq) * float(q or 0)
out[tgt] = out.get(tgt, 0.0) + float(mq) * float(q or 0)
except (TypeError, ValueError):
pass
return out
def _split_remap_by_uw(sc, sid):
"""拆码重定向表 {uw_id: {旧码: 新码}}(2026-11-14 304 缺口修复配套)。
口径:登记簿 recode_ident 的每个 (旧码→新码) 身份包——旧码行所在单位集 U_old、
新码行所在单位集 U_new——U_new − U_old 中的单位 u:本桶传导目标 old→new
(该桶旧码已无行、实际行=新码)。无登记簿/无拆码→返回 {}。"""
try:
row = sc.execute("SELECT v FROM s_settings WHERE scope=? AND k=?",
("session:%d" % sid, "recode_ident")).fetchone()
rec = __import__("json").loads(row[0] or "{}") if row and row[0] else {}
if not rec:
return {}
units = {}
for r in sc.execute("""SELECT code, uw_id FROM s_lme_uw
WHERE session_id=? AND uw_id IS NOT NULL AND code IS NOT NULL""",
(sid,)):
units.setdefault(r["code"], set()).add(r["uw_id"])
out = {}
for old, idents in rec.items():
u_old = units.get(old) or set()
for new in set(idents.values()):
for u in (units.get(new) or set()) - u_old:
out.setdefault(u, {})[old] = new
return out
except Exception:
return {}
def _qmap_build_all(sc, sid):
consume = _consumption_by_code(sc, sid, None, by_uw=True)
kids = _children_map(sc, sid)
return {u: _propagate(m, kids) for u, m in consume.items()}
remaps = _split_remap_by_uw(sc, sid)
return {u: _propagate(m, kids, remaps.get(u)) for u, m in consume.items()}
def qmap_all_cached(sc, sid):
@@ -587,7 +620,8 @@ def qmap_touch_uw(sc, sid, uw_id, pre_mt=None):
if ent is None:
return
try:
umap = _propagate(_consumption_by_code(sc, sid, uw_id), _children_map(sc, sid))
umap = _propagate(_consumption_by_code(sc, sid, uw_id), _children_map(sc, sid),
_split_remap_by_uw(sc, sid).get(uw_id))
except Exception:
with _QLOCK:
_QCACHE.pop(key, None)