Browse Source

1.安装方式的消息体通知
2.服务号模板推送添加

hxd 1 month ago
parent
commit
9e2406dad3

+ 3 - 2
portal-service-common/src/main/java/com/hfln/portal/common/request/device/DeviceBandingParams.java

@@ -14,11 +14,11 @@ import java.math.BigDecimal;
 public class DeviceBandingParams extends BaseVO {
 
     @NotEmpty(message = "设备Id不能为空")
-    @Schema(description = "设备ID", required = true)
+    @Schema(description = "设备ID")
     private String clientId;
 
     @NotNull(message = "用户Id不能为空")
-    @Schema(description = "用户Id", required = true)
+    @Schema(description = "用户Id")
     private Long userId;
 
     @Schema(description = "设备名称:最多10个字符")
@@ -40,6 +40,7 @@ public class DeviceBandingParams extends BaseVO {
     private BigDecimal northAngle;
 
     @Schema(description = "安装方式:Wall-墙装,Ceiling-顶装")
+    @NotBlank(message = "安装方式不能为空")
     private String mountPlain;
 
     @Schema(description = "安装位置:Toilet-卫生间,Bedroom-卧室,LivingRoom-客厅,Restaurant-餐厅")

+ 3 - 2
portal-service-common/src/main/java/com/hfln/portal/common/request/device/UpdateDeviceParams.java

@@ -15,11 +15,11 @@ import java.math.BigDecimal;
 public class UpdateDeviceParams extends BaseVO {
 
     @NotEmpty(message = "设备Id不能为空")
-    @Schema(description = "设备ID", required = true)
+    @Schema(description = "设备ID")
     private String clientId;
 
     @NotNull(message = "用户Id不能为空")
-    @Schema(description = "用户Id", required = true)
+    @Schema(description = "用户Id")
     private Long userId;
 
 
@@ -42,6 +42,7 @@ public class UpdateDeviceParams extends BaseVO {
     private BigDecimal northAngle;
 
     @Schema(description = "安装方式:Wall-墙装,Ceiling-顶装")
+    @NotBlank(message = "安装方式不能为空")
     private String mountPlain;
 
     @Schema(description = "安装位置:Toilet-卫生间,Bedroom-卧室,LivingRoom-客厅,Restaurant-餐厅")

+ 13 - 12
portal-service-common/src/main/java/com/hfln/portal/common/request/device/WebUpdateDeviceParams.java

@@ -44,42 +44,43 @@ public class WebUpdateDeviceParams extends BaseVO {
     private BigDecimal northAngle;
 
     @Schema(description = "安装方式:Wall-墙装,Ceiling-顶装")
+    @NotBlank(message = "安装方式不能为空")
     private String mountPlain;
 
     @Schema(description = "安装位置:Toilet-卫生间,Bedroom-卧室,LivingRoom-客厅,Restaurant-餐厅")
     private String installPosition;
 
     @Schema(description = "雷达监测范围x开始,范围:-200-200 cm之内")
-//    @DecimalMin(value = "-200", message = "xxStart不能小于-200")
-//    @DecimalMax(value = "200", message = "xxStart不能大于200")
+    @DecimalMin(value = "-200", message = "xxStart不能小于-200")
+    @DecimalMax(value = "200", message = "xxStart不能大于200")
     private BigDecimal xxStart;
 
     @Schema(description = "雷达监测范围x结束,范围:-200-200 cm之内,且xxEnd > xxStart")
-//    @DecimalMin(value = "-200", message = "xxEnd不能小于-200")
-//    @DecimalMax(value = "200", message = "xxEnd不能大于200")
+    @DecimalMin(value = "-200", message = "xxEnd不能小于-200")
+    @DecimalMax(value = "200", message = "xxEnd不能大于200")
     private BigDecimal xxEnd;
 
 
     @Schema(description = "雷达监测范围y开始,范围:-250-250 cm之内")
-//    @DecimalMin(value = "-250", message = "yyStart不能小于-250")
-//    @DecimalMax(value = "250", message = "yyStart不能大于250")
+    @DecimalMin(value = "-250", message = "yyStart不能小于-250")
+    @DecimalMax(value = "250", message = "yyStart不能大于250")
     private BigDecimal yyStart;
 
     @Schema(description = "雷达监测范围y结束,范围:-250-250 cm之内,且yyEnd > yyStart")
-//    @DecimalMin(value = "-250", message = "yyEnd不能小于-250")
-//    @DecimalMax(value = "250", message = "yyEnd不能大于250")
+    @DecimalMin(value = "-250", message = "yyEnd不能小于-250")
+    @DecimalMax(value = "250", message = "yyEnd不能大于250")
     private BigDecimal yyEnd;
 
 
     @Schema(description = "雷达监测范围z开始,范围:0-5 cm之内")
-//    @DecimalMin(value = "0", message = "zzStart不能小于0")
-//    @DecimalMax(value = "5", message = "zzStart不能大于5")
+    @DecimalMin(value = "0", message = "zzStart不能小于0")
+    @DecimalMax(value = "5", message = "zzStart不能大于5")
     private BigDecimal zzStart;
 
 
     @Schema(description = "雷达监测范围z结束,范围:200-300 cm之内")
-//    @DecimalMin(value = "200", message = "zzEnd不能小于200")
-//    @DecimalMax(value = "300", message = "zzEnd不能大于300")
+    @DecimalMin(value = "200", message = "zzEnd不能小于200")
+    @DecimalMax(value = "300", message = "zzEnd不能大于300")
     private BigDecimal zzEnd;
 
     @Schema(description = "设备跌倒确认时间,大于0")

+ 35 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/mqtt/MqttSend.java

@@ -127,11 +127,21 @@ public class MqttSend {
             fallingStateMachineDurations.put("durationUntilReset_sec", 3);
         }
 
+        //构建安装方式消息
+        Map<String, String> mount_plain_map = new HashMap<>();
+        String mountPlainValue = getFieldValueAsString(params, "mountPlain");
+        mount_plain_map.put("mount_plain", mountPlainValue);
+
+        // 根据值设置 isCeiling
+        int isCeiling = "Ceiling".equalsIgnoreCase(mountPlainValue) ? 1 : 0;
+
+
         //发送最终消息
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("ext_region", baseParent);
         jsonObject.put("sensor_location", z_cm);
         jsonObject.put("fallingStateMachineDurations", fallingStateMachineDurations);
+        jsonObject.put("isCeiling", isCeiling);
 
         try {
             mqttClient.sendMessage(topic, jsonObject.toJSONString());
@@ -164,11 +174,19 @@ public class MqttSend {
         Map<String, BigDecimal> z_cm = new HashMap<>();
         z_cm.put("z_cm", getFieldValue(params, "height"));
 
+        //构建安装方式消息
+        Map<String, String> mount_plain_map = new HashMap<>();
+        String mountPlainValue = getFieldValueAsString(params, "mountPlain");
+        mount_plain_map.put("mount_plain", mountPlainValue);
+
+        // 根据值设置 isCeiling
+        int isCeiling = "Ceiling".equalsIgnoreCase(mountPlainValue) ? 1 : 0;
 
         //发送最终消息
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("ext_region", baseParent);
         jsonObject.put("sensor_location", z_cm);
+        jsonObject.put("isCeiling", isCeiling);
 
         try {
             mqttClient.sendMessage(topic, jsonObject.toJSONString());
@@ -196,6 +214,23 @@ public class MqttSend {
     }
 
     /**
+     * 通过反射获取对象字段值并转换为字符串
+     * @param obj 对象
+     *            字段名
+     */
+    private String getFieldValueAsString(Object obj, String fieldName) {
+        try {
+            Field field = obj.getClass().getDeclaredField(fieldName);
+            field.setAccessible(true);
+            Object value = field.get(obj);
+            return value != null ? value.toString() : "";
+        } catch (Exception e) {
+            log.error("获取字段值失败: {}", fieldName, e);
+            return "";
+        }
+    }
+
+    /**
      * 发送告警计划到LAS
      * @param planUUid 告警计划ID
      * @param operation 操作类型

+ 3 - 4
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/mqtt/MqttSubHandle.java

@@ -633,7 +633,7 @@ public class MqttSubHandle {
         log.info("发送微信公众号信息:devName={}, phoneNumber={}, fwhOpenId={}", devInfo.getDevName(), targetUser.getPhone(), fwhOpenId);
 
         // 服务号推送消息
-        wxOfficeAccountClient.sendMsg(devInfo.getClientId(), devInfo.getDevName(),targetUser.getPhone(), fwhOpenId, "设备转移成功,请前往小程序查看");
+        wxOfficeAccountClient.sendMsg(devInfo.getClientId(), devInfo.getDevName(),targetUser.getPhone(), fwhOpenId, "设备运行检测到设备转移,请前往小程序查看");
 
         log.info("发送微信公众号信息完毕");
     }
@@ -702,7 +702,6 @@ public class MqttSubHandle {
         if (TopicConstants.TOPIC_LAS_ALARM_EVENT.equals(topic)) {
             JSONObject obj = JSONObject.parseObject(payload);
             String eventType = obj.getString("event_type");
-            String msg = obj.getString("msg");
             // 1.1 判断 消息类型是否符合  起夜异常 or 异常滞留
             if (AlarmEventType.isTargetEvent(eventType)) {
                 String clientId = obj.getString("dev_id");
@@ -750,7 +749,7 @@ public class MqttSubHandle {
                 log.info("发送微信公众号信息:devName=" + devName + ", phoneNo=" + user.getPhone() + "fwhOpenId=" + fwhOpenId);
 
                 // 1.7 发送微信公告号消息
-                wxOfficeAccountClient.sendMsg(devId, devName, user.getPhone(), fwhOpenId, msg);
+                wxOfficeAccountClient.sendMsg(devId, devName, user.getPhone(), fwhOpenId, "设备运行检测到告警异常,请前往小程序查看");
                 log.info("发送微信公众号消息发完了");
                 return;
             }
@@ -788,7 +787,7 @@ public class MqttSubHandle {
                 log.info("发送微信公众号信息:devName=" + devName.toString() + ", phoneNo=" + user.getPhone() + "fwhOpenId=" + fwhOpenId);
                 // 发送微信公告号消息
                 if (StringUtils.contains(devName.toString(), "卫生间")) {
-                    wxOfficeAccountClient.sendMsg(devId, devName.toString(), user.getPhone(), fwhOpenId, "设备检测到,请前往小程序查看详细信息");
+                    wxOfficeAccountClient.sendMsg(devId, devName.toString(), user.getPhone(), fwhOpenId, "设备运行检测到告警异常,请前往小程序查看");
                     log.info("发送微信公众号消息发完了");
                 }
             }