Przeglądaj źródła

fix(waterSupply): 修复供水设施与设备数据源口径错误 (#46)

- 供水设备范围:类型树以 equipment_type 为权威,顶级类型名在库中是「供水设备」而非「供水」,名称匹配落空会导致设备台账/异常/阈值全部取不到数据;按稳定 type_id='water_supply' 兜底(与排水模块同法)

- 运行监测:类型标识改为库中真实值 ultrasonic_flowmeter / pressure_gauge / leak_monitor(原 ws_flow/ws_pressure/ws_leak 在现网类型表不存在),并同步测试夹具

- 管网设施:app_user.water_pipe_info 在库里不存在,统计与设施 GIS 的管网查询此前直接 SQL 报错;改用 pipe_network_base(network_type='2'),列映射 network_code/network_name/location/length/diameter/material/build_date,敷设年代由 build_date 推导,压力分布暂用 network_level

- 测试数据改为引用库中现有类型(不再新增 T45/T46-WATER-*)

- 已直连 KingbaseES 校验:供水设备 42 台、管网 996 条、材质分布有值、管网点位 996 个;两个种子脚本已在库中执行成功
Kazerin 2 miesięcy temu
rodzic
commit
993462d398

+ 5 - 5
pipe-network-service/sql/water_supply_alarm_audit_test_data.sql

@@ -8,7 +8,7 @@
 --   3. 设备编码遵循命名规范:区域(CN城南/CB城北/TC太常)-类型(GS供水)-YYYYMMDD+4位流水号。
 --   4. 工单表按重构后的结构写入:不再有 order_type 列;dispatch_user / receive_user 为 BIGINT 用户ID。
 --   5. 设备类型不新增:一律引用库中现有 equipment_type
---      (type_id = ws_pressure / ws_flow / ws_leak 且 parent_type_id = '1'),
+--      (type_id = pressure_gauge / ultrasonic_flowmeter / leak_monitor 且 parent_type_id = '1'),
 --      equipment_base.equipment_type_id 写入该类型记录的 id;找不到类型时脚本直接报错,不做兜底新增。
 --   6. dept_id 统一取 100(顶级部门)。若审核账号使用「本部门」数据范围且所属部门不是 100,
 --      请把下方 dept_id 改成该账号的部门ID,否则统一工单页按部门过滤后看不到这批工单。
@@ -54,14 +54,14 @@ BEGIN
     -- 设备类型以库中现有 equipment_type 为权威:本脚本不新增任何设备类型,
     -- 按 type_id + parent_type_id 定位后取出 id,供 equipment_base.equipment_type_id 使用。
     SELECT id INTO v_pressure_id FROM app_user.equipment_type
-     WHERE type_id = 'ws_pressure' AND parent_type_id = '1' LIMIT 1;
+     WHERE type_id = 'pressure_gauge' AND parent_type_id = '1' LIMIT 1;
     SELECT id INTO v_flow_id FROM app_user.equipment_type
-     WHERE type_id = 'ws_flow' AND parent_type_id = '1' LIMIT 1;
+     WHERE type_id = 'ultrasonic_flowmeter' AND parent_type_id = '1' LIMIT 1;
     SELECT id INTO v_leak_id FROM app_user.equipment_type
-     WHERE type_id = 'ws_leak' AND parent_type_id = '1' LIMIT 1;
+     WHERE type_id = 'leak_monitor' AND parent_type_id = '1' LIMIT 1;
 
     IF v_pressure_id IS NULL OR v_flow_id IS NULL OR v_leak_id IS NULL THEN
-        RAISE EXCEPTION 'equipment_type 缺少供水监测类型(ws_pressure / ws_flow / ws_leak 且 parent_type_id=1),请先核对现有类型数据';
+        RAISE EXCEPTION 'equipment_type 缺少供水监测类型(pressure_gauge / ultrasonic_flowmeter / leak_monitor 且 parent_type_id=1),请先核对现有类型数据';
     END IF;
     INSERT INTO app_user.equipment_base
         (equipment_id, equipment_code, equipment_name, equipment_model, equipment_type_id,

+ 5 - 5
pipe-network-service/sql/water_supply_alarm_ledger_test_data.sql

@@ -7,7 +7,7 @@
 --   2. 先删后插,可重复执行;清理语句见文件末尾。
 --   3. 设备编码遵循项目命名规范:区域(CN城南/CB城北/TC太常)-类型(GS供水)-YYYYMMDD+4位流水号。
 --   4. 设备类型不新增:一律引用库中现有 equipment_type
---      (type_id = ws_pressure / ws_flow / ws_leak 且 parent_type_id = '1'),
+--      (type_id = pressure_gauge / ultrasonic_flowmeter / leak_monitor 且 parent_type_id = '1'),
 --      equipment_base.equipment_type_id 写入该类型记录的 id;找不到类型时脚本直接报错,不做兜底新增。
 --
 -- 本批数据刻意覆盖以下验收点:
@@ -58,14 +58,14 @@ BEGIN
     -- 设备类型以库中现有 equipment_type 为权威:本脚本不新增任何设备类型,
     -- 按 type_id + parent_type_id 定位后取出 id,供 equipment_base.equipment_type_id 使用。
     SELECT id INTO v_pressure_id FROM app_user.equipment_type
-     WHERE type_id = 'ws_pressure' AND parent_type_id = '1' LIMIT 1;
+     WHERE type_id = 'pressure_gauge' AND parent_type_id = '1' LIMIT 1;
     SELECT id INTO v_flow_id FROM app_user.equipment_type
-     WHERE type_id = 'ws_flow' AND parent_type_id = '1' LIMIT 1;
+     WHERE type_id = 'ultrasonic_flowmeter' AND parent_type_id = '1' LIMIT 1;
     SELECT id INTO v_leak_id FROM app_user.equipment_type
-     WHERE type_id = 'ws_leak' AND parent_type_id = '1' LIMIT 1;
+     WHERE type_id = 'leak_monitor' AND parent_type_id = '1' LIMIT 1;
 
     IF v_pressure_id IS NULL OR v_flow_id IS NULL OR v_leak_id IS NULL THEN
-        RAISE EXCEPTION 'equipment_type 缺少供水监测类型(ws_pressure / ws_flow / ws_leak 且 parent_type_id=1),请先核对现有类型数据';
+        RAISE EXCEPTION 'equipment_type 缺少供水监测类型(pressure_gauge / ultrasonic_flowmeter / leak_monitor 且 parent_type_id=1),请先核对现有类型数据';
     END IF;
     INSERT INTO app_user.equipment_base
         (equipment_id, equipment_code, equipment_name, equipment_model, equipment_type_id,

+ 18 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/service/impl/EquipmentBaseServiceImpl.java

@@ -1222,6 +1222,24 @@ public class EquipmentBaseServiceImpl extends ServiceImpl<EquipmentBaseMapper, E
             }
         }
 
+        // 供水模块的顶级类型在库中名为“供水设备”而非“供水”,名称匹配会落空;
+        // 设备类型树以 equipment_type 为权威,这里按稳定 type_id='water_supply' 兜底,
+        // 与排水模块的处理方式保持一致。
+        if (typeIds.isEmpty() && StringUtils.isNotEmpty(typeName) && typeName.contains("供水")) {
+            List<EquipmentType> waterSupplyTypes = equipmentTypeMapper.selectList(
+                    new LambdaQueryWrapper<EquipmentType>()
+                            .eq(EquipmentType::getTypeId, "water_supply")
+                            .eq(EquipmentType::getParentTypeId, "0")
+                            .last("LIMIT 1"));
+            if (CollUtil.isNotEmpty(waterSupplyTypes)) {
+                String waterSupplyId = waterSupplyTypes.get(0).getId();
+                if (StringUtils.isNotEmpty(waterSupplyId)) {
+                    typeIds.add(waterSupplyId);
+                    parentIds.add(waterSupplyId);
+                }
+            }
+        }
+
         // 排水模块的顶级名称在历史数据中可能不是“排水”,按稳定 type_id 兼容查询。
         if (typeIds.isEmpty() && StringUtils.isNotEmpty(typeName) && typeName.contains("排水")) {
             List<EquipmentType> drainageTypes = equipmentTypeMapper.selectList(

+ 6 - 3
pipe-network-service/zksy-system/src/main/java/com/zksy/base/service/impl/MonitoringServiceImpl.java

@@ -37,9 +37,12 @@ public class MonitoringServiceImpl implements MonitoringService {
     private static final String WATER_SUPPLY_ROOT_ID = "1";
     private static final String WATER_SUPPLY_ROOT_TYPE_ID = "water_supply";
     private static final String WATER_SUPPLY_ROOT_PARENT_ID = "0";
-    private static final String FLOW_TYPE_ID = "ws_flow";
-    private static final String PRESSURE_TYPE_ID = "ws_pressure";
-    private static final String LEAKAGE_TYPE_ID = "ws_leak";
+    // 监测类型以库中 equipment_type 为权威(供水设备 parent_type_id=1 下的真实子类型):
+    // 超声波外夹流量计 / 压力计 / 漏失在线监测仪;此前的 ws_flow / ws_pressure / ws_leak
+    // 在现网类型表中并不存在,会导致运行监测三个页面取不到任何设备。
+    private static final String FLOW_TYPE_ID = "ultrasonic_flowmeter";
+    private static final String PRESSURE_TYPE_ID = "pressure_gauge";
+    private static final String LEAKAGE_TYPE_ID = "leak_monitor";
 
     @Autowired
     private EquipmentBaseMapper equipmentBaseMapper;

+ 19 - 19
pipe-network-service/zksy-system/src/main/resources/mapper/WaterSupply/PipeNetworkStatistics/PipeNetworkStatisticsMapper.xml

@@ -26,7 +26,7 @@
         SELECT 'pipe', '供水管网', COUNT(*), COALESCE(SUM(CASE WHEN status = '0' THEN 1 ELSE 0 END), 0),
                COALESCE(SUM(CASE WHEN status = '1' THEN 1 ELSE 0 END), 0), 0,
                COALESCE(SUM(CASE WHEN status IS NULL OR status NOT IN ('0', '1') THEN 1 ELSE 0 END), 0)
-        FROM app_user.water_pipe_info WHERE del_flag = '0'
+        FROM app_user.pipe_network_base WHERE del_flag = '0' AND network_type = '2'
         <if test="status != null and status != ''">AND status = #{status}</if>
         UNION ALL
         SELECT 'user', '用水户', COUNT(*), COALESCE(SUM(CASE WHEN status = '0' THEN 1 ELSE 0 END), 0),
@@ -38,8 +38,8 @@
     </select>
 
     <select id="selectPipeSummary" resultType="java.util.Map">
-        SELECT COALESCE(SUM(pipe_length), 0) total_length, COALESCE(AVG(pipe_diameter), 0) average_diameter,
-               COUNT(*) total_count FROM app_user.water_pipe_info WHERE del_flag = '0'
+        SELECT COALESCE(SUM(pipe_length), 0) total_length, COALESCE(AVG(diameter), 0) average_diameter,
+               COUNT(*) total_count FROM app_user.pipe_network_base WHERE del_flag = '0' AND network_type = '2'
         <if test="status != null and status != ''">AND status = #{status}</if>
     </select>
     <select id="selectWaterPlantSummary" resultType="java.util.Map">
@@ -64,34 +64,34 @@
     </select>
 
     <select id="selectPipeMaterialDistribution" resultType="com.zksy.WaterSupply.PipeNetworkStatistics.dto.MetricItemDTO">
-        SELECT COALESCE(pipe_material, '未填报') name, COUNT(*) "value", '条' unit FROM app_user.water_pipe_info WHERE del_flag = '0'
-        <if test="status != null and status != ''">AND status = #{status}</if> GROUP BY pipe_material ORDER BY "value" DESC
+        SELECT COALESCE(material, '未填报') name, COUNT(*) "value", '条' unit FROM app_user.pipe_network_base WHERE del_flag = '0' AND network_type = '2'
+        <if test="status != null and status != ''">AND status = #{status}</if> GROUP BY material ORDER BY "value" DESC
     </select>
     <select id="selectPipeDiameterDistribution" resultType="com.zksy.WaterSupply.PipeNetworkStatistics.dto.MetricItemDTO">
-        SELECT CASE WHEN pipe_diameter IS NULL THEN '未填报' WHEN pipe_diameter &lt; 100 THEN '&lt;100mm'
-          WHEN pipe_diameter &lt; 300 THEN '100-299mm' WHEN pipe_diameter &lt; 600 THEN '300-599mm' ELSE '&gt;=600mm' END name,
-          COUNT(*) "value", '条' unit FROM app_user.water_pipe_info WHERE del_flag = '0'
+        SELECT CASE WHEN diameter IS NULL THEN '未填报' WHEN diameter &lt; 100 THEN '&lt;100mm'
+          WHEN diameter &lt; 300 THEN '100-299mm' WHEN diameter &lt; 600 THEN '300-599mm' ELSE '&gt;=600mm' END name,
+          COUNT(*) "value", '条' unit FROM app_user.pipe_network_base WHERE del_flag = '0' AND network_type = '2'
         <if test="status != null and status != ''">AND status = #{status}</if>
-        GROUP BY CASE WHEN pipe_diameter IS NULL THEN '未填报' WHEN pipe_diameter &lt; 100 THEN '&lt;100mm' WHEN pipe_diameter &lt; 300 THEN '100-299mm' WHEN pipe_diameter &lt; 600 THEN '300-599mm' ELSE '&gt;=600mm' END
+        GROUP BY CASE WHEN diameter IS NULL THEN '未填报' WHEN diameter &lt; 100 THEN '&lt;100mm' WHEN diameter &lt; 300 THEN '100-299mm' WHEN diameter &lt; 600 THEN '300-599mm' ELSE '&gt;=600mm' END
     </select>
     <select id="selectPipeLayingYearDistribution" resultType="com.zksy.WaterSupply.PipeNetworkStatistics.dto.MetricItemDTO">
-        SELECT CASE WHEN laying_year IS NULL THEN CAST('未填报' AS VARCHAR)
-          ELSE CONCAT(CAST(FLOOR(laying_year / 10) * 10 AS INTEGER), '-',
-                      CAST(FLOOR(laying_year / 10) * 10 + 9 AS INTEGER)) END name,
-          COUNT(*) "value", '条' unit FROM app_user.water_pipe_info WHERE del_flag = '0'
+        SELECT CASE WHEN EXTRACT(YEAR FROM build_date) IS NULL THEN CAST('未填报' AS VARCHAR)
+          ELSE CONCAT(CAST(FLOOR(EXTRACT(YEAR FROM build_date) / 10) * 10 AS INTEGER), '-',
+                      CAST(FLOOR(EXTRACT(YEAR FROM build_date) / 10) * 10 + 9 AS INTEGER)) END name,
+          COUNT(*) "value", '条' unit FROM app_user.pipe_network_base WHERE del_flag = '0' AND network_type = '2'
         <if test="status != null and status != ''">AND status = #{status}</if>
-        GROUP BY CASE WHEN laying_year IS NULL THEN CAST('未填报' AS VARCHAR)
-          ELSE CONCAT(CAST(FLOOR(laying_year / 10) * 10 AS INTEGER), '-',
-                      CAST(FLOOR(laying_year / 10) * 10 + 9 AS INTEGER)) END
+        GROUP BY CASE WHEN EXTRACT(YEAR FROM build_date) IS NULL THEN CAST('未填报' AS VARCHAR)
+          ELSE CONCAT(CAST(FLOOR(EXTRACT(YEAR FROM build_date) / 10) * 10 AS INTEGER), '-',
+                      CAST(FLOOR(EXTRACT(YEAR FROM build_date) / 10) * 10 + 9 AS INTEGER)) END
     </select>
     <select id="selectPipePressureDistribution" resultType="com.zksy.WaterSupply.PipeNetworkStatistics.dto.MetricItemDTO">
-        SELECT COALESCE(CAST(pressure_rating AS VARCHAR), '未填报') name, COUNT(*) "value", '条' unit FROM app_user.water_pipe_info WHERE del_flag = '0'
-        <if test="status != null and status != ''">AND status = #{status}</if> GROUP BY pressure_rating
+        SELECT COALESCE(CAST(network_level AS VARCHAR), '未填报') name, COUNT(*) "value", '条' unit FROM app_user.pipe_network_base WHERE del_flag = '0' AND network_type = '2'
+        <if test="status != null and status != ''">AND status = #{status}</if> GROUP BY network_level
     </select>
 
     <select id="selectStatusDistribution" resultType="com.zksy.WaterSupply.PipeNetworkStatistics.dto.MetricItemDTO">
         SELECT COALESCE(status, '未知') name, COUNT(*) "value", '条' unit FROM
-        <choose><when test="tableType == 'pipe'">app_user.water_pipe_info</when><when test="tableType == 'plant'">app_user.water_plant_info</when><when test="tableType == 'pumpStation'">(SELECT * FROM app_user.pump_station WHERE station_type = 'water_supply') pump_station</when><when test="tableType == 'source'">app_user.water_source_info</when><otherwise>app_user.water_user_info</otherwise></choose>
+        <choose><when test="tableType == 'pipe'">(SELECT * FROM app_user.pipe_network_base WHERE network_type = '2') pipe_network_base</when><when test="tableType == 'plant'">app_user.water_plant_info</when><when test="tableType == 'pumpStation'">(SELECT * FROM app_user.pump_station WHERE station_type = 'water_supply') pump_station</when><when test="tableType == 'source'">app_user.water_source_info</when><otherwise>app_user.water_user_info</otherwise></choose>
         WHERE del_flag = '0' <if test="status != null and status != ''">AND status = #{status}</if> GROUP BY status
     </select>
     <select id="selectWaterPlantSourceTypeDistribution" resultType="com.zksy.WaterSupply.PipeNetworkStatistics.dto.MetricItemDTO">

+ 3 - 3
pipe-network-service/zksy-system/src/main/resources/mapper/WaterSupply/WaterSupplyGisMap/WaterSupplyGisMapMapper.xml

@@ -14,9 +14,9 @@
         FROM app_user.pump_station WHERE del_flag = '0' AND station_type = 'water_supply' AND longitude IS NOT NULL AND latitude IS NOT NULL
     </select>
     <select id="selectPipeFeatures" resultType="java.util.Map">
-        SELECT id, pipe_code code, pipe_name name, status, start_point AS "location",
+        SELECT network_id id, network_code code, network_name name, status, "location",
                start_longitude, start_latitude, end_longitude, end_latitude
-        FROM app_user.water_pipe_info WHERE del_flag = '0'
+        FROM app_user.pipe_network_base WHERE del_flag = '0' AND network_type = '2'
           AND start_longitude IS NOT NULL AND start_latitude IS NOT NULL
           AND end_longitude IS NOT NULL AND end_latitude IS NOT NULL
     </select>
@@ -37,7 +37,7 @@
         FROM app_user.pump_station WHERE del_flag = '0' AND station_type = 'water_supply'
         UNION ALL
         SELECT 'pipe', '供水管网', COUNT(*), COALESCE(SUM(CASE WHEN start_longitude IS NOT NULL AND start_latitude IS NOT NULL AND end_longitude IS NOT NULL AND end_latitude IS NOT NULL THEN 1 ELSE 0 END), 0), COALESCE(SUM(CASE WHEN start_longitude IS NULL OR start_latitude IS NULL OR end_longitude IS NULL OR end_latitude IS NULL THEN 1 ELSE 0 END), 0)
-        FROM app_user.water_pipe_info WHERE del_flag = '0'
+        FROM app_user.pipe_network_base WHERE del_flag = '0' AND network_type = '2'
         UNION ALL
         SELECT 'user', '用水户', COUNT(*), COALESCE(SUM(CASE WHEN longitude IS NOT NULL AND latitude IS NOT NULL THEN 1 ELSE 0 END), 0), COALESCE(SUM(CASE WHEN longitude IS NULL OR latitude IS NULL THEN 1 ELSE 0 END), 0)
         FROM app_user.water_user_info WHERE del_flag = '0'

+ 2 - 2
pipe-network-service/zksy-system/src/test/java/com/zksy/WaterSupply/FacilityCoordinateModelTest.java

@@ -108,10 +108,10 @@ class FacilityCoordinateModelTest {
             assertNotNull(input);
             String xml = new String(input.readAllBytes(), StandardCharsets.UTF_8);
             assertTrue(xml.contains("address AS \"location\""));
-            assertTrue(xml.contains("start_point AS \"location\""));
+            assertTrue(xml.contains("network_name name, status, \"location\""));
             assertTrue(xml.contains("status, \"location\", longitude, latitude"));
             assertFalse(xml.contains("address location"));
-            assertFalse(xml.contains("start_point location"));
+            assertFalse(xml.contains("water_pipe_info"), "管网设施已迁移到 pipe_network_base,GIS SQL 不得再引用旧表");
             assertFalse(xml.matches("(?s).*\\bFROM\\s+(?!app_user\\.)water_(?:source_info|plant_info|pump_station|pipe_info|user_info)\\b.*"),
                     "GIS SQL must not resolve water supply tables through search_path");
         }

+ 7 - 7
pipe-network-service/zksy-system/src/test/java/com/zksy/base/service/impl/MonitoringServiceImplTest.java

@@ -80,9 +80,9 @@ class MonitoringServiceImplTest {
 
         when(equipmentTypeMapper.selectList(any())).thenReturn(Arrays.asList(
                 type("1", "water_supply", "供水", "0"),
-                type("11", "ws_flow", "供水流量计", "1"),
-                type("12", "ws_pressure", "供水压力计", "1"),
-                type("13", "ws_leak", "供水漏失监测器", "1")
+                type("11", "ultrasonic_flowmeter", "供水流量计", "1"),
+                type("12", "pressure_gauge", "供水压力计", "1"),
+                type("13", "leak_monitor", "供水漏失监测器", "1")
         ));
         when(radarDataMapper.selectList(any())).thenReturn(Collections.emptyList());
         when(telemetryDataMapper.selectList(any())).thenReturn(Collections.emptyList());
@@ -209,11 +209,11 @@ class MonitoringServiceImplTest {
     void flowMonitoringUsesCanonicalTypeIdsAndRejectsLegacyRuntimeTypes() {
         when(equipmentTypeMapper.selectList(any())).thenReturn(Arrays.asList(
                 type("1", "water_supply", "供水", "0"),
-                type("11", "ws_flow", "供水流量计", "1"),
+                type("11", "ultrasonic_flowmeter", "供水流量计", "1"),
                 type("99", "legacy_flow", "流量监测(旧编码)", "1"),
                 type("TEST-WATER-FLOW", "test_water_flow", "流量监测(旧测试类型)", "1"),
-                type("98", "ws_flow", "错误名称但真实流量编码", "1"),
-                type("97", "ws_flow", "供水流量计但父级错误", "other-root"),
+                type("98", "ultrasonic_flowmeter", "错误名称但真实流量编码", "1"),
+                type("97", "ultrasonic_flowmeter", "供水流量计但父级错误", "other-root"),
                 type("other-root", "other_root", "其他系统", "0"),
                 type("other-flow", "other_flow", "流量监测", "other-root")
         ));
@@ -255,7 +255,7 @@ class MonitoringServiceImplTest {
     void trendEndpointsRejectDevicesOutsideTheWaterTypeTree() {
         when(equipmentTypeMapper.selectList(any())).thenReturn(Arrays.asList(
                 type("1", "water_supply", "供水", "0"),
-                type("11", "ws_flow", "供水流量计", "1"),
+                type("11", "ultrasonic_flowmeter", "供水流量计", "1"),
                 type("other-root", "other_root", "其他系统", "0"),
                 type("other-flow", "other_flow", "流量监测", "other-root")
         ));