Pārlūkot izejas kodu

feat(cockpit): 设备状态统计收敛为唯一计数函数

票 133 前端一半。运行概况「报警设备」原用 /events/current 的报警流水反推设备状态,
与设备状态表口径(管理平台 16 台)对不上,也与同一面板的六态环各说各话。

- 新增 domain/deviceStatusStats.js:全站唯一的设备状态计数入口(纯函数)。
  标签可叠加(一台设备可同时进多个池)、在线/离线互斥、缺状态单列 UNKNOWN_STATE
- deviceStatusStore 改为只取 /monitoring/overview 的 devices[](含后端下发的 tags),
  不再请求 /monitoring/situation 与 /events/current,不再用报警流水二次推断(CONTEXT.md 明令禁止)
- 删除两处死代码:monitoringPanels.deviceStatusPools()(被 import 却从未调用)、store 内 records();
  DEVICE_POOL_KEYS 迁到新模块,环图行序不变
- 「独立设备」筛选改由地图快照对象类别单独判定,不再混进设备标签
- 新增 tests/deviceStatusStats.test.js(6 条全过);node 测试全量 13/14,
  detailStorePreload.test.js 失败与本票无关(detailStore 缺 DEMO_DEVICE_CODE 导出,既有问题)
ChenJZ 1 dienu atpakaļ
vecāks
revīzija
9ed01e4897

+ 69 - 0
src/modules/cockpit/domain/deviceStatusStats.js

@@ -0,0 +1,69 @@
+/**
+ * 设备状态统计池(票 133)——**全站唯一的设备状态计数入口**。
+ *
+ * 语义(CONTEXT.md「设备预警/报警统计」「图例入桶规则」两节):
+ *   · **报警 / 预警 / 工单处置是可叠加标签**:一台设备可以同时进多个池(它可能同时有
+ *     未结束工单和未解除预警);各池之和因此允许大于设备台数,这是规则本身,不是重复计数。
+ *   · **在线 / 离线是互斥的基础属性**:只按台账状态显式入桶,**不拿「总数减某一桶」倒推**
+ *     (那样任何没有状态的设备都会被算成在线,把「不知道」冒充成「在线」)。
+ *   · 台账没给状态、或给了认不出的值 → 单独计 `UNKNOWN_STATE`,既不并入在线也不并入离线。
+ *
+ * 输入是后端 `/monitoring/overview` 的 `devices[]`:
+ *   `{ code, name, status: 'ONLINE'|'OFFLINE'|..., tags: ['ALARM','WARNING','WORK_ORDER'] }`
+ * 其中 `tags` 由后端 `BusinessCockpitDeviceFactResolver` 统一给出(在线/报警取
+ * `equipment_status`、预警取「未解除预警」、工单取「未结束工单」)。**前端不再用报警流水
+ * 二次推断设备状态** —— CONTEXT.md 明令禁止,那正是本票要修掉的旧做法。
+ *
+ * 纯函数:不 import service、不碰 DOM、不发请求。
+ */
+
+/** 五个计数桶(顺序即图例/环图的展示序)。 */
+export const DEVICE_POOL_KEYS = ['ALARM', 'WARNING', 'WORK_ORDER', 'NORMAL', 'OFFLINE']
+
+/** 可叠加标签的取值域(与后端 `tags` 对齐)。 */
+const TAG_KEYS = ['ALARM', 'WARNING', 'WORK_ORDER']
+
+/** 台账在线状态 → 基础属性(只有在线/离线二值,其余如实为 `''`)。 */
+function baseOf(status) {
+    const state = String(status || '').toUpperCase()
+    if (state === 'ONLINE') return 'NORMAL'
+    if (state === 'OFFLINE') return 'OFFLINE'
+    return ''
+}
+
+/**
+ * 设备台账 → 计数池 + 逐设备标签事实。
+ *
+ * @param {Array<{code?:string, deviceCode?:string, name?:string, status?:string, tags?:string[]}>} devices
+ * @returns {{available:boolean, total:number|null, counts:object, devices:Array<{deviceCode:string, deviceName:string, base:string, tags:string[]}>}}
+ *   `available:false` 表示一份设备台账都没有(界面应如实降级,**不补 0**)。
+ */
+export function deviceStatusStats(devices) {
+    const list = Array.isArray(devices) ? devices : []
+    if (!list.length) return { available: false, total: null, counts: {}, devices: [] }
+
+    const counts = Object.fromEntries([...DEVICE_POOL_KEYS, 'UNKNOWN_STATE'].map((key) => [key, 0]))
+    const rows = []
+    for (const device of list) {
+        const code = String((device && (device.code || device.deviceCode)) || '').trim()
+        if (!code) continue
+        // 标签去重后只留可计数项:后端重复下发同一标签时不重复计数。
+        const tags = [...new Set((Array.isArray(device && device.tags) ? device.tags : [])
+            .map((tag) => String(tag || '').toUpperCase())
+            .filter((tag) => TAG_KEYS.includes(tag)))]
+        const base = baseOf(device && device.status)
+
+        rows.push({
+            deviceCode: code,
+            deviceName: (device && device.name) || code,
+            base,
+            tags,
+        })
+
+        for (const tag of tags) counts[tag] += 1
+        if (base === 'OFFLINE') counts.OFFLINE += 1
+        else if (base === 'NORMAL') counts.NORMAL += 1
+        else counts.UNKNOWN_STATE += 1
+    }
+    return { available: true, total: rows.length, counts, devices: rows }
+}

+ 3 - 45
src/modules/cockpit/domain/monitoringPanels.js

@@ -29,6 +29,7 @@ import { valueText } from './equipmentDetailView.js'
 import { industryLabel, normalizeDistrict, districtLabel, districtFilterLabel } from './filterOptions.js'
 import { legendLabelFor, legendVisuals, visualForStatus } from './pointStatus.js'
 import { abnormalCountRows } from './abnormalCounts.js'
+import { DEVICE_POOL_KEYS } from './deviceStatusStats.js'
 import {
     barsBlock,
     CARD_ACTION,
@@ -626,51 +627,8 @@ function deviceTypeLabel(rows, code) {
  * @param {object} section 分区
  * @param {object} [extra] `{ statusDistribution, selectedStatuses }`(外壳给的共用数据与当前选中)
  */
-/**
- * 设备状态池 → **全站共用**的计数(维护者 2026-11-04 补充裁定)。
- *
- * 工单、报警、预警**不是互斥状态**:只要该设备存在关联的报警、预警或未结束工单,就分别
- * 加入对应状态池;只有「正常」与「离线」是冲突态(一台设备只能是其中之一)。
- * 所以各池之和**可以大于设备总数**——这是规则本身,不是重复计数缺陷。
- *
- * 输入是同一批设备的**证据集合**,每条 `{ deviceCode, statuses, monitoringState }`:
- * statuses 来自各读模型已发布的设备状态(地图业务、监测分布业务、指标异常行),
- * monitoringState 来自监测概览台账(ONLINE/OFFLINE/...)。任一来源声明某状态即入该池,
- * 这正是「存在关联记录即可入池」的落地;没有任何来源时不臆造。
- *
- * 一份设备证据都没有时回 `available:false`,界面如实降级,**不补 0**。
- * @param {Array<{deviceCode:string, statuses?:string[], monitoringState?:string}>} records
- */
-export const DEVICE_POOL_KEYS = ['ALARM', 'WARNING', 'WORK_ORDER', 'NORMAL', 'OFFLINE']
-
-export function deviceStatusPools(records) {
-    const list = Array.isArray(records) ? records : []
-    const byCode = new Map()
-    for (const record of list) {
-        if (!record || !record.deviceCode) continue
-        const entry = byCode.get(record.deviceCode) || { statuses: new Set(), monitoringState: '' }
-        for (const status of record.statuses || []) {
-            if (status) entry.statuses.add(String(status).toUpperCase())
-        }
-        if (record.monitoringState) entry.monitoringState = String(record.monitoringState).toUpperCase()
-        byCode.set(record.deviceCode, entry)
-    }
-    if (!byCode.size) return { available: false, counts: {}, total: null }
-    const counts = Object.fromEntries(DEVICE_POOL_KEYS.map((key) => [key, 0]))
-    for (const entry of byCode.values()) {
-        const statuses = entry.statuses
-        // 冲突态只有「正常 / 离线」:先判离线,非离线且没有任何异常状态的设备才算正常。
-        const offline = entry.monitoringState === 'OFFLINE' || statuses.has('OFFLINE')
-        if (statuses.has('ALARM')) counts.ALARM += 1
-        if (statuses.has('WARNING')) counts.WARNING += 1
-        if (statuses.has('WORK_ORDER')) counts.WORK_ORDER += 1
-        if (offline) counts.OFFLINE += 1
-        else if (!statuses.has('ALARM') && !statuses.has('WARNING') && !statuses.has('WORK_ORDER') && !statuses.has('EXPIRED')) {
-            counts.NORMAL += 1
-        }
-    }
-    return { available: true, counts, total: byCode.size }
-}
+// 票 133:设备状态池的唯一实现搬到 `domain/deviceStatusStats.js`(唯一计数入口)。
+// 这里只 import `DEVICE_POOL_KEYS` 用于环图行序,不再保留第二份计数实现。
 
 export function abnormalPointCards(counts) {
     const source = counts && typeof counts === 'object' ? counts : {}

+ 35 - 140
src/modules/cockpit/stores/deviceStatusStore.js

@@ -1,152 +1,53 @@
 /**
- * 设备状态池的**全局**数据源(维护者 2026-11-04)。
+ * 设备状态池的**全局**数据源(维护者 2026-11-04;票 133 收敛为单一计数入口)。
  *
  * 为什么单独成 store:状态池是全站口径——顶部状态栏在四个一级模式里都常驻,不能挂在
- * 「运行监测」的面板分区上,否则不进那个模式就不刷新(这正是本次要修的缺陷)。
- * 因此本 store 自己持有两个全局读模型:监测概览台账(在线/离线)与运行概况异常清单
- * (逐设备异常状态),在任何一级模式下都能取到同一份证据。
+ * 「运行监测」的面板分区上,否则不进那个模式就不刷新(这正是当初要修的缺陷)。
  *
- * 语义(见 domain 的 deviceStatusPools):工单/报警/预警可同时存在,只有正常与离线互斥。
+ * **票 133 起它只做一件事**:取 `/monitoring/overview` 的逐设备台账(含后端给的
+ * `tags`:ALARM / WARNING / WORK_ORDER),交给 `domain/deviceStatusStats.deviceStatusStats()`
+ * 算计数。设备状态标签的唯一事实源是后端 `BusinessCockpitDeviceFactResolver`
+ * (在线/报警=equipment_status、预警=未解除预警、工单=未结束工单)。
+ *
+ * **不再请求 `/monitoring/situation` 与 `/events/current`,也不用报警流水二次推断设备状态**
+ * —— CONTEXT.md「设备预警/报警统计」明令禁止那套做法,它正是本票要修掉的旧实现。
+ *
+ * 语义见 `domain/deviceStatusStats.js`:标签可叠加、在线/离线互斥、缺状态单列未知。
  * 数据没到时 `pools.available:false`,界面如实降级,不补 0。
  */
 import { computed, ref } from 'vue'
 import { defineStore } from 'pinia'
-import { fetchMonitoringOverview, fetchMonitoringSituation } from '../services/monitoringApi.js'
-import { fetchCurrentEvents } from '../services/eventApi.js'
-import { EVENT_FAMILY } from '../domain/events.js'
-import { deviceStatusPools } from '../domain/monitoringPanels.js'
+import { fetchMonitoringOverview } from '../services/monitoringApi.js'
+import { deviceStatusStats } from '../domain/deviceStatusStats.js'
 import { useMapStore } from './mapStore.js'
 
 export const useDeviceStatusStore = defineStore('deviceStatusStore', () => {
-    /** 监测概览分区(逐设备 monitoringState) */
+    /** 监测概览分区(逐设备 monitoringState + 状态标签 tags) */
     const overview = ref(null)
-    /** 运行概况分区(逐设备异常状态) */
-    const situation = ref(null)
-    /** 当前预警/报警事件(用于「设备打了什么标签」:预警=有预警事件的设备,报警=有未处理报警的设备) */
-    const warnings = ref(null)
-    const alarms = ref(null)
     const loading = ref(false)
     const loaded = ref(false)
 
     /** 请求序号:换筛选时旧的在途响应作废。 */
     let token = 0
 
-    /**
-     * 三条读模型 → 设备证据。
-     * 地图那份由 mapStore 提供(它本来就在全模式加载),所以未关联设备的业务状态不必重取。
-     */
-    /** 从事件分区取出「涉及的设备编码」(去重)。事件行缺设备编码时不计数,不臆造。 */
-    function eventDeviceCodes(section) {
-        const rows = section && section.data && section.data.sections && section.data.sections.events
-            ? section.data.sections.events.data : null
-        const codes = new Set()
-        for (const row of rows || []) {
-            const code = row && (row.deviceCode || '')
-            if (code) codes.add(String(code).trim())
-        }
-        return codes
-    }
+    const pools = computed(() => {
+        const devices = overview.value && overview.value.data && overview.value.data.devices
+        return deviceStatusStats(devices)
+    })
 
     /**
-     * 设备标签口径(维护者 2026-11-05):
-     *   · 基础属性只有「正常 / 离线」二选一(按台账 monitoringState);
-     *   · 报警、预警、工单、独立设备是**可叠加标签**,一台设备可同时带上多个;
-     *   · 图例只数设备,不数监测点。
-     * 因此四类标签各自独立去重,互不排斥,也不与正常/离线互斥。
+     * 未关联设备(附加状态,不是业务标签):来自地图快照的对象类别桶。
+     * 它不是设备业务状态,所以不进 `counts`;只用于「独立设备」图例行的筛选。
      */
-    function records() {
+    const unassociatedCodes = computed(() => {
         const mapStore = useMapStore()
-        const list = []
-        const ledger = overview.value && overview.value.data && overview.value.data.devices
-        for (const device of ledger || []) {
-            list.push({ deviceCode: device && device.code, monitoringState: device && device.status })
-        }
-        for (const object of mapStore.summary.objects || []) {
-            if (object && object.kind === 'unassociated-equipment') {
-                list.push({ deviceCode: object.code, labels: ['UNASSOCIATED'] })
+        const set = new Set()
+        for (const object of (mapStore.summary && mapStore.summary.objects) || []) {
+            if (object && object.kind === 'unassociated-equipment' && object.code) {
+                set.add(String(object.code).trim())
             }
         }
-        return list
-    }
-
-    const pools = computed(() => {
-        const ledger = overview.value && overview.value.data && overview.value.data.devices
-        const devices = Array.isArray(ledger) ? ledger : []
-        if (!devices.length) return { available: false, counts: {}, total: null }
-        const mapStore = useMapStore()
-        const unassociated = new Set(
-            (mapStore.summary.objects || [])
-                .filter((object) => object && object.kind === 'unassociated-equipment' && object.code)
-                .map((object) => String(object.code).trim()),
-        )
-        const rowsOf = (section) => {
-            const events = section && section.data && section.data.sections && section.data.sections.events
-            return (events && events.data) || []
-        }
-        const workOrders = new Set()
-        for (const section of [warnings.value, alarms.value]) {
-            for (const row of rowsOf(section)) {
-                const brief = row && row.workOrder
-                const state = brief && typeof brief.stateCode === 'number' ? brief.stateCode : null
-                const open = state !== null && ((state >= 0 && state <= 4) || state === 6)
-                if (open && row.deviceCode) workOrders.add(String(row.deviceCode).trim())
-            }
-        }
-        // 台账里的设备编码集合:**状态池只数设备**(维护者 2026-11-04/05 口径)。
-        // 为什么要拿它做交集:现网事件表里存着**不是设备**的编码(实测 15/16/20、
-        // TEST-CBYL5432168 —— 设备档案接口逐个 404,它们是历史脏值或类型码),
-        // 若直接按事件行的 deviceCode 入池,预警池会多报 4 台「不存在的设备」(图例 7 台,
-        // 而地图最多只有 2 个坐标点)。设备池里只该有设备台账里存在的设备。
-        const ledgerCodes = new Set(devices.map((device) => String((device && device.code) || '').trim()).filter(Boolean))
-        const onlyDevices = (codes) => new Set([...codes].filter((code) => ledgerCodes.has(code)))
-        // 设备明细:基础属性(NORMAL/OFFLINE,互斥)+ 可叠加标签(ALARM/WARNING/WORK_ORDER/UNASSOCIATED)
-        const tagSets = {
-            ALARM: onlyDevices(eventDeviceCodes(alarms.value)),
-            WARNING: onlyDevices(eventDeviceCodes(warnings.value)),
-            WORK_ORDER: onlyDevices(workOrders),
-            UNASSOCIATED: onlyDevices(unassociated),
-        }
-        const byCode = new Map()
-        for (const device of devices) {
-            // 台账行是**领域字段**:code/name/status(适配层已从 deviceCode/monitoringState 改名)。
-            const code = String((device && device.code) || '').trim()
-            if (!code) continue
-            const state = String((device && device.status) || '').toUpperCase()
-            byCode.set(code, {
-                deviceCode: code,
-                deviceName: (device && device.name) || code,
-                // 只有正常与离线互斥;其余按标签判断
-                base: state === 'OFFLINE' ? 'OFFLINE' : state === 'ONLINE' ? 'NORMAL' : '',
-                tags: Object.keys(tagSets).filter((key) => tagSets[key].has(code)),
-            })
-        }
-        // 在线/离线按台账状态**显式入桶**,不用「总数-离线」倒推:那样任何没有状态
-        // (UNKNOWN/空)的设备都会被算成在线,把「不知道」冒充成「在线」。
-        let online = 0
-        let offline = 0
-        let unknownState = 0
-        for (const device of devices) {
-            const state = String((device && device.status) || '').toUpperCase()
-            if (state === 'ONLINE') online += 1
-            else if (state === 'OFFLINE') offline += 1
-            else unknownState += 1
-        }
-        return {
-            available: true,
-            total: devices.length,
-            devices: [...byCode.values()],
-            counts: {
-                // 六个池与 devices[] 的标签**同源同数**(都读 tagSets),不重复计算第二遍。
-                ALARM: tagSets.ALARM.size,
-                WARNING: tagSets.WARNING.size,
-                WORK_ORDER: tagSets.WORK_ORDER.size,
-                NORMAL: online,
-                OFFLINE: offline,
-                // 台账没给状态(或给了认不出的值)的台数:不并入在线,也不并入离线。
-                UNKNOWN_STATE: unknownState,
-                UNASSOCIATED: tagSets.UNASSOCIATED.size,
-            },
-        }
+        return set
     })
 
     async function refresh(options = {}) {
@@ -160,17 +61,9 @@ export const useDeviceStatusStore = defineStore('deviceStatusStore', () => {
                 config: options.config,
                 fetchImpl: options.fetchImpl,
             }
-            const [overviewSection, situationSection, warningSection, alarmSection] = await Promise.all([
-                fetchMonitoringOverview(query),
-                fetchMonitoringSituation(query),
-                fetchCurrentEvents({ mode: EVENT_FAMILY.WARNING, page: 1, pageSize: 1000, config: options.config, fetchImpl: options.fetchImpl }),
-                fetchCurrentEvents({ mode: EVENT_FAMILY.ALARM, page: 1, pageSize: 1000, config: options.config, fetchImpl: options.fetchImpl }),
-            ])
+            const overviewSection = await fetchMonitoringOverview(query)
             if (mine !== token) return pools.value
             overview.value = overviewSection
-            situation.value = situationSection
-            warnings.value = warningSection
-            alarms.value = alarmSection
             loaded.value = true
         } finally {
             if (mine === token) loading.value = false
@@ -182,7 +75,6 @@ export const useDeviceStatusStore = defineStore('deviceStatusStore', () => {
     function reset() {
         token += 1
         overview.value = null
-        situation.value = null
         loading.value = false
         loaded.value = false
     }
@@ -191,7 +83,7 @@ export const useDeviceStatusStore = defineStore('deviceStatusStore', () => {
      * 按选中的状态行筛选设备(与图例同一份台账/标签)。
      * 空集合=不筛;「无设备监测点」不参与设备筛选(它是点位特殊状态)。
      * @param {string[]} keys 选中的图例键
-     * @returns {Set<string>|null} 命中的设备编码集;null=不筛
+     * @returns {Set<string>|{codes:Set<string>, emptyPoints:boolean}|null} 命中的设备编码集;null=不筛
      */
     function filterDeviceCodes(keys) {
         const all = Array.isArray(keys) ? keys.filter(Boolean) : []
@@ -202,15 +94,18 @@ export const useDeviceStatusStore = defineStore('deviceStatusStore', () => {
         if (!selected.length) return { codes: new Set(), emptyPoints }
         const current = pools.value
         if (!current.available) return new Set()
+        const unassociated = unassociatedCodes.value
         const codes = new Set()
         for (const device of current.devices || []) {
-            const hit = selected.some((key) => (key === 'NORMAL' || key === 'OFFLINE')
-                ? device.base === key
-                : device.tags.includes(key))
+            const hit = selected.some((key) => {
+                if (key === 'NORMAL' || key === 'OFFLINE') return device.base === key
+                if (key === 'UNASSOCIATED') return unassociated.has(device.deviceCode)
+                return device.tags.includes(key)
+            })
             if (hit) codes.add(device.deviceCode)
         }
         return { codes, emptyPoints }
     }
 
-    return { overview, situation, pools, filterDeviceCodes, loading, loaded, refresh, reset }
+    return { overview, pools, filterDeviceCodes, loading, loaded, refresh, reset }
 })

+ 70 - 0
tests/deviceStatusStats.test.js

@@ -0,0 +1,70 @@
+/**
+ * 票 133:设备状态统计池的唯一计数入口。
+ *
+ * 钉住三条规则(CONTEXT.md「设备预警/报警统计」「图例入桶规则」):
+ *   1. 报警/预警/工单是**可叠加标签**,一台设备可同时进多个池,池之和可大于台数;
+ *   2. 在线/离线是**互斥**基础属性,只按台账状态入桶,不用「总数减离线」倒推;
+ *   3. 缺状态/认不出的状态单列 UNKNOWN_STATE,不并入在线。
+ */
+import assert from 'node:assert/strict'
+import { test } from 'node:test'
+
+import { deviceStatusStats, DEVICE_POOL_KEYS } from '../src/modules/cockpit/domain/deviceStatusStats.js'
+
+test('标签可叠加:一台设备可同时进报警/预警/工单三个池', () => {
+    const { available, total, counts } = deviceStatusStats([
+        { code: 'D1', name: '一号', status: 'ONLINE', tags: ['ALARM', 'WARNING', 'WORK_ORDER'] },
+        { code: 'D2', status: 'ONLINE', tags: ['ALARM'] },
+        { code: 'D3', status: 'OFFLINE', tags: ['WARNING'] },
+    ])
+    assert.equal(available, true)
+    assert.equal(total, 3)
+    assert.equal(counts.ALARM, 2)
+    assert.equal(counts.WARNING, 2)
+    assert.equal(counts.WORK_ORDER, 1)
+    // 在线/离线互斥,且与标签无关(离线设备照样可以带预警标签)
+    assert.equal(counts.NORMAL, 2)
+    assert.equal(counts.OFFLINE, 1)
+    assert.equal(counts.UNKNOWN_STATE, 0)
+    // 池之和允许大于台数 —— 这是规则本身,不是重复计数
+    assert.ok(counts.ALARM + counts.WARNING + counts.WORK_ORDER > total)
+})
+
+test('在线/离线只按台账状态入桶;缺状态与认不出的状态单列未知', () => {
+    const { counts } = deviceStatusStats([
+        { code: 'A', status: 'ONLINE', tags: [] },
+        { code: 'B', status: 'OFFLINE', tags: [] },
+        { code: 'C', status: '', tags: [] },
+        { code: 'D', tags: [] },
+        { code: 'E', status: 'STALE', tags: [] },
+    ])
+    assert.equal(counts.NORMAL, 1)
+    assert.equal(counts.OFFLINE, 1)
+    assert.equal(counts.UNKNOWN_STATE, 3, '缺状态不得并入在线')
+})
+
+test('标签大小写归一、重复只计一次、认不出的丢弃', () => {
+    const { counts } = deviceStatusStats([
+        { code: 'X', status: 'ONLINE', tags: ['alarm', 'ALARM', 'ALARM', 'UNASSOCIATED', 'nonsense'] },
+    ])
+    assert.equal(counts.ALARM, 1)
+    assert.equal(counts.WARNING, 0)
+    assert.equal(counts.WORK_ORDER, 0)
+    assert.equal(counts.NORMAL, 1)
+})
+
+test('空台账 → available:false,不补 0', () => {
+    assert.deepEqual(deviceStatusStats([]), { available: false, total: null, counts: {}, devices: [] })
+    assert.deepEqual(deviceStatusStats(null), { available: false, total: null, counts: {}, devices: [] })
+})
+
+test('逐设备事实供详情/筛选消费:deviceCode + base + tags', () => {
+    const { devices } = deviceStatusStats([
+        { code: 'D9', name: '九号', status: 'OFFLINE', tags: ['WARNING'] },
+    ])
+    assert.deepEqual(devices, [{ deviceCode: 'D9', deviceName: '九号', base: 'OFFLINE', tags: ['WARNING'] }])
+})
+
+test('计数桶顺序固定(环图与图例共用一份行序)', () => {
+    assert.deepEqual(DEVICE_POOL_KEYS, ['ALARM', 'WARNING', 'WORK_ORDER', 'NORMAL', 'OFFLINE'])
+})