feat(energy): improve hydrogen drill workspace and verification cutoff

Co-authored-by: HiFox Agent <agents-noreply@hifox.com>
This commit is contained in:
kfluous
2026-09-05 18:04:33 +08:00
co-authored by HiFox Agent
parent a177781fe7
commit df259fc12b
8 changed files with 304 additions and 69 deletions
@@ -186,6 +186,7 @@ function resolveFilter(query: (key: string) => string | undefined): Filter {
if (verifyScope === "unverified")
clauses.push(
"LOWER(COALESCE(NULLIF(TRIM(b.verify_status), ''), 'unverified')) <> 'verified'",
"b.refuel_time >= '2026-05-01'",
);
return {
startDate: safeStart,
+23
View File
@@ -43,6 +43,25 @@ interface CacheCall {
force: boolean | undefined;
}
test("待核对的汇总和下钻统一从核对上线期初起统计,不影响其他核对范围", async () => {
for (const scope of ["unverified", "all", "verified"]) {
for (const endpoint of ["overview", "drill"]) {
const calls: QueryCall[] = [];
const app = new Hono();
registerHydrogenBiV2Routes(app, {
hydrogenPool: { query: createQueryMock([], calls) },
} as unknown as HydrogenBiV2Dependencies);
const response = await app.request(`/h2/v2/${endpoint}?year=2026&verifyScope=${scope}`);
assert.equal(response.status, 200);
const ledgerQueries = calls.filter(({ sql }) => sql.includes("FROM hydrogen_fuel_ledger b"));
assert.ok(ledgerQueries.length > 0);
for (const { sql } of ledgerQueries) {
assert.equal(sql.includes("b.refuel_time >= '2026-05-01'"), scope === "unverified");
}
}
}
});
function createQueryMock(resultSets: unknown[][], calls: QueryCall[]) {
return async (sql: string, params?: unknown) => {
calls.push({ sql, params });
@@ -116,6 +135,10 @@ test("氢能 BI v2 使用独立真实账本合同,并且不让前端拼接旧
assert.match(calls[0].sql, /FROM hydrogen_fuel_ledger/);
assert.match(calls[1].sql, /FROM new_hydrogen_site/);
assert.match(calls[1].sql, /EXISTS\s*\([\s\S]*amount_kg[\s\S]*> 0/);
// 所有真实下钻共用此站点选项池:历史加氢量为正,而非仅当前区间活跃。
assert.match(calls[1].sql, /b\.station_id = s\.id/);
assert.match(calls[1].sql, /external_recharge_manual/);
assert.doesNotMatch(calls[1].sql, /refuel_time\s*[<>]/);
});
test("氢能 BI v2 下钻在日期、站点、客户、车辆及区域上下文中复用同一过滤口径", async () => {