修复控制台实时参数展示
补充检测柜核心字段和采集器电位编码的实时映射,未开始接收时不再展示设备历史快照,并增加前端参数契约测试。
| | |
| | | const source = batterySources.find(item => item.sourceType === 'CABINET_CHANNEL') || batterySources[0] |
| | | const cabinetSource = batterySources.find(item => item.sourceType === 'CABINET_CHANNEL') |
| | | const collectorSource = batterySources.find(item => item.sourceType === 'COLLECTOR') |
| | | const metric = (codes: string[], preferred = cabinetSource) => { |
| | | const item = (preferred?.latestSnapshot?.measurements || []).find(value => codes.includes(String(value.metricCode))) |
| | | return item && item.value !== undefined ? String(item.value) : undefined |
| | | const metric = (codes: string[], preferred = cabinetSource, snapshotField?: string) => { |
| | | const snapshot = preferred?.latestSnapshot |
| | | const item = (snapshot?.measurements || []).find(value => codes.includes(String(value.metricCode))) |
| | | if (item && item.value !== undefined && item.value !== null) return String(item.value) |
| | | const directValue = snapshotField ? snapshot?.[snapshotField] : undefined |
| | | return directValue !== undefined && directValue !== null ? String(directValue) : undefined |
| | | } |
| | | return { |
| | | no: batteryNo, |
| | | cabinet: binding?.cabinetName || binding?.cabinetCode || '-', |
| | | channel: binding?.displayNo ? `通道 ${binding.displayNo}` : '-', |
| | | voltage: metric(['VOLTAGE', 'voltage']) || '-', |
| | | voltage: metric(['VOLTAGE', 'voltage'], cabinetSource, 'voltageV') || '-', |
| | | temperature: metric(['TEMPERATURE', 'temperature', 'PRIMARY_TEMPERATURE'], collectorSource) || '-', |
| | | positive: metric(['POSITIVE_POTENTIAL', 'PRIMARY_POSITIVE_POTENTIAL'], collectorSource) || '-', |
| | | negative: metric(['NEGATIVE_POTENTIAL', 'PRIMARY_NEGATIVE_POTENTIAL'], collectorSource) || '-', |
| | | capacity: metric(['CAPACITY', 'capacity']) || '-', |
| | | current: metric(['CURRENT', 'current']) || '-', |
| | | positive: metric(['POSITIVE_POTENTIAL', 'PRIMARY_POSITIVE_POTENTIAL', 'positive_potential'], collectorSource) || '-', |
| | | negative: metric(['NEGATIVE_POTENTIAL', 'PRIMARY_NEGATIVE_POTENTIAL', 'negative_potential'], collectorSource) || '-', |
| | | capacity: metric(['CAPACITY', 'capacity'], cabinetSource, 'capacityAh') || '-', |
| | | current: metric(['CURRENT', 'current'], cabinetSource, 'currentA') || '-', |
| | | source: source?.latestSnapshot?.source || (source?.sourceType === 'COLLECTOR' ? '采集器' : '检测柜'), |
| | | unit: source?.latestSnapshot?.units?.join('/') || '-', |
| | | observedAt: source?.latestSnapshot?.observedAt, |
| New file |
| | |
| | | import assert from 'node:assert/strict' |
| | | import { readFile } from 'node:fs/promises' |
| | | |
| | | const view = await readFile(new URL('../src/views/TestConsole.vue', import.meta.url), 'utf8') |
| | | const liveService = await readFile(new URL('../../BatteryDetection/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TTestLiveServiceImpl.java', import.meta.url), 'utf8') |
| | | |
| | | assert.match(view, /metric\(\['VOLTAGE', 'voltage'\], cabinetSource, 'voltageV'\)/) |
| | | assert.match(view, /metric\(\['CURRENT', 'current'\], cabinetSource, 'currentA'\)/) |
| | | assert.match(view, /metric\(\['CAPACITY', 'capacity'\], cabinetSource, 'capacityAh'\)/) |
| | | assert.match(view, /'positive_potential'/) |
| | | assert.match(view, /'negative_potential'/) |
| | | assert.match(liveService, /value\.put\("voltageV", channel\.latestSnapshot\(\)\.voltageV\(\)\)/) |
| | | assert.match(liveService, /value\.put\("currentA", channel\.latestSnapshot\(\)\.currentA\(\)\)/) |
| | | assert.match(liveService, /value\.put\("capacityAh", channel\.latestSnapshot\(\)\.capacityAh\(\)\)/) |
| | | |
| | | console.log('实时参数字段映射契约通过') |