| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import assert from 'node:assert/strict'
- import { planPipeEnhancement } from '../../../src/modules/cockpit/domain/pipeEnhancement.js'
- import { planEnhancementDevices } from '../../../src/modules/cockpit/domain/enhancementDevices.js'
- import { fetchDeviceFacilityRelations, relationIndex } from '../../../src/modules/cockpit/services/deviceFacilityRelations.js'
- const pipe = { code: 'P', networkId: 'raw_P11920', industry: 'WATER_SUPPLY', positions: [[110, 28], [110.001, 28]] }
- const plan = planPipeEnhancement({ selected: { kind: 'pipe', code: 'P' }, visiblePipes: [pipe] })
- const device = { code: 'D-1', industry: 'WATER_SUPPLY', longitude: 110.0005, latitude: 28, coordinate: { renderable: true } }
- const hit = planEnhancementDevices(plan, [device], {
- facilityRelations: new Map([['D-1', { deviceCode: 'D-1', facilityCode: 'raw_P11920', facilityKind: 'PIPE', relationType: 'GAS_PIPE_POINT_DEVICE' }]]),
- })
- assert.equal(hit.devices[0].placement, 'linked')
- assert.equal(hit.devices[0].placementText, '真实设施关联 · 位置示意')
- assert.equal(hit.devices[0].relationType, 'GAS_PIPE_POINT_DEVICE')
- assert.equal(hit.devices[0].pipeCode, 'P')
- const miss = planEnhancementDevices(plan, [device], {
- facilityRelations: new Map([['D-1', { deviceCode: 'D-1', facilityCode: 'not-a-pipe', facilityKind: 'MANHOLE', relationType: 'MANHOLE_DEVICE' }]]),
- })
- assert.equal(miss.devices[0].placement, 'nearby', '设施编码对不上时必须降级为邻近示意')
- assert.equal(miss.devices[0].placementText, '邻近设备 · 示意安装')
- const empty = planEnhancementDevices(plan, [device], { facilityRelations: new Map() })
- assert.equal(empty.devices[0].placement, 'nearby')
- assert.equal(empty.devices[0].relationType, '')
- const section = await fetchDeviceFacilityRelations({
- config: { dataSource: 'real', api: { baseUrl: 'http://test.invalid/api/cockpit/v1' } },
- fetchImpl: async () => new Response(JSON.stringify({ code: 200, data: { relations: [
- { deviceCode: 'D-1', facilityCode: 'raw_P11920', facilityKind: 'PIPE', relationType: 'GAS_PIPE_POINT_DEVICE' },
- { deviceCode: null, facilityCode: 'raw_X', facilityKind: 'MANHOLE', relationType: 'MANHOLE_DEVICE' },
- { deviceCode: '', facilityCode: 'raw_Y', facilityKind: 'MANHOLE', relationType: 'MANHOLE_DEVICE' },
- { deviceCode: 'D-2', facilityCode: '', facilityKind: 'MANHOLE', relationType: 'MANHOLE_DEVICE' },
- ], statistics: { skippedManholeFacilityMissing: 4, deviceCodeUnresolved: 2 } } })),
- })
- assert.equal(section.state, 'success')
- const index = relationIndex(section)
- assert.equal(index.size, 1, '只有 deviceCode 与 facilityCode 都齐全的行可回联')
- assert.equal(index.get('D-1').facilityCode, 'raw_P11920')
- const failed = await fetchDeviceFacilityRelations({
- config: { dataSource: 'real', api: { baseUrl: 'http://test.invalid/api/cockpit/v1' } },
- fetchImpl: async () => new Response(JSON.stringify({ code: 500, msg: 'boom' })),
- })
- assert.equal(relationIndex(failed).size, 0)
- console.log('PASS 真实设施关联优先/设施编码不匹配降级/空索引降级/只回联齐全行/取数失败降级')
|