瀏覽代碼

fix(cockpit): expose drainage network levels without changing legacy data (#32)

Kazerin 6 天之前
父節點
當前提交
7150d431fb

+ 2 - 1
pipe-network-service/zksy-admin/src/test/java/com/zksy/web/controller/cockpit/CockpitFacilityGeometryControllerTest.java

@@ -64,7 +64,7 @@ class CockpitFacilityGeometryControllerTest {
     @Test
     void invalidGeometryIsExplicitJsonNullWithRawCoordinatesAndSameValidationShape() throws Exception {
         Properties properties = new Properties("gas_pipe_point", "1", "G1", "阀门", "GAS", "GAS_PIPE_POINT",
-                null, "阀门", null, null, null, Collections.singletonList(Arrays.asList(null, new BigDecimal("28.4"))),
+                null, null, "阀门", null, null, null, Collections.singletonList(Arrays.asList(null, new BigDecimal("28.4"))),
                 CockpitCoordinateValidator.validate(null, new BigDecimal("28.4"), true),
                 Collections.singletonList(CockpitCoordinateValidator.validate(null, new BigDecimal("28.4"), true)));
         when(service.load()).thenReturn(new CockpitFacilityGeometryResponse("2026-10-12T10:00:00+08:00",
@@ -73,6 +73,7 @@ class CockpitFacilityGeometryControllerTest {
                 .andExpect(status().isOk())
                 .andExpect(jsonPath("$.data.features[0].type").value("Feature"))
                 .andExpect(jsonPath("$.data.features[0].geometry").value(nullValue()))
+                .andExpect(jsonPath("$.data.features[0].properties.networkLevel").value(nullValue()))
                 .andExpect(jsonPath("$.data.features[0].properties.networkId").value(nullValue()))
                 .andExpect(jsonPath("$.data.features[0].properties.pointType").value("阀门"))
                 .andExpect(jsonPath("$.data.features[0].properties.sourceCoordinates[0][0]").value(nullValue()))

+ 25 - 0
pipe-network-service/zksy-admin/src/test/java/com/zksy/web/controller/cockpit/CockpitFacilityGeometryServiceTest.java

@@ -133,6 +133,31 @@ class CockpitFacilityGeometryServiceTest {
         assertTrue(json.get("features").get(2).get("properties").get("remark").isNull());
     }
 
+    @Test
+    void exposesNetworkLevelForDrainageAndDefaultsLegacyMissingLevelWithoutMutatingSource() {
+        PipeNetworkBase sewage = network("level-zero", "1");
+        sewage.setNetworkLevel("0");
+        PipeNetworkBase rain = network("level-one", "1");
+        rain.setNetworkLevel("1");
+        PipeNetworkBase legacy = network("level-missing", "1");
+        PipeNetworkBase blank = network("level-blank", "1");
+        blank.setNetworkLevel("  ");
+        PipeNetworkBase gas = network("gas-level-one", "0");
+        gas.setNetworkLevel("1");
+        when(networks.list()).thenReturn(Arrays.asList(sewage, rain, legacy, blank, gas));
+        com.fasterxml.jackson.databind.JsonNode json = new com.fasterxml.jackson.databind.ObjectMapper().valueToTree(service.load());
+        assertEquals("0", json.get("features").get(0).get("properties").get("networkLevel").asText());
+        assertEquals("1", json.get("features").get(1).get("properties").get("networkLevel").asText());
+        assertEquals("0", json.get("features").get(2).get("properties").get("networkLevel").asText());
+        assertEquals("0", json.get("features").get(3).get("properties").get("networkLevel").asText());
+        assertEquals("GAS", json.get("features").get(4).get("properties").get("industry").asText());
+        assertEquals("1", json.get("features").get(4).get("properties").get("networkLevel").asText());
+        assertNull(legacy.getNetworkLevel());
+        assertEquals("  ", blank.getNetworkLevel());
+        verify(networks).list();
+        verifyNoMoreInteractions(networks);
+    }
+
     @Test
     void preservesEveryComponentTypeIncludingUnknownAndMissingTypesWithoutFabricatingNodes() {
         List<String> types = Arrays.asList("阀门", "调压", "计量", "阴极保护", "弯头", "三通", "其它", "未知原始值", null);

+ 3 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/geometry/CockpitFacilityGeometryResponse.java

@@ -50,6 +50,9 @@ public class CockpitFacilityGeometryResponse {
         private final String industry;
         private final String typeCode;
         private final String networkType;
+        /** Drainage subtype: 0 sewage (legacy default), 1 rainwater; ignored by other industries. */
+        @JsonInclude(JsonInclude.Include.ALWAYS)
+        private final String networkLevel;
         @JsonInclude(JsonInclude.Include.ALWAYS)
         private final String pointType;
         @JsonInclude(JsonInclude.Include.ALWAYS)

+ 6 - 4
pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/geometry/CockpitFacilityGeometryService.java

@@ -53,19 +53,21 @@ public class CockpitFacilityGeometryService {
                 features.add(feature("pipe_network_base", network.getNetworkId(), network.getNetworkCode(),
                         network.getNetworkName(), industry == null ? "UNKNOWN" : industry,
                         CockpitPipeNetworkType.typeCodeOf(network.getNetworkType()), network.getNetworkType(),
+                        "DRAINAGE".equals(industry) && (network.getNetworkLevel() == null || network.getNetworkLevel().trim().isEmpty())
+                                ? "0" : network.getNetworkLevel(),
                         null, network.getNetworkId(), network.getDiameter(), network.getRemark(), "LineString", Arrays.asList(
                                 pair(network.getStartLongitude(), network.getStartLatitude()),
                                 pair(network.getEndLongitude(), network.getEndLatitude()))));
             }
             for (GasPipePoint point : Objects.requireNonNull(gasPoints.list())) {
                 features.add(feature("gas_pipe_point", String.valueOf(point.getPointId()), point.getPointCode(),
-                        point.getPointName(), "GAS", "GAS_PIPE_POINT", null, point.getPointType(),
+                        point.getPointName(), "GAS", "GAS_PIPE_POINT", null, null, point.getPointType(),
                         point.getNetworkId(), point.getDiameter(), null, "Point",
                         Collections.singletonList(pair(point.getLongitude(), point.getLatitude()))));
             }
             for (ManholeBase manhole : Objects.requireNonNull(manholes.list())) {
                 features.add(feature("manhole_base", manhole.getManholeId(), manhole.getManholeCode(),
-                        manhole.getManholeName(), "MANHOLE", "MANHOLE", null, null,
+                        manhole.getManholeName(), "MANHOLE", "MANHOLE", null, null, null,
                         manhole.getNetworkId(), null, null, "Point",
                         Collections.singletonList(pair(manhole.getLongitude(), manhole.getLatitude()))));
             }
@@ -94,7 +96,7 @@ public class CockpitFacilityGeometryService {
     }
 
     private static Feature feature(String source, String sourceId, String code, String name, String industry,
-            String typeCode, String networkType, String pointType, String networkId, BigDecimal diameter, String remark, String geometryType,
+            String typeCode, String networkType, String networkLevel, String pointType, String networkId, BigDecimal diameter, String remark, String geometryType,
             List<List<BigDecimal>> coordinates) {
         List<CockpitCoordinateValidation> validations = coordinates.stream()
                 .map(pair -> validate(pair.get(0), pair.get(1)))
@@ -105,7 +107,7 @@ public class CockpitFacilityGeometryService {
         // Invalid GeoJSON coordinates cannot be represented as an empty or invented geometry.
         Geometry geometry = "INVALID".equals(overall.getState()) ? null : new Geometry(geometryType,
                 "Point".equals(geometryType) ? coordinates.get(0) : coordinates);
-        Properties properties = new Properties(source, sourceId, code, name, industry, typeCode, networkType,
+        Properties properties = new Properties(source, sourceId, code, name, industry, typeCode, networkType, networkLevel,
                 pointType, networkId, diameter, remark, coordinates, overall, validations);
         return new Feature(source + ":" + sourceId, geometry, properties);
     }