Procházet zdrojové kódy

feat(cockpit): 设施点图层纳入统一刷新,轮询只补详情

票 03:地图刷新此前不带设施点,管理端改了位置/状态后图上的点不动。

- 刷新计划新增「设施点」一项,文案点名它;该项有独立成败,
  失败只标自己,地图摘要与面板照常(新鲜度记账仍只看地图摘要)。
- 手动刷新重取全量:重新枚举运行信息 + 逐条补详情(重算图例)。
- 自动轮询只按已枚举设施补坐标/状态(不重拉运行信息与档案),
  避免 30 秒一次把全量台账拖一遍;全失败时保留点位并如实降级,不整层清空。
- 新增回归 t136:两种刷新来源的请求计数、逐项失败隔离、文案点名设施点。
ChenJZ před 4 hodinami
rodič
revize
cf7b212850

+ 4 - 1
src/modules/cockpit/CockpitShell.vue

@@ -1783,6 +1783,9 @@ refreshStore.configure({
         detailStore.syncMapSnapshotSection()
         return state
     },
+    // 票 03:设施点图层单独一项。手动刷新重取全量(枚举 + 详情),
+    // 轮询只补已枚举设施的坐标/状态(facilityMode=details),不重拉运行信息。
+    refreshFacilityLayer: async (plan, extra) => facilityPointStore.refresh({ mode: extra && extra.mode }),
     // 面板:取完当前模式的全部分区,回一个「panelId → 分区」查表函数供判据用
     // (判据在 domain/refreshRun.js,外壳不自己数哪块坏)。
     refreshPanels: async () => {
@@ -2257,7 +2260,7 @@ onMounted(() => {
                     // 避免同一轮记两次;取数成败在 refreshStore.lastRun 里如实留痕。
                     tick: () => (failForever
                         ? { ok: false, reason: '演示:取数持续失败' }
-                        : requestRefresh({ account: false })),
+                        : requestRefresh({ account: false, facilityMode: 'details' })),
                 })
             }
         }

+ 20 - 2
src/modules/cockpit/domain/refreshRun.js

@@ -21,6 +21,9 @@ import { SECTION_STATE } from './sectionState.js'
 /** 一次统一刷新覆盖的两类部件(`kind` 是判据分派键,`key` 是断言面)。 */
 export const REFRESH_PART = {
     MAP: 'map-summary',
+    // 票 03:设施点图层单独一项 —— 它有自己的取数路径(运行信息枚举 + 逐条详情),
+    // 失败时也只降级这一层,不牵连地图摘要与面板。
+    FACILITY_LAYER: 'facility-layer',
     PANEL: 'panel',
 }
 
@@ -50,6 +53,7 @@ export function planRefresh(mode) {
         panels,
         parts: [
             { key: REFRESH_PART.MAP, kind: 'map', label: '地图摘要' },
+            { key: REFRESH_PART.FACILITY_LAYER, kind: REFRESH_PART.FACILITY_LAYER, label: '设施点' },
             ...panels.map((panelId) => ({ key: panelId, kind: 'panel', label: labelForPanel(panelId) })),
         ],
     }
@@ -91,6 +95,19 @@ export function judgePanels(panelIds, sectionOf) {
     })
 }
 
+/**
+ * 设施点图层取数后的分区 → 这一项的成败(票 03)。
+ *
+ * 判据与面板同一条纪律:`success`/`empty`/`stale` 都算本轮取到(空≠失败、过期≠失败),
+ * 其余(failed/unavailable/缺失)如实算失败。缺状态对象时不当成功。
+ * @param {object|null} section 设施点分区
+ */
+export function judgeFacilityLayer(section) {
+    const state = (section && section.state) || ''
+    const ok = PANEL_OK_STATES.includes(state)
+    return { ok, state, reason: ok ? '' : ((section && section.reason) || 'unavailable') }
+}
+
 /** 逐项结果 → 整轮结论(`ok`/`reason` 是新鲜度记账口径,见文件抬头)。 */
 export function summarizeRefresh(run = {}) {
     const parts = Array.isArray(run.parts) ? run.parts : []
@@ -134,7 +151,8 @@ function labelOf(parts, key) {
 export function refreshText(state, context = {}) {
     const plan = context.plan || null
     const panelCount = plan && Array.isArray(plan.panels) ? plan.panels.length : 0
-    const scope = panelCount > 0 ? `地图摘要 + ${panelCount} 个面板` : '地图摘要'
+    // 票 03:设施点图层也是本轮覆盖的一处,文案要点名它。
+    const scope = panelCount > 0 ? `地图摘要 + 设施点 + ${panelCount} 个面板` : '地图摘要 + 设施点'
     const failedLabels = (context.failed || []).map((key) => labelOf(context.parts, key))
     if (state === REFRESH_STATE.RUNNING) return `统一刷新中:${scope}`
     if (state === REFRESH_STATE.OK) return `统一刷新完成:${scope}`
@@ -142,5 +160,5 @@ export function refreshText(state, context = {}) {
     if (state === REFRESH_STATE.FAILED) {
         return `统一刷新失败:${failedLabels.join('、') || '地图摘要'}未更新`
     }
-    return `刷新地图摘要与当前模式的面板`
+    return `刷新地图摘要、设施点与当前模式的面板`
 }

+ 31 - 1
src/modules/cockpit/services/facilityPointService.js

@@ -78,7 +78,7 @@ export async function fetchFacilityPoints(options = {}) {
             reason: operating.reason || '',
             mode: operating.mode || '',
             // `points: null` 是「图层没取到」的唯一形状(空数组=取到了、确实没有设施)。
-            data: { points: null, inventory: facilityInventory(archivesData, null), archivesAvailable: archivesData !== null, detailFailures: 0 },
+            data: { points: null, inventory: facilityInventory(archivesData, null), archivesAvailable: archivesData !== null, archivesData, detailFailures: 0 },
         })
     }
 
@@ -92,7 +92,37 @@ export async function fetchFacilityPoints(options = {}) {
             points,
             inventory: facilityInventory(archivesData, points),
             archivesAvailable: archivesData !== null,
+            // 票 03:档案分布留底 —— 轮询只补详情时据此重算图例,不再重取档案。
+            archivesData,
             detailFailures,
         },
     })
 }
+
+/**
+ * 只刷新**已枚举**设施的坐标/状态(票 03 的轮询路径)。
+ *
+ * 与 {@link fetchFacilityPoints} 的区别只在取数范围:不请求运行信息、不请求档案,
+ * 只按已有设施行的实体身份逐条补详情。这样 30 秒一次的轮询不会把全量台账拖一遍。
+ *
+ * @param {Array} points 当前设施点(`type` + `id` 已就绪;通常来自上一轮全量取数)
+ * @param {object} [options] `{ config, fetchImpl }`
+ * @returns {Promise<{points:Array, detailFailures:number, ok:boolean, reason:string}>}
+ *   全部详情都失败时 `ok:false`(图层如实降级,但仍保留已枚举的点位)。
+ */
+export async function refreshFacilityPointDetails(points, options = {}) {
+    const rows = Array.isArray(points) ? points : []
+    if (!rows.length) return { points: rows, detailFailures: 0, ok: true, reason: '' }
+    const requestOptions = { config: options.config, fetchImpl: options.fetchImpl }
+    const requests = facilityDetailRequests(rows)
+    const details = await loadFacilityDetails(requests, requestOptions)
+    const refreshed = facilityPointsWithDetails(rows, details)
+    const detailFailures = Object.values(details).filter((result) => !result.ok).length
+    const allFailed = requests.length > 0 && detailFailures === requests.length
+    return {
+        points: refreshed,
+        detailFailures,
+        ok: !allFailed,
+        reason: allFailed ? REQUEST_REASON.UNAVAILABLE : '',
+    }
+}

+ 46 - 4
src/modules/cockpit/stores/facilityPointStore.js

@@ -11,7 +11,7 @@ import { computed, ref } from 'vue'
 import { defineStore, acceptHMRUpdate } from 'pinia'
 import { SECTION_STATE, section } from '../domain/sectionState.js'
 import { facilityInventory, filterFacilityPoints } from '../domain/facilityPoints.js'
-import { fetchFacilityPoints } from '../services/facilityPointService.js'
+import { fetchFacilityPoints, refreshFacilityPointDetails } from '../services/facilityPointService.js'
 import { useFilterStore } from './filterStore.js'
 import { useEntityDetailStore } from './entityDetailStore.js'
 import { usePipeNetworkStore } from './pipeNetworkStore.js'
@@ -26,7 +26,7 @@ import { cancelPointLocate, locateFacilityPoint } from '../services/mapService.j
 function pending() {
     return {
         ...section(SECTION_STATE.EMPTY, {
-            data: { points: null, inventory: facilityInventory(null, null), archivesAvailable: false, detailFailures: 0 },
+            data: { points: null, inventory: facilityInventory(null, null), archivesAvailable: false, archivesData: null, detailFailures: 0 },
         }),
         loaded: false,
     }
@@ -127,14 +127,56 @@ export const useFacilityPointStore = defineStore('facilityPointStore', () => {
         } catch {
             // 适配层不抛;真抛了也要收成失败分区,不能让一次台账失败掀掉整个外壳。
             result = section(SECTION_STATE.FAILED, {
-                data: { points: null, inventory: facilityInventory(null, null), archivesAvailable: false, detailFailures: 0 },
+                data: { points: null, inventory: facilityInventory(null, null), archivesAvailable: false, archivesData: null, detailFailures: 0 },
             })
         }
         layer.value = { ...result, loaded: true }
         return layer.value
     }
 
-    return { layer, loaded, state, reason, points, inventory, filtered, selectedPoint, renderPoints, locate, select, clearLocate, load, configure, setLayer }
+    /**
+     * 统一刷新里的设施点那一项(票 03)。
+     *
+     * `mode='full'`  —— 手动刷新:重新枚举运行信息 + 逐条补详情(与 {@link load} 同一条路径);
+     * `mode='details'` —— 自动轮询:只对**已枚举**的设施补详情,不重拉全量运行信息与档案。
+     *
+     * 失败只降级本层:全量失败时 `points: null`(图例说未取到);轮询全失败时保留已枚举的点位
+     * (如实标 failed,界面仍能看见上一轮的位置,不整层清空)。
+     *
+     * @param {{mode?: 'full'|'details'}} [options]
+     * @returns {Promise<object>} 设施的 section(供 `judgeFacilityLayer` 判成败)
+     */
+    async function refresh(options = {}) {
+        const mode = options.mode === 'details' ? 'details' : 'full'
+        const current = layer.value && layer.value.data
+        const existing = current && Array.isArray(current.points) ? current.points : null
+        // 还没枚举过就没有「已枚举设施」可刷 —— 退回全量,否则图层会永远停在未取到。
+        if (mode === 'details' && !existing) return load()
+        if (mode === 'full') return load()
+
+        let result
+        try {
+            result = await refreshFacilityPointDetails(existing, requestOptions)
+        } catch {
+            result = { points: existing, detailFailures: existing.length, ok: false, reason: '' }
+        }
+        const state = result.ok ? SECTION_STATE.SUCCESS : SECTION_STATE.FAILED
+        const next = section(state, {
+            reason: result.reason || '',
+            data: {
+                // 失败时保留上一轮的点位(不整层清空),成功时用新坐标/状态替换。
+                points: result.points,
+                inventory: facilityInventory(current.archivesData || null, result.points),
+                archivesAvailable: current.archivesAvailable,
+                archivesData: current.archivesData || null,
+                detailFailures: result.detailFailures,
+            },
+        })
+        layer.value = { ...next, loaded: true }
+        return layer.value
+    }
+
+    return { layer, loaded, state, reason, points, inventory, filtered, selectedPoint, renderPoints, locate, select, clearLocate, load, refresh, configure, setLayer }
 })
 
 // 更新设施选择/定位 API 时必须同步已有 Pinia 实例,不能让新组件拿着旧 store 接口。

+ 24 - 7
src/modules/cockpit/stores/refreshStore.js

@@ -22,6 +22,7 @@ import { defineStore } from 'pinia'
 import {
     REFRESH_PART,
     REFRESH_STATE,
+    judgeFacilityLayer,
     judgeMapRefresh,
     judgePanels,
     planRefresh,
@@ -31,13 +32,13 @@ import {
 
 /** 取数接缝(外壳 configure 注入真实现;逻辑闸门注入假服务,不依赖网络)。 */
 function emptyDeps() {
-    return { refreshMap: null, refreshPanels: null, recordFreshness: null }
+    return { refreshMap: null, refreshFacilityLayer: null, refreshPanels: null, recordFreshness: null }
 }
 
 /** 接缝没接上时如实失败,而不是静默跳过(跳过会被读成"刷新成功")。 */
-function callDependency(fn, plan, missing) {
+function callDependency(fn, plan, missing, extra) {
     if (typeof fn !== 'function') throw new Error(missing)
-    return fn(plan)
+    return fn(plan, extra)
 }
 
 /** 单路取数隔离:任一路抛错都收成 `{ ok:false, reason }`,不影响另一路。 */
@@ -84,10 +85,11 @@ export const useRefreshStore = defineStore('refreshStore', () => {
 
     /**
      * 统一刷新:地图摘要 + 当前模式面板。
-     * @param {object} [options] `{ mode, account }`
+     * @param {object} [options] `{ mode, account, facilityMode }`
      *   `mode` 当前一级模式(计划据此取面板清单);
      *   `account` 是否记新鲜度(默认 true;轮询那条路传 false —— 本轮记账归
-     *   `freshnessService` 的周期,同一本账不重复记)
+     *   `freshnessService` 的周期,同一本账不重复记);
+     *   `facilityMode` 设施点刷新节奏 `full`(手动全量)/ `details`(轮询只补详情),默认 `full`。
      * @returns {Promise<object>} 本轮结论(`summarizeRefresh` 的结果)
      */
     function requestRefresh(options = {}) {
@@ -110,14 +112,21 @@ export const useRefreshStore = defineStore('refreshStore', () => {
     async function runOnce(current, options, mine) {
         let outcome = null
         try {
-            const [mapResult, panelResult] = await Promise.all([
+            const [mapResult, facilityResult, panelResult] = await Promise.all([
                 guard(() => callDependency(deps.refreshMap, current, '地图摘要取数未接入')),
+                guard(() => callDependency(deps.refreshFacilityLayer, current, '设施点图层取数未接入', {
+                    mode: options.facilityMode === 'details' ? 'details' : 'full',
+                })),
                 guard(() => callDependency(deps.refreshPanels, current, '面板取数未接入')),
             ])
             outcome = summarizeRefresh({
                 mode: current.mode,
                 plan: current,
-                parts: [mapPartOf(current, mapResult), ...panelPartsOf(current, panelResult)],
+                parts: [
+                    mapPartOf(current, mapResult),
+                    facilityPartOf(current, facilityResult),
+                    ...panelPartsOf(current, panelResult),
+                ],
             })
         } catch (error) {
             // 兜底:连计划/判据都炸了也要给出一轮"全失败"的结论(界面不能停在刷新中)。
@@ -150,6 +159,14 @@ export const useRefreshStore = defineStore('refreshStore', () => {
         return { ...base, ...judgeMapRefresh(result.value) }
     }
 
+    /** 设施点图层那一项的逐项结果(取数抛错时按抛错原因记失败)。 */
+    function facilityPartOf(current, result) {
+        const base = current.parts.find((part) => part.kind === REFRESH_PART.FACILITY_LAYER)
+            || { key: REFRESH_PART.FACILITY_LAYER, kind: REFRESH_PART.FACILITY_LAYER, label: '设施点' }
+        if (!result.ok) return { ...base, ok: false, reason: result.reason }
+        return { ...base, ...judgeFacilityLayer(result.value) }
+    }
+
     /**
      * 面板各项的逐项结果。
      *