feat(core): 历史批次打开即原位自动升级(决策 34)并加固启动探活
- 解析器版本过期的批次在 /api/audit / /api/session/reparse 成功后原位重导:batches.id 不变,x_note/x_enabled/x_attach_sha 与会话绑定、询价/采纳附件一概不动;lme_attach 按 x_hash_exact 重映射,内容真变才解绑。 - 升级护栏:源文件缺失/内容哈希不符/加密/不可解析一律保旧数据只打日志。 - 取消后台「数据过期需重导」提示条(打开即升级后口径不再成立)。 - shell 启动加 HTTP 探活:端口被占但垂死的旧服务不再误复用,等待让位最多约 10 秒,仍无响应则明确报错。 - 工作台分组规则操作列加 ↑/↓ 移动,删除改两段式行内确认(绕开 WebView2 里 confirm() 失效);原数据标签去掉恒为 0 的徽标。
This commit is contained in:
@@ -403,10 +403,13 @@ def parse_std(path, out):
|
||||
# 已导入的 xml 批次也已从库中清除(tools/purge_batches.py --by-ext .xml)。
|
||||
# 将来若要恢复:git 历史里有,照 parse_std 的同款容器记账规则重写即可。
|
||||
|
||||
def save(con, kind, out, fn, sha, mtime, meta=None):
|
||||
def save(con, kind, out, fn, sha, mtime, meta=None, bid=None):
|
||||
"""
|
||||
meta = {name, province, city, district, period_from, period_to, bulid_unit, file_kind}
|
||||
元数据全部来自导入弹框(你填的);不传时退回旧行为(文件名 + 默认地区 + 文件时间)
|
||||
bid = 传批次 id 则**原位升级**(UPDATE 该行 + 重写其明细,方案 A 打开即升级用);
|
||||
不传 = 新导入(INSERT 新批次行)。原位路径不动 x_note / x_enabled / x_attach_sha,
|
||||
也不产生新 id —— sessions.x_batch_id 与 lme_attach 绑定才不至于断链(2026-10-11)
|
||||
"""
|
||||
ym = int(time.strftime("%Y", time.localtime(mtime))) * 12 + int(time.strftime("%m", time.localtime(mtime)))
|
||||
if meta:
|
||||
@@ -433,12 +436,21 @@ def save(con, kind, out, fn, sha, mtime, meta=None):
|
||||
info_json = json.dumps(_info, ensure_ascii=False) if _info else None
|
||||
_feat = out.get("feat") or []
|
||||
feat_json = json.dumps([{"n": n, "v": v} for n, v in _feat], ensure_ascii=False) if _feat else None
|
||||
cur.execute("""INSERT INTO batches(kind, Name, FileKind, BulidUnit, x_province, x_city, x_district,
|
||||
x_period_start_m, x_period_end_m, x_enabled, x_total, x_rows_bill, x_rows_lme, x_imported_at,
|
||||
x_src_hash, x_note, x_parser_ver, x_info, x_feat) VALUES(?,?,?,?,?,?,?,?,?,1,?,?,?,?,?,?,?,?,?)""",
|
||||
(kind, name, fk, bu, prov, city, dist, p_from, p_to, out["total"], 0, 0,
|
||||
time.strftime("%Y-%m-%d %H:%M:%S"), sha, "", PARSER_VER, info_json, feat_json))
|
||||
bid = cur.lastrowid
|
||||
if bid is None:
|
||||
cur.execute("""INSERT INTO batches(kind, Name, FileKind, BulidUnit, x_province, x_city, x_district,
|
||||
x_period_start_m, x_period_end_m, x_enabled, x_total, x_rows_bill, x_rows_lme, x_imported_at,
|
||||
x_src_hash, x_note, x_parser_ver, x_info, x_feat) VALUES(?,?,?,?,?,?,?,?,?,1,?,?,?,?,?,?,?,?,?)""",
|
||||
(kind, name, fk, bu, prov, city, dist, p_from, p_to, out["total"], 0, 0,
|
||||
time.strftime("%Y-%m-%d %H:%M:%S"), sha, "", PARSER_VER, info_json, feat_json))
|
||||
bid = cur.lastrowid
|
||||
else:
|
||||
cur.execute("""UPDATE batches SET kind=?, Name=?, FileKind=?, BulidUnit=?, x_province=?, x_city=?,
|
||||
x_district=?, x_period_start_m=?, x_period_end_m=?, x_total=?, x_rows_bill=0, x_rows_lme=0,
|
||||
x_imported_at=?, x_parser_ver=?, x_info=?, x_feat=? WHERE id=?""",
|
||||
(kind, name, fk, bu, prov, city, dist, p_from, p_to, out["total"],
|
||||
time.strftime("%Y-%m-%d %H:%M:%S"), PARSER_VER, info_json, feat_json, bid))
|
||||
if cur.rowcount != 1:
|
||||
raise RuntimeError("原位升级失败:批次 #%s 不存在" % bid)
|
||||
|
||||
# ===== 2026-10-01:与工作台会话库对齐,后台批次库同样**存层级 + 工程量** =====
|
||||
# ⚠️ 此处推翻了原「历史库不存工程量 / 单位工程表已删除、清单不分层」两条旧口径:
|
||||
|
||||
Reference in New Issue
Block a user