refactor(stage1): 删除已证实无引用的死代码

按 import 图可达性分析(从 main.tsx / server index+local / vite.config 出发)
删除 0 引用的文件,删除后可达性分析 UNREACHABLE 归零。

- 删旧氢能实现:PrototypeBoard / HydrogenBiV2App / prototype-adapter /
  prototype-source 全部 / HydrogenView+Overview+Daily+Settlement+BoardChrome+
  StationBoard / hydrogen-overview / hydrogen-daily
- 删死 CSS 4 个(约 12k 行)、删死 vendor 残留(自挂载 index.tsx、AccessGate、SdDatePicker)
- 删 server/mileage-db.ts(含硬编码凭据的死模块)
- DailyRangeControls:移除从未被传入的 vehicleScope/onVehicleScopeChange 死分支
- tsconfig:移除指向已删除/不存在路径的 exclude

测试 146 -> 131(删掉的 3 个测试文件覆盖的是被删的死代码)。
lint / test / build 全绿。
This commit is contained in:
dsh-agent
2026-09-11 10:11:33 +08:00
parent 89dca5c5a4
commit 3daa9808ce
51 changed files with 18 additions and 34286 deletions
@@ -1,160 +0,0 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import type { HydrogenDailyRow } from '../types.js';
import {
buildHydrogenDailyTrend,
getQuickRange,
filterHydrogenRowsByStation,
getHydrogenDailyStations,
getRangeModeLabel,
mergeHydrogenDailyRows,
normalizeRange,
summarizeHydrogenRows,
} from './model.js';
test('快捷日期继续使用本地自然日并覆盖本周、本月和近15天', () => {
const now = new Date(2026, 7, 12, 23, 30);
assert.deepEqual(getQuickRange('thisWeek', now), {
start: '2026-08-10',
end: '2026-08-12',
});
assert.deepEqual(getQuickRange('thisMonth', now), {
start: '2026-08-01',
end: '2026-08-12',
});
assert.deepEqual(getQuickRange('last15', now), {
start: '2026-07-29',
end: '2026-08-12',
});
});
test('全部车辆由两类真实日报按日期和站点合并', () => {
const lingniu: HydrogenDailyRow[] = [{
date: '2026-08-11', totalKg: 100, totalFee: 2_400, chainPct: 0, customerType: 'lingniu',
stations: [{ id: 1, name: 'A站', kg: 100, fee: 2_400, pricePerKg: 24, chainPct: 0 }],
}];
const external: HydrogenDailyRow[] = [{
date: '2026-08-11', totalKg: 50, totalFee: 1_000, chainPct: 0, customerType: 'external',
stations: [{ id: 1, name: 'A站', kg: 50, fee: 1_000, pricePerKg: 20, chainPct: 0 }],
}];
const merged = mergeHydrogenDailyRows(lingniu, external)!;
assert.equal(merged[0].totalKg, 150);
assert.equal(merged[0].totalFee, 3_400);
assert.equal(merged[0].stations[0].pricePerKg, 22.67);
assert.deepEqual(buildHydrogenDailyTrend(lingniu, external, 'all', null), [{
date: '2026-08-11', totalKg: 150, lingniuKg: 100, externalKg: 50,
}]);
});
test('趋势数据同时遵守车辆归属和单站筛选', () => {
const lingniu: HydrogenDailyRow[] = [{
date: '2026-08-11', totalKg: 130, totalFee: 3_000, chainPct: 0, customerType: 'lingniu',
stations: [
{ id: 1, name: 'A站', kg: 80, fee: 1_920, pricePerKg: 24, chainPct: 0 },
{ id: 2, name: 'B站', kg: 50, fee: 1_080, pricePerKg: 21.6, chainPct: 0 },
],
}];
const external: HydrogenDailyRow[] = [{
date: '2026-08-11', totalKg: 20, totalFee: 400, chainPct: 0, customerType: 'external',
stations: [{ id: 1, name: 'A站', kg: 20, fee: 400, pricePerKg: 20, chainPct: 0 }],
}];
assert.deepEqual(buildHydrogenDailyTrend(lingniu, external, 'lingniu', 1), [{
date: '2026-08-11', totalKg: 80, lingniuKg: 80, externalKg: 0,
}]);
});
test('自定义日期倒置时仅交换查询边界', () => {
assert.deepEqual(normalizeRange('2026-08-12', '2026-08-01'), {
start: '2026-08-01',
end: '2026-08-12',
});
assert.equal(getRangeModeLabel('custom'), '自定义区间');
assert.equal(getRangeModeLabel('last15'), '近 15 天');
});
test('每日加氢统计保持排序、有效天、站点去重和峰谷口径', () => {
const rows: HydrogenDailyRow[] = [
{
date: '2026-08-12',
totalKg: 0,
totalFee: 0,
chainPct: -1,
customerType: 'lingniu',
stations: [{ id: 1, name: 'A站', kg: 0, fee: 0, pricePerKg: 0, chainPct: -1 }],
},
{
date: '2026-08-10',
totalKg: 100,
totalFee: 2_000,
chainPct: 0,
customerType: 'lingniu',
stations: [{ id: 1, name: 'A站', kg: 100, fee: 2_000, pricePerKg: 20, chainPct: 0 }],
},
{
date: '2026-08-11',
totalKg: 300,
totalFee: 7_500,
chainPct: 2,
customerType: 'lingniu',
stations: [{ id: 2, name: 'B站', kg: 300, fee: 7_500, pricePerKg: 25, chainPct: 2 }],
},
];
const summary = summarizeHydrogenRows(rows);
assert.deepEqual(rows.map(row => row.date), ['2026-08-12', '2026-08-10', '2026-08-11']);
assert.deepEqual(summary.trendData.map(row => row.date), ['2026-08-10', '2026-08-11', '2026-08-12']);
assert.equal(summary.totalKg, 400);
assert.equal(summary.totalFee, 9_500);
assert.equal(summary.activeDays, 2);
assert.equal(summary.avgKg, 200);
assert.equal(summary.avgPrice, 23.75);
assert.equal(summary.stationCount, 2);
assert.equal(summary.peakDay?.date, '2026-08-11');
assert.equal(summary.lowDay?.date, '2026-08-10');
assert.equal(summary.zeroDays, 1);
});
test('空数据保持零值且没有峰谷日', () => {
assert.deepEqual(summarizeHydrogenRows(null), {
trendData: [],
totalKg: 0,
totalFee: 0,
activeDays: 0,
stationCount: 0,
avgKg: 0,
avgPrice: 0,
peakDay: null,
lowDay: null,
zeroDays: 0,
});
});
test('站点筛选按站点 ID 重算日报总量、费用和环比', () => {
const rows: HydrogenDailyRow[] = [
{
date: '2026-08-11', totalKg: 150, totalFee: 3_400, chainPct: 0, customerType: 'lingniu',
stations: [
{ id: 1, name: 'A站', kg: 100, fee: 2_400, pricePerKg: 24, chainPct: 0 },
{ id: 2, name: 'B站', kg: 50, fee: 1_000, pricePerKg: 20, chainPct: 0 },
],
},
{
date: '2026-08-10', totalKg: 80, totalFee: 1_760, chainPct: 0, customerType: 'lingniu',
stations: [{ id: 1, name: 'A站', kg: 80, fee: 1_760, pricePerKg: 22, chainPct: 0 }],
},
];
assert.deepEqual(getHydrogenDailyStations(rows), [
{ id: 1, name: 'A站', totalKg: 180, totalFee: 4_160 },
{ id: 2, name: 'B站', totalKg: 50, totalFee: 1_000 },
]);
const filtered = filterHydrogenRowsByStation(rows, 1)!;
assert.deepEqual(filtered.map(row => ({ date: row.date, kg: row.totalKg, fee: row.totalFee, chain: row.chainPct })), [
{ date: '2026-08-11', kg: 100, fee: 2_400, chain: 0.25 },
{ date: '2026-08-10', kg: 80, fee: 1_760, chain: 0 },
]);
assert.equal(summarizeHydrogenRows(filtered).totalFee, 4_160);
});