浏览代码

1.调整 告警计划相关的微信服务号标志位
2.增添 发送告警异常事件 服务号推送

hxd 1 月之前
父节点
当前提交
63923591c5

+ 2 - 0
portal-service-common/src/main/java/com/hfln/portal/common/constant/mqtt/topic/TopicConstants.java

@@ -58,6 +58,8 @@ public interface TopicConstants {
      */
     String TOPIC_LAS_ALARM_PLAN_UPDATE = "/las/alarm_plan_update";
 
+    String TOPIC_LAS_ALARM_EVENT = "/las/alarm_event";
+
 
     /**
      * dev设备 接收主题交互

+ 3 - 0
portal-service-common/src/main/java/com/hfln/portal/common/dto/data/event/AlarmPlanDTO.java

@@ -44,6 +44,9 @@ public class AlarmPlanDTO extends BaseVO {
     @Schema(description = "参数")
     private String param;
 
+    @Schema(description = "是否开启服务号消息推送 1:开启 0:关闭")
+    private Integer linkagePushWechatService;
+
     @Schema(description = "创建时间")
     private LocalDateTime createTime;
 

+ 3 - 0
portal-service-common/src/main/java/com/hfln/portal/common/dto/data/event/AlarmPlanTplDTO.java

@@ -38,6 +38,9 @@ public class AlarmPlanTplDTO extends BaseVO {
     @Schema(description = "参数")
     private String param;
 
+    @Schema(description = "是否开启服务号消息推送 1:开启 0:关闭")
+    private Integer linkagePushWechatService;
+
     @Schema(description = "创建时间")
     private LocalDateTime createTime;
 

+ 3 - 0
portal-service-common/src/main/java/com/hfln/portal/common/request/event/AlarmPlanSaveReq.java

@@ -46,6 +46,9 @@ public class AlarmPlanSaveReq extends BaseVO {
     @Schema(description = "参数")
     private String param;
 
+    @Schema(description = "是否开启服务号消息推送 1:开启 0:关闭")
+    private Integer linkagePushWechatService;
+
     @Schema(description = "备注")
     private String remark;
 

+ 3 - 0
portal-service-common/src/main/java/com/hfln/portal/common/request/event/AlarmPlanTplSaveReq.java

@@ -42,6 +42,9 @@ public class AlarmPlanTplSaveReq extends BaseVO {
     @Schema(description = "参数")
     private String param;
 
+    @Schema(description = "是否开启服务号消息推送 1:开启 0:关闭")
+    private Integer linkagePushWechatService;
+
     @Schema(description = "备注")
     private String remark;
 

+ 43 - 0
portal-service-domain/src/main/java/com/hfln/portal/domain/customer/AlarmEventType.java

@@ -0,0 +1,43 @@
+package com.hfln.portal.domain.customer;
+
+public enum AlarmEventType {
+    /**
+     *   起夜异常
+     */
+    NIGHT_TOILETING_FREQUENCY_ABNORMAL("1", "night_toileting_frequency_abnormal"),
+
+    /**
+     *   异常滞留
+     */
+
+    RETENTION_DETECTION("2", "retention_detection");
+
+    String code;
+    String desc;
+
+    AlarmEventType(String code, String desc) {
+        this.code = code;
+        this.desc = desc;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getDesc() {
+        return desc;
+    }
+
+    public void setDesc(String desc) {
+        this.desc = desc;
+    }
+
+    public static boolean isTargetEvent(String desc) {
+        return NIGHT_TOILETING_FREQUENCY_ABNORMAL.desc.equals(desc)
+                || RETENTION_DETECTION.desc.equals(desc);
+    }
+}

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

@@ -31,7 +31,6 @@ import com.hfln.portal.domain.customer.OprLogType;
 import com.hfln.portal.domain.customer.OssBusiType;
 import com.hfln.portal.domain.customer.util.DevPosFixUtil;
 import com.hfln.portal.domain.customer.util.PhoneUtils;
-import com.hfln.portal.domain.customer.util.WxOfficeAccountClient;
 import com.hfln.portal.domain.exception.ErrorEnum;
 import com.hfln.portal.domain.gateway.DeviceGateway;
 import com.hfln.portal.infrastructure.mqtt.MqttClient;
@@ -96,12 +95,6 @@ public class DeviceGatewayImpl implements DeviceGateway {
     private OssClient ossClient;
 
     @Autowired
-    private WxOfficeAccountClient wxOfficeAccountClient;
-
-    @Autowired
-    private WxRelationService wxRelationService;
-
-    @Autowired
     private TblTenantService tblTenantService;
 
     @Autowired

+ 54 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/mqtt/MqttSubHandle.java

@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.hfln.portal.common.constant.mqtt.topic.TopicConstants;
 import com.hfln.portal.common.constant.redis.RedisCacheConstant;
 import com.hfln.portal.common.dto.data.user.SendMsgUserDto;
+import com.hfln.portal.domain.customer.AlarmEventType;
 import com.hfln.portal.domain.customer.util.MsgClient;
 import com.hfln.portal.domain.customer.util.WxOfficeAccountClient;
 import com.hfln.portal.infrastructure.po.*;
@@ -97,6 +98,8 @@ public class MqttSubHandle {
                 case "event":
                     subDasEvent(topic, payload);
                     break;
+
+                // 接收LAS告警事件主题消息  if里面判断新逻辑, else 保持旧逻辑
                 case "alarm_event":
                     subDasAlarmEvent(topic, payload);
                     break;
@@ -690,6 +693,57 @@ public class MqttSubHandle {
     public void subDasAlarmEvent(String topic, String payload) {
 
         log.info("Received device message: topic={}, payload={}", topic, payload);
+        // 1.判断是否为新逻辑 从LAS获取
+        if (TopicConstants.TOPIC_LAS_ALARM_EVENT.equals(topic)) {
+            JSONObject obj = JSONObject.parseObject(payload);
+            String eventType = obj.getString("event_type");
+
+            // 1.1 判断 消息类型是否符合  起夜异常 or 异常滞留
+            if (AlarmEventType.isTargetEvent(eventType)) {
+                String clientId = obj.getString("dev_id");
+
+                // 1.2 查找设备信息,获取主绑人的userId
+                DevInfo dev = devInfoService.queryByClientId(clientId);
+
+                if (dev == null) {
+                    log.info("服务号通知发送失败,当前设备不存在: clientId={}", clientId);
+                    return;
+                }
+
+                Long userId = dev.getUserId();
+                String devName = dev.getDevName();
+                String devId = dev.getClientId();
+
+
+                // 1.3 如果userId为空,则没有绑定人
+                if (userId == null) {
+                    log.info("服务号通知发送失败,设备未绑定用户: clientId={}", clientId);
+                    return;
+                }
+
+                // 1.4 查询主绑人信息
+                UserInfo user = userService.queryById(userId);
+
+                // 1.5 获取用户微信服务号OpenId
+                WxRelation wxRelations = wxRelationService.queryOneByUnionId(user.getUnionId());
+
+                if (wxRelations == null) {
+                    log.info("服务号通知发送失败,用户未绑定微信服务号: userId={}", userId);
+                }
+                String fwhOpenId = wxRelations.getFwhOpenId();
+
+                log.info("mqttutil--当前useropenid=" + user.getOpenid() + ", fwhopenId=" + fwhOpenId);
+                log.info("发送微信公众号信息:devName=" + devName.toString() + ", phoneNo=" + user.getPhone() + "fwhOpenId=" + fwhOpenId);
+
+                // 1.6 发送微信公告号消息
+                wxOfficeAccountClient.sendMsg(devId, devName.toString(), user.getPhone(), fwhOpenId, "设备检测到异常滞留,请前往小程序查看详细信息");
+                log.info("发送微信公众号消息发完了");
+                return;
+            }
+            return;
+        }
+
+        // 2. 如果为旧逻辑 走下面流程
         JSONObject obj = JSONObject.parseObject(payload);
         String clientId = obj.getString("dev_id");
 

+ 5 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/po/AlarmPlan.java

@@ -75,6 +75,11 @@ public class AlarmPlan extends BaseVO {
     private String param;
 
     /**
+     * 是否开启服务号推送 0-禁用,1-启用
+     */
+    private Integer linkagePushWechatService;
+
+    /**
      * 创建时间
      */
     private LocalDateTime createTime;

+ 5 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/po/AlarmPlanTpl.java

@@ -68,6 +68,11 @@ public class AlarmPlanTpl extends BaseVO {
     private String param;
 
     /**
+     * 是否开启服务号推送 0-禁用,1-启用
+     */
+    private Integer linkagePushWechatService;
+
+    /**
      * 创建时间
      */
     private LocalDateTime createTime;

+ 2 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/WxRelationService.java

@@ -8,6 +8,8 @@ import java.util.List;
 public interface WxRelationService extends IService<WxRelation> {
 
     List<WxRelation> queryByUnionId(String unionId);
+
     WxRelation queryOneByUnionId(String unionId);
+
     List<WxRelation> queryByUnionIdAndOpenId(String unionId, String fwhOpenId);
 }