from pathlib import Path root = Path('.scratch/cockpit-real-data-wayfinding/t28-patch/work/pipe-network-service/zksy-admin/src/test/java/com/zksy/web/controller/cockpit') p = root / 'CockpitMonitoringDistributionControllerTest.java' s = p.read_text(encoding='utf-8') changes = [ ('jsonPath("$.data.pagination.total").value(8)', 'jsonPath("$.data.pagination.total").value(9)', 3), ('jsonPath("$.data.unassociatedEquipment", hasSize(3))', 'jsonPath("$.data.unassociatedEquipment", hasSize(4))', 2), ('jsonPath("$.data.pointStatusDistribution[3].count").value(1)', 'jsonPath("$.data.pointStatusDistribution[3].count").value(2)', 2), ('.deviceCount").value(4)', '.deviceCount").value(5)', 3), ('jsonPath("$.data.mapFilter.deviceCodes", hasSize(8))', 'jsonPath("$.data.mapFilter.deviceCodes", hasSize(9))', 1), ('jsonPath("$.data.excluded.invalidCoordinateCount").value(1)', 'jsonPath("$.data.excluded.invalidCoordinateCount").value(0)', 1), ('get(ENDPOINT).param("industry", "GAS"))\n .andExpect(status().isOk())\n .andExpect(jsonPath("$.data.pagination.total").value(3))', 'get(ENDPOINT).param("industry", "GAS"))\n .andExpect(status().isOk())\n .andExpect(jsonPath("$.data.pagination.total").value(4))', 1), ('jsonPath("$.data.unassociatedEquipment", hasSize(1))', 'jsonPath("$.data.unassociatedEquipment", hasSize(2))', 1), ('get(ENDPOINT).param("deviceType", "GAS_SENSOR"))\n .andExpect(status().isOk())\n .andExpect(jsonPath("$.data.pagination.total").value(3))', 'get(ENDPOINT).param("deviceType", "GAS_SENSOR"))\n .andExpect(status().isOk())\n .andExpect(jsonPath("$.data.pagination.total").value(4))', 1), ('assertEquals(1, statusCount(initial, CockpitMonitoringPointStatus.NORMAL));', 'assertEquals(2, statusCount(initial, CockpitMonitoringPointStatus.NORMAL));', 1), ('assertEquals(2, statusCount(applied, CockpitMonitoringPointStatus.NORMAL));', 'assertEquals(3, statusCount(applied, CockpitMonitoringPointStatus.NORMAL));', 1), ('assertEquals(2, statusCount(ignoredOld, CockpitMonitoringPointStatus.NORMAL));', 'assertEquals(3, statusCount(ignoredOld, CockpitMonitoringPointStatus.NORMAL));', 1), ('assertEquals(2, statusCount(ignoredUnknown, CockpitMonitoringPointStatus.NORMAL));', 'assertEquals(3, statusCount(ignoredUnknown, CockpitMonitoringPointStatus.NORMAL));', 1), ] for old, new, count in changes: assert s.count(old) == count, (old, s.count(old), count) s = s.replace(old, new) anchor = ' private int statusCount(CockpitMonitoringDistributionResponse response,' assert s.count(anchor) == 1 s = s.replace(anchor, ''' @Test void sixEmptyUntypedPointsRemainInLedgerAndStatusTotalsWithoutVerifiedCoordinates() throws Exception { List points = new java.util.ArrayList<>(); for (String code : Arrays.asList("GS001", "GS002", "PS001", "PS002", "RQ001", "RQ002")) { points.add(new CockpitMonitoringDistributionSnapshot.SourceMonitoringPoint( code, code, null, null, new BigDecimal("110.399876"), new BigDecimal("28.458287"), false, Collections.emptyList())); } CockpitMonitoringDistributionSnapshot snapshot = new CockpitMonitoringDistributionSnapshot( SNAPSHOT_AT, SNAPSHOT_AT, Collections.emptyList(), points, Collections.emptyList()); when(adapter.load(null)).thenReturn(snapshot); when(adapter.load(SNAPSHOT_AT)).thenReturn(snapshot); mockMvc.perform(get(ENDPOINT).param("pointStatus", "EMPTY").param("pageSize", "2")) .andExpect(status().isOk()) .andExpect(jsonPath("$.data.pagination.total").value(6)) .andExpect(jsonPath("$.data.pagination.totalPages").value(3)) .andExpect(jsonPath("$.data.pagination.hasMore").value(true)) .andExpect(jsonPath("$.data.monitoringPoints", hasSize(2))) .andExpect(jsonPath("$.data.monitoringPoints[0].pointCode").value("GS001")) .andExpect(jsonPath("$.data.monitoringPoints[0].pointStatus").value("EMPTY")) .andExpect(jsonPath("$.data.monitoringPoints[0].industry").value(nullValue())) .andExpect(jsonPath("$.data.monitoringPoints[0].deviceType.code").value(nullValue())) .andExpect(jsonPath("$.data.monitoringPoints[0].coordinateValidation.renderable").value(false)) .andExpect(jsonPath("$.data.pointStatusDistribution[5].count").value(6)) .andExpect(jsonPath("$.data.districtDistribution[0].districtName").value("未分区")) .andExpect(jsonPath("$.data.districtDistribution[0].pointCount").value(6)) .andExpect(jsonPath("$.data.industryDistribution[0].industry").value(nullValue())) .andExpect(jsonPath("$.data.industryDistribution[0].pointCount").value(6)) .andExpect(jsonPath("$.data.deviceTypeDistribution[0].deviceType.code").value(nullValue())) .andExpect(jsonPath("$.data.mapFilter.pointCodes", hasSize(6))) .andExpect(jsonPath("$.data.mapFilter.deviceCodes", hasSize(0))) .andExpect(jsonPath("$.data.excluded.unknownTypeCount").value(0)) .andExpect(jsonPath("$.data.excluded.invalidCoordinateCount").value(0)) .andExpect(jsonPath("$.data.freshness.status").value("CURRENT")) .andExpect(jsonPath("$.data.freshness.reason").value("READY")); mockMvc.perform(get(ENDPOINT).param("page", "3").param("pageSize", "2").param("snapshotAt", SNAPSHOT_AT)) .andExpect(status().isOk()) .andExpect(jsonPath("$.data.pagination.total").value(6)) .andExpect(jsonPath("$.data.pagination.hasMore").value(false)) .andExpect(jsonPath("$.data.monitoringPoints[0].pointCode").value("RQ001")); mockMvc.perform(get(ENDPOINT).param("district", "UNASSIGNED")) .andExpect(status().isOk()).andExpect(jsonPath("$.data.pagination.total").value(6)); for (String[] filter : Arrays.asList(new String[]{"industry", "GAS"}, new String[]{"deviceType", "GAS_SENSOR"}, new String[]{"district", "0"}, new String[]{"pointStatus", "NORMAL"})) { mockMvc.perform(get(ENDPOINT).param(filter[0], filter[1])) .andExpect(status().isOk()).andExpect(jsonPath("$.data.pagination.total").value(0)); } } @Test void coordinatesDoNotAffectStatisticsAndAssociatedDevicesNeverBecomeStandaloneMarkers() { CockpitMonitoringPointDeviceSnapshot bound = device( "BOUND", "关联设备", true, true, false, false, Collections.emptyList()); CockpitMonitoringDistributionSnapshot snapshot = new CockpitMonitoringDistributionSnapshot( SNAPSHOT_AT, SNAPSHOT_AT, fixture().getTypes(), Collections.singletonList(new CockpitMonitoringDistributionSnapshot.SourceMonitoringPoint( "P", "点位", 0, "GAS_SENSOR", null, null, false, Collections.singletonList(bound))), Arrays.asList(smartDevice("BOUND", "关联设备", 1, "GAS_SENSOR", "110.4", "28.4", false, true, true, false, false, Collections.emptyList()), smartDevice("FREE", "独立设备", 1, "GAS_SENSOR", "181", "28.4", true, true, false, false, false, Collections.emptyList()))); when(adapter.load(null)).thenReturn(snapshot); CockpitMonitoringDistributionResponse all = service.load("all", null, null, null, null, 1, 100, null); assertEquals(2, all.getPagination().getTotal()); assertEquals(1, all.getUnassociatedEquipment().size()); assertEquals("FREE", all.getUnassociatedEquipment().get(0).getDeviceCode()); assertTrue(!all.getMonitoringPoints().get(0).getCoordinateValidation().isRenderable()); assertTrue(!all.getUnassociatedEquipment().get(0).getCoordinateValidation().isRenderable()); assertEquals(0, all.getExcluded().getInvalidCoordinateCount()); assertEquals("READY", all.getFreshness().getReason()); assertEquals(1, statusCount(all, CockpitMonitoringPointStatus.ALARM)); assertEquals(1, statusCount(all, CockpitMonitoringPointStatus.NORMAL)); CockpitMonitoringDistributionResponse normal = service.load("normal", null, null, "NORMAL", null, 1, 100, null); assertEquals(Collections.singletonList("FREE"), normal.getMapFilter().getDeviceCodes()); assertTrue(normal.getMapFilter().getPointCodes().isEmpty()); CockpitMonitoringDistributionResponse district = service.load("district", null, null, null, "1", 1, 100, null); assertEquals(1, district.getPagination().getTotal(), "被筛掉的点位不能让关联设备变成独立设备"); assertEquals(Collections.singletonList("FREE"), district.getMapFilter().getDeviceCodes()); } @Test void exclusionsCountEachRejectedObjectOnceRegardlessOfAssociatedDeviceCount() { CockpitMonitoringPointDeviceSnapshot d = device("D", "设备", true, false, false, false, Collections.emptyList()); CockpitMonitoringDistributionSnapshot snapshot = new CockpitMonitoringDistributionSnapshot( SNAPSHOT_AT, SNAPSHOT_AT, fixture().getTypes(), Arrays.asList( point("EMPTY", "合法空点", null, null, "110.4", "28.4"), point("UNKNOWN", "未知类型", 0, "LEGACY", "110.4", "28.4", d, d, d), point("MISMATCH", "错种类", 0, "WATER_PLANT", "110.4", "28.4", d, d), point("NONFORMAL", "无行业", 0, "SMART_MANHOLE", "110.4", "28.4", d)), Arrays.asList( smartDevice("U", "未知", 0, "LEGACY", "110.4", "28.4", true, true, false, false, false, Collections.emptyList()), smartDevice("M", "错种类", 0, "WATER_PLANT", "110.4", "28.4", true, true, false, false, false, Collections.emptyList()), smartDevice("N", "无行业", 0, "SMART_MANHOLE", "110.4", "28.4", true, true, false, false, false, Collections.emptyList()))); when(adapter.load(null)).thenReturn(snapshot); CockpitMonitoringDistributionResponse response = service.load("reconcile", null, null, null, null, 1, 100, null); assertEquals(1, response.getPagination().getTotal()); assertEquals(1, statusCount(response, CockpitMonitoringPointStatus.EMPTY)); assertEquals(2, response.getExcluded().getUnknownTypeCount()); assertEquals(2, response.getExcluded().getTypeKindMismatchCount()); assertEquals(2, response.getExcluded().getNonFormalIndustryCount()); int excluded = response.getExcluded().getUnknownTypeCount() + response.getExcluded().getTypeKindMismatchCount() + response.getExcluded().getNonFormalIndustryCount() + response.getExcluded().getInvalidCoordinateCount(); assertEquals(7, response.getPagination().getTotal() + excluded); } ''' + anchor) p.write_text(s, encoding='utf-8', newline='\n') p = root / 'CockpitMonitoringOverviewControllerTest.java' s = p.read_text(encoding='utf-8') anchor = ' private static CockpitMonitoringOverviewSnapshot fixture() {' assert s.count(anchor) == 1 s = s.replace(anchor, ''' @Test void sixEmptyUntypedPointsAreCountedAndEchoedWithoutFabricatingDevicesOrIndustry() throws Exception { List points = new ArrayList<>(); for (String code : Arrays.asList("GS001", "GS002", "PS001", "PS002", "RQ001", "RQ002")) { points.add(new CockpitMonitoringOverviewSnapshot.SourceMonitoringPoint(code, null, 0)); } when(adapter.load()).thenReturn(new CockpitMonitoringOverviewSnapshot( "2026-09-02T09:59:50+08:00", Collections.emptyList(), Collections.emptyList(), points)); mockMvc.perform(get(ENDPOINT)) .andExpect(status().isOk()) .andExpect(jsonPath("$.data.counts.monitoringPointCount").value(6)) .andExpect(jsonPath("$.data.counts.equipmentCount").value(0)) .andExpect(jsonPath("$.data.mapFilter.pointCodes", hasSize(6))) .andExpect(jsonPath("$.data.mapFilter.deviceCodes", hasSize(0))) .andExpect(jsonPath("$.data.status.denominator").value(0)) .andExpect(jsonPath("$.data.onlineRate.state").value("EMPTY")) .andExpect(jsonPath("$.data.freshness.status").value("CURRENT")) .andExpect(jsonPath("$.data.freshness.reason").value("READY")); for (String[] filter : Arrays.asList(new String[]{"industry", "GAS"}, new String[]{"deviceType", "GAS_SENSOR"})) { mockMvc.perform(get(ENDPOINT).param(filter[0], filter[1])) .andExpect(status().isOk()) .andExpect(jsonPath("$.data.counts.monitoringPointCount").value(0)) .andExpect(jsonPath("$.data.mapFilter.pointCodes", hasSize(0))); } } @Test void unknownOrMixedTypeWithDevicesIsNotReinterpretedAsAnEmptyPoint() { when(adapter.load()).thenReturn(new CockpitMonitoringOverviewSnapshot( "2026-09-02T09:59:50+08:00", fixture().getTypes(), Collections.emptyList(), Arrays.asList( new CockpitMonitoringOverviewSnapshot.SourceMonitoringPoint("EMPTY", null, 0), new CockpitMonitoringOverviewSnapshot.SourceMonitoringPoint("MIXED", null, 2), new CockpitMonitoringOverviewSnapshot.SourceMonitoringPoint("LEGACY", null), new CockpitMonitoringOverviewSnapshot.SourceMonitoringPoint("FACILITY", "WATER_PLANT", 0)))); CockpitMonitoringOverviewResponse response = service.load("points", null, null); assertEquals(1, response.getCounts().getMonitoringPointCount()); assertEquals(Collections.singletonList("EMPTY"), response.getMapFilter().getPointCodes()); } ''' + anchor) p.write_text(s, encoding='utf-8', newline='\n') p = root / 'BusinessCockpitMonitoringOverviewAdapterTest.java' s = p.read_text(encoding='utf-8') anchor = ' // ---- helpers ----' assert s.count(anchor) == 1 s = s.replace(anchor, ''' @Test void realEmptyPointsAndMissingDeviceTypesPublishDistinctAssociationFacts() { stubPoints(Arrays.asList(point("P0", "EMPTY"), point("P1", "UNKNOWN"))); stubTypes(Collections.emptyList()); EquipmentBase bound = device("D", "BOUND", "99"); when(equipmentBaseService.list()).thenReturn(Collections.singletonList(bound)); when(equipmentBaseService.getEquipmentByPoint("P0")).thenReturn(Collections.emptyList()); when(equipmentBaseService.getEquipmentByPoint("P1")).thenReturn(Arrays.asList(bound, bound)); CockpitMonitoringOverviewSnapshot snapshot = adapter.load(); assertNull(snapshot.getMonitoringPoints().get(0).getTypeCode()); assertEquals(0, snapshot.getMonitoringPoints().get(0).getAssociatedDeviceCount()); assertNull(snapshot.getMonitoringPoints().get(1).getTypeCode()); assertEquals(1, snapshot.getMonitoringPoints().get(1).getAssociatedDeviceCount()); CockpitMonitoringOverviewService service = new CockpitMonitoringOverviewService( () -> snapshot, Clock.fixed(Instant.parse("2026-09-02T02:00:00Z"), ZoneOffset.UTC)); var response = service.load("empty-real", null, null); assertEquals(1, response.getCounts().getMonitoringPointCount()); assertEquals(Collections.singletonList("EMPTY"), response.getMapFilter().getPointCodes()); } ''' + anchor) p.write_text(s, encoding='utf-8', newline='\n') print('Updated existing coordinate expectations and added six contract regression tests; tests not executed.')