|
@@ -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");
|
|
|
|