|
@@ -1,13 +1,8 @@
|
|
|
/**
|
|
/**
|
|
|
- * 设施点取数(票 68):设施台账枚举 + 实体详情补坐标。
|
|
|
|
|
|
|
+ * 设施点取数(票 68 / 票 12):设施台账枚举 + `/infrastructure/geometry` 批量坐标。
|
|
|
*
|
|
*
|
|
|
- * 为什么是两跳(而不是一条几何端点):
|
|
|
|
|
- * · cockpit 没有「设施列表」端点,四类设施的实体标识只出现在
|
|
|
|
|
- * `/infrastructure/operating-information` 的指标行上(`facilityId` + `facilityKind`);
|
|
|
|
|
- * · 坐标只出现在 `/infrastructure/entities/{id}/detail?category=…` 的 `coordinates` 上。
|
|
|
|
|
- * 两条都是 `GET /api/cockpit/v1/**` 免鉴权只读端点,不碰业务 GIS 路径(ADR 0005)。
|
|
|
|
|
- * **契约缺口**(票 68 登记):实体详情不带几何图层那套 `coordinateValidation`,
|
|
|
|
|
- * 基础设施也还没进 `/infrastructure/geometry` —— 后端补齐后可去掉这层两跳拼装。
|
|
|
|
|
|
|
+ * 坐标优先从一次 `/infrastructure/geometry` 的 Point Feature 取;只有旧后端/批量未上线时
|
|
|
|
|
+ * 才回退逐设施实体详情。这样冷进入的请求数不随设施数增长;点击详情仍按需请求。
|
|
|
*
|
|
*
|
|
|
* 失败纪律沿用全舱:台账取不到 → 设施点图层整体 `failed`(图例如实「未取到」;
|
|
* 失败纪律沿用全舱:台账取不到 → 设施点图层整体 `failed`(图例如实「未取到」;
|
|
|
* 不是「这里没有设施」);单条详情取不到 → 该条进「无地图位置」(原因是详情未取到),
|
|
* 不是「这里没有设施」);单条详情取不到 → 该条进「无地图位置」(原因是详情未取到),
|
|
@@ -18,6 +13,7 @@ import { entityDetailPath } from './entityDetailApi.js'
|
|
|
import { SECTION_STATE, section, sectionStateFromReason } from '../domain/sectionState.js'
|
|
import { SECTION_STATE, section, sectionStateFromReason } from '../domain/sectionState.js'
|
|
|
import { REQUEST_REASON } from '../domain/requestReason.js'
|
|
import { REQUEST_REASON } from '../domain/requestReason.js'
|
|
|
import {
|
|
import {
|
|
|
|
|
+ facilityGeometryIndex,
|
|
|
facilityDetailRequests,
|
|
facilityDetailRequests,
|
|
|
facilityInventory,
|
|
facilityInventory,
|
|
|
facilityPointsWithDetails,
|
|
facilityPointsWithDetails,
|
|
@@ -26,6 +22,7 @@ import {
|
|
|
|
|
|
|
|
export const FACILITY_OPERATING_PATH = '/infrastructure/operating-information'
|
|
export const FACILITY_OPERATING_PATH = '/infrastructure/operating-information'
|
|
|
export const FACILITY_ARCHIVES_PATH = '/infrastructure/base-archives'
|
|
export const FACILITY_ARCHIVES_PATH = '/infrastructure/base-archives'
|
|
|
|
|
+export const FACILITY_GEOMETRY_PATH = '/infrastructure/geometry'
|
|
|
|
|
|
|
|
/** 详情并发上限:现网四类设施合计个位数,4 路并发足够,不把一次启动打成请求风暴。 */
|
|
/** 详情并发上限:现网四类设施合计个位数,4 路并发足够,不把一次启动打成请求风暴。 */
|
|
|
const DETAIL_CONCURRENCY = 4
|
|
const DETAIL_CONCURRENCY = 4
|
|
@@ -67,11 +64,14 @@ async function loadFacilityDetails(requests, options) {
|
|
|
*/
|
|
*/
|
|
|
export async function fetchFacilityPoints(options = {}) {
|
|
export async function fetchFacilityPoints(options = {}) {
|
|
|
const requestOptions = { config: options.config, fetchImpl: options.fetchImpl }
|
|
const requestOptions = { config: options.config, fetchImpl: options.fetchImpl }
|
|
|
- const [operating, archives] = await Promise.all([
|
|
|
|
|
|
|
+ const [operating, archives, geometry] = await Promise.all([
|
|
|
requestCockpitJson(FACILITY_OPERATING_PATH, requestOptions),
|
|
requestCockpitJson(FACILITY_OPERATING_PATH, requestOptions),
|
|
|
requestCockpitJson(FACILITY_ARCHIVES_PATH, requestOptions),
|
|
requestCockpitJson(FACILITY_ARCHIVES_PATH, requestOptions),
|
|
|
|
|
+ requestCockpitJson(FACILITY_GEOMETRY_PATH, requestOptions),
|
|
|
])
|
|
])
|
|
|
const archivesData = archives.ok && archives.data && typeof archives.data === 'object' ? archives.data : null
|
|
const archivesData = archives.ok && archives.data && typeof archives.data === 'object' ? archives.data : null
|
|
|
|
|
+ const geometryIndex = geometry.ok && geometry.data && typeof geometry.data === 'object'
|
|
|
|
|
+ ? facilityGeometryIndex(geometry.data) : {}
|
|
|
|
|
|
|
|
if (!operating.ok) {
|
|
if (!operating.ok) {
|
|
|
return section(sectionStateFromReason(operating.reason), {
|
|
return section(sectionStateFromReason(operating.reason), {
|
|
@@ -83,9 +83,12 @@ export async function fetchFacilityPoints(options = {}) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const rows = facilityRowsFromOperating(operating.data)
|
|
const rows = facilityRowsFromOperating(operating.data)
|
|
|
- const details = await loadFacilityDetails(facilityDetailRequests(rows), requestOptions)
|
|
|
|
|
- const points = facilityPointsWithDetails(rows, details)
|
|
|
|
|
- const detailFailures = Object.values(details).filter((result) => !result.ok).length
|
|
|
|
|
|
|
+ // 票 12:坐标来自一次 /infrastructure/geometry,不再逐设施请求 entity detail。
|
|
|
|
|
+ // 旧后端/批量未上线时才回退详情路径(保持旧契约可用;新后端不在正常路径发 N+1)。
|
|
|
|
|
+ const batchReady = geometry.ok && Object.keys(geometryIndex).length > 0
|
|
|
|
|
+ const details = batchReady ? {} : await loadFacilityDetails(facilityDetailRequests(rows), requestOptions)
|
|
|
|
|
+ const points = facilityPointsWithDetails(rows, details, batchReady ? geometryIndex : null)
|
|
|
|
|
+ const detailFailures = batchReady ? 0 : Object.values(details).filter((result) => !result.ok).length
|
|
|
return section(SECTION_STATE.SUCCESS, {
|
|
return section(SECTION_STATE.SUCCESS, {
|
|
|
mode: operating.mode || '',
|
|
mode: operating.mode || '',
|
|
|
data: {
|
|
data: {
|
|
@@ -114,15 +117,18 @@ export async function refreshFacilityPointDetails(points, options = {}) {
|
|
|
const rows = Array.isArray(points) ? points : []
|
|
const rows = Array.isArray(points) ? points : []
|
|
|
if (!rows.length) return { points: rows, detailFailures: 0, ok: true, reason: '' }
|
|
if (!rows.length) return { points: rows, detailFailures: 0, ok: true, reason: '' }
|
|
|
const requestOptions = { config: options.config, fetchImpl: options.fetchImpl }
|
|
const requestOptions = { config: options.config, fetchImpl: options.fetchImpl }
|
|
|
|
|
+ const geometry = await requestCockpitJson(FACILITY_GEOMETRY_PATH, requestOptions)
|
|
|
|
|
+ const geometryIndex = geometry.ok && geometry.data && typeof geometry.data === 'object'
|
|
|
|
|
+ ? facilityGeometryIndex(geometry.data) : {}
|
|
|
|
|
+ if (Object.keys(geometryIndex).length > 0) {
|
|
|
|
|
+ const refreshed = facilityPointsWithDetails(rows, {}, geometryIndex)
|
|
|
|
|
+ return { points: refreshed, detailFailures: 0, ok: true, reason: '' }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 旧后端/批量未上线回退;新后端正常路径不会走到这里。
|
|
|
const requests = facilityDetailRequests(rows)
|
|
const requests = facilityDetailRequests(rows)
|
|
|
const details = await loadFacilityDetails(requests, requestOptions)
|
|
const details = await loadFacilityDetails(requests, requestOptions)
|
|
|
const refreshed = facilityPointsWithDetails(rows, details)
|
|
const refreshed = facilityPointsWithDetails(rows, details)
|
|
|
const detailFailures = Object.values(details).filter((result) => !result.ok).length
|
|
const detailFailures = Object.values(details).filter((result) => !result.ok).length
|
|
|
const allFailed = requests.length > 0 && detailFailures === requests.length
|
|
const allFailed = requests.length > 0 && detailFailures === requests.length
|
|
|
- return {
|
|
|
|
|
- points: refreshed,
|
|
|
|
|
- detailFailures,
|
|
|
|
|
- ok: !allFailed,
|
|
|
|
|
- reason: allFailed ? REQUEST_REASON.UNAVAILABLE : '',
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return { points: refreshed, detailFailures, ok: !allFailed, reason: allFailed ? REQUEST_REASON.UNAVAILABLE : '' }
|
|
|
}
|
|
}
|