feat(testdata): 面板新增「数据库资产总览」——打开即自动清点参考库/测试库全量家底(批次/清单/定额/工料机/附件/会话),只读连接,生成前后可对账

This commit is contained in:
lianjianwei2024
2026-10-10 11:19:26 +08:00
parent b8513cdb8b
commit a3697ba271
2 changed files with 73 additions and 1 deletions

View File

@@ -131,6 +131,11 @@ class H(BaseHTTPRequestHandler):
s["ref_ok"] = [os.path.exists(rh), os.path.exists(rs)]
s["test_ok"] = [os.path.exists(th), os.path.exists(ts)]
s["running"] = running()
if dd and "error" not in s:
try:
s["totals"] = G.totals_of(dd)
except Exception as te_:
s["totals_err"] = str(te_)
s["mode"] = _state["mode"] if running() else None
self._send(200, s)
elif self.path == "/api/log":
@@ -246,6 +251,12 @@ height:300px;overflow-y:auto;padding:12px;border-radius:6px;white-space:pre-wrap
padding:2px 0;font-size:12px;color:#fff;flex:none}
.dblab.ref{background:#646a73}.dblab.test{background:var(--pri)}
.dbin{flex:1;min-width:260px}
table.assets{border-collapse:collapse;width:100%;font-size:12px}
table.assets th,table.assets td{border:1px solid var(--line,#d5d9e0);
padding:3px 8px;text-align:right}
table.assets th:first-child,table.assets td:first-child{text-align:left}
table.assets th{background:#f2f4f7;font-weight:600}
table.assets .grp td{background:#fafbfc;font-weight:600;text-align:left}
.dbname{font:12px Consolas,monospace}
.badge{font-size:12px;padding:1px 8px;border-radius:10px;flex:none}
.badge.ok{color:var(--ok);background:#eaf6e8}
@@ -321,6 +332,11 @@ history-test.db / session-test.db(首次自动从真实库克隆底子),<b
<div><label>期次止(年-月)</label><input type="text" id="to_ym" value="2026-10" placeholder="2026-10"></div>
</div></div>
<div class="card"><h2>数据库资产总览(全量,含非测试数据)</h2>
<table class="assets" id="assets"></table>
<div class="sub" style="margin-top:6px">打开面板即自动清点;生成前后各看一眼即可对账。
参考库 = history.db / session.db;测试库 = history-test.db / session-test.db。</div></div>
<div class="card"><h2>操作</h2>
<div class="row">
<button id="bRun" onclick="doRun()">开始生成</button>
@@ -384,7 +400,21 @@ async function loadStats(){const s=await(await fetch("/api/stats")).json();
h+=kpi("询价附件",s.inquiry_files??0);h+=kpi("绑定",s.lme_attach??0);
h+=kpi("价格原件批次",s.price_attach_batches??0);
h+=kpi("工作台会话",s.s_sessions??0);
document.getElementById("kpis").innerHTML=h;}
document.getElementById("kpis").innerHTML=h;
renderAssets(s.totals);}
function renderAssets(t){
const el=document.getElementById("assets");
if(!t){el.innerHTML='<tr><td>暂无数据(数据目录未就绪)</td></tr>';return;}
const HH=[["batches","批次"],["bills","清单"],["norms","定额"],["norm_res","定额消耗"],
["lmes","工料机"],["lme_lib","价格库"],["prices","价格明细"],["attachments","附件"]];
const SS=[["sessions","会话"],["s_bills","清单"],["s_norms","定额"],["s_lmes","工料机"]];
const fmt=v=>v==null?"缺文件":(v<0?"-":v.toLocaleString());
let h='<tr><th>指标</th><th>参考库 history</th><th>测试库 history-test</th><th>参考库 session</th><th>测试库 session-test</th></tr>';
HH.forEach(([k,n])=>{h+='<tr><td>'+n+'</td><td>'+fmt((t.ref_h||{})[k])
+'</td><td>'+fmt((t.test_h||{})[k])+'</td><td>—</td><td>—</td></tr>';});
SS.forEach(([k,n])=>{h+='<tr><td>'+n+'</td><td>—</td><td>—</td><td>'+fmt((t.ref_s||{})[k])
+'</td><td>'+fmt((t.test_s||{})[k])+'</td></tr>';});
el.innerHTML=h;}
let last=0;
async function poll(){const r=await(await fetch("/api/log")).json();
if(r.lines.length!==last){const el=document.getElementById("log");