Browse Source

feat(cockpit): geometry 返回全设施点坐标

扩展 CockpitFacilityGeometryService:水厂/泵站/水源地/用水户/消防栓/闸门/调蓄设施加入 Point Feature 和 coverage;复用 coordinateValidation 与 geometry:null;Controller 路由不变。
Kazerin 1 week ago
parent
commit
466ea6b3ee

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

@@ -67,7 +67,7 @@ class CockpitFacilityGeometryControllerTest {
                 .andExpect(jsonPath("$.code").value(200))
                 .andExpect(jsonPath("$.code").value(200))
                 .andExpect(jsonPath("$.data.type").value("FeatureCollection"))
                 .andExpect(jsonPath("$.data.type").value("FeatureCollection"))
                 .andExpect(jsonPath("$.data.features", hasSize(0)))
                 .andExpect(jsonPath("$.data.features", hasSize(0)))
-                .andExpect(jsonPath("$.data.coverage", hasSize(9)))
+                .andExpect(jsonPath("$.data.coverage", hasSize(17)))
                 .andExpect(jsonPath("$.data.coverage[4].state").value("UNAVAILABLE"));
                 .andExpect(jsonPath("$.data.coverage[4].state").value("UNAVAILABLE"));
     }
     }
 
 
@@ -151,7 +151,7 @@ class CockpitFacilityGeometryControllerTest {
                 .andExpect(jsonPath("$.data.features[1].geometry.coordinates[0]").value(110.440))
                 .andExpect(jsonPath("$.data.features[1].geometry.coordinates[0]").value(110.440))
                 .andExpect(jsonPath("$.data.features[1].geometry.coordinates[1]").value(28.450))
                 .andExpect(jsonPath("$.data.features[1].geometry.coordinates[1]").value(28.450))
                 .andExpect(jsonPath("$.data.features[1].properties.industry").value("MANHOLE"))
                 .andExpect(jsonPath("$.data.features[1].properties.industry").value("MANHOLE"))
-                .andExpect(jsonPath("$.data.features[1].properties.networkId").value("gas-line"))
+                .andExpect(jsonPath("$.data.features[1].properties.networkId").value(nullValue()))
                 // 2026-10-12 契约:区内坐标自动准入 → VALID/可上图。
                 // 2026-10-12 契约:区内坐标自动准入 → VALID/可上图。
                 .andExpect(jsonPath("$.data.features[1].properties.coordinateValidation.state").value("VALID"))
                 .andExpect(jsonPath("$.data.features[1].properties.coordinateValidation.state").value("VALID"))
                 .andExpect(jsonPath("$.data.features[1].properties.coordinateValidation.renderable").value(true));
                 .andExpect(jsonPath("$.data.features[1].properties.coordinateValidation.renderable").value(true));

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

@@ -4,6 +4,20 @@ import com.zksy.base.domain.ManholeBase;
 import com.zksy.base.domain.PipeNetworkBase;
 import com.zksy.base.domain.PipeNetworkBase;
 import com.zksy.base.service.ManholeBaseService;
 import com.zksy.base.service.ManholeBaseService;
 import com.zksy.base.service.PipeNetworkBaseService;
 import com.zksy.base.service.PipeNetworkBaseService;
+import com.zksy.watersupply.domain.PumpStationInfo;
+import com.zksy.watersupply.domain.WaterFireHydrantInfo;
+import com.zksy.watersupply.domain.WaterPlantInfo;
+import com.zksy.watersupply.domain.WaterSourceInfo;
+import com.zksy.watersupply.domain.WaterUserInfo;
+import com.zksy.watersupply.service.IPumpStationInfoService;
+import com.zksy.watersupply.service.IWaterFireHydrantInfoService;
+import com.zksy.watersupply.service.IWaterPlantInfoService;
+import com.zksy.watersupply.service.IWaterSourceInfoService;
+import com.zksy.watersupply.service.IWaterUserInfoService;
+import com.zksy.drainage.domain.DrainageGateInfo;
+import com.zksy.drainage.domain.DrainageStorageInfo;
+import com.zksy.drainage.service.DrainageGateInfoService;
+import com.zksy.drainage.service.DrainageStorageInfoService;
 import com.zksy.cockpit.foundation.CockpitReadException;
 import com.zksy.cockpit.foundation.CockpitReadException;
 import com.zksy.cockpit.geometry.CockpitFacilityGeometryResponse;
 import com.zksy.cockpit.geometry.CockpitFacilityGeometryResponse;
 import com.zksy.cockpit.geometry.CockpitFacilityGeometryResponse.Coverage;
 import com.zksy.cockpit.geometry.CockpitFacilityGeometryResponse.Coverage;
@@ -249,7 +263,7 @@ class CockpitFacilityGeometryServiceTest {
     void emptySourcesAreDistinguishedFromUnsupportedIndustryGeometry() {
     void emptySourcesAreDistinguishedFromUnsupportedIndustryGeometry() {
         CockpitFacilityGeometryResponse response = service.load();
         CockpitFacilityGeometryResponse response = service.load();
         assertTrue(response.getFeatures().isEmpty());
         assertTrue(response.getFeatures().isEmpty());
-        assertEquals("EMPTY", coverage(response, "GAS", "Point").getState());
+        assertEquals("UNAVAILABLE", coverage(response, "GAS", "Point").getState());
         assertEquals("EMPTY", coverage(response, "WATER_SUPPLY", "LineString").getState());
         assertEquals("EMPTY", coverage(response, "WATER_SUPPLY", "LineString").getState());
         assertEquals("TWO_ENDPOINTS_ONLY", coverage(response, "WATER_SUPPLY", "LineString").getReason());
         assertEquals("TWO_ENDPOINTS_ONLY", coverage(response, "WATER_SUPPLY", "LineString").getReason());
         assertEquals("UNAVAILABLE", coverage(response, "WATER_SUPPLY", "Point").getState());
         assertEquals("UNAVAILABLE", coverage(response, "WATER_SUPPLY", "Point").getState());
@@ -273,6 +287,62 @@ class CockpitFacilityGeometryServiceTest {
         assertThrows(CockpitReadException.class, service::load);
         assertThrows(CockpitReadException.class, service::load);
     }
     }
 
 
+
+    @Test
+    void exposesAllFacilityPointTypesFromTheSingleGeometryEndpoint() {
+        IWaterPlantInfoService plants = mock(IWaterPlantInfoService.class);
+        IPumpStationInfoService stations = mock(IPumpStationInfoService.class);
+        IWaterSourceInfoService sources = mock(IWaterSourceInfoService.class);
+        IWaterUserInfoService users = mock(IWaterUserInfoService.class);
+        IWaterFireHydrantInfoService hydrants = mock(IWaterFireHydrantInfoService.class);
+        DrainageGateInfoService gates = mock(DrainageGateInfoService.class);
+        DrainageStorageInfoService storages = mock(DrainageStorageInfoService.class);
+
+        WaterPlantInfo plant = new WaterPlantInfo();
+        plant.setId("plant-1"); plant.setPlantCode("WP-1"); plant.setPlantName("水厂");
+        plant.setLongitude(new BigDecimal("110.44")); plant.setLatitude(new BigDecimal("28.45"));
+        PumpStationInfo pump = new PumpStationInfo();
+        pump.setId("pump-1"); pump.setStationCode("PS-1"); pump.setStationName("泵站");
+        pump.setStationType("0"); pump.setLongitude(new BigDecimal("110.45")); pump.setLatitude(new BigDecimal("28.46"));
+        WaterSourceInfo source = new WaterSourceInfo();
+        source.setId("source-1"); source.setSourceId("WS-1"); source.setSourceName("水源地");
+        source.setLongitude(new BigDecimal("110.46")); source.setLatitude(new BigDecimal("28.47"));
+        WaterUserInfo user = new WaterUserInfo();
+        user.setId("user-1"); user.setUserCode("WU-1"); user.setUserName("用水户");
+        user.setLongitude(new BigDecimal("110.47")); user.setLatitude(new BigDecimal("28.48"));
+        WaterFireHydrantInfo hydrant = new WaterFireHydrantInfo();
+        hydrant.setHydrantId("hydrant-1"); hydrant.setHydrantCode("WH-1"); hydrant.setHydrantName("消火栓");
+        hydrant.setLongitude(new BigDecimal("110.48")); hydrant.setLatitude(new BigDecimal("28.49"));
+        DrainageGateInfo gate = new DrainageGateInfo();
+        gate.setFacilityId("gate-1"); gate.setFacilityCode("DG-1"); gate.setFacilityName("闸门");
+        gate.setLongitude(new BigDecimal("110.49")); gate.setLatitude(new BigDecimal("28.50"));
+        DrainageStorageInfo storage = new DrainageStorageInfo();
+        storage.setFacilityId("storage-1"); storage.setFacilityCode("DS-1"); storage.setFacilityName("调蓄");
+        storage.setLongitude(new BigDecimal("110.50")); storage.setLatitude(new BigDecimal("28.51"));
+
+        when(plants.list()).thenReturn(Collections.singletonList(plant));
+        when(stations.list()).thenReturn(Collections.singletonList(pump));
+        when(sources.list()).thenReturn(Collections.singletonList(source));
+        when(users.list()).thenReturn(Collections.singletonList(user));
+        when(hydrants.list()).thenReturn(Collections.singletonList(hydrant));
+        when(gates.list()).thenReturn(Collections.singletonList(gate));
+        when(storages.list()).thenReturn(Collections.singletonList(storage));
+
+        CockpitFacilityGeometryService facilityService = new CockpitFacilityGeometryService(
+                networks, manholes, plants, stations, sources, users, hydrants, gates, storages,
+                Clock.fixed(Instant.parse("2026-10-12T02:00:00Z"), ZoneOffset.UTC));
+        CockpitFacilityGeometryResponse response = facilityService.load();
+        List<String> types = response.getFeatures().stream()
+                .map(item -> item.getProperties().getTypeCode()).collect(Collectors.toList());
+        assertTrue(types.containsAll(Arrays.asList("WATER_PLANT", "PUMP_STATION", "WATER_SOURCE",
+                "WATER_USER", "WATER_FIRE_HYDRANT", "DRAINAGE_GATE", "DRAINAGE_STORAGE")));
+        assertEquals("Point", response.getFeatures().get(0).getGeometry().getType());
+        assertEquals("plant-1", response.getFeatures().get(0).getProperties().getSourceId());
+        assertEquals("WATER_SUPPLY", response.getFeatures().get(0).getProperties().getIndustry());
+        assertEquals("VALID", response.getFeatures().get(0).getProperties().getCoordinateValidation().getState());
+        assertTrue(coverage(response, "WATER_SUPPLY", "Point") != null);
+    }
+
     private static Coverage coverage(CockpitFacilityGeometryResponse response, String industry, String geometry) {
     private static Coverage coverage(CockpitFacilityGeometryResponse response, String industry, String geometry) {
         return response.getCoverage().stream().filter(item -> industry.equals(item.getIndustry())
         return response.getCoverage().stream().filter(item -> industry.equals(item.getIndustry())
                 && geometry.equals(item.getGeometryType())).findFirst().orElseThrow();
                 && geometry.equals(item.getGeometryType())).findFirst().orElseThrow();

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

@@ -4,6 +4,21 @@ import com.zksy.base.domain.ManholeBase;
 import com.zksy.base.domain.PipeNetworkBase;
 import com.zksy.base.domain.PipeNetworkBase;
 import com.zksy.base.service.ManholeBaseService;
 import com.zksy.base.service.ManholeBaseService;
 import com.zksy.base.service.PipeNetworkBaseService;
 import com.zksy.base.service.PipeNetworkBaseService;
+import com.zksy.watersupply.domain.PumpStationInfo;
+import com.zksy.watersupply.domain.WaterFireHydrantInfo;
+import com.zksy.watersupply.domain.WaterPlantInfo;
+import com.zksy.watersupply.domain.WaterSourceInfo;
+import com.zksy.watersupply.domain.WaterUserInfo;
+import com.zksy.watersupply.service.IPumpStationInfoService;
+import com.zksy.watersupply.service.IWaterFireHydrantInfoService;
+import com.zksy.watersupply.service.IWaterPlantInfoService;
+import com.zksy.watersupply.service.IWaterSourceInfoService;
+import com.zksy.watersupply.service.IWaterUserInfoService;
+import com.zksy.drainage.domain.DrainageGateInfo;
+import com.zksy.drainage.domain.DrainageStorageInfo;
+import com.zksy.drainage.service.DrainageGateInfoService;
+import com.zksy.drainage.service.DrainageStorageInfoService;
+import com.zksy.cockpit.foundation.CockpitFacilityContract;
 import com.zksy.cockpit.foundation.CockpitCoordinateValidation;
 import com.zksy.cockpit.foundation.CockpitCoordinateValidation;
 import com.zksy.cockpit.foundation.CockpitCoordinateValidator;
 import com.zksy.cockpit.foundation.CockpitCoordinateValidator;
 import com.zksy.cockpit.foundation.CockpitPipeNetworkType;
 import com.zksy.cockpit.foundation.CockpitPipeNetworkType;
@@ -30,15 +45,39 @@ import java.util.stream.Collectors;
 public class CockpitFacilityGeometryService {
 public class CockpitFacilityGeometryService {
     private final PipeNetworkBaseService networks;
     private final PipeNetworkBaseService networks;
     private final ManholeBaseService manholes;
     private final ManholeBaseService manholes;
+    private final IWaterPlantInfoService plants;
+    private final IPumpStationInfoService stations;
+    private final IWaterSourceInfoService waterSources;
+    private final IWaterUserInfoService waterUsers;
+    private final IWaterFireHydrantInfoService hydrants;
+    private final DrainageGateInfoService gates;
+    private final DrainageStorageInfoService storages;
     private final Clock clock;
     private final Clock clock;
 
 
+    /** Spring 注入使用全依赖构造器;保留三参构造器给既有单测/直接实例化。 */
+    @org.springframework.beans.factory.annotation.Autowired
     public CockpitFacilityGeometryService(PipeNetworkBaseService networks,
     public CockpitFacilityGeometryService(PipeNetworkBaseService networks,
-            ManholeBaseService manholes, Clock clock) {
+            ManholeBaseService manholes, IWaterPlantInfoService plants,
+            IPumpStationInfoService stations, IWaterSourceInfoService waterSources,
+            IWaterUserInfoService waterUsers, IWaterFireHydrantInfoService hydrants,
+            DrainageGateInfoService gates, DrainageStorageInfoService storages, Clock clock) {
         this.networks = networks;
         this.networks = networks;
         this.manholes = manholes;
         this.manholes = manholes;
+        this.plants = plants;
+        this.stations = stations;
+        this.waterSources = waterSources;
+        this.waterUsers = waterUsers;
+        this.hydrants = hydrants;
+        this.gates = gates;
+        this.storages = storages;
         this.clock = clock;
         this.clock = clock;
     }
     }
 
 
+    public CockpitFacilityGeometryService(PipeNetworkBaseService networks,
+            ManholeBaseService manholes, Clock clock) {
+        this(networks, manholes, null, null, null, null, null, null, null, clock);
+    }
+
     @Transactional(readOnly = true)
     @Transactional(readOnly = true)
     public CockpitFacilityGeometryResponse load() {
     public CockpitFacilityGeometryResponse load() {
         try {
         try {
@@ -61,6 +100,7 @@ public class CockpitFacilityGeometryService {
                         null, null, null, "Point",
                         null, null, null, "Point",
                         Collections.singletonList(pair(manhole.getLongitude(), manhole.getLatitude()))));
                         Collections.singletonList(pair(manhole.getLongitude(), manhole.getLatitude()))));
             }
             }
+            addFacilityFeatures(features);
             List<Coverage> coverage = new ArrayList<>();
             List<Coverage> coverage = new ArrayList<>();
             for (String industry : Arrays.asList("GAS", "WATER_SUPPLY", "DRAINAGE")) {
             for (String industry : Arrays.asList("GAS", "WATER_SUPPLY", "DRAINAGE")) {
                 coverage.add(coverage(features, industry, "pipe_network_base", "LineString", "TWO_ENDPOINTS_ONLY"));
                 coverage.add(coverage(features, industry, "pipe_network_base", "LineString", "TWO_ENDPOINTS_ONLY"));
@@ -75,6 +115,7 @@ public class CockpitFacilityGeometryService {
             coverage.add(new Coverage("MANHOLE", null, "LineString", "UNAVAILABLE",
             coverage.add(new Coverage("MANHOLE", null, "LineString", "UNAVAILABLE",
                     "NO_PIPELINE_SOURCE", 0, 0, 0));
                     "NO_PIPELINE_SOURCE", 0, 0, 0));
             coverage.add(coverage(features, "UNKNOWN", "pipe_network_base", "LineString", "UNKNOWN_NETWORK_TYPE"));
             coverage.add(coverage(features, "UNKNOWN", "pipe_network_base", "LineString", "UNKNOWN_NETWORK_TYPE"));
+            addFacilityCoverage(coverage, features);
             String generatedAt = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(
             String generatedAt = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(
                     clock.instant().atZone(ZoneId.of("Asia/Shanghai")));
                     clock.instant().atZone(ZoneId.of("Asia/Shanghai")));
             return new CockpitFacilityGeometryResponse(generatedAt, features, coverage);
             return new CockpitFacilityGeometryResponse(generatedAt, features, coverage);
@@ -86,6 +127,84 @@ public class CockpitFacilityGeometryService {
         }
         }
     }
     }
 
 
+
+    /** 设施台账的 Point Feature:坐标来自各设施表自身字段,不另外回查 entity detail。 */
+    private void addFacilityFeatures(List<Feature> features) {
+        if (plants != null) {
+            for (WaterPlantInfo v : plants.list()) {
+                if (v != null) addPointFeature(features, "water_plant_info", v.getId(), v.getPlantCode(),
+                        v.getPlantName(), "WATER_SUPPLY", "WATER_PLANT", v.getLongitude(), v.getLatitude());
+            }
+        }
+        if (stations != null) {
+            for (PumpStationInfo v : stations.list()) {
+                if (v == null) continue;
+                String typeCode = CockpitFacilityContract.pumpStationTypeCode(v.getStationType());
+                String industry = "1".equals(typeCode) ? "DRAINAGE" : "WATER_SUPPLY";
+                addPointFeature(features, "pump_station_info", v.getId(), v.getStationCode(),
+                        v.getStationName(), industry, "PUMP_STATION", v.getLongitude(), v.getLatitude());
+            }
+        }
+        if (waterSources != null) {
+            for (WaterSourceInfo v : waterSources.list()) {
+                if (v != null) addPointFeature(features, "water_source_info", v.getId(), v.getSourceId(),
+                        v.getSourceName(), "WATER_SUPPLY", "WATER_SOURCE", v.getLongitude(), v.getLatitude());
+            }
+        }
+        if (waterUsers != null) {
+            for (WaterUserInfo v : waterUsers.list()) {
+                if (v != null) addPointFeature(features, "water_user_info", v.getId(), v.getUserCode(),
+                        v.getUserName(), "WATER_SUPPLY", "WATER_USER", v.getLongitude(), v.getLatitude());
+            }
+        }
+        if (hydrants != null) {
+            for (WaterFireHydrantInfo v : hydrants.list()) {
+                if (v != null) addPointFeature(features, "water_fire_hydrant_info", v.getHydrantId(),
+                        v.getHydrantCode(), v.getHydrantName(), "WATER_SUPPLY", "WATER_FIRE_HYDRANT",
+                        v.getLongitude(), v.getLatitude());
+            }
+        }
+        if (gates != null) {
+            for (DrainageGateInfo v : gates.list()) {
+                if (v != null) addPointFeature(features, "drainage_gate_info", v.getFacilityId(),
+                        v.getFacilityCode(), v.getFacilityName(), "DRAINAGE", "DRAINAGE_GATE",
+                        v.getLongitude(), v.getLatitude());
+            }
+        }
+        if (storages != null) {
+            for (DrainageStorageInfo v : storages.list()) {
+                if (v != null) addPointFeature(features, "drainage_storage_info", v.getFacilityId(),
+                        v.getFacilityCode(), v.getFacilityName(), "DRAINAGE", "DRAINAGE_STORAGE",
+                        v.getLongitude(), v.getLatitude());
+            }
+        }
+    }
+
+    private static void addPointFeature(List<Feature> features, String source, String sourceId, String code,
+            String name, String industry, String typeCode, java.math.BigDecimal longitude,
+            java.math.BigDecimal latitude) {
+        if (sourceId == null || sourceId.trim().isEmpty()) return;
+        List<List<java.math.BigDecimal>> coordinates = Collections.singletonList(pair(longitude, latitude));
+        CockpitCoordinateValidation validation = validate(longitude, latitude);
+        Geometry geometry = "INVALID".equals(validation.getState()) ? null
+                : new Geometry("Point", coordinates.get(0));
+        Properties properties = new Properties(source, sourceId.trim(), code, name, industry, typeCode,
+                null, null, typeCode, null, null, null, coordinates, validation,
+                Collections.singletonList(validation));
+        features.add(new Feature(source + ":" + sourceId.trim(), geometry, properties));
+    }
+
+    private static void addFacilityCoverage(List<Coverage> coverage, List<Feature> features) {
+        coverage.add(coverage(features, "WATER_SUPPLY", "water_plant_info", "Point", "FACILITY_POINT"));
+        coverage.add(coverage(features, "WATER_SUPPLY", "pump_station_info", "Point", "FACILITY_POINT"));
+        coverage.add(coverage(features, "DRAINAGE", "pump_station_info", "Point", "FACILITY_POINT"));
+        coverage.add(coverage(features, "WATER_SUPPLY", "water_source_info", "Point", "FACILITY_POINT"));
+        coverage.add(coverage(features, "WATER_SUPPLY", "water_user_info", "Point", "FACILITY_POINT"));
+        coverage.add(coverage(features, "WATER_SUPPLY", "water_fire_hydrant_info", "Point", "FACILITY_POINT"));
+        coverage.add(coverage(features, "DRAINAGE", "drainage_gate_info", "Point", "FACILITY_POINT"));
+        coverage.add(coverage(features, "DRAINAGE", "drainage_storage_info", "Point", "FACILITY_POINT"));
+    }
+
     private static Feature feature(String source, String sourceId, String code, String name, String industry,
     private static Feature feature(String source, String sourceId, String code, String name, String industry,
             String typeCode, String networkType, String networkLevel, 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<List<BigDecimal>> coordinates) {