Sfoglia il codice sorgente

feat(cockpit): 接通基础设施概览与当前库结构

Kazerin 2 mesi fa
parent
commit
54dd693cb1

+ 16 - 19
docs/cockpit/README.md

@@ -169,13 +169,15 @@ mvn -pl zksy-admin -am test -Dtest='Cockpit*Test'
 - 内存基线:`ry.sh` 默认 `-Xms512m -Xmx1024m`,如需在驾驶舱工作站与渲染任务共存,建议按实际并发上调堆上限。
 - 性能测量:本轮未做生产规模压测,属未验证项;建议在取得真实设备规模后,用同一 `snapshotAt` 对 `map-snapshot` 与 `monitoring/distribution` 做分页吞吐与前端渲染测量,再决定是否加投影或索引。
 
-## 8. 当前重建基线(2026-09-24)
+## 8. 当前重建基线(2026-09-28)
 
-本节记录需求重同步时读取到的当前代码与 KingbaseES 事实。它覆盖并取代 2026-09-18 以前的真实库数量与旧字段假设;不表示当前 cockpit 适配器已经可运行。
+本节记录本轮读取到的当前代码、KingbaseES schema 事实和真实 HTTP 验收结果;它覆盖并取代 2026-09-18 以前的真实库数量与旧字段假设。认证验收使用本机 IntelliJ 启动的 `127.0.0.1:8301`,该实例通过 Nacos 连接当前 KingbaseES;`192.168.110.30:8301` 部署端口仍不可达。
 
 ### 当前数据库模型
 
-- `equipment_type` 当前列为 `id`、`type_name`、`parent_id`;旧 `type_id`、`parent_type_id` 不存在。已裁定对外 `typeCode = String(equipment_type.id)`;行业沿类型树上溯到根,正式行业为 `GAS`、`WATER_SUPPLY`、`DRAINAGE`、`MANHOLE`。`monitoring/overview` 与 `monitoring/situation` 已使用该映射;其余切片尚未改完。
+- `equipment_type` 当前列为 `id`、`type_name`、`parent_id`;旧 `type_id`、`parent_type_id` 不存在。对外 `typeCode = String(equipment_type.id)`;行业沿类型树上溯到根,正式行业为 `GAS`、`WATER_SUPPLY`、`DRAINAGE`、`MANHOLE`。
+- `monitor_point` 当前实际列为 `point_id`、`point_code`、`point_name`、`location`、`longitude`、`latitude`、`remark`、`create_by`、`create_time`、`update_by`、`update_time`、`del_flag`;`network_id`、`point_type`、`installation_date`、`status` 不存在。Java 实体保留这些兼容字段但以 `@TableField(exist = false)` 标记,驾驶舱不臆造这些值。
+- `equipment_point_rel` 当前实际列为 `rel_id`、`equipment_id`、`point_id`、`create_time`,没有 `del_flag`;Java 兼容字段不参与持久化映射,关联查询按当前表列执行。
 - `equipment_base.equipment_type_id` 指向 `equipment_type.id`;`equipment_type_name` 是查询补充字段,不是持久化列。
 - `work_order` 当前以 `device_id` 关联 `equipment_base.equipment_id`,不再有 `device_code`、`alarm_id`、`case_id`、`hazard_id` 列;报警转工单使用 `alarm_data.work_order_id → work_order.order_id`,案例和隐患分别通过各自的 `work_order_id` 关系读取。
 - `alarm_data` 持久化 `device_code`、`work_order_id`、`warning_code`、`alarm_level`、`alarm_status`、`create_time`、`audit_status` 等;设备名称、设备类型、坐标、工单补充字段属于查询投影,不是表列。
@@ -183,25 +185,20 @@ mvn -pl zksy-admin -am test -Dtest='Cockpit*Test'
 
 ### 当前真实库只读观测
 
-当前 KingbaseES `app_user` 观测值:`work_order=1`、`alarm_data=3`、`early_warning=35`、`alarm_warning_rel=3`、`equipment_base=2`、`equipment_status=2`、`monitor_point=7`、`equipment_point_rel=20`、`case_info=2`、`hazard_hidden_account=12`。
-
-- 当前两台设备中,一台为离线报警,一台在线正常;当前样例不能代表生产规模。
-- 20 条点位关系中 10 条逻辑有效,但当前两台设备均无法匹配到有效关系行,旧的“设备回联 3 条/37 台设备”数字已失效。
-- 3 条报警中 1 条通过 `alarm_data.work_order_id` 关联当前唯一工单;35 条预警中仅 6 条能经设备台账和类型层级解析类型。
-- 点位仍存在空坐标与 `(12,12)` 等异常坐标;坐标校核字段仍未出现在当前表模型中。按最小修改与现有校验器复用原则,缺可信校核来源一律 `coordinateVerified=false`、`renderable=false`;单纯经纬度范围校验会放过 `(12,12)`,不得用它代替业务校核。新增区域边界校核需另行确认边界与坐标系来源。
+- 既有只读探查记录:`work_order=1`、`alarm_data=3`、`early_warning=35`、`alarm_warning_rel=3`、`equipment_base=2`、`equipment_status=2`、`monitor_point=7`、`equipment_point_rel=20`、`case_info=2`、`hazard_hidden_account=12`;这些数量是观测时点事实,不代表生产规模。
+- 点位仍存在空坐标与 `(12,12)` 等异常坐标;当前 schema 没有可信坐标校核字段。缺可信校核来源一律 `coordinateVerified=false`、`renderable=false`;单纯经纬度范围校验不能替代业务校核。
+- 真实 `map-snapshot` HTTP 响应在本轮样例中返回 `total=15`,分页样例包含 9 个点位对象和 7 个设备编码;设备关系与样本数据会随数据库内容变化,响应的 `snapshotAt` 是唯一分页依据。
 
 ### 当前代码可验收性
 
-本工作树**已重新编译通过**,但仍不是 #63 的验收基线:
-
-- 旧编译阻断(`WorkOrder::getDeviceCode`、`EquipmentType.getTypeId/getParentTypeId`)在当前工作树中已不存在;`mvn -pl zksy-admin -am compile -q` 于 2026-09-24 通过。
-- `monitoring/overview` 与 `monitoring/situation` 已把 `MANHOLE` 纳入正式行业,并沿类型树上溯到根。定向测试 34 例 0 失败:两个控制器测试、两个真实适配器测试。
-- 地图、分布、事件、基础设施等服务仍拒绝 `MANHOLE`。工单对外字典仍是旧 1–7 模型。第 6 节检查表的真实登录态联调没有执行。
-- 历史“4/22 片已接真实库”只代表旧 schema 下的尝试,不能当作当前验收。
-- 人工澄清:“工单字典”指代码枚举 `WorkOrderStatusEnum`,不是独立数据库表;其当前取值为 0–7,与 ADR-0010 一致。只读查询 `app_user.sys_dict_type`/`sys_dict_data` 未发现工单状态字典项,无需再以数据库字典表为联调前置条件。
+- `mvn -pl zksy-admin -am compile -q` 通过;`mvn -pl zksy-admin -am test "-DfailIfNoTests=false" -q` 全量回归通过。
+- 地图、分布、事件、基础设施及概览服务当前均接受四个正式行业;地图快照通过 Redis 共享同一 `snapshotAt` 内容,带 10 分钟有效窗口、过期重校验和单节点 256 条本地缓存上限。
+- 本机真实登录态 HTTP 验收通过:登录成功;未认证请求返回 401 `UNAUTHORIZED`;4 个非法参数样例返回 400 `INVALID_REQUEST`;同一 `snapshotAt` 的 5 页地图请求总数稳定且点位不重复;点位详情和同一设备的 archive / metrics / events / work-orders / detail-aggregate / freshness 均返回 200 且 `readOnly=true`;列出的概览、基础设施、监测、事件和契约自检端点均返回 200 且只读。
+- WebSocket `/ws/deviceStatus` 真实浏览器验收通过:发送 `cockpitSubscribe(scope=all)` 后收到 `cockpitSubscribed`,响应带 `serverUpdatedAt`;所有抽查时间戳为 `+08:00`。
+- 目标部署地址 `192.168.110.30:8301` TCP 不可达,因此没有把它当作本轮 HTTP 证据;生产部署实例、性能压测、银河麒麟与 Docker 实机验证仍未执行。
 
 ## 9. 已知边界与未验证项
 
-- 当前工单运行时状态以 ADR-0010 的 0–7 八值枚举为权威;旧 cockpit 七态目录仍存在于响应模型/测试中,需先确认映射方案后才可宣称真实工单状态已对齐。
-- 本轮已对 KingbaseES 当前 schema 与数据做**只读探查**,但**未启动应用并完成第 6 节检查表 1–7 的真实登录态端到端联调**;生产规模性能、银河麒麟与 Docker 的实机验证仍为未执行项。
-- 本仓库的工作区可能包含与本契约无关的在途改动,联调前请确认部署来源是其预期提交。
+- 当前工单运行时状态以 ADR-0010 的 0–7 八值枚举为权威;旧 cockpit 七态目录仍存在于部分响应模型/测试中,需继续确认映射方案后才可宣称所有工单详情状态已完全对齐。
+- 本轮已完成本机 8301 真实登录态和当前 KingbaseES 的第 6 节检查表 1–7 主要路径验收,但目标部署端口不可达;生产规模性能、银河麒麟与 Docker 的实机验证仍为未执行项。
+- 认证凭据未写入仓库、文档或记忆库。

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

@@ -1,5 +1,10 @@
 package com.zksy.web.controller.cockpit;
 
+import com.zksy.WaterSupply.WaterPlantInfo.domain.WaterPlantInfo;
+import com.zksy.WaterSupply.WaterPlantInfo.service.IWaterPlantInfoService;
+import com.zksy.WaterSupply.WaterPumpStation.domain.PumpStationType;
+import com.zksy.WaterSupply.WaterPumpStation.domain.WaterPumpStation;
+import com.zksy.WaterSupply.WaterPumpStation.service.IWaterPumpStationService;
 import com.zksy.base.domain.EquipmentBase;
 import com.zksy.base.domain.EquipmentType;
 import com.zksy.base.domain.PipeNetworkBase;
@@ -19,6 +24,8 @@ import java.util.Collections;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 class BusinessCockpitOverviewInfrastructureAdapterTest {
@@ -26,6 +33,8 @@ class BusinessCockpitOverviewInfrastructureAdapterTest {
     private EquipmentTypeService equipmentTypeService;
     private EquipmentBaseService equipmentBaseService;
     private PipeNetworkBaseService pipeNetworkBaseService;
+    private IWaterPlantInfoService plantService;
+    private IWaterPumpStationService pumpStationService;
     private BusinessCockpitOverviewInfrastructureAdapter adapter;
 
     @BeforeEach
@@ -33,8 +42,11 @@ class BusinessCockpitOverviewInfrastructureAdapterTest {
         equipmentTypeService = mock(EquipmentTypeService.class);
         equipmentBaseService = mock(EquipmentBaseService.class);
         pipeNetworkBaseService = mock(PipeNetworkBaseService.class);
+        plantService = mock(IWaterPlantInfoService.class);
+        pumpStationService = mock(IWaterPumpStationService.class);
         adapter = new BusinessCockpitOverviewInfrastructureAdapter(
-                equipmentTypeService, equipmentBaseService, pipeNetworkBaseService);
+                equipmentTypeService, equipmentBaseService, pipeNetworkBaseService,
+                plantService, pumpStationService);
     }
 
     @Test
@@ -78,6 +90,38 @@ class BusinessCockpitOverviewInfrastructureAdapterTest {
         assertNull(facilityCount.getValue().getRange());
     }
 
+    @Test
+    void countsWaterPlantsAndSharedPumpStationsSeparately() {
+        WaterPlantInfo plant = new WaterPlantInfo();
+        plant.setPlantCode("WP-1");
+        plant.setUpdateTime(LocalDateTime.parse("2026-09-03T08:00:00"));
+        when(plantService.list()).thenReturn(Collections.singletonList(plant));
+
+        WaterPumpStation water = new WaterPumpStation();
+        water.setStationCode("PS-1");
+        water.setStationType(PumpStationType.WATER_SUPPLY);
+        WaterPumpStation drainage = new WaterPumpStation();
+        drainage.setStationCode("PS-2");
+        drainage.setStationType(PumpStationType.DRAINAGE);
+        WaterPumpStation unclassified = new WaterPumpStation();
+        unclassified.setStationCode("PS-3");
+        unclassified.setStationType("unknown");
+        when(pumpStationService.list()).thenReturn(Arrays.asList(water, drainage, unclassified));
+
+        CockpitOverviewInfrastructureSnapshot snapshot = adapter.load();
+        assertEquals("2026-09-03T08:00:00+08:00", snapshot.getUpdatedAt());
+        assertEquals(3, snapshot.getCounts().size());
+        assertEquals("WATER_PLANT", snapshot.getCounts().get(0).getTypeCode());
+        assertEquals("WATER_PUMP_STATION", snapshot.getCounts().get(1).getTypeCode());
+        assertEquals("DRAINAGE_PUMP_STATION", snapshot.getCounts().get(2).getTypeCode());
+        assertEquals("DRAINAGE", snapshot.getTypes().get(2).getIndustry());
+        verify(equipmentTypeService, times(1)).list();
+        verify(equipmentBaseService, times(1)).list();
+        verify(pipeNetworkBaseService, times(1)).list();
+        verify(plantService, times(1)).list();
+        verify(pumpStationService, times(1)).list();
+    }
+
     private static EquipmentType type(int id, String name, int parentId) {
         EquipmentType type = new EquipmentType();
         type.setId(id);

+ 31 - 3
pipe-network-service/zksy-admin/src/test/java/com/zksy/web/controller/cockpit/CockpitOverviewInfrastructureControllerTest.java

@@ -53,7 +53,7 @@ class CockpitOverviewInfrastructureControllerTest {
                 .andExpect(status().isOk())
                 .andExpect(jsonPath("$.data.totals.facilityCount").value(3))
                 .andExpect(jsonPath("$.data.totals.smartDeviceCount").value(14))
-                .andExpect(jsonPath("$.data.industries", hasSize(3)))
+                .andExpect(jsonPath("$.data.industries", hasSize(4)))
                 .andExpect(jsonPath("$.data.industries[0].code").value("GAS"))
                 .andExpect(jsonPath("$.data.industries[0].facilityCount").value(0))
                 .andExpect(jsonPath("$.data.industries[0].smartDeviceCount").value(3))
@@ -85,7 +85,7 @@ class CockpitOverviewInfrastructureControllerTest {
                 .andExpect(jsonPath("$.data.readOnly").value(true))
                 .andExpect(jsonPath("$.data.totals.facilityCount").value(1))
                 .andExpect(jsonPath("$.data.totals.smartDeviceCount").value(1))
-                .andExpect(jsonPath("$.data.industries", org.hamcrest.Matchers.hasSize(3)))
+                .andExpect(jsonPath("$.data.industries", org.hamcrest.Matchers.hasSize(4)))
                 .andExpect(jsonPath("$.data.industries[0].code").value("GAS"))
                 .andExpect(jsonPath("$.data.industries[1].code").value("WATER_SUPPLY"))
                 .andExpect(jsonPath("$.data.industries[1].facilityCount").value(1))
@@ -137,13 +137,41 @@ class CockpitOverviewInfrastructureControllerTest {
                 .andExpect(status().isOk())
                 .andExpect(jsonPath("$.data.totals.facilityCount").value(0))
                 .andExpect(jsonPath("$.data.totals.smartDeviceCount").value(0))
-                .andExpect(jsonPath("$.data.industries", hasSize(3)))
+                .andExpect(jsonPath("$.data.industries", hasSize(4)))
                 .andExpect(jsonPath("$.data.industries[0].facilityTypes", hasSize(0)))
                 .andExpect(jsonPath("$.data.industries[0].deviceTypes", hasSize(0)))
                 .andExpect(jsonPath("$.data.industries[1].facilityTypes", hasSize(0)))
                 .andExpect(jsonPath("$.data.industries[1].deviceTypes", hasSize(0)))
                 .andExpect(jsonPath("$.data.industries[2].facilityTypes", hasSize(0)))
                 .andExpect(jsonPath("$.data.industries[2].deviceTypes", hasSize(0)))
+                .andExpect(jsonPath("$.data.industries[3].code").value("MANHOLE"))
+                .andExpect(jsonPath("$.data.industries[3].facilityTypes", hasSize(0)))
+                .andExpect(jsonPath("$.data.industries[3].deviceTypes", hasSize(0)))
+                .andExpect(jsonPath("$.data.excluded.unknownTypeCount").value(0))
+                .andExpect(jsonPath("$.data.excluded.typeKindMismatchCount").value(0));
+    }
+
+    @Test
+    void sameTypeCodeAcrossObjectKindsIsResolvedIndependently() throws Exception {
+        when(adapter.load()).thenReturn(new CockpitOverviewInfrastructureSnapshot(
+                "2026-09-02T09:59:50+08:00",
+                Arrays.asList(
+                        new CockpitOverviewInfrastructureSnapshot.SourceType(
+                                "1", "设备一", "GAS", null, "SMART_DEVICE"),
+                        new CockpitOverviewInfrastructureSnapshot.SourceType(
+                                "1", "设施一", "WATER_SUPPLY", null, "FACILITY")),
+                Arrays.asList(
+                        new CockpitOverviewInfrastructureSnapshot.SourceCount("SMART_DEVICE", "1", 2),
+                        new CockpitOverviewInfrastructureSnapshot.SourceCount("FACILITY", "1", 3))));
+
+        mockMvc.perform(get("/api/cockpit/v1/overview/infrastructure"))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.data.totals.facilityCount").value(3))
+                .andExpect(jsonPath("$.data.totals.smartDeviceCount").value(2))
+                .andExpect(jsonPath("$.data.industries[0].facilityCount").value(0))
+                .andExpect(jsonPath("$.data.industries[0].smartDeviceCount").value(2))
+                .andExpect(jsonPath("$.data.industries[1].facilityCount").value(3))
+                .andExpect(jsonPath("$.data.industries[1].smartDeviceCount").value(0))
                 .andExpect(jsonPath("$.data.excluded.unknownTypeCount").value(0))
                 .andExpect(jsonPath("$.data.excluded.typeKindMismatchCount").value(0));
     }

+ 3 - 3
pipe-network-service/zksy-system/src/main/java/com/zksy/base/domain/EquipmentPointRel.java

@@ -1,8 +1,8 @@
 package com.zksy.base.domain;
 
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableLogic;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModelProperty;
@@ -36,7 +36,7 @@ public class EquipmentPointRel {
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     private LocalDateTime createTime;
 
-    @TableLogic(value = "0", delval = "2")
-    @ApiModelProperty("删除标志(0=正常 2=删除)")
+    @TableField(exist = false)
+    @ApiModelProperty("删除标志(当前 schema 未提供)")
     private String delFlag;
 }

+ 9 - 4
pipe-network-service/zksy-system/src/main/java/com/zksy/base/domain/MonitorPoint.java

@@ -1,6 +1,7 @@
 package com.zksy.base.domain;
 
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableLogic;
 import com.baomidou.mybatisplus.annotation.TableName;
@@ -33,10 +34,12 @@ public class MonitorPoint {
     @ApiModelProperty("监测点名称")
     private String pointName;
 
-    @ApiModelProperty("关联管网设施ID")
+    @TableField(exist = false)
+    @ApiModelProperty("关联管网设施ID(当前 schema 未提供)")
     private String networkId;
 
-    @ApiModelProperty("监测点类型")
+    @TableField(exist = false)
+    @ApiModelProperty("监测点类型(当前 schema 未提供)")
     private String pointType;
 
     @ApiModelProperty("位置描述")
@@ -48,11 +51,13 @@ public class MonitorPoint {
     @ApiModelProperty("纬度")
     private BigDecimal latitude;
 
-    @ApiModelProperty("安装日期")
+    @TableField(exist = false)
+    @ApiModelProperty("安装日期(当前 schema 未提供)")
     @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
     private Date installationDate;
 
-    @ApiModelProperty("状态")
+    @TableField(exist = false)
+    @ApiModelProperty("状态(当前 schema 未提供)")
     private String status;
 
     @ApiModelProperty("备注")

+ 1 - 1
pipe-network-service/zksy-system/src/main/java/com/zksy/base/mapper/EquipmentPointRelMapper.java

@@ -36,6 +36,6 @@ public interface EquipmentPointRelMapper extends BaseMapper<EquipmentPointRel> {
             + "FROM equipment_point_rel t1 "
             + "INNER JOIN monitor_point t2 ON t1.point_id = t2.point_id "
             + "WHERE t1.equipment_id = #{equipmentId} "
-            + "AND t1.del_flag = '0' AND t2.del_flag = '0'")
+            + "AND t2.del_flag = '0'")
     List<Map<String, Object>> selectPointRelByEquipmentId(@Param("equipmentId") String equipmentId);
 }

+ 75 - 11
pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/overview/BusinessCockpitOverviewInfrastructureAdapter.java

@@ -1,5 +1,10 @@
 package com.zksy.cockpit.overview;
 
+import com.zksy.WaterSupply.WaterPlantInfo.domain.WaterPlantInfo;
+import com.zksy.WaterSupply.WaterPlantInfo.service.IWaterPlantInfoService;
+import com.zksy.WaterSupply.WaterPumpStation.domain.PumpStationType;
+import com.zksy.WaterSupply.WaterPumpStation.domain.WaterPumpStation;
+import com.zksy.WaterSupply.WaterPumpStation.service.IWaterPumpStationService;
 import com.zksy.base.domain.EquipmentBase;
 import com.zksy.base.domain.EquipmentType;
 import com.zksy.base.domain.PipeNetworkBase;
@@ -28,9 +33,10 @@ import java.util.stream.Collectors;
  * 总体概览-基础设施 真实数据适配器(BT-5)。
  *
  * <p>智能设备按 {@code equipment_type} 分组计数({@code objectKind=SMART_DEVICE});
+ * 水厂和泵站分别取自其设施台账,共用泵站按 {@code station_type} 区分供水/排水。
  * 管网设施按 {@code pipe_network_base.network_type} 分组计数({@code objectKind=FACILITY})。
- * 设施类型无行业字典,{@code industry} 如实为 {@code null};设施长度由 {@code length}(米)换算公里。
- * {@code updatedAt} 取台账/设施表最新更新时间。
+ * 管网类型无可信行业字典,{@code industry} 如实为 {@code null};设施长度由 {@code length}(米)换算公里。
+ * {@code updatedAt} 取各台账最新更新时间。
  */
 @Component
 @Primary
@@ -43,22 +49,29 @@ public class BusinessCockpitOverviewInfrastructureAdapter
     private final EquipmentTypeService equipmentTypeService;
     private final EquipmentBaseService equipmentBaseService;
     private final PipeNetworkBaseService pipeNetworkBaseService;
+    private final IWaterPlantInfoService plantService;
+    private final IWaterPumpStationService pumpStationService;
 
     public BusinessCockpitOverviewInfrastructureAdapter(
             EquipmentTypeService equipmentTypeService,
             EquipmentBaseService equipmentBaseService,
-            PipeNetworkBaseService pipeNetworkBaseService) {
+            PipeNetworkBaseService pipeNetworkBaseService,
+            IWaterPlantInfoService plantService,
+            IWaterPumpStationService pumpStationService) {
         this.equipmentTypeService = equipmentTypeService;
         this.equipmentBaseService = equipmentBaseService;
         this.pipeNetworkBaseService = pipeNetworkBaseService;
+        this.plantService = plantService;
+        this.pumpStationService = pumpStationService;
     }
 
     @Override
     public CockpitOverviewInfrastructureSnapshot load() {
-        Map<Integer, EquipmentType> types = equipmentTypes();
+        List<EquipmentType> equipmentTypes = safeList(equipmentTypeService.list());
+        Map<Integer, EquipmentType> types = equipmentTypes(equipmentTypes);
 
         List<CockpitOverviewInfrastructureSnapshot.SourceType> sourceTypes = new ArrayList<>();
-        for (EquipmentType type : safeList(equipmentTypeService.list())) {
+        for (EquipmentType type : equipmentTypes) {
             if (type == null || type.getId() == null) {
                 continue;
             }
@@ -70,9 +83,10 @@ public class BusinessCockpitOverviewInfrastructureAdapter
                     "SMART_DEVICE"));
         }
 
+        List<EquipmentBase> devices = safeList(equipmentBaseService.list());
         List<CockpitOverviewInfrastructureSnapshot.SourceCount> counts = new ArrayList<>();
         Map<Integer, Integer> deviceCountByType = new LinkedHashMap<>();
-        for (EquipmentBase device : safeList(equipmentBaseService.list())) {
+        for (EquipmentBase device : devices) {
             if (device == null || device.getEquipmentTypeId() == null) {
                 continue;
             }
@@ -84,7 +98,8 @@ public class BusinessCockpitOverviewInfrastructureAdapter
         }
 
         Map<String, FacilityAggregate> facilityByType = new LinkedHashMap<>();
-        for (PipeNetworkBase facility : safeList(pipeNetworkBaseService.list())) {
+        List<PipeNetworkBase> facilities = safeList(pipeNetworkBaseService.list());
+        for (PipeNetworkBase facility : facilities) {
             if (facility == null) {
                 continue;
             }
@@ -112,29 +127,74 @@ public class BusinessCockpitOverviewInfrastructureAdapter
                     new CockpitOverviewInfrastructureSnapshot.SourceValue(lengthKm, "km", null)));
         }
 
+        List<WaterPlantInfo> plants = safeList(plantService.list());
+        int plantCount = 0;
+        for (WaterPlantInfo plant : plants) {
+            if (!isBlank(plant.getPlantCode())) {
+                plantCount++;
+            }
+        }
+        addFacilityCount(sourceTypes, counts, "WATER_PLANT", "水厂", "WATER_SUPPLY", plantCount);
+
+        List<WaterPumpStation> stations = safeList(pumpStationService.list());
+        int waterStationCount = 0;
+        int drainageStationCount = 0;
+        for (WaterPumpStation station : stations) {
+            if (isBlank(station.getStationCode())) {
+                continue;
+            }
+            String stationType = trimToNull(station.getStationType());
+            if (PumpStationType.WATER_SUPPLY.equalsIgnoreCase(stationType)) {
+                waterStationCount++;
+            } else if (PumpStationType.DRAINAGE.equalsIgnoreCase(stationType)) {
+                drainageStationCount++;
+            }
+        }
+        addFacilityCount(sourceTypes, counts, "WATER_PUMP_STATION", "供水泵站", "WATER_SUPPLY", waterStationCount);
+        addFacilityCount(sourceTypes, counts, "DRAINAGE_PUMP_STATION", "排水泵站", "DRAINAGE", drainageStationCount);
+
         LocalDateTime updatedAt = null;
-        for (EquipmentBase device : safeList(equipmentBaseService.list())) {
+        for (EquipmentBase device : devices) {
             if (device == null) {
                 continue;
             }
             updatedAt = latest(updatedAt, device.getUpdateTime());
             updatedAt = latest(updatedAt, device.getCreateTime());
         }
-        for (PipeNetworkBase facility : safeList(pipeNetworkBaseService.list())) {
+        for (PipeNetworkBase facility : facilities) {
             if (facility == null) {
                 continue;
             }
             updatedAt = latest(updatedAt, facility.getUpdateTime());
             updatedAt = latest(updatedAt, facility.getCreateTime());
         }
+        for (WaterPlantInfo plant : plants) {
+            updatedAt = latest(updatedAt, plant.getUpdateTime());
+            updatedAt = latest(updatedAt, plant.getCreateTime());
+        }
+        for (WaterPumpStation station : stations) {
+            updatedAt = latest(updatedAt, station.getUpdateTime());
+            updatedAt = latest(updatedAt, station.getCreateTime());
+        }
 
         return new CockpitOverviewInfrastructureSnapshot(
                 offsetTime(updatedAt), sourceTypes, counts);
     }
 
-    private Map<Integer, EquipmentType> equipmentTypes() {
+    private static void addFacilityCount(
+            List<CockpitOverviewInfrastructureSnapshot.SourceType> types,
+            List<CockpitOverviewInfrastructureSnapshot.SourceCount> counts,
+            String code, String name, String industry, int count) {
+        if (count == 0) {
+            return;
+        }
+        types.add(new CockpitOverviewInfrastructureSnapshot.SourceType(code, name, industry, null, "FACILITY"));
+        counts.add(new CockpitOverviewInfrastructureSnapshot.SourceCount("FACILITY", code, count));
+    }
+
+    private static Map<Integer, EquipmentType> equipmentTypes(List<EquipmentType> values) {
         Map<Integer, EquipmentType> result = new HashMap<>();
-        for (EquipmentType type : safeList(equipmentTypeService.list())) {
+        for (EquipmentType type : values) {
             if (type != null && type.getId() != null) {
                 result.put(type.getId(), type);
             }
@@ -163,6 +223,10 @@ public class BusinessCockpitOverviewInfrastructureAdapter
         return value.trim();
     }
 
+    private static boolean isBlank(String value) {
+        return value == null || value.trim().isEmpty();
+    }
+
     private static <T> List<T> safeList(List<T> value) {
         return value == null ? Collections.emptyList() : value.stream().filter(Objects::nonNull).collect(Collectors.toList());
     }

+ 21 - 12
pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/overview/CockpitOverviewInfrastructureService.java

@@ -35,34 +35,42 @@ public class CockpitOverviewInfrastructureService {
         String updatedAt = snapshot == null || isBlank(snapshot.getUpdatedAt())
                 ? serverUpdatedAt
                 : snapshot.getUpdatedAt();
-        CockpitOverviewInfrastructureResponse.Freshness freshness =
-                new CockpitOverviewInfrastructureResponse.Freshness(
-                        "CURRENT", snapshot == null ? null : snapshot.getUpdatedAt(), serverUpdatedAt);
         TotalsBuilder totals = new TotalsBuilder();
         List<IndustryBuilder> industryBuilders = new ArrayList<>();
         industryBuilders.add(new IndustryBuilder("GAS", "gas", "燃气"));
         industryBuilders.add(new IndustryBuilder("WATER_SUPPLY", "waterSupply", "供水"));
         industryBuilders.add(new IndustryBuilder("DRAINAGE", "drainage", "排水"));
+        industryBuilders.add(new IndustryBuilder("MANHOLE", "manhole", "窨井"));
         int unknownTypeCount = 0;
         int typeKindMismatchCount = 0;
 
         if (snapshot != null && snapshot.getCounts() != null) {
-            Map<String, CockpitOverviewInfrastructureSnapshot.SourceType> types = types(snapshot);
+            Map<String, Map<String, CockpitOverviewInfrastructureSnapshot.SourceType>> types = types(snapshot);
             for (CockpitOverviewInfrastructureSnapshot.SourceCount count : snapshot.getCounts()) {
                 if (count == null || isBlank(count.getTypeCode())) {
                     continue;
                 }
-                CockpitOverviewInfrastructureSnapshot.SourceType type = types.get(count.getTypeCode());
+                Map<String, CockpitOverviewInfrastructureSnapshot.SourceType> byCode = types.get(count.getObjectKind());
+                CockpitOverviewInfrastructureSnapshot.SourceType type =
+                        byCode == null ? null : byCode.get(count.getTypeCode());
                 if (type == null) {
-                    unknownTypeCount += count.getCount();
-                } else if (!Objects.equals(count.getObjectKind(), type.getObjectKind())) {
-                    typeKindMismatchCount += count.getCount();
+                    boolean wrongKind = types.values().stream()
+                            .anyMatch(group -> group.containsKey(count.getTypeCode()));
+                    if (wrongKind) {
+                        typeKindMismatchCount += count.getCount();
+                    } else {
+                        unknownTypeCount += count.getCount();
+                    }
                 } else {
                     addResolvedCount(count, type, industryBuilders, totals);
                 }
             }
         }
 
+        CockpitOverviewInfrastructureResponse.Freshness freshness =
+                new CockpitOverviewInfrastructureResponse.Freshness(
+                        totals.facilityCount == 0 && totals.smartDeviceCount == 0 ? "EMPTY" : "CURRENT",
+                        snapshot == null ? null : snapshot.getUpdatedAt(), serverUpdatedAt);
         return new CockpitOverviewInfrastructureResponse(
                 requestId,
                 "v1",
@@ -84,15 +92,16 @@ public class CockpitOverviewInfrastructureService {
                 businessTime());
     }
 
-    private static Map<String, CockpitOverviewInfrastructureSnapshot.SourceType> types(
+    private static Map<String, Map<String, CockpitOverviewInfrastructureSnapshot.SourceType>> types(
             CockpitOverviewInfrastructureSnapshot snapshot) {
         if (snapshot.getTypes() == null) {
             return Collections.emptyMap();
         }
-        Map<String, CockpitOverviewInfrastructureSnapshot.SourceType> types = new LinkedHashMap<>();
+        Map<String, Map<String, CockpitOverviewInfrastructureSnapshot.SourceType>> types = new LinkedHashMap<>();
         for (CockpitOverviewInfrastructureSnapshot.SourceType type : snapshot.getTypes()) {
-            if (type != null && !isBlank(type.getCode())) {
-                types.put(type.getCode(), type);
+            if (type != null && !isBlank(type.getCode()) && !isBlank(type.getObjectKind())) {
+                types.computeIfAbsent(type.getObjectKind(), key -> new LinkedHashMap<>())
+                        .put(type.getCode(), type);
             }
         }
         return types;

+ 27 - 16
pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/overview/CockpitOverviewMonitoringService.java

@@ -133,7 +133,7 @@ public class CockpitOverviewMonitoringService {
             String selectedIndustry,
             RuntimeState currentState) {
         CockpitOverviewMonitoringSnapshot snapshot = currentState.getSnapshot();
-        Map<String, CockpitOverviewMonitoringSnapshot.SourceType> types = types(snapshot);
+        Map<String, Map<String, CockpitOverviewMonitoringSnapshot.SourceType>> types = types(snapshot);
         List<CockpitOverviewMonitoringSnapshot.SourceDevice> selectedDevices = new ArrayList<>();
         Map<String, Integer> distributionCounts = new LinkedHashMap<>();
         Map<String, CockpitOverviewMonitoringSnapshot.SourceType> distributionTypes = new LinkedHashMap<>();
@@ -149,13 +149,18 @@ public class CockpitOverviewMonitoringService {
                 unknownTypeCount++;
                 continue;
             }
-            CockpitOverviewMonitoringSnapshot.SourceType type = types.get(device.getTypeCode());
-            if (type == null || !isFormal(type)) {
-                unknownTypeCount++;
+            CockpitOverviewMonitoringSnapshot.SourceType type = typeOf(types, "SMART_DEVICE", device.getTypeCode());
+            if (type == null) {
+                CockpitOverviewMonitoringSnapshot.SourceType other = typeOf(types, "FACILITY", device.getTypeCode());
+                if (isFormal(other)) {
+                    typeKindMismatchCount++;
+                } else {
+                    unknownTypeCount++;
+                }
                 continue;
             }
-            if (!"SMART_DEVICE".equals(type.getObjectKind())) {
-                typeKindMismatchCount++;
+            if (!isFormal(type)) {
+                unknownTypeCount++;
                 continue;
             }
             if (selectedIndustry != null && !selectedIndustry.equals(type.getIndustry())) {
@@ -276,7 +281,7 @@ public class CockpitOverviewMonitoringService {
             CockpitOverviewMonitoringSnapshot snapshot,
             List<T> sources,
             java.util.function.Function<T, String> typeCodeGetter,
-            Map<String, CockpitOverviewMonitoringSnapshot.SourceType> types,
+            Map<String, Map<String, CockpitOverviewMonitoringSnapshot.SourceType>> types,
             String selectedIndustry,
             String expectedKind) {
         if (snapshot == null || sources == null) {
@@ -288,11 +293,9 @@ public class CockpitOverviewMonitoringService {
                 continue;
             }
             String typeCode = typeCodeGetter.apply(source);
-            CockpitOverviewMonitoringSnapshot.SourceType type = isBlank(typeCode) ? null : types.get(typeCode);
-            if (type == null) {
-                continue;
-            }
-            if (!isFormal(type) || !expectedKind.equals(type.getObjectKind())) {
+            CockpitOverviewMonitoringSnapshot.SourceType type =
+                    isBlank(typeCode) ? null : typeOf(types, expectedKind, typeCode);
+            if (!isFormal(type)) {
                 continue;
             }
             if (selectedIndustry != null && !selectedIndustry.equals(type.getIndustry())) {
@@ -309,15 +312,23 @@ public class CockpitOverviewMonitoringService {
                 && FORMAL_INDUSTRIES.contains(type.getIndustry());
     }
 
-    private static Map<String, CockpitOverviewMonitoringSnapshot.SourceType> types(
+    private static CockpitOverviewMonitoringSnapshot.SourceType typeOf(
+            Map<String, Map<String, CockpitOverviewMonitoringSnapshot.SourceType>> types,
+            String objectKind, String code) {
+        Map<String, CockpitOverviewMonitoringSnapshot.SourceType> byCode = types.get(objectKind);
+        return byCode == null ? null : byCode.get(code);
+    }
+
+    private static Map<String, Map<String, CockpitOverviewMonitoringSnapshot.SourceType>> types(
             CockpitOverviewMonitoringSnapshot snapshot) {
         if (snapshot == null || snapshot.getTypes() == null) {
             return Collections.emptyMap();
         }
-        Map<String, CockpitOverviewMonitoringSnapshot.SourceType> types = new LinkedHashMap<>();
+        Map<String, Map<String, CockpitOverviewMonitoringSnapshot.SourceType>> types = new LinkedHashMap<>();
         for (CockpitOverviewMonitoringSnapshot.SourceType type : snapshot.getTypes()) {
-            if (type != null && !isBlank(type.getCode())) {
-                types.putIfAbsent(type.getCode(), type);
+            if (type != null && !isBlank(type.getCode()) && !isBlank(type.getObjectKind())) {
+                types.computeIfAbsent(type.getObjectKind(), key -> new LinkedHashMap<>())
+                        .putIfAbsent(type.getCode(), type);
             }
         }
         return types;