zengy 3 днів тому
батько
коміт
ce4e7c7537
15 змінених файлів з 346 додано та 120 видалено
  1. 74 1
      pipe-network-service/zksy-admin/src/main/java/com/zksy/web/controller/base/EquipmentBaseController.java
  2. 0 6
      pipe-network-service/zksy-system/pom.xml
  3. 4 14
      pipe-network-service/zksy-system/src/main/java/com/zksy/base/domain/dto/EquipmentBatchCreateDTO.java
  4. 55 0
      pipe-network-service/zksy-system/src/main/java/com/zksy/base/domain/dto/EquipmentExportDTO.java
  5. 5 0
      pipe-network-service/zksy-system/src/main/java/com/zksy/base/perception/mapper/PerceptionMapper.java
  6. 9 0
      pipe-network-service/zksy-system/src/main/java/com/zksy/base/perception/service/PerceptionService.java
  7. 89 0
      pipe-network-service/zksy-system/src/main/java/com/zksy/base/perception/service/impl/PerceptionServiceImpl.java
  8. 3 0
      pipe-network-service/zksy-system/src/main/java/com/zksy/base/service/EquipmentTypeService.java
  9. 9 3
      pipe-network-service/zksy-system/src/main/java/com/zksy/base/service/impl/EquipmentBatchCreateServiceImpl.java
  10. 21 0
      pipe-network-service/zksy-system/src/main/java/com/zksy/base/service/impl/EquipmentTypeServiceImpl.java
  11. 12 7
      pipe-network-service/zksy-system/src/main/java/com/zksy/base/util/EquipmentImportTemplateWriter.java
  12. 10 0
      pipe-network-service/zksy-system/src/main/resources/mapper/perception/PerceptionMapper.xml
  13. 0 46
      pipe-network-service/zksy-system/src/test/java/com/zksy/cockpit/collectionRecords/CollectionThresholdRulesPackagingTest.java
  14. 37 31
      sql/pipi_ner_full.sql
  15. 18 12
      verify/bean-threshold-regression/README.md

+ 74 - 1
pipe-network-service/zksy-admin/src/main/java/com/zksy/web/controller/base/EquipmentBaseController.java

@@ -3,11 +3,16 @@ package com.zksy.web.controller.base;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.zksy.base.domain.EquipmentBase;
+import com.zksy.base.domain.EquipmentType;
 import com.zksy.base.domain.dto.EquipmentBatchCreateDTO;
 import com.zksy.base.domain.dto.EquipmentBatchCreateResult;
+import com.zksy.base.domain.dto.EquipmentExportDTO;
 import com.zksy.base.domain.vo.EquipmentBaseVO;
+import com.zksy.base.enums.DistrictEnum;
+import com.zksy.base.perception.service.PerceptionService;
 import com.zksy.base.service.EquipmentBaseService;
 import com.zksy.base.service.EquipmentBatchCreateService;
+import com.zksy.base.service.EquipmentTypeService;
 import com.zksy.base.util.EquipmentImportTemplateWriter;
 import com.zksy.common.annotation.Anonymous;
 import com.zksy.common.annotation.Log;
@@ -24,8 +29,13 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.Comparator;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 @Slf4j
 @RestController
@@ -33,12 +43,21 @@ import java.util.Map;
 @Api(tags = "物联感知设备-设备管理")
 public class EquipmentBaseController {
 
+    private static final long EXPORT_MAX_ROWS = 100000;
+    private static final DateTimeFormatter LAST_COMM_TIME_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+
     @Autowired
     private EquipmentBaseService service;
 
     @Autowired
     private EquipmentBatchCreateService equipmentBatchCreateService;
 
+    @Autowired
+    private EquipmentTypeService equipmentTypeService;
+
+    @Autowired
+    private PerceptionService perceptionService;
+
     @GetMapping
     @ApiOperation(value = "设备基础信息分页")
     @Anonymous
@@ -103,7 +122,7 @@ public class EquipmentBaseController {
         FileUtils.setAttachmentResponseHeader(response, "设备台账导入模板.xlsx");
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
         response.setCharacterEncoding("utf-8");
-        EquipmentImportTemplateWriter.write(response.getOutputStream());
+        EquipmentImportTemplateWriter.write(response.getOutputStream(), equipmentTypeService.listImportableTypeNames());
     }
 
     @PostMapping("/importData")
@@ -124,6 +143,60 @@ public class EquipmentBaseController {
         return AjaxResult.success(result.getMessage(), result);
     }
 
+    @PostMapping("/export")
+    @ApiOperation(value = "导出设备台账(列同导入模板,末尾追加最后通讯时间)")
+    @Log(title = "设备台账导出", businessType = BusinessType.EXPORT)
+    public void exportEquipment(HttpServletResponse response,
+                                @RequestParam(required = false) String equipmentCode,
+                                @RequestParam(required = false) String equipmentName,
+                                @ApiParam("设备类型ID") @RequestParam(required = false) Integer equipmentTypeId,
+                                @ApiParam("设备根类型ID(菜单 rootTypeId 数据范围过滤)")
+                                @RequestParam(required = false) Integer rootTypeId,
+                                @ApiParam("设备类型ID集合") @RequestParam(required = false) List<Integer> equipmentTypeIds,
+                                @ApiParam("在线状态(0-离线,1-在线)") @RequestParam(required = false) Integer onlineStatus,
+                                @ApiParam("报警状态(0-正常,1-报警)") @RequestParam(required = false) Integer alarmStatus,
+                                @ApiParam("设备编码/名称模糊关键字") @RequestParam(required = false) String keyword) throws Exception {
+        Page<EquipmentBaseVO> page = service.findByPage(1, EXPORT_MAX_ROWS, equipmentCode, equipmentName,
+                equipmentTypeId, rootTypeId, equipmentTypeIds, onlineStatus, alarmStatus, null, null, null, keyword);
+        Map<Integer, Integer> typeRank = new HashMap<>();
+        List<EquipmentType> orderedTypes = equipmentTypeService.listOrdered();
+        for (int i = 0; i < orderedTypes.size(); i++) {
+            EquipmentType type = orderedTypes.get(i);
+            if (type != null && type.getId() != null) {
+                typeRank.put(type.getId(), i);
+            }
+        }
+        List<EquipmentBaseVO> sortedRecords = page.getRecords().stream()
+                .sorted(Comparator
+                        .comparingInt((EquipmentBaseVO vo) -> typeRank.getOrDefault(toInt(vo.getEquipmentTypeId()), Integer.MAX_VALUE))
+                        .thenComparing(vo -> vo.getEquipmentCode() == null ? "" : vo.getEquipmentCode()))
+                .collect(Collectors.toList());
+        Map<String, LocalDateTime> lastCommTimes = perceptionService.getLastCommTimes(sortedRecords);
+        FileUtils.setAttachmentResponseHeader(response, "设备台账.xlsx");
+        List<EquipmentExportDTO> rows = sortedRecords.stream().map(vo -> {
+            LocalDateTime lastCommTime = lastCommTimes.get(vo.getEquipmentCode());
+            String formatted = lastCommTime == null ? "" : lastCommTime.format(LAST_COMM_TIME_FORMAT);
+            return EquipmentExportDTO.from(vo, districtName(vo.getDistrict()), formatted);
+        }).collect(Collectors.toList());
+        new ExcelUtil<>(EquipmentExportDTO.class).exportExcel(response, rows, "设备台账");
+    }
+
+    private String districtName(Integer district) {
+        String name = DistrictEnum.getDescByCode(district);
+        return name == null ? "" : name;
+    }
+
+    private Integer toInt(String value) {
+        if (value == null || value.trim().isEmpty()) {
+            return null;
+        }
+        try {
+            return Integer.valueOf(value.trim());
+        } catch (NumberFormatException ignored) {
+            return null;
+        }
+    }
+
     @PostMapping
     @ApiOperation(value = "新增设备基础信息")
     @Log(title = "新增设备基础信息", businessType = BusinessType.INSERT)

+ 0 - 6
pipe-network-service/zksy-system/pom.xml

@@ -12,12 +12,6 @@
     <artifactId>zksy-system</artifactId>
 
     <dependencies>
-        <!-- 仅共享纯阈值规则,不引入采集服务的组件和写入服务。 -->
-        <dependency>
-            <groupId>com.zksy</groupId>
-            <artifactId>monitoring-threshold-rules</artifactId>
-            <version>1.0.0</version>
-        </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-test</artifactId>

+ 4 - 14
pipe-network-service/zksy-system/src/main/java/com/zksy/base/domain/dto/EquipmentBatchCreateDTO.java

@@ -23,20 +23,7 @@ public class EquipmentBatchCreateDTO {
     private String equipmentName;
 
     @Excel(name = "*设备类型", sort = 3, width = 26,
-            combo = {
-                    "平升压力流量终端",
-                    "消火栓压力监测终端",
-                    "漏失监测仪",
-                    "视频监控(排口+内涝点)",
-                    "平升液位流量终端",
-                    "平升易涝点水位计",
-                    "环境监测终端(污水)",
-                    "环境监测终端(雨水)",
-                    "视频监控(场站)",
-                    "可燃气体检测仪",
-                    "排水窨井盖监测"
-            },
-            prompt = "必填,请从下拉框中选择设备类型")
+            prompt = "必填,请从下拉框中选择设备类型;选项来自 equipment_type 末级类型,按 order_num 升序")
     private String equipmentTypeName;
 
     @Excel(name = "*所属片区", sort = 4, width = 16,
@@ -52,4 +39,7 @@ public class EquipmentBatchCreateDTO {
 
     @Excel(name = "纬度", sort = 7, width = 16)
     private String latitude;
+
+    @Excel(name = "备注", sort = 8, width = 32)
+    private String remark;
 }

+ 55 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/domain/dto/EquipmentExportDTO.java

@@ -0,0 +1,55 @@
+package com.zksy.base.domain.dto;
+
+import com.zksy.base.domain.vo.EquipmentBaseVO;
+import com.zksy.common.annotation.Excel;
+import lombok.Data;
+
+/**
+ * 设备台账导出行。
+ *
+ * <p>前 8 列与设备导入模板一一对应,但不含必填 {@code *} 标记;末尾追加“最后通讯时间”。</p>
+ */
+@Data
+public class EquipmentExportDTO {
+
+    @Excel(name = "设备编码", sort = 1, width = 22)
+    private String equipmentCode;
+
+    @Excel(name = "设备名称", sort = 2, width = 22)
+    private String equipmentName;
+
+    @Excel(name = "设备类型", sort = 3, width = 26)
+    private String equipmentTypeName;
+
+    @Excel(name = "所属片区", sort = 4, width = 16)
+    private String districtName;
+
+    @Excel(name = "安装位置", sort = 5, width = 32)
+    private String equipmentLocation;
+
+    @Excel(name = "经度", sort = 6, width = 16)
+    private String longitude;
+
+    @Excel(name = "纬度", sort = 7, width = 16)
+    private String latitude;
+
+    @Excel(name = "备注", sort = 8, width = 32)
+    private String remark;
+
+    @Excel(name = "最后通讯时间", sort = 9, width = 20)
+    private String lastCommTime;
+
+    public static EquipmentExportDTO from(EquipmentBaseVO vo, String districtName, String lastCommTime) {
+        EquipmentExportDTO dto = new EquipmentExportDTO();
+        dto.setEquipmentCode(vo.getEquipmentCode());
+        dto.setEquipmentName(vo.getEquipmentName());
+        dto.setEquipmentTypeName(vo.getEquipmentTypeName());
+        dto.setDistrictName(districtName);
+        dto.setEquipmentLocation(vo.getEquipmentLocation());
+        dto.setLongitude(vo.getLongitude() == null ? "" : vo.getLongitude().toPlainString());
+        dto.setLatitude(vo.getLatitude() == null ? "" : vo.getLatitude().toPlainString());
+        dto.setRemark(vo.getRemark());
+        dto.setLastCommTime(lastCommTime);
+        return dto;
+    }
+}

+ 5 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/perception/mapper/PerceptionMapper.java

@@ -23,6 +23,11 @@ public interface PerceptionMapper {
                                     @Param("idColumn") String idColumn,
                                     @Param("deviceCode") String deviceCode);
 
+    /** 批量取某原始采集表多个设备的最新通讯时间(表名/标识列由白名单约束,外部已校验)。 */
+    List<Map<String, Object>> selectLastCommTimes(@Param("table") String table,
+                                                 @Param("idColumn") String idColumn,
+                                                 @Param("codes") List<String> codes);
+
     /** 按片区(district)聚合设备在线/离线/报警统计。 */
     List<Map<String, Object>> selectAreaStats();
 

+ 9 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/perception/service/PerceptionService.java

@@ -1,13 +1,16 @@
 package com.zksy.base.perception.service;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.zksy.base.domain.vo.EquipmentBaseVO;
 import com.zksy.base.perception.domain.vo.AlarmTypeDistVO;
 import com.zksy.base.perception.domain.vo.AlarmVO;
 import com.zksy.base.perception.domain.vo.AreaRankVO;
 import com.zksy.base.perception.domain.vo.EquipmentProfileVO;
 import com.zksy.base.perception.domain.vo.EquipmentRealtimeVO;
 
+import java.time.LocalDateTime;
 import java.util.List;
+import java.util.Map;
 
 /** 感知信息实时展示服务。 */
 public interface PerceptionService {
@@ -22,6 +25,12 @@ public interface PerceptionService {
     /** 设备档案:基础信息 + 原始采集表最近 50 条 + 关联指标单位。 */
     EquipmentProfileVO getProfile(String equipmentId);
 
+    /** 仅查询设备最后通讯时间(与设备档案同口径:按 orig_coll_table 定位原始采集表)。 */
+    LocalDateTime getLastCommTime(String equipmentId);
+
+    /** 批量查询设备最后通讯时间,key 为设备编码;供台账导出使用。 */
+    Map<String, LocalDateTime> getLastCommTimes(List<EquipmentBaseVO> devices);
+
     /** 未解除报警(audit_status=1 & alarm_status=0)分页列表。 */
     Page<AlarmVO> pageActiveAlarms(long pageNum, long pageSize);
 

+ 89 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/perception/service/impl/PerceptionServiceImpl.java

@@ -27,8 +27,10 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.sql.Timestamp;
 import java.text.DecimalFormat;
 import java.time.LocalDateTime;
+import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.TemporalAccessor;
 import java.util.ArrayList;
@@ -39,6 +41,8 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.Set;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -48,6 +52,9 @@ import java.util.stream.Collectors;
 @Service
 public class PerceptionServiceImpl implements PerceptionService {
 
+    /** 批量查询最后通讯时间时每批设备编码数量。 */
+    private static final int LAST_COMM_CODE_BATCH = 500;
+
     /** 原始采集表 -> 设备标识列(白名单,防止动态表名 SQL 注入)。 */
     private static final Map<String, String> TABLE_ID_COLUMN = new LinkedHashMap<>();
     static {
@@ -112,6 +119,88 @@ public class PerceptionServiceImpl implements PerceptionService {
         return perceptionMapper.selectLastCommTime(table, TABLE_ID_COLUMN.get(table), base.getEquipmentCode());
     }
 
+    @Override
+    public LocalDateTime getLastCommTime(String equipmentId) {
+        if (equipmentId == null || equipmentId.trim().isEmpty()) {
+            return null;
+        }
+        EquipmentBase base = equipmentBaseMapper.selectById(equipmentId);
+        if (base == null || base.getEquipmentTypeId() == null) {
+            return null;
+        }
+        EquipmentType type = equipmentTypeMapper.selectById(base.getEquipmentTypeId());
+        return queryLastCommTime(base, resolveTable(type));
+    }
+
+    @Override
+    public Map<String, LocalDateTime> getLastCommTimes(List<EquipmentBaseVO> devices) {
+        Map<String, LocalDateTime> result = new HashMap<>();
+        if (devices == null || devices.isEmpty()) {
+            return result;
+        }
+        Set<Integer> typeIds = devices.stream()
+                .filter(Objects::nonNull)
+                .map(EquipmentBaseVO::getEquipmentTypeId)
+                .map(this::toInt)
+                .filter(Objects::nonNull)
+                .collect(Collectors.toSet());
+        Map<Integer, EquipmentType> typeMap = typeIds.isEmpty() ? Collections.emptyMap() :
+                equipmentTypeMapper.selectBatchIds(typeIds).stream()
+                        .filter(Objects::nonNull)
+                        .collect(Collectors.toMap(EquipmentType::getId, Function.identity(), (a, b) -> a));
+
+        Map<String, List<String>> codesByTable = new HashMap<>();
+        for (EquipmentBaseVO vo : devices) {
+            if (vo == null || vo.getEquipmentCode() == null || vo.getEquipmentCode().trim().isEmpty()) {
+                continue;
+            }
+            EquipmentType type = typeMap.get(toInt(vo.getEquipmentTypeId()));
+            String table = resolveTable(type);
+            if (table == null) {
+                continue;
+            }
+            codesByTable.computeIfAbsent(table, key -> new ArrayList<>()).add(vo.getEquipmentCode().trim());
+        }
+
+        for (Map.Entry<String, List<String>> entry : codesByTable.entrySet()) {
+            List<String> codes = entry.getValue().stream().distinct().collect(Collectors.toList());
+            String table = entry.getKey();
+            for (int i = 0; i < codes.size(); i += LAST_COMM_CODE_BATCH) {
+                List<String> batch = codes.subList(i, Math.min(i + LAST_COMM_CODE_BATCH, codes.size()));
+                List<Map<String, Object>> rows = perceptionMapper.selectLastCommTimes(
+                        table, TABLE_ID_COLUMN.get(table), batch);
+                for (Map<String, Object> row : rows) {
+                    Object codeValue = row.get("device_code");
+                    LocalDateTime time = toLocalDateTime(row.get("last_comm_time"));
+                    if (codeValue != null && time != null) {
+                        result.put(String.valueOf(codeValue), time);
+                    }
+                }
+            }
+        }
+        return result;
+    }
+
+    private LocalDateTime toLocalDateTime(Object value) {
+        if (value == null) {
+            return null;
+        }
+        if (value instanceof LocalDateTime) {
+            return (LocalDateTime) value;
+        }
+        if (value instanceof Timestamp) {
+            return ((Timestamp) value).toLocalDateTime();
+        }
+        if (value instanceof java.util.Date) {
+            return LocalDateTime.ofInstant(((java.util.Date) value).toInstant(), ZoneId.systemDefault());
+        }
+        try {
+            return LocalDateTime.parse(String.valueOf(value).trim().replace(' ', 'T'));
+        } catch (Exception ignored) {
+            return null;
+        }
+    }
+
     /** 由已加载的 equipment_type -> orig_coll_table 解析原始采集表;不在白名单返回 null。 */
     private String resolveTable(EquipmentType type) {
         if (type == null || type.getOrigCollTable() == null) {

+ 3 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/service/EquipmentTypeService.java

@@ -18,6 +18,9 @@ public interface EquipmentTypeService extends IService<EquipmentType> {
     /** 按显示顺序升序返回指定父类型下的设备类型,parentId 为空时返回全部。 */
     List<EquipmentType> listOrderedByParentId(Integer parentId);
 
+    /** 按 order_num 升序返回可用于设备导入的末级设备类型名称。 */
+    List<String> listImportableTypeNames();
+
     /**
      * 新增设备类别
      * @param entity

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

@@ -64,7 +64,7 @@ public class EquipmentBatchCreateServiceImpl implements EquipmentBatchCreateServ
         Map<String, EquipmentBase> existingByCode = loadExistingByCode(rows);
 
         for (EquipmentBatchCreateDTO row : rows) {
-            String code = trim(row == null ? null : row.getEquipmentCode());
+            String code = normalizeCode(row == null ? null : row.getEquipmentCode());
             String reason = validate(row, code, typeIndex);
             if (reason != null) {
                 result.addFailure(code, reason);
@@ -126,7 +126,7 @@ public class EquipmentBatchCreateServiceImpl implements EquipmentBatchCreateServ
     private Map<String, EquipmentBase> loadExistingByCode(List<EquipmentBatchCreateDTO> rows) {
         List<String> codes = rows.stream()
                 .filter(Objects::nonNull)
-                .map(row -> trim(row.getEquipmentCode()))
+                .map(row -> normalizeCode(row.getEquipmentCode()))
                 .filter(code -> !code.isEmpty())
                 .distinct()
                 .collect(Collectors.toList());
@@ -137,7 +137,7 @@ public class EquipmentBatchCreateServiceImpl implements EquipmentBatchCreateServ
                             .in(EquipmentBase::getEquipmentCode, batch))
                     .forEach(item -> {
                         if (item != null && item.getEquipmentCode() != null) {
-                            existing.put(item.getEquipmentCode(), item);
+                            existing.put(normalizeCode(item.getEquipmentCode()), item);
                         }
                     });
         }
@@ -202,6 +202,7 @@ public class EquipmentBatchCreateServiceImpl implements EquipmentBatchCreateServ
         entity.setLongitude(longitude.isEmpty() ? null : new BigDecimal(longitude));
         String latitude = trim(row.getLatitude());
         entity.setLatitude(latitude.isEmpty() ? null : new BigDecimal(latitude));
+        entity.setRemark(nullIfBlank(row.getRemark()));
     }
 
     private Integer resolveTypeId(String typeName, Map<String, Integer> typeIndex) {
@@ -243,6 +244,11 @@ public class EquipmentBatchCreateServiceImpl implements EquipmentBatchCreateServ
                 .replace("+", "+").replaceAll("\\s+", "");
     }
 
+    /** 设备编码只允许连续有效字符,导入时去除首尾及中间所有空白字符。 */
+    private static String normalizeCode(String value) {
+        return trim(value).replaceAll("\\s+", "");
+    }
+
     private static String trim(String value) {
         return value == null ? "" : value.trim();
     }

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

@@ -75,6 +75,27 @@ public class EquipmentTypeServiceImpl extends ServiceImpl<EquipmentTypeMapper, E
         return this.list(wrapper);
     }
 
+    @Override
+    public List<String> listImportableTypeNames() {
+        List<EquipmentType> types = listOrdered();
+        if (types == null || types.isEmpty()) {
+            return Collections.emptyList();
+        }
+        Set<Integer> parentIds = types.stream()
+                .filter(Objects::nonNull)
+                .map(EquipmentType::getParentId)
+                .filter(Objects::nonNull)
+                .collect(Collectors.toSet());
+        return types.stream()
+                .filter(Objects::nonNull)
+                .filter(type -> type.getParentId() != null && type.getParentId() > 0)
+                .filter(type -> type.getId() != null && !parentIds.contains(type.getId()))
+                .map(EquipmentType::getTypeName)
+                .filter(name -> name != null && !name.trim().isEmpty())
+                .map(String::trim)
+                .collect(Collectors.toList());
+    }
+
     /**
      * 新增设备类别
      * @param entity

+ 12 - 7
pipe-network-service/zksy-system/src/main/java/com/zksy/base/util/EquipmentImportTemplateWriter.java

@@ -23,6 +23,7 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.lang.reflect.Field;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Comparator;
 import java.util.List;
 
@@ -30,9 +31,9 @@ import java.util.List;
  * 设备导入模板生成。
  *
  * <p>不使用 {@code ExcelUtil.importTemplateExcel}:它基于 SXSSFWorkbook,写出时会丢失
- * 富文本格式,必填列的红色 {@code *} 无法保留。这里用 XSSFWorkbook 生成,表头文字、
- * 列宽与下拉字典统一从 {@link EquipmentBatchCreateDTO} 的 {@code @Excel} 注解读取,
- * 保证模板表头与导入解析时的列名完全一致。</p>
+ * 富文本格式,必填列的红色 {@code *} 无法保留。这里用 XSSFWorkbook 生成,表头文字与
+ * 列宽从 {@link EquipmentBatchCreateDTO} 的 {@code @Excel} 注解读取;设备类型下拉改由
+ * 调用方传入 equipment_type 表按 order_num 升序排列的末级类型,保证与最新数据一致。</p>
  */
 public final class EquipmentImportTemplateWriter {
 
@@ -42,7 +43,7 @@ public final class EquipmentImportTemplateWriter {
     private EquipmentImportTemplateWriter() {
     }
 
-    public static void write(OutputStream os) throws IOException {
+    public static void write(OutputStream os, List<String> equipmentTypeNames) throws IOException {
         try (Workbook wb = new XSSFWorkbook()) {
             Sheet sheet = wb.createSheet("设备台账");
             CellStyle headerStyle = createHeaderStyle(wb);
@@ -51,13 +52,17 @@ public final class EquipmentImportTemplateWriter {
             header.setHeightInPoints(24);
 
             for (int column = 0; column < fields.size(); column++) {
-                Excel attr = fields.get(column).getAnnotation(Excel.class);
+                Field field = fields.get(column);
+                Excel attr = field.getAnnotation(Excel.class);
                 Cell cell = header.createCell(column);
                 cell.setCellStyle(headerStyle);
                 cell.setCellValue(buildHeaderText(wb, attr.name()));
                 sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256));
-                if (attr.combo().length > 0) {
-                    addCombo(sheet, attr.combo(), column);
+                List<String> options = "equipmentTypeName".equals(field.getName())
+                        ? equipmentTypeNames
+                        : Arrays.asList(attr.combo());
+                if (options != null && !options.isEmpty()) {
+                    addCombo(sheet, options.toArray(new String[0]), column);
                 }
             }
             wb.write(os);

+ 10 - 0
pipe-network-service/zksy-system/src/main/resources/mapper/perception/PerceptionMapper.xml

@@ -14,6 +14,16 @@
         WHERE ${idColumn} = #{deviceCode}
     </select>
 
+    <select id="selectLastCommTimes" resultType="java.util.HashMap">
+        SELECT ${idColumn} AS device_code, MAX(create_time) AS last_comm_time
+        FROM ${table}
+        WHERE ${idColumn} IN
+        <foreach collection="codes" item="code" open="(" separator="," close=")">
+            #{code}
+        </foreach>
+        GROUP BY ${idColumn}
+    </select>
+
     <select id="selectAreaStats" resultType="java.util.HashMap">
         SELECT b.district AS district,
                COUNT(*) AS total,

+ 0 - 46
pipe-network-service/zksy-system/src/test/java/com/zksy/cockpit/collectionRecords/CollectionThresholdRulesPackagingTest.java

@@ -1,46 +0,0 @@
-package com.zksy.cockpit.collectionRecords;
-
-import com.zksy.api.utils.AlarmLevelUtil;
-import com.zksy.api.utils.EarlyWarningLevelUtil;
-import org.junit.jupiter.api.Test;
-
-import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Set;
-import java.util.jar.JarFile;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import static org.junit.jupiter.api.Assertions.*;
-
-class CollectionThresholdRulesPackagingTest {
-    @Test
-    void sharedModuleContainsOnlyPureRulesIncludingNestedResultClass() throws Exception {
-        URL source = AlarmLevelUtil.class.getProtectionDomain().getCodeSource().getLocation();
-        Path location = Paths.get(source.toURI());
-        assertTrue(source.toString().contains("monitoring-threshold-rules"), source.toString());
-        assertEquals(source, EarlyWarningLevelUtil.class.getProtectionDomain().getCodeSource().getLocation());
-        Set<String> entries;
-        if (Files.isDirectory(location)) {
-            // Maven test 阶段引用 reactor 的 target/classes,而 install 后引用共享规则 jar。
-            try (Stream<Path> files = Files.walk(location)) {
-                entries = files.filter(Files::isRegularFile)
-                        .map(file -> location.relativize(file).toString().replace('\\', '/'))
-                        .collect(Collectors.toSet());
-            }
-        } else {
-            try (JarFile jar = new JarFile(location.toFile())) {
-                entries = jar.stream().filter(entry -> !entry.isDirectory())
-                        .map(java.util.jar.JarEntry::getName).filter(name -> !name.startsWith("META-INF/"))
-                        .collect(Collectors.toSet());
-            }
-        }
-        assertEquals(Set.of("com/zksy/api/utils/AlarmLevelUtil.class",
-                "com/zksy/api/utils/EarlyWarningLevelUtil.class",
-                "com/zksy/api/utils/EarlyWarningLevelUtil$EarlyWarningLevelResult.class"), entries);
-        assertThrows(ClassNotFoundException.class,
-                () -> Class.forName("com.zksy.api.service.impl.EarlyWarningAutoServiceImpl"));
-    }
-}

+ 37 - 31
sql/pipi_ner_full.sql

@@ -24856,22 +24856,25 @@ COPY app_user.equipment_status (status_id, equipment_id, current_status, alarm_s
 -- Data for Name: equipment_type; Type: TABLE DATA; Schema: app_user; Owner: app_user
 --
 
-COPY app_user.equipment_type (id, type_name, parent_id, remark, create_time, update_time, orig_coll_table) FROM stdin;
-12	平升压力流量终端	1	平升遥测终端,可采集压力,流速,瞬时流量,累计流量	2026-09-21 09:51:56	2026-09-21 09:51:56	telemetry_data
-15	环境监测终端(污水)	2	环境监测终端(污水):悬浮物,COD,氨氮,电导率EC,PH值	2026-09-21 09:51:56	2026-11-27 00:00:00	e_real_time_data
-22	可燃气体检测仪	3	可燃气体协议	2026-09-21 09:51:56	2026-09-21 09:51:56	gas_monitor_data
-14	消火栓压力监测终端	1	平升消防协议	2026-09-21 09:51:56	2026-09-21 09:51:56	firefighting_pressure
-13	漏失监测仪	1	普奇漏失监测仪	2026-09-21 09:51:56	2026-09-21 09:51:56	noise_info
-16	平升液位流量终端	2	平升遥测终端,可采集水位,流速,瞬时流量,累计流量	2026-09-21 09:51:56	2026-09-21 09:51:56	radar_data
-24	排水窨井盖监测	4	123井盖协议	2026-09-21 09:51:56	2026-09-21 09:51:56	jg_device_data
-20	视频监控(排口+内涝点)	2	视频监控(排口+内涝点)	2026-09-21 09:51:56	2026-09-21 09:51:56	\N
-23	视频监控(场站)	3	视频监控(场站)	2026-09-21 09:51:56	2026-09-21 09:51:56	\N
-1	供水设备	0	供水系统设备	2026-09-21 09:51:56	2026-09-21 09:51:56	\N
-2	排水设备	0	排水系统设备	2026-09-21 09:51:56	2026-09-21 09:51:56	\N
-3	燃气设备	0	燃气系统设备	2026-09-21 09:51:56	2026-09-21 09:51:56	\N
-4	窨井设备	0	窨井系统设备	2026-09-21 09:51:56	2026-09-21 09:51:56	\N
-25	平升易涝点水位计	2	平升易涝点水位计,采集水位(water_monitor_data)	2026-11-26 00:00:00	2026-11-26 00:00:00	water_monitor_data
-26	环境监测终端(雨水)	15	环境监测终端(雨水):悬浮物,COD,氨氮,电导率EC,PH值	2026-11-27 00:00:00	2026-11-27 00:00:00	e_real_time_data
+COPY app_user.equipment_type (id, type_name, parent_id, remark, create_time, update_time, orig_coll_table, order_num) FROM stdin;
+1	供水设备	0	供水系统设备	2026-09-21 09:51:56	2026-09-21 09:51:56	\N	1
+2	排水设备	0	排水系统设备	2026-09-21 09:51:56	2026-09-21 09:51:56	\N	2
+3	燃气设备	0	燃气系统设备	2026-09-21 09:51:56	2026-09-21 09:51:56	\N	3
+4	窨井设备	0	窨井系统设备	2026-09-21 09:51:56	2026-09-21 09:51:56	\N	4
+12	供水压力流量终端	1	平升遥测终端,可采集压力,流速,瞬时流量,累计流量	2026-09-21 09:51:56	2026-09-21 09:51:56	telemetry_data	1
+13	漏失监测终端	1	普奇漏失监测仪	2026-09-21 09:51:56	2026-09-21 09:51:56	noise_info	2
+14	消火栓压力终端	1	平升消防协议	2026-09-21 09:51:56	2026-09-21 09:51:56	firefighting_pressure	3
+15	环境监测终端(污水)	2	仁科4G采集终端(悬浮物,COD传感器,氨氮传感器,电导率EC,PH值)	2026-09-21 09:51:56	2026-09-21 09:51:56	e_real_time_data	1
+16	排水液位计终端(污水)	2	平升遥测终端,可采集排口水位	2026-09-21 09:51:56	2026-09-21 09:51:56	radar_data	5
+20	易涝点水位计终端	2	平升易涝点水位计	2026-09-21 09:51:56	2026-09-21 09:51:56	water_monitor_data	7
+22	可燃气体检测终端	3	可燃气体协议	2026-09-21 09:51:56	2026-09-21 09:51:56	gas_monitor_data	1
+23	视频监控(场站)	3	视频监控(场站)	2026-09-21 09:51:56	2026-09-21 09:51:56	\N	2
+24	排水窨井盖监测	4	123井盖协议	2026-09-21 09:51:56	2026-09-21 09:51:56	jg_device_data	1
+25	视频监控(排口+内涝点)	2	视频监控(排口+内涝点)	2026-09-21 09:51:56	2026-09-21 09:51:56	\N	8
+26	环境监测终端(雨水)	2	仁科4G采集终端(悬浮物,COD传感器,氨氮传感器,电导率EC,PH值)	2026-09-21 09:51:56	2026-09-21 09:51:56	e_real_time_data	2
+27	排水液位计终端(雨水)	2	平升遥测终端,可采集排口水位	2026-09-21 09:51:56	2026-09-21 09:51:56	radar_data	6
+28	排水流量计终端(污水)	2	平升遥测终端,可采集排口流速,瞬时流量,累计流量	2026-09-21 09:51:56	2026-09-21 09:51:56	radar_data	3
+29	排水流量计终端(雨水)	2	平升遥测终端,可采集排口流速,瞬时流量,累计流量	2026-09-21 09:51:56	2026-09-21 09:51:56	radar_data	4
 \.
 
 
@@ -24893,32 +24896,35 @@ b437e2e87c00a84a1d0d6c848ccf9208	GB28181	\N	41010500002000000004	340200000013100
 --
 
 COPY app_user.equipment_warning_type (equipment_type_id, create_time, update_time, warning_type_id) FROM stdin;
+12	2026-10-16 15:02:26	2026-10-16 15:02:39	3
 12	2026-10-16 15:02:26	2026-10-16 15:02:39	1
 12	2026-10-16 15:02:26	2026-10-16 15:02:39	2
-12	2026-10-16 15:02:26	2026-10-16 15:02:39	3
-16	2026-10-16 15:02:26	2026-11-26 00:00:00	22
-16	2026-10-16 15:02:26	2026-10-16 15:02:39	5
-16	2026-10-16 15:02:26	2026-10-16 15:02:39	6
-15	2026-10-16 15:02:26	2026-10-16 15:02:39	8
+13	2026-10-16 15:02:26	2026-10-16 15:02:39	13
+14	2026-10-16 15:02:26	2026-10-16 15:02:39	21
 15	2026-10-16 15:02:26	2026-10-16 15:02:39	9
-15	2026-10-16 15:02:26	2026-10-16 15:02:39	10
 15	2026-10-16 15:02:26	2026-10-16 15:02:39	11
 15	2026-10-16 15:02:26	2026-10-16 15:02:39	12
-13	2026-10-16 15:02:26	2026-10-16 15:02:39	13
-22	2026-10-16 15:02:26	2026-10-16 15:02:39	7
+15	2026-10-16 15:02:26	2026-10-16 15:02:39	10
+15	2026-10-16 15:02:26	2026-10-16 15:02:39	8
+16	2026-10-16 15:02:26	2026-10-16 15:02:39	4
+20	2026-10-16 15:02:26	2026-10-16 15:02:26	22
 22	2026-10-16 15:02:26	2026-10-16 15:02:39	15
 22	2026-10-16 15:02:26	2026-10-16 15:02:39	16
 22	2026-10-16 15:02:26	2026-10-16 15:02:39	17
+22	2026-10-16 15:02:26	2026-10-16 15:02:39	7
 24	2026-10-16 15:02:26	2026-10-16 15:02:39	18
 24	2026-10-16 15:02:26	2026-10-16 15:02:39	19
 24	2026-10-16 15:02:26	2026-10-16 15:02:39	20
-14	2026-10-16 15:02:26	2026-10-16 15:02:39	21
-25	2026-11-26 00:00:00	2026-11-26 00:00:00	23
-26	2026-11-27 00:00:00	2026-11-27 00:00:00	8
-26	2026-11-27 00:00:00	2026-11-27 00:00:00	9
-26	2026-11-27 00:00:00	2026-11-27 00:00:00	10
-26	2026-11-27 00:00:00	2026-11-27 00:00:00	11
-26	2026-11-27 00:00:00	2026-11-27 00:00:00	12
+26	2026-11-27 11:17:00	2026-11-27 11:17:00	8
+26	2026-11-27 11:17:00	2026-11-27 11:17:00	9
+26	2026-11-27 11:17:00	2026-11-27 11:17:00	10
+26	2026-11-27 11:17:00	2026-11-27 11:17:00	11
+26	2026-11-27 11:17:00	2026-11-27 11:17:00	12
+27	2026-10-16 15:02:26	2026-10-16 15:02:39	4
+28	2026-10-16 15:02:26	2026-10-16 15:02:39	5
+28	2026-10-16 15:02:26	2026-10-16 15:02:39	6
+29	2026-10-16 15:02:26	2026-10-16 15:02:39	5
+29	2026-10-16 15:02:26	2026-10-16 15:02:39	6
 \.
 
 

+ 18 - 12
verify/bean-threshold-regression/README.md

@@ -1,17 +1,25 @@
-# 后端 Bean 冲突与阈值规则编译回归
+# 后端 Bean 冲突与阈值规则编译回归(历史记录)
+
+> 本文记录当时修复 Bean 冲突的验证过程。后续架构已调整:`monitoring-threshold-rules` 现在仅由采集端使用,`zksy-system` 已移除对该模块的依赖及对应的打包边界测试。下文涉及"两端引用"的描述为当时的历史状态。
 
 ## 原始问题
 
 1. `com.zksy.base.event.DeviceStatusChangePublisher` 和 `com.zksy.api.event.DeviceStatusChangePublisher` 都用默认 Bean 名 `deviceStatusChangePublisher`。在同一 classpath 下进行组件扫描会抛出 `ConflictingBeanDefinitionException`。
-2. 驾驶舱 `CollectionRecordAssessmentService` 引用采集端的纯阈值工具,而 `zksy-system` 没有合法的编译依赖,Maven 报 `com.zksy.api.utils` 不存在。
+2. 当时驾驶舱 `CollectionRecordAssessmentService` 引用采集端的纯阈值工具,而 `zksy-system` 没有合法的编译依赖,Maven 报 `com.zksy.api.utils` 不存在。
 
-## 修复
+## 修复(当时的做法)
 
 - 两端发布器分别使用明确的管理端/采集端 Bean 名;所有现有调用方按类型 `@Autowired`,不改变 Redis 频道、事务提交后发布行为或事件载荷。
-- 将两个纯规则源文件原样移到 `monitoring-threshold-rules` 模块,保留包名和接口;两端显式引用该模块。规则实现内容经换行归一比对与原实现完全一致。
+- 将两个纯规则源文件原样移到 `monitoring-threshold-rules` 模块,保留包名和接口;当时两端均显式引用该模块。规则实现内容经换行归一比对与原实现完全一致。
 - 不允许 Bean 覆盖、不排除正常发布器、不把整个 `zk-api-service` 作为驾驶舱规则依赖。
 
-## 无外部服务的红 → 绿检查
+## 后续调整(当前状态)
+
+- 驾驶舱 `CollectionRecordAssessmentService` 已改为使用管理端自身的 `ThresholdConfigVO`/`ThresholdCodes` 分级机制,不再依赖 `monitoring-threshold-rules` 的两个工具类。
+- 因此 `zksy-system/pom.xml` 已移除对 `monitoring-threshold-rules` 的依赖;对应的架构打包测试 `CollectionThresholdRulesPackagingTest` 已删除。
+- `monitoring-threshold-rules` 模块保留,仅服务采集端:`zk-api-service`(`EarlyWarningAutoServiceImpl`、`AlarmDataServiceImpl`)与 `manhole-service`(`AlarmUtil`)。它是纯计算规则、零依赖的小 jar。
+
+## 无外部服务的红 → 绿检查(历史验证)
 
 ```bash
 bash verify/bean-threshold-regression/run.sh
@@ -23,24 +31,22 @@ bash verify/bean-threshold-regression/run.sh
 - 修改后:通过;在用户 JDK 11.0.16 下重跑也通过。
 - SLF4J 的 NOP logger 提示仅因回归不加载日志实现,不影响检查结果。
 
-## 编译与测试
+## 编译与测试(当时的结果)
 
 ```bash
 mvn -o -pl pipe-network-service/zksy-system -am \
-  -Dtest=CollectionRecordAssessmentServiceTest,CollectionThresholdRulesPackagingTest \
+  -Dtest=CollectionRecordAssessmentServiceTest \
   -Dsurefire.failIfNoSpecifiedTests=false test
 ```
 
-结果:14 项测试全部通过;覆盖实际采集评估规则、嵌套结果类与规则模块隔离。
+当时结果:`CollectionRecordAssessmentServiceTest` 等测试全部通过,覆盖驾驶舱采集记录评估规则。`CollectionThresholdRulesPackagingTest` 已随依赖一并删除,不再纳入该命令。
 
-管理服务及全部 Maven 上游模块的 `install` 已通过(包含编译、打包和安装到本地仓库);随后使用用户 IDEA 内置 Maven 和用户 `.m2/repository` 重新 `install` 也通过。采集端使用相同的 IDEA Maven 和 `.m2/repository` 编译也通过。
+管理服务及全部 Maven 上游模块的 `install` 当时已通过(包含编译、打包和安装到本地仓库);采集端使用相同的 IDEA Maven 和 `.m2/repository` 编译也通过。
 
 最初使用 PATH 上的另一套 Maven 时,遇到 `net-device` 缺失及离线插件元数据不匹配;改用用户原本的 Maven 配置后这些问题不再出现,未改动或移除 `net-device` 依赖。
 
-管理服务 Boot 包包含 `monitoring-threshold-rules-1.0.0.jar`,不包含 `zk-api-service` 的整个 jar。共享规则 jar 除 Maven 元数据外只有两个工具类和一个嵌套结果类。
-
 ## 使用提醒
 
 在 IDEA 中 Reload All Maven Projects,重新构建相关模块,再运行 `ZksyApplication`;管理服务不要保留旧的手工采集模块 classpath。移动工具源码后,旧采集模块 `target/classes` 的残留类可通过重新构建清理。
 
-本次没有启动完整 Boot 应用,没有连接 Nacos/数据库/Redis,没有改业务配置或前端,也没有提交或推送其它会话的在制品。
+本次记录没有启动完整 Boot 应用,没有连接 Nacos/数据库/Redis,没有改业务配置或前端。