Kaynağa Gözat

fix(cockpit): expose reported pipe diameters in geometry (#32)

Kazerin 1 hafta önce
ebeveyn
işleme
a96091ce08

+ 4 - 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, Collections.singletonList(Arrays.asList(null, new BigDecimal("28.4"))),
+                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",
@@ -101,6 +101,7 @@ class CockpitFacilityGeometryControllerTest {
         com.zksy.base.domain.PipeNetworkBase line = new com.zksy.base.domain.PipeNetworkBase();
         line.setNetworkId("gas-line");
         line.setNetworkType("0");
+        line.setDiameter(new BigDecimal("400.50"));
         line.setStartLongitude(new BigDecimal("110.360"));
         line.setStartLatitude(new BigDecimal("28.420"));
         line.setEndLongitude(new BigDecimal("110.420"));
@@ -122,6 +123,8 @@ class CockpitFacilityGeometryControllerTest {
                 .andExpect(status().isOk())
                 .andExpect(jsonPath("$.data.features", hasSize(2)))
                 .andExpect(jsonPath("$.data.features[0].geometry.type").value("LineString"))
+                .andExpect(jsonPath("$.data.features[0].properties.diameter").value(400.50))
+                .andExpect(jsonPath("$.data.features[1].properties.diameter").value(nullValue()))
                 .andExpect(jsonPath("$.data.features[0].geometry.coordinates", hasSize(2)))
                 .andExpect(jsonPath("$.data.features[0].geometry.coordinates[0][0]").value(110.360))
                 .andExpect(jsonPath("$.data.features[0].geometry.coordinates[0][1]").value(28.420))

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

@@ -84,6 +84,38 @@ class CockpitFacilityGeometryServiceTest {
         verifyNoMoreInteractions(networks, points, manholes);
     }
 
+    @Test
+    void exposesReportedDiameterInMillimetresAndKeepsMissingDiameterExplicit() {
+        PipeNetworkBase known = network("known-diameter", "0");
+        known.setDiameter(new BigDecimal("400.50"));
+        PipeNetworkBase missing = network("missing-diameter", "0");
+        PipeNetworkBase zero = network("zero-diameter", "0");
+        zero.setDiameter(BigDecimal.ZERO);
+        GasPipePoint point = point(7L, "阀门");
+        point.setDiameter(new BigDecimal("125.25"));
+        ManholeBase well = new ManholeBase();
+        well.setManholeId("well");
+        well.setLongitude(new BigDecimal("110.440"));
+        well.setLatitude(new BigDecimal("28.450"));
+        when(networks.list()).thenReturn(Arrays.asList(known, missing, zero));
+        when(points.list()).thenReturn(Collections.singletonList(point));
+        when(manholes.list()).thenReturn(Collections.singletonList(well));
+        com.fasterxml.jackson.databind.JsonNode json = new com.fasterxml.jackson.databind.ObjectMapper()
+                .valueToTree(service.load());
+        com.fasterxml.jackson.databind.JsonNode properties = json.get("features").get(0).get("properties");
+        assertTrue(properties.has("diameter"));
+        assertEquals(400.50, properties.get("diameter").asDouble());
+        assertTrue(json.get("features").get(1).get("properties").has("diameter"));
+        assertTrue(json.get("features").get(1).get("properties").get("diameter").isNull());
+        assertEquals(0, json.get("features").get(2).get("properties").get("diameter").asInt());
+        assertEquals(125.25, json.get("features").get(3).get("properties").get("diameter").asDouble());
+        assertTrue(json.get("features").get(4).get("properties").get("diameter").isNull());
+        assertEquals(new BigDecimal("400.50"), known.getDiameter());
+        assertNull(missing.getDiameter());
+        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

@@ -54,6 +54,9 @@ public class CockpitFacilityGeometryResponse {
         private final String pointType;
         @JsonInclude(JsonInclude.Include.ALWAYS)
         private final String networkId;
+        /** Original reported diameter in millimetres; null means not supplied. */
+        @JsonInclude(JsonInclude.Include.ALWAYS)
+        private final BigDecimal diameter;
         // Raw pairs remain available for objects whose GeoJSON geometry must be null.
         private final List<List<BigDecimal>> sourceCoordinates;
         private final CockpitCoordinateValidation coordinateValidation;

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

@@ -53,20 +53,20 @@ 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(),
-                        null, network.getNetworkId(), "LineString", Arrays.asList(
+                        null, network.getNetworkId(), network.getDiameter(), "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.getNetworkId(), "Point",
+                        point.getNetworkId(), point.getDiameter(), "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.getNetworkId(), "Point",
+                        manhole.getNetworkId(), null, "Point",
                         Collections.singletonList(pair(manhole.getLongitude(), manhole.getLatitude()))));
             }
             List<Coverage> coverage = new ArrayList<>();
@@ -94,7 +94,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, String geometryType,
+            String typeCode, String networkType, String pointType, String networkId, BigDecimal diameter, String geometryType,
             List<List<BigDecimal>> coordinates) {
         List<CockpitCoordinateValidation> validations = coordinates.stream()
                 .map(pair -> validate(pair.get(0), pair.get(1)))
@@ -106,7 +106,7 @@ public class CockpitFacilityGeometryService {
         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,
-                pointType, networkId, coordinates, overall, validations);
+                pointType, networkId, diameter, coordinates, overall, validations);
         return new Feature(source + ":" + sourceId, geometry, properties);
     }