LAPTOP-JI2IUVG1\26646 vor 4 Wochen
Ursprung
Commit
b4ebe75bb6

+ 57 - 3
pipe-network-service/zksy-system/src/main/java/com/zksy/base/alarm/service/impl/AlarmDataServiceImpl.java

@@ -7,13 +7,18 @@ import com.zksy.base.alarm.domain.AlarmData;
 import com.zksy.base.alarm.mapper.AlarmDataMapper;
 import com.zksy.base.alarm.mapper.AlarmDataMapper;
 import com.zksy.base.alarm.service.AlarmDataService;
 import com.zksy.base.alarm.service.AlarmDataService;
 import com.zksy.base.domain.EquipmentBase;
 import com.zksy.base.domain.EquipmentBase;
+import com.zksy.base.domain.EquipmentType;
 import com.zksy.base.mapper.EquipmentBaseMapper;
 import com.zksy.base.mapper.EquipmentBaseMapper;
+import com.zksy.base.mapper.EquipmentTypeMapper;
 import com.zksy.ops.mapper.WorkOrderMapper;
 import com.zksy.ops.mapper.WorkOrderMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import java.time.LocalDateTime;
 import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.List;
+import java.util.Set;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
 
 
 @Service
 @Service
@@ -23,6 +28,9 @@ public class AlarmDataServiceImpl extends ServiceImpl<AlarmDataMapper, AlarmData
     @Autowired
     @Autowired
     private EquipmentBaseMapper equipmentBaseMapper;
     private EquipmentBaseMapper equipmentBaseMapper;
 
 
+    @Autowired
+    private EquipmentTypeMapper equipmentTypeMapper;
+
     @Autowired
     @Autowired
     private WorkOrderMapper workOrderMapper;
     private WorkOrderMapper workOrderMapper;
 
 
@@ -34,11 +42,15 @@ public class AlarmDataServiceImpl extends ServiceImpl<AlarmDataMapper, AlarmData
         Page<AlarmData> page = new Page<>(pageNum, pageSize);
         Page<AlarmData> page = new Page<>(pageNum, pageSize);
         LambdaQueryWrapper<AlarmData> queryWrapper = new LambdaQueryWrapper<>();
         LambdaQueryWrapper<AlarmData> queryWrapper = new LambdaQueryWrapper<>();
 
 
-        // 当传入 equipmentType='drainage' 时,通过 equipment_base 关联查询排水类设备编码列表
-        // alarm_data 表的 warning_type 字段含义不同于 early_warning 表,不能直接用 '2' 过滤
+        // 当传入 equipmentType='drainage' 时,通过设备类型树关联查询排水类设备编码列表。
+        // 不能再写死历史类型 ID:当前排水根类型为 2,子类型由 equipment_type.parent_id 维护。
         if ("drainage".equals(equipmentType)) {
         if ("drainage".equals(equipmentType)) {
+            List<String> drainageTypeIds = findDrainageTypeIds();
+            if (drainageTypeIds.isEmpty()) {
+                return new Page<>(pageNum, pageSize);
+            }
             LambdaQueryWrapper<EquipmentBase> eqQuery = new LambdaQueryWrapper<>();
             LambdaQueryWrapper<EquipmentBase> eqQuery = new LambdaQueryWrapper<>();
-            eqQuery.in(EquipmentBase::getEquipmentTypeId, "6", "7", "8", "9")
+            eqQuery.in(EquipmentBase::getEquipmentTypeId, drainageTypeIds)
                    .select(EquipmentBase::getEquipmentCode);
                    .select(EquipmentBase::getEquipmentCode);
             List<EquipmentBase> devices = equipmentBaseMapper.selectList(eqQuery);
             List<EquipmentBase> devices = equipmentBaseMapper.selectList(eqQuery);
             List<String> deviceCodes = devices.stream()
             List<String> deviceCodes = devices.stream()
@@ -73,6 +85,48 @@ public class AlarmDataServiceImpl extends ServiceImpl<AlarmDataMapper, AlarmData
         return result;
         return result;
     }
     }
 
 
+    /**
+     * 读取排水设备根类型及其全部后代类型,避免设备类型调整后报警列表被错误过滤为空。
+     */
+    private List<String> findDrainageTypeIds() {
+        List<EquipmentType> allTypes = equipmentTypeMapper.selectList(null);
+        if (allTypes == null || allTypes.isEmpty()) {
+            return new ArrayList<>();
+        }
+
+        Set<Integer> drainageIds = new LinkedHashSet<>();
+        for (EquipmentType type : allTypes) {
+            if (type == null || type.getId() == null) {
+                continue;
+            }
+            boolean namedDrainageRoot = "排水设备".equals(type.getTypeName())
+                    && (type.getParentId() == null || type.getParentId() == 0);
+            boolean currentDrainageRoot = type.getId() == 2
+                    && (type.getParentId() == null || type.getParentId() == 0);
+            if (namedDrainageRoot || currentDrainageRoot) {
+                drainageIds.add(type.getId());
+            }
+        }
+
+        // 兼容数据中根类型名称被修改但仍使用稳定业务 ID=2 的情况。
+        if (drainageIds.isEmpty()) {
+            drainageIds.add(2);
+        }
+
+        boolean added;
+        do {
+            added = false;
+            for (EquipmentType type : allTypes) {
+                if (type != null && type.getId() != null && type.getParentId() != null
+                        && drainageIds.contains(type.getParentId())) {
+                    added |= drainageIds.add(type.getId());
+                }
+            }
+        } while (added);
+
+        return drainageIds.stream().map(String::valueOf).collect(Collectors.toList());
+    }
+
     private void fillWorkOrderStatus(List<AlarmData> records) {
     private void fillWorkOrderStatus(List<AlarmData> records) {
         if (records == null || records.isEmpty()) {
         if (records == null || records.isEmpty()) {
             return;
             return;