瀏覽代碼

feat(device): 添加坐摔检测相关配置字段

- 在 DeviceDTO 中新增坐摔检测相关字段,包括 fallSettingEnabled、lowHighSnrRatio 等- 在 DevInfo 实体类中添加对应的数据库字段映射
- 更新 DeviceGatewayImpl 和 DevInfoServiceImpl 实现坐摔配置字段的传递与保存
- MQTT 消息发送中构建并发送坐摔检测配置参数
- 在 ReportDeviceParamHandler 中解析并更新设备坐摔配置信息
- 在 UpdateDeviceParams 和 WebUpdateDeviceParams 中添加坐摔检测相关请求参数及校验规则
hxd 3 周之前
父節點
當前提交
2a97c907c1

+ 50 - 0
portal-service-common/src/main/java/com/hfln/portal/common/dto/data/device/DeviceDTO.java

@@ -224,6 +224,56 @@ public class DeviceDTO extends BaseVO {
     @Schema(description = "指示灯开关:0-关闭,1-开启")
     private Integer statusLight;
 
+
+    /**
+     * 是否开启坐摔检测,1:开启,0:关闭
+     */
+    @Schema(description = "是否开启坐摔检测,1:开启,0:关闭")
+    private Integer fallSettingEnabled;
+
+    /**
+     * 目标低部分的信噪比与高部分的信信噪比之比
+     */
+    @Schema(description = "目标低部分的信噪比与高部分的信信噪比之比")
+    private BigDecimal lowHighSnrRatio;
+
+    /**
+     * 目标低部分信噪比与中间部分信噪比对
+     */
+    @Schema(description = "目标低部分信噪比与中间部分信噪比对")
+    private BigDecimal lowMidSnrRatio;
+
+    /**
+     * 启动ToG事件的阈值
+     */
+    @Schema(description = "启动ToG事件的阈值")
+    private BigDecimal lowSnrThr;
+
+    /**
+     * 检测到坐摔的最低Z轴高度,范围0.1-2.5,单位m
+     */
+    @Schema(description = "检测到坐摔的最低Z轴高度,范围0.1-2.5,单位m")
+    private BigDecimal lowZMax;
+
+    /**
+     * 判断当前是否坐摔的门限值
+     */
+    @Schema(description = "判断当前是否坐摔的门限值")
+    private BigDecimal humanPredThreshold;
+
+    /**
+     * 最小连续多次的满足坐摔检测才会触发坐摔判断,范围 1-100
+     */
+    @Schema(description = "最小连续多次的满足坐摔检测才会触发坐摔判断,范围 1-100")
+    private BigDecimal minEventsForDetection;
+
+    /**
+     * 最小连续多次的满足坐摔检测才会触发坐摔检测状态改变,范围 1-100
+     */
+    @Schema(description = "最小连续多次的满足坐摔检测才会触发坐摔检测状态改变")
+    private BigDecimal minHumanEventsForDetection;
+
+
     /**
      * 创建人
      */

+ 41 - 0
portal-service-common/src/main/java/com/hfln/portal/common/request/device/UpdateDeviceParams.java

@@ -76,4 +76,45 @@ public class UpdateDeviceParams extends BaseVO {
 //    @DecimalMax(value = "300", message = "zzEnd不能大于300")
     private BigDecimal zzEnd;
 
+    @Schema(description = "是否开启坐摔检测,1:开启,0:关闭")
+    private Integer fallSettingEnabled;
+
+    @Schema(description = "目标低部分的信噪比与高部分的信信噪比之比")
+    @Digits(integer = 1, fraction = 2, message = "目标低部分的信噪比与高部分的信信噪比之比最多保留2位小数")
+    private BigDecimal lowHighSnrRatio;
+
+
+    @Schema(description = "目标低部分信噪比与中间部分信噪比对")
+    @Digits(integer = 1, fraction = 2, message = "目标低部分信噪比与中间部分信噪比对最多保留2位小数")
+    private BigDecimal lowMidSnrRatio;
+
+
+    @Schema(description = "启动ToG事件的阈值")
+    @Digits(integer = 1, fraction = 2, message = "启动ToG事件的阈值最多保留2位小数")
+    private BigDecimal lowSnrThr;
+
+
+    @Schema(description = "检测到坐摔的最低Z轴高度,范围0.1-2.5,单位m")
+    @DecimalMin(value = "0.1", message = "检测到坐摔的最低Z轴高度不能小于0.1")
+    @DecimalMax(value = "2.5", message = "检测到坐摔的最低Z轴高度不能大于2.5")
+    @Digits(integer = 1, fraction = 2, message = "检测到坐摔的最低Z轴高度最多保留2位小数")
+    private BigDecimal lowZMax;
+
+
+    @Schema(description = "判断当前是否坐摔的门限值")
+    @Digits(integer = 1, fraction = 2, message = "判断当前是否坐摔的门限值最多保留2位小数")
+    private BigDecimal humanPredThreshold;
+
+
+    @Schema(description = "最小连续多次的满足坐摔检测才会触发坐摔判断,范围 1-100")
+    @DecimalMin(value = "1", message = "最小连续多次的满足坐摔检测才会触发坐摔判断不能小于1")
+    @DecimalMax(value = "100", message = "最小连续多次的满足坐摔检测才会触发坐摔判断不能大于100")
+    private BigDecimal minEventsForDetection;
+
+
+    @Schema(description = "最小连续多次的满足坐摔检测才会触发坐摔检测状态改变,范围 1-100")
+    @DecimalMin(value = "1", message = "最小连续多次的满足坐摔检测才会触发坐摔检测状态改变不能小于1")
+    @DecimalMax(value = "100", message = "最小连续多次的满足坐摔检测才会触发坐摔检测状态改变不能大于100")
+    private BigDecimal minHumanEventsForDetection;
+
 }

+ 42 - 0
portal-service-common/src/main/java/com/hfln/portal/common/request/device/WebUpdateDeviceParams.java

@@ -94,4 +94,46 @@ public class WebUpdateDeviceParams extends BaseVO {
 
     @Schema(description = "监护对象类型")
     private String guardianshipType;
+
+
+    @Schema(description = "是否开启坐摔检测,1:开启,0:关闭")
+    private Integer fallSettingEnabled;
+
+    @Schema(description = "目标低部分的信噪比与高部分的信信噪比之比")
+    @Digits(integer = 1, fraction = 2, message = "目标低部分的信噪比与高部分的信信噪比之比最多保留2位小数")
+    private BigDecimal lowHighSnrRatio;
+
+
+    @Schema(description = "目标低部分信噪比与中间部分信噪比对")
+    @Digits(integer = 1, fraction = 2, message = "目标低部分信噪比与中间部分信噪比对最多保留2位小数")
+    private BigDecimal lowMidSnrRatio;
+
+
+    @Schema(description = "启动ToG事件的阈值")
+    @Digits(integer = 1, fraction = 2, message = "启动ToG事件的阈值最多保留2位小数")
+    private BigDecimal lowSnrThr;
+
+
+    @Schema(description = "检测到坐摔的最低Z轴高度,范围0.1-2.5,单位m")
+    @DecimalMin(value = "0.1", message = "检测到坐摔的最低Z轴高度不能小于0.1")
+    @DecimalMax(value = "2.5", message = "检测到坐摔的最低Z轴高度不能大于2.5")
+    @Digits(integer = 1, fraction = 2, message = "检测到坐摔的最低Z轴高度最多保留2位小数")
+    private BigDecimal lowZMax;
+
+
+    @Schema(description = "判断当前是否坐摔的门限值")
+    @Digits(integer = 1, fraction = 2, message = "判断当前是否坐摔的门限值最多保留2位小数")
+    private BigDecimal humanPredThreshold;
+
+
+    @Schema(description = "最小连续多次的满足坐摔检测才会触发坐摔判断,范围 1-100")
+    @DecimalMin(value = "1", message = "最小连续多次的满足坐摔检测才会触发坐摔判断不能小于1")
+    @DecimalMax(value = "100", message = "最小连续多次的满足坐摔检测才会触发坐摔判断不能大于100")
+    private BigDecimal minEventsForDetection;
+
+
+    @Schema(description = "最小连续多次的满足坐摔检测才会触发坐摔检测状态改变,范围 1-100")
+    @DecimalMin(value = "1", message = "最小连续多次的满足坐摔检测才会触发坐摔检测状态改变不能小于1")
+    @DecimalMax(value = "100", message = "最小连续多次的满足坐摔检测才会触发坐摔检测状态改变不能大于100")
+    private BigDecimal minHumanEventsForDetection;
 }

+ 8 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/DeviceGatewayImpl.java

@@ -405,6 +405,14 @@ public class DeviceGatewayImpl implements DeviceGateway {
         devInfo.setWidth(params.getYyEnd().subtract(params.getYyStart()));
         devInfo.setAge(params.getAge());
         devInfo.setGuardianshipType(params.getGuardianshipType());
+        devInfo.setFallSettingEnabled(params.getFallSettingEnabled());
+        devInfo.setLowHighSnrRatio(params.getLowHighSnrRatio());
+        devInfo.setLowMidSnrRatio(params.getLowMidSnrRatio());
+        devInfo.setLowSnrThr(params.getLowSnrThr());
+        devInfo.setLowZMax(params.getLowZMax());
+        devInfo.setHumanPredThreshold(params.getHumanPredThreshold());
+        devInfo.setMinEventsForDetection(params.getMinEventsForDetection());
+        devInfo.setMinHumanEventsForDetection(params.getMinHumanEventsForDetection());
 
         if (params.getFallingConfirm() != null) {
             devInfo.setFallingConfirm(params.getFallingConfirm());

+ 47 - 1
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/mqtt/MqttSend.java

@@ -141,6 +141,18 @@ public class MqttSend {
         // 根据值设置 isCeiling
         int isCeiling = "Ceiling".equalsIgnoreCase(mountPlainValue) ? 1 : 0;
 
+        // 构建坐摔配置消息体
+        Map<String, Object> target_on_ground_setting = new HashMap<>();
+        target_on_ground_setting.put("fallSettingEnabled",getFieldValue(params,"fallSettingEnabled"));
+        target_on_ground_setting.put("lowHighSnrRatio",getFieldValue(params,"lowHighSnrRatio"));
+        target_on_ground_setting.put("lowMidSnrRatio",getFieldValue(params,"lowMidSnrRatio"));
+        target_on_ground_setting.put("lowSnrThr",getFieldValue(params,"lowSnrThr"));
+        target_on_ground_setting.put("lowZMax",getFieldValue(params,"lowZMax"));
+        target_on_ground_setting.put("humanPredThreshold",getFieldValue(params,"humanPredThreshold"));
+        target_on_ground_setting.put("minEventsForDetection",getFieldValue(params,"minEventsForDetection"));
+        target_on_ground_setting.put("minHumanEventsForDetection",getFieldValue(params,"minHumanEventsForDetection"));
+
+
 
         //发送最终消息
         JSONObject jsonObject = new JSONObject();
@@ -148,6 +160,8 @@ public class MqttSend {
         jsonObject.put("sensor_location", z_cm);
         jsonObject.put("fallingStateMachineDurations", fallingStateMachineDurations);
         jsonObject.put("isCeiling", isCeiling);
+        jsonObject.put("target_on_ground_setting",target_on_ground_setting);
+
 
         try {
             mqttClient.sendMessage(topic, jsonObject.toJSONString());
@@ -189,11 +203,23 @@ public class MqttSend {
         // 根据值设置 isCeiling
         int isCeiling = "Ceiling".equalsIgnoreCase(mountPlainValue) ? 1 : 0;
 
+        // 构建坐摔配置消息体
+        Map<String, Object> target_on_ground_setting = new HashMap<>();
+        target_on_ground_setting.put("fallSettingEnabled",getFieldValue(params,"fallSettingEnabled"));
+        target_on_ground_setting.put("lowHighSnrRatio",getFieldValue(params,"lowHighSnrRatio"));
+        target_on_ground_setting.put("lowMidSnrRatio",getFieldValue(params,"lowMidSnrRatio"));
+        target_on_ground_setting.put("lowSnrThr",getFieldValue(params,"lowSnrThr"));
+        target_on_ground_setting.put("lowZMax",getFieldValue(params,"lowZMax"));
+        target_on_ground_setting.put("humanPredThreshold",getFieldValue(params,"humanPredThreshold"));
+        target_on_ground_setting.put("minEventsForDetection",getFieldValue(params,"minEventsForDetection"));
+        target_on_ground_setting.put("minHumanEventsForDetection",getFieldValue(params,"minHumanEventsForDetection"));
+
         //发送最终消息
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("ext_region", baseParent);
         jsonObject.put("sensor_location", z_cm);
         jsonObject.put("isCeiling", isCeiling);
+        jsonObject.put("target_on_ground_setting",target_on_ground_setting);
 
         try {
             mqttClient.sendMessage(topic, jsonObject.toJSONString());
@@ -214,7 +240,27 @@ public class MqttSend {
         try {
             Field field = obj.getClass().getDeclaredField(fieldName);
             field.setAccessible(true);
-            return (BigDecimal) field.get(obj);
+            Object value = field.get(obj);
+
+            if (value == null) {
+                return BigDecimal.ZERO;
+            }
+
+            if (value instanceof BigDecimal) {
+                return (BigDecimal) value;
+            } else if (value instanceof Integer) {
+                return BigDecimal.valueOf((Integer) value);
+            } else if (value instanceof Long) {
+                return BigDecimal.valueOf((Long) value);
+            } else if (value instanceof Double) {
+                return BigDecimal.valueOf((Double) value);
+            } else if (value instanceof Float) {
+                return BigDecimal.valueOf((Float) value);
+            } else if (value instanceof String) {
+                return new BigDecimal((String) value);
+            } else {
+                return BigDecimal.ZERO;
+            }
         } catch (Exception e) {
             log.error("获取字段值失败: {}", fieldName, e);
             return BigDecimal.ZERO;

+ 33 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/mqtt/handlers/ReportDeviceParamHandler.java

@@ -5,6 +5,9 @@ import com.hfln.portal.infrastructure.po.DevInfo;
 import com.hfln.portal.infrastructure.service.DevInfoService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+
+import java.math.BigDecimal;
 
 @Slf4j
 @Component
@@ -40,6 +43,36 @@ public class ReportDeviceParamHandler extends BaseMqttHandler implements MqttMes
         int isCeiling = obj.getIntValue("isCeiling");
         dev.setMountPlain(isCeiling == 1 ? DevInfo.Constants.MountPlain.CEILING : DevInfo.Constants.MountPlain.WALL);
 
+        // 获取设备中坐摔配置 来更新数据库
+        String fallSettingInfo = obj.getString("target_on_ground_setting");
+        if (StringUtils.hasText(fallSettingInfo)) {
+            JSONObject fallSetting = JSONObject.parseObject(fallSettingInfo);
+
+            Integer fallSettingEnabled = fallSetting.getIntValue("enabled");
+            dev.setFallSettingEnabled(fallSettingEnabled);
+
+            BigDecimal lowHighSnrRatio = fallSetting.getBigDecimal("lowHighSnrRatio");
+            dev.setLowHighSnrRatio(lowHighSnrRatio);
+
+            BigDecimal lowMidSnrRatio = fallSetting.getBigDecimal("lowMidSnrRatio");
+            dev.setLowMidSnrRatio(lowMidSnrRatio);
+
+            BigDecimal lowSnrThr = fallSetting.getBigDecimal("lowSnrThr");
+            dev.setLowSnrThr(lowSnrThr);
+
+            BigDecimal lowZMax = fallSetting.getBigDecimal("lowZMax");
+            dev.setLowZMax(lowZMax);
+
+            BigDecimal humanPredThreshold = fallSetting.getBigDecimal("humanPredThreshold");
+            dev.setHumanPredThreshold(humanPredThreshold);
+
+            BigDecimal minEventsForDetection = fallSetting.getBigDecimal("minEventsForDetection");
+            dev.setMinEventsForDetection(minEventsForDetection);
+
+            BigDecimal minHumanEventsForDetection = fallSetting.getBigDecimal("minHumanEventsForDetection");
+            dev.setMinHumanEventsForDetection(minHumanEventsForDetection);
+        }
+
         devInfoService.updateById(dev);
     }
 }

+ 48 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/po/DevInfo.java

@@ -222,6 +222,54 @@ public class DevInfo extends BasePO {
     private String guardianshipType;
 
     /**
+     * 是否开启坐摔检测,1:开启,0:关闭
+     */
+    @TableField("fall_setting_enabled")
+    private Integer fallSettingEnabled;
+
+    /**
+     * 目标低部分的信噪比与高部分的信信噪比之比
+     */
+    @TableField("low_high_snr_ratio")
+    private BigDecimal lowHighSnrRatio;
+
+    /**
+     * 目标低部分信噪比与中间部分信噪比对
+     */
+    @TableField("low_mid_snr_ratio")
+    private BigDecimal lowMidSnrRatio;
+
+    /**
+     * 启动ToG事件的阈值
+     */
+    @TableField("low_snr_thr")
+    private BigDecimal lowSnrThr;
+
+    /**
+     * 检测到坐摔的最低Z轴高度,范围0.1-2.5,单位m
+     */
+    @TableField("low_z_max")
+    private BigDecimal lowZMax;
+
+    /**
+     * 判断当前是否坐摔的门限值
+     */
+    @TableField("human_pred_threshold")
+    private BigDecimal humanPredThreshold;
+
+    /**
+     * 最小连续多次的满足坐摔检测才会触发坐摔判断,范围 1-100
+     */
+    @TableField("min_events_for_detection")
+    private BigDecimal minEventsForDetection;
+
+    /**
+     * 最小连续多次的满足坐摔检测才会触发坐摔检测状态改变,范围 1-100
+     */
+    @TableField("min_human_events_for_detection")
+    private BigDecimal minHumanEventsForDetection;
+
+    /**
      * 设备信息常量类
      */
     public static class Constants {

+ 9 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/impl/DevInfoServiceImpl.java

@@ -120,6 +120,15 @@ public class DevInfoServiceImpl extends ServiceImpl<DevInfoMapper, DevInfo> impl
                 .setIfNotNull(DevInfo::getZzStart, params.getZzStart())
                 .setIfNotNull(DevInfo::getZzEnd, params.getZzEnd())
                 .setIfNotNull(DevInfo::getFallingConfirm, 53)
+                .setIfNotNull(DevInfo::getFallSettingEnabled, params.getFallSettingEnabled())
+                .setIfNotNull(DevInfo::getLowHighSnrRatio, params.getLowHighSnrRatio())
+                .setIfNotNull(DevInfo::getLowMidSnrRatio, params.getLowMidSnrRatio())
+                .setIfNotNull(DevInfo::getLowSnrThr, params.getLowSnrThr())
+                .setIfNotNull(DevInfo::getLowZMax, params.getLowZMax())
+                .setIfNotNull(DevInfo::getHumanPredThreshold, params.getHumanPredThreshold())
+                .setIfNotNull(DevInfo::getMinEventsForDetection, params.getMinEventsForDetection())
+                .setIfNotNull(DevInfo::getMinHumanEventsForDetection, params.getMinHumanEventsForDetection())
+
                 // 无条件更新的字段
                 .set(DevInfo::getUpdateTime, LocalDateTime.now());