Selaa lähdekoodia

feat(alarm): 支持设备预警阈值配置多设备编号

- 修改 WarningThreshold 实体类中 deviceCode 字段注释,标明支持多个设备编号用逗号分隔
- 更新 ManholeDeviceController 中查询设备预警阈值逻辑,使用 SQL CONCAT 函数实现多设备编号匹配
- 修改 WarningThresholdServiceImpl 中分页查询方法,添加设备编号多值匹配条件判断
- 更新 WarningThresholdServiceImpl 中列表查询方法,支持多设备编号模糊匹配
- 重构 WarningThresholdServiceImpl 中按设备和编码查询方法,移除通配符逻辑并改用多设备编号匹配
- 简化 zk-api-service 中 WarningThresholdServiceImpl 的查询逻辑,统一使用多设备编号匹配方式
林仔 5 päivää sitten
vanhempi
commit
58eeb0f946

+ 2 - 2
pipe-network-service/zksy-admin/src/main/java/com/zksy/web/controller/manhole/ManholeDeviceController.java

@@ -116,9 +116,9 @@ public class ManholeDeviceController extends BaseController
             ManholeDataOutDTO manholeDataOutDTO = BeanUtil.copyProperties(manholeData, ManholeDataOutDTO.class);
             outDTO.setManholeData(manholeDataOutDTO);
         }
-        // 查询设备预警阈值
+        // 查询设备预警阈值(支持多个设备编号,用逗号分隔)
         List<WarningThreshold> warningThresholdList = warningThresholdService.list(new LambdaQueryWrapper<WarningThreshold>()
-                .eq(WarningThreshold::getDeviceCode, outDTO.getEquipmentCode())
+                .apply("CONCAT(',', device_code, ',') LIKE CONCAT('%,', {0}, ',%')", outDTO.getEquipmentCode())
                 .orderByDesc(WarningThreshold::getCreateTime));
         if(CollUtil.isNotEmpty(warningThresholdList)){
             List<WarningThresholdOutDTO> warningThresholdOutDTOList = BeanUtil.copyToList(warningThresholdList, WarningThresholdOutDTO.class);

+ 2 - 2
pipe-network-service/zksy-system/src/main/java/com/zksy/base/alarm/domain/WarningThreshold.java

@@ -25,10 +25,10 @@ public class WarningThreshold implements Serializable {
     private String id;
 
     /**
-     * 设备编码
+     * 设备编码,支持多个设备编号,用逗号分隔
      */
     @TableField(value = "device_code")
-    @ApiModelProperty(value = "设备编码")
+    @ApiModelProperty(value = "设备编码,支持多个设备编号,用逗号分隔")
     private String deviceCode;
 
     /**

+ 10 - 5
pipe-network-service/zksy-system/src/main/java/com/zksy/base/alarm/service/impl/WarningThresholdServiceImpl.java

@@ -24,8 +24,10 @@ public class WarningThresholdServiceImpl extends ServiceImpl<WarningThresholdMap
     public Page<WarningThreshold> findByPage(long pageNum, long pageSize, String deviceCode, String warningType, String warningCode) {
         Page<WarningThreshold> page = new Page<>(pageNum, pageSize);
         LambdaQueryWrapper<WarningThreshold> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.like(WarningThreshold::getDeviceCode,deviceCode)
-                .like(WarningThreshold::getWarningType,warningType)
+        if (deviceCode != null && !deviceCode.isEmpty()) {
+            queryWrapper.apply("CONCAT(',', device_code, ',') LIKE CONCAT('%,', {0}, ',%')", deviceCode);
+        }
+        queryWrapper.like(WarningThreshold::getWarningType,warningType)
                 .like(WarningThreshold::getWarningCode,warningCode);
         queryWrapper.orderByDesc(WarningThreshold::getUpdateTime);
         return this.page(page, queryWrapper);
@@ -34,8 +36,10 @@ public class WarningThresholdServiceImpl extends ServiceImpl<WarningThresholdMap
     @Override
     public List<WarningThreshold> getWarningThresholdList(String deviceCode, String warningType, String warningCode) {
         LambdaQueryWrapper<WarningThreshold> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.like(WarningThreshold::getDeviceCode,deviceCode)
-                .like(WarningThreshold::getWarningType,warningType)
+        if (deviceCode != null && !deviceCode.isEmpty()) {
+            queryWrapper.apply("CONCAT(',', device_code, ',') LIKE CONCAT('%,', {0}, ',%')", deviceCode);
+        }
+        queryWrapper.like(WarningThreshold::getWarningType,warningType)
                 .like(WarningThreshold::getWarningCode,warningCode);
         queryWrapper.orderByDesc(WarningThreshold::getUpdateTime);
         return this.list(queryWrapper);
@@ -43,11 +47,12 @@ public class WarningThresholdServiceImpl extends ServiceImpl<WarningThresholdMap
 
     /**
      * 根据设备编号查询该设备所有预警值
+     * device_code 字段支持多个设备编号,用逗号分隔
      */
     @Override
     public WarningThreshold getWarningThresholdByDeviceAndCode(String deviceCode, String warningCodes) {
         LambdaQueryWrapper<WarningThreshold> lambdaQueryWrapper = Wrappers.lambdaQuery(WarningThreshold.class)
-                .eq(WarningThreshold::getDeviceCode, deviceCode)
+                .apply("CONCAT(',', device_code, ',') LIKE CONCAT('%,', {0}, ',%')", deviceCode)
                 .eq(WarningThreshold::getWarningCode,warningCodes);
 
         return baseMapper.selectOne(lambdaQueryWrapper);

+ 2 - 2
zk-api-service/src/main/java/com/zksy/api/domain/WarningThreshold.java

@@ -25,10 +25,10 @@ public class WarningThreshold implements Serializable {
     private String id;
 
     /**
-     * 设备编码
+     * 设备编码,支持多个设备编号,用逗号分隔
      */
     @TableField(value = "device_code")
-    @ApiModelProperty(value = "设备编码")
+    @ApiModelProperty(value = "设备编码,支持多个设备编号,用逗号分隔")
     private String deviceCode;
 
     /**

+ 4 - 15
zk-api-service/src/main/java/com/zksy/api/service/impl/WarningThresholdServiceImpl.java

@@ -21,26 +21,15 @@ public class WarningThresholdServiceImpl extends ServiceImpl<WarningThresholdMap
     implements WarningThresholdService{
     /**
      * 根据设备编号查询该设备所有预警值
-     * 先尝试精确匹配设备编码,没找到再查询通用阈值(deviceCode = "*")
+     * device_code 字段支持多个设备编号,用逗号分隔
      */
     @Override
     public WarningThreshold getWarningThresholdByDeviceAndCode(String deviceCode, String warningCodes) {
-        // 1. 先尝试精确匹配设备编码
         LambdaQueryWrapper<WarningThreshold> lambdaQueryWrapper = Wrappers.lambdaQuery(WarningThreshold.class)
-                .eq(WarningThreshold::getDeviceCode, deviceCode)
-                .eq(WarningThreshold::getWarningCode, warningCodes);
+                .apply("CONCAT(',', device_code, ',') LIKE CONCAT('%,', {0}, ',%')", deviceCode)
+                .eq(WarningThreshold::getWarningCode,warningCodes);
 
-        WarningThreshold result = baseMapper.selectOne(lambdaQueryWrapper);
-
-        // 2. 如果没找到,查询通用阈值(deviceCode = "*")
-        if (result == null) {
-            LambdaQueryWrapper<WarningThreshold> defaultQueryWrapper = Wrappers.lambdaQuery(WarningThreshold.class)
-                    .eq(WarningThreshold::getDeviceCode, "*")
-                    .eq(WarningThreshold::getWarningCode, warningCodes);
-            result = baseMapper.selectOne(defaultQueryWrapper);
-        }
-
-        return result;
+        return baseMapper.selectOne(lambdaQueryWrapper);
     }
 }