feat(mileage): 外部三选筛选 + 车牌多选粘贴 + 运营区域 + xlsx 下载
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

- 外部行改为 批次型号 / 运营区域 / 车牌多选;按部门、按客户移入详情面板
- 车牌多选支持从 Excel 粘贴(换行/逗号/空格分隔),未匹配项显示警告
- 新增运营区域筛选:基于 136 批次区域映射(华东/华南/西南/西北)
- 新增 xlsx 数据下载,导出当前筛选结果(带表头样式与列宽)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
kkfluous
2026-04-29 15:19:00 +08:00
parent d1acdafa7e
commit 3809e785c1
11 changed files with 670 additions and 72 deletions

View File

@@ -1,8 +1,17 @@
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
import pool from '../../db.js';
import mileagePool from '../../mileage-db.js';
import { fetchVehicleInfoMap } from './vehicle-info.js';
import type { CachedVehicle, MonitoringCache, MonitoringFilters, PlatePrefix, VehicleInfoRow } from './types.js';
const __dirname = dirname(fileURLToPath(import.meta.url));
const regionMap: Record<string, string> = JSON.parse(
readFileSync(join(__dirname, 'region-map.json'), 'utf8')
);
const REGION_ORDER = ['华东区域', '华南区域', '西南区域', '西北区域', '华北区域', '华中区域', '东北区域'];
let monitoringCache: MonitoringCache | null = null;
export function getCache(): MonitoringCache | null {
@@ -38,7 +47,14 @@ function buildFilters(vehicles: CachedVehicle[], targetNames: string[]): Monitor
.map(([prefix, count]) => ({ prefix, count }))
.sort((a, b) => b.count - a.count);
return { departments, customers, plates, projects, entities, rentStatuses, platePrefixes, targetNames };
const regionSet = new Set(vehicles.map(v => v.region).filter((r): r is string => r !== null));
const regions = Array.from(regionSet).sort((a, b) => {
const ai = REGION_ORDER.indexOf(a);
const bi = REGION_ORDER.indexOf(b);
return (ai === -1 ? 99 : ai) - (bi === -1 ? 99 : bi);
});
return { departments, customers, plates, projects, entities, rentStatuses, platePrefixes, targetNames, regions };
}
interface MileageRow {
@@ -99,6 +115,7 @@ function mergeVehicles(
rentStatus: info?.rent_status || null,
entity: info?.entity || null,
project: info?.project || null,
region: regionMap[m.plate] || null,
yesterdayKm: yesterdayMap.get(m.plate) || 0,
};
});

View File

@@ -9,7 +9,7 @@ const app = new Hono();
const EMPTY_RESPONSE: MonitoringResponse = {
vehicles: [],
stats: { totalToday: 0, totalAll: 0, vehicleCount: 0, yesterdayTotal: 0 },
filters: { departments: [], customers: [], plates: [], projects: [], entities: [], rentStatuses: [], platePrefixes: [], targetNames: [] },
filters: { departments: [], customers: [], plates: [], projects: [], entities: [], rentStatuses: [], platePrefixes: [], targetNames: [], regions: [] },
total: 0,
page: 1,
totalPages: 1,
@@ -19,7 +19,7 @@ const EMPTY_RESPONSE: MonitoringResponse = {
function applyFilters(vehicles: CachedVehicle[], params: {
search: string; dept: string; customer: string; project: string;
entity: string; rentStatus: string; plate: string; platePrefix: string;
targetName: string; mileageMin: string; mileageMax: string;
targetName: string; region: string; mileageMin: string; mileageMax: string;
}): CachedVehicle[] {
let result = vehicles;
@@ -36,8 +36,12 @@ function applyFilters(vehicles: CachedVehicle[], params: {
if (params.project) result = result.filter(v => v.project === params.project);
if (params.entity) result = result.filter(v => v.entity === params.entity);
if (params.rentStatus) result = result.filter(v => v.rentStatus === params.rentStatus);
if (params.plate) result = result.filter(v => v.plate === params.plate);
if (params.plate) {
const wanted = new Set(params.plate.split(',').map(s => s.trim()).filter(Boolean));
if (wanted.size > 0) result = result.filter(v => wanted.has(v.plate));
}
if (params.platePrefix) result = result.filter(v => v.plate.startsWith(params.platePrefix));
if (params.region) result = result.filter(v => v.region === params.region);
if (params.targetName) {
const cache = getCache();
const tPlates = cache?.targetPlatesMap.get(params.targetName);
@@ -66,6 +70,7 @@ app.get('/', async (c) => {
plate: c.req.query('plate') || '',
platePrefix: c.req.query('platePrefix') || '',
targetName: c.req.query('targetName') || '',
region: c.req.query('region') || '',
mileageMin: c.req.query('mileageMin') || '',
mileageMax: c.req.query('mileageMax') || '',
};

View File

@@ -0,0 +1,138 @@
{
"粤AGP2009": "华南区域",
"粤AGP2011": "华南区域",
"粤AGP2017": "华南区域",
"粤AGP2032": "华南区域",
"粤AGP2035": "华东区域",
"粤AGP3027": "华东区域",
"粤AGP3029": "华南区域",
"粤AGP3071": "华南区域",
"粤AGP3078": "华东区域",
"粤AGP3079": "华东区域",
"粤AGP3082": "西南区域",
"粤AGP3087": "西南区域",
"粤AGP3097": "华南区域",
"粤AGP3486": "西北区域",
"粤AGP3502": "华南区域",
"粤AGP3503": "华东区域",
"粤AGP3505": "西南区域",
"粤AGP3506": "华东区域",
"粤AGP3509": "西南区域",
"粤AGP3513": "华东区域",
"粤AGP3515": "华东区域",
"粤AGP3605": "华东区域",
"粤AGP3607": "华东区域",
"粤AGP3609": "华东区域",
"粤AGP3612": "华东区域",
"粤AGP3615": "华南区域",
"粤AGP3617": "西北区域",
"粤AGP3625": "华东区域",
"粤AGP3627": "华东区域",
"粤AGP3631": "西南区域",
"粤AGP3642": "华南区域",
"粤AGP3645": "华南区域",
"粤AGP3649": "华东区域",
"粤AGP3651": "华东区域",
"粤AGP3659": "华东区域",
"粤AGP3660": "华南区域",
"粤AGP3667": "华南区域",
"粤AGP3672": "华南区域",
"粤AGP3673": "西南区域",
"粤AGP3690": "华东区域",
"粤AGP3692": "华东区域",
"粤AGP3695": "华东区域",
"粤AGP4223": "华南区域",
"粤AGP4318": "华东区域",
"粤AGP4321": "华东区域",
"粤AGP4325": "华南区域",
"粤AGP4335": "华东区域",
"粤AGP4355": "华东区域",
"粤AGP4377": "华东区域",
"粤AGP4386": "华东区域",
"粤AGP4396": "西南区域",
"粤AGP4422": "华南区域",
"粤AGP4435": "华南区域",
"粤AGP4451": "华南区域",
"粤AGP4482": "华南区域",
"粤AGP4486": "华南区域",
"粤AGP4489": "华东区域",
"粤AGP4502": "华南区域",
"粤AGP4522": "华东区域",
"粤AGP4538": "华南区域",
"粤AGP4548": "华东区域",
"粤AGP4566": "华南区域",
"粤AGP4569": "华南区域",
"粤AGP4583": "华东区域",
"粤AGP4586": "华东区域",
"粤AGP4587": "西南区域",
"粤AGP4596": "华南区域",
"粤AGP4597": "华东区域",
"粤AGP4599": "华东区域",
"粤AGP4623": "华东区域",
"粤AGP4629": "华南区域",
"粤AGP5165": "华东区域",
"粤AGP5167": "华东区域",
"粤AGP5169": "华南区域",
"粤AGP5301": "华东区域",
"粤AGP5350": "华南区域",
"粤AGP5351": "华东区域",
"粤AGP5357": "华东区域",
"粤AGP5363": "华南区域",
"粤AGP5379": "华东区域",
"粤AGP5613": "华南区域",
"粤AGP5615": "华东区域",
"粤AGP5617": "华东区域",
"粤AGP5621": "西南区域",
"粤AGP5622": "华东区域",
"粤AGP5623": "华南区域",
"粤AGP5642": "华东区域",
"粤AGP5643": "西北区域",
"粤AGP5646": "华东区域",
"粤AGP5651": "华东区域",
"粤AGP5661": "华东区域",
"粤AGP5681": "华南区域",
"粤AGP5691": "华东区域",
"粤AGP5710": "华东区域",
"粤AGP5711": "西北区域",
"粤AGP5712": "华东区域",
"粤AGP5719": "华南区域",
"粤AGP5749": "华东区域",
"粤AGP5760": "华东区域",
"粤AGP5763": "华东区域",
"粤AGP5769": "华东区域",
"粤AGP5770": "华东区域",
"粤AGP5791": "西北区域",
"粤AGP5792": "华南区域",
"粤AGP5797": "华东区域",
"粤AGP7016": "华南区域",
"粤AGP7019": "西南区域",
"粤AGP7022": "华南区域",
"粤AGP7026": "华东区域",
"粤AGP7047": "华东区域",
"粤AGP9330": "华南区域",
"粤AGP9346": "华东区域",
"粤AGP9347": "华南区域",
"粤AGP9350": "华东区域",
"粤AGP9351": "华南区域",
"粤AGP9702": "华东区域",
"粤AGP9703": "西北区域",
"粤AGP9706": "华东区域",
"粤AGP9707": "华东区域",
"粤AGP9713": "华东区域",
"粤AGP9717": "华南区域",
"粤AGP9721": "华东区域",
"粤AGP9726": "华南区域",
"粤AGP9731": "华南区域",
"粤AGP9735": "华东区域",
"粤AGP9739": "华南区域",
"粤AGP9751": "华南区域",
"粤AGP9753": "华东区域",
"粤AGP9755": "华东区域",
"粤AGP9759": "华东区域",
"粤AGP9782": "华东区域",
"粤AGP9790": "华南区域",
"粤AGP9791": "华东区域",
"粤AGP9817": "华南区域",
"粤AGP9827": "华南区域",
"粤AGP9836": "华南区域"
}

View File

@@ -14,6 +14,7 @@ export interface CachedVehicle {
rentStatus: string | null;
entity: string | null;
project: string | null;
region: string | null;
yesterdayKm: number;
}
@@ -33,6 +34,7 @@ export interface MonitoringFilters {
rentStatuses: string[];
platePrefixes: PlatePrefix[];
targetNames: string[];
regions: string[];
}
/** 监控缓存 */