diff --git a/.zcodeignore b/.zcodeignore new file mode 100644 index 0000000..96447c4 --- /dev/null +++ b/.zcodeignore @@ -0,0 +1,66 @@ +.workbuddy/ +.venv/ +*.db +*.db-shm +*.db-wal +*.sqlite +*.sqlite3 +__pycache__/ +*.pyc +node_modules/ +/release/* +# testdata 测试数据生成器是源码,必须入库(2026-10-09 差点因未跟踪丢失) +!/release/testdata/ +# 运行时配置(存本机数据目录路径),不入库 +/release/testdata/config.json + + +# ===== 数据 / 样本 / 生成物:不入库 ===== +/后台需要导入的项目/ +/造价审核/data/* +# 2026-10-06:history.db / session.db 已 git rm --cached 移出版本控制 +# (库内全是测试数据、无保存价值,两库合计约 130MB,不再入库)。 +# 确有必要提交一次数据库快照时:git add -f 造价审核/data/xxx.db +/输出/ +/2025造价数据标准.docx +/横琴高位水池及加压泵房工程(1).html +/珠海信息价_2026年7月.html +*.pdf +*.docx +*.cos4 +*.COS +*.xml +*.XML + +# 废弃代码只留本地(2026-10-09 主人定:不入新仓库) +造价审核/app/_deprecated/ + +# ===== ↑ 以上同步自 .gitignore(「从 .gitignore 同步」只重写以上部分)===== +.git/ +.hg/ +.svn/ +bower_components/ +jspm_packages/ +site-packages/ +venv/ +coverage/ +htmlcov/ +lcov-report/ +cmakefiles/ +cmake-build-*/ +bazel-*/ +pods/ +deriveddata/ +storybook-static/ +playwright-report/ +test-results/ +allure-results/ +allure-report/ +cdk.out/ +*.egg-info/ +*.dist-info/ +eggs/ +pip-wheel-metadata/ +wheels/ +# ----- ↑ 以上为 ZCode 默认排除规则(自定义规则请写在本行下方,不会被同步/恢复改动)----- +# 自定义规则写在下方(本行提示可删除) diff --git a/release/testdata/gen_testdata.py b/release/testdata/gen_testdata.py index c456b97..684d67a 100644 --- a/release/testdata/gen_testdata.py +++ b/release/testdata/gen_testdata.py @@ -572,6 +572,18 @@ def _open_db(path): con.execute("PRAGMA busy_timeout=30000") return con + +def _open_ro(path, timeout=3): + """只读打开,短超时:库被其它进程(造价审核软件 / 生成子进程)占用时快速失败返回 + None,绝不死等。原 stats_of/totals_of 用 15~30s 超时,会导致面板整页卡死。""" + try: + con = sqlite3.connect("file:%s?mode=ro" % path.replace("\\", "/"), + uri=True, timeout=timeout) + con.execute("PRAGMA busy_timeout=%d" % int(timeout * 1000)) + return con + except Exception: + return None + # ---------------- 结构级插入(history 与 session 两库共用一份逻辑数据) ---------------- # 逻辑行里的 owner 索引是本地序号,插入时映射为真实 id。 @@ -1189,7 +1201,10 @@ def stats_of(dd): if not os.path.exists(th): out["note"] = "测试库尚未生成(%s 不存在),真实库从未被本工具写过" % TEST_H return out - hc = _open_db(th) + hc = _open_ro(th) + if hc is None: + out["note"] = "测试库被占用(可能正在生成或造价审核软件打开中),稍后点「刷新统计」重试" + return out q = "FROM batches WHERE is_mock=1 AND Name LIKE '测试%'" for k in ("project", "market", "info"): out["b_%s" % k] = hc.execute("SELECT COUNT(*) " + q + " AND kind=?", (k,)).fetchone()[0] @@ -1214,65 +1229,62 @@ def stats_of(dd): hc.close() sp = ts if os.path.exists(sp): - sc = _open_db(sp) - out["s_sessions"] = sc.execute( - "SELECT COUNT(*) FROM sessions WHERE name LIKE '测试%'").fetchone()[0] - for t in ("s_bills", "s_norms", "s_lmes"): - try: - if t == "s_norms": # s_norms.bill_id 挂在 s_bills 上,要经两层 - out[t] = sc.execute( - "SELECT COUNT(*) FROM s_norms WHERE bill_id IN (SELECT id FROM s_bills " - "WHERE session_id IN (SELECT id FROM sessions WHERE name LIKE '测试%'))" - ).fetchone()[0] - else: - out[t] = sc.execute( - "SELECT COUNT(*) FROM %s WHERE session_id IN " - "(SELECT id FROM sessions WHERE name LIKE '测试%%')" % t).fetchone()[0] - except Exception: + sc = _open_ro(sp) + if sc is None: + out["s_sessions"] = -1 + for t in ("s_bills", "s_norms", "s_lmes"): out[t] = -1 - sc.close() + else: + out["s_sessions"] = sc.execute( + "SELECT COUNT(*) FROM sessions WHERE name LIKE '测试%'").fetchone()[0] + for t in ("s_bills", "s_norms", "s_lmes"): + try: + if t == "s_norms": # s_norms.bill_id 挂在 s_bills 上,要经两层 + out[t] = sc.execute( + "SELECT COUNT(*) FROM s_norms WHERE bill_id IN (SELECT id FROM s_bills " + "WHERE session_id IN (SELECT id FROM sessions WHERE name LIKE '测试%'))" + ).fetchone()[0] + else: + out[t] = sc.execute( + "SELECT COUNT(*) FROM %s WHERE session_id IN " + "(SELECT id FROM sessions WHERE name LIKE '测试%%')" % t).fetchone()[0] + except Exception: + out[t] = -1 + sc.close() return out # ---------------- 数据库资产总览(两库全量家底,打开面板即看) ---------------- def totals_of(dd): """参考库与测试库的全量资产计数(不区分 mock,只数行数)。 - 缺文件的库返回 None。全部走只读连接,不碰写入。""" + 缺文件 / 被占用的库返回 None。全部走只读短超时连接,库被造价审核软件或生成子进程 + 占用时快速返回(带 locked 标记),绝不死等——否则 /api/stats 卡 15~30s 会让整页假死。""" rh, th, rs, ts = db_paths(dd) - def h_totals(p): + def one(p, tables): if not os.path.exists(p): - return None - c = sqlite3.connect("file:%s?mode=ro" % p.replace("\\", "/"), uri=True, - timeout=15) - c.execute("PRAGMA busy_timeout=15000") + return None, False + c = _open_ro(p, timeout=3) + if c is None: + return None, True # 被占用 out = {} - for t in ("batches", "bills", "norms", "norm_res", "lmes", "lme_lib", - "prices", "attachments"): + for t in tables: try: out[t] = c.execute("SELECT COUNT(*) FROM %s" % t).fetchone()[0] except Exception: out[t] = -1 c.close() - return out + return out, False - def s_totals(p): - if not os.path.exists(p): - return None - c = sqlite3.connect("file:%s?mode=ro" % p.replace("\\", "/"), uri=True, - timeout=15) - c.execute("PRAGMA busy_timeout=15000") - out = {} - for t in ("sessions", "s_bills", "s_norms", "s_lmes"): - try: - out[t] = c.execute("SELECT COUNT(*) FROM %s" % t).fetchone()[0] - except Exception: - out[t] = -1 - c.close() - return out - - return {"ref_h": h_totals(rh), "ref_s": s_totals(rs), - "test_h": h_totals(th), "test_s": s_totals(ts)} + H = ("batches", "bills", "norms", "norm_res", "lmes", "lme_lib", + "prices", "attachments") + S = ("sessions", "s_bills", "s_norms", "s_lmes") + rh_d, l1 = one(rh, H); th_d, l2 = one(th, H) + rs_d, l3 = one(rs, S); ts_d, l4 = one(ts, S) + locked = [n for n, f in (("参考history", l1), ("参考session", l3), + ("测试history", l2), ("测试session", l4)) if f] + return {"ref_h": rh_d, "ref_s": rs_d, "test_h": th_d, "test_s": ts_d, + "locked": locked} # ---------------- 分块删除 ---------------- diff --git a/release/testdata/panel_server.py b/release/testdata/panel_server.py index 41c5777..10324be 100644 --- a/release/testdata/panel_server.py +++ b/release/testdata/panel_server.py @@ -11,6 +11,7 @@ import json import os import subprocess import sys +import time import threading import webbrowser from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer @@ -247,6 +248,9 @@ height:300px;overflow-y:auto;padding:12px;border-radius:6px;white-space:pre-wrap .chk{display:flex;align-items:center;gap:6px;font-size:13px;color:var(--txt)} .sec-h{font-size:12px;color:var(--sub);margin:10px 0 6px;font-weight:bold} .err{color:var(--warn)} +.banner{display:none;margin:0 0 12px;padding:8px 12px;border-radius:6px;font-size:13px} +.banner.err{background:#fdecea;color:#d83931;border:1px solid #f5c6c0} +.banner.ok{background:#eaf6e8;color:#2ea121;border:1px solid #cde9c8} .dblab{display:inline-block;width:84px;text-align:center;border-radius:4px; padding:2px 0;font-size:12px;color:#fff;flex:none} .dblab.ref{background:#646a73}.dblab.test{background:var(--pri)} @@ -268,6 +272,8 @@ table.assets .grp td{background:#fafbfc;font-weight:600;text-align:left} history-test.db / session-test.db(首次自动从真实库克隆底子),真实库零污染—— 对接软件时把测试库改名换上即可;换到别的母体后点一次「版本对齐」,删除只是兜底手段。 +
+