|
@@ -1,8 +1,6 @@
|
|
|
package com.hfln.portal.infrastructure.mqtt;
|
|
|
|
|
|
import cn.hfln.framework.redis.util.RedisUtil;
|
|
|
-import com.alibaba.fastjson2.JSON;
|
|
|
-import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.hfln.portal.common.constant.mqtt.topic.TopicConstants;
|
|
@@ -20,7 +18,6 @@ import org.springframework.messaging.Message;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
@@ -30,10 +27,6 @@ import java.util.List;
|
|
|
@Component
|
|
|
@Slf4j
|
|
|
public class MqttSubHandle {
|
|
|
- // 常量定义
|
|
|
- private static final double VERSION_THRESHOLD = 2.0; // 版本阈值,用于判断设备协议版本
|
|
|
- private static final int QOS = 1; // MQTT服务质量等级
|
|
|
- private static final boolean RETAIN = true; // MQTT保留消息标志
|
|
|
|
|
|
@Autowired
|
|
|
private MqttClient mqttClient; // MQTT消息发布器
|
|
@@ -76,7 +69,7 @@ public class MqttSubHandle {
|
|
|
|
|
|
/**
|
|
|
* MQTT消息统一入口处理方法
|
|
|
- *
|
|
|
+ * <p>
|
|
|
* 业务流程:
|
|
|
* 1. 从消息头提取MQTT主题和负载
|
|
|
* 2. 从主题路径中提取操作类型(action)
|
|
@@ -101,23 +94,11 @@ public class MqttSubHandle {
|
|
|
|
|
|
// 根据主题路由到不同的处理方法
|
|
|
switch (action) {
|
|
|
- case "event":
|
|
|
- subDasEvent(topic, payload);
|
|
|
- break;
|
|
|
|
|
|
// 接收LAS告警事件主题消息 if里面判断新逻辑, else 保持旧逻辑
|
|
|
case "alarm_event":
|
|
|
subDasAlarmEvent(topic, payload);
|
|
|
break;
|
|
|
-// case "realtime_pos":
|
|
|
-// subDasRealtimePos(topic, payload);
|
|
|
-// break;
|
|
|
-// case "dev_status":
|
|
|
-// subDasDevStatus(topic, payload);
|
|
|
-// break;
|
|
|
- case "exist":
|
|
|
- subDasExist(topic, payload);
|
|
|
- break;
|
|
|
case "connect":
|
|
|
subMqttClientConnect(topic, payload);
|
|
|
break;
|
|
@@ -184,32 +165,13 @@ public class MqttSubHandle {
|
|
|
int falling = obj.getIntValue("falling");
|
|
|
//0:no fall 1:detected 2: confirmed 3:calling
|
|
|
|
|
|
-// String event = obj.getString("event");
|
|
|
-// byte messageType = obj.getByteValue("message_type");
|
|
|
-// byte pose = obj.getByteValue("pose");
|
|
|
-// JSONArray targetPointArray = obj.getJSONArray("target_point");
|
|
|
-// if (targetPointArray == null || targetPointArray.isEmpty()) {
|
|
|
-// log.info("mqttsub target_point is Empty, do nothing");
|
|
|
-// return;
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
// 2 有跌倒事件发生
|
|
|
if (falling == 2) {
|
|
|
|
|
|
-// BigDecimal[][] targetPoints = new BigDecimal[targetPointArray.size()][3];
|
|
|
-// for (int i = 0; i < targetPointArray.size(); i++) {
|
|
|
-// JSONArray targetPoint = targetPointArray.getJSONArray(i);
|
|
|
-// targetPoints[i] = new BigDecimal[]{targetPoint.getBigDecimal(0), targetPoint.getBigDecimal(1), targetPoint.getBigDecimal(2)};
|
|
|
-// }
|
|
|
-// String targetPointsStr = JSON.toJSONString(targetPoints);
|
|
|
-
|
|
|
//存储跌倒时间到数据库
|
|
|
EventList eventListVO = new EventList();
|
|
|
eventListVO.setDevId(dev.getDevId());
|
|
|
-// eventListVO.setPose((int) pose);
|
|
|
eventListVO.setIsHandle(0);
|
|
|
-// eventListVO.setTargetPoints(targetPointsStr);
|
|
|
eventListVO.setEventType(falling);
|
|
|
eventListVO.setTenantId(dev.getTenantId());
|
|
|
eventListService.save(eventListVO);
|
|
@@ -237,12 +199,7 @@ public class MqttSubHandle {
|
|
|
sendList.add(msgUserDto);
|
|
|
|
|
|
// 对于 小程序拥有者,给出全局跌倒提醒,-- 被分享者是否需要
|
|
|
-
|
|
|
JSONObject wxMsg = new JSONObject();
|
|
|
-// wxMsg.put("targetPoints", targetPointArray);
|
|
|
-// wxMsg.put("x", x);
|
|
|
-// wxMsg.put("y", y);
|
|
|
-// wxMsg.put("zt", pose);
|
|
|
wxMsg.put("clientId", clientId);
|
|
|
wxMsg.put("event", "fall_confirmed");
|
|
|
wxMsg.put("msgType", "fall");
|
|
@@ -307,10 +264,6 @@ public class MqttSubHandle {
|
|
|
tenantName = tblTenant.getTenantName();
|
|
|
|
|
|
JSONObject webMsg = new JSONObject();
|
|
|
-// webMsg.put("targetPoints", targetPointArray);
|
|
|
-// webMsg.put("x", x);
|
|
|
-// webMsg.put("y", y);
|
|
|
-// webMsg.put("zt", pose);
|
|
|
webMsg.put("clientId", clientId);
|
|
|
webMsg.put("event", "fall_confirmed");
|
|
|
webMsg.put("msgType", "fall");
|
|
@@ -323,18 +276,6 @@ public class MqttSubHandle {
|
|
|
if (!CollectionUtils.isEmpty(adminUserInfos)) {
|
|
|
for (AdminUserInfo adminUserInfo : adminUserInfos) {
|
|
|
|
|
|
- // 3 对当前设备 具有管理权限的 web管理用户
|
|
|
- // todo 确定网页 管理用户 是否有 短信 服务号发送 功能
|
|
|
-// SendMsgUserDto sendDto = new SendMsgUserDto();
|
|
|
-// sendDto.setUserId(adminUserInfo.getUserId());
|
|
|
-// sendDto.setPhone(adminUserInfo.getPhone());
|
|
|
-//// sendDto.setUnionId(adminUserInfo.getUnionId());
|
|
|
-//// WxRelation wxRelation = wxRelationService.queryOneByUnionId(userInfo.getUnionId());
|
|
|
-//// if (wxRelation != null) {
|
|
|
-//// msgUserDto.setFwhOpenId(wxRelation.getFwhOpenId());
|
|
|
-//// }
|
|
|
-// sendList.add(sendDto);
|
|
|
-
|
|
|
// 判断当前用户是否登录网页
|
|
|
if (redisUtil.sIsMember(RedisCacheConstant.MQTT_CLIENT_USERID, RedisCacheConstant.WEB_USER_PRE + adminUserInfo.getUserId())) {
|
|
|
log.info("发送网页跌倒主题消息:topic:{}, msg:{}", String.format(TopicConstants.TOPIC_MPS_NOTIC, RedisCacheConstant.WEB_USER_PRE + adminUserInfo.getUserId()), webMsg.toString());
|
|
@@ -435,210 +376,9 @@ public class MqttSubHandle {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 处理跌倒事件消息
|
|
|
- *
|
|
|
- * @param topic MQTT主题
|
|
|
- * @param payload 消息负载
|
|
|
- */
|
|
|
- public void subDasEvent(String topic, String payload) {
|
|
|
-
|
|
|
- log.info("Received device message: topic={}, payload={}", topic, payload);
|
|
|
- JSONObject obj = JSONObject.parseObject(payload);
|
|
|
- String clientId = obj.getString("dev_id");
|
|
|
- String event = obj.getString("event");
|
|
|
-
|
|
|
- // 1 校验
|
|
|
- DevInfo dev = devInfoService.queryByClientId(clientId);
|
|
|
- if (dev == null) {
|
|
|
- log.warn("Device not found for clientId: {}", clientId);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- byte messageType = obj.getByteValue("message_type");
|
|
|
- byte pose = obj.getByteValue("pose");
|
|
|
- JSONArray targetPointArray = obj.getJSONArray("target_point");
|
|
|
- if (targetPointArray == null || targetPointArray.isEmpty()) {
|
|
|
- log.info("mqttsub target_point is Empty, do nothing");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // 2 有跌倒事件发生
|
|
|
- if (messageType == 3 && ("fall_confirmed").equals(event)) {
|
|
|
-
|
|
|
- BigDecimal[][] targetPoints = new BigDecimal[targetPointArray.size()][3];
|
|
|
- for (int i = 0; i < targetPointArray.size(); i++) {
|
|
|
- JSONArray targetPoint = targetPointArray.getJSONArray(i);
|
|
|
- targetPoints[i] = new BigDecimal[]{targetPoint.getBigDecimal(0), targetPoint.getBigDecimal(1), targetPoint.getBigDecimal(2)};
|
|
|
- }
|
|
|
- String targetPointsStr = JSON.toJSONString(targetPoints);
|
|
|
-
|
|
|
- //存储跌倒时间到数据库
|
|
|
- EventList eventListVO = new EventList();
|
|
|
- eventListVO.setDevId(dev.getDevId());
|
|
|
- eventListVO.setPose((int) pose);
|
|
|
- eventListVO.setIsHandle(0);
|
|
|
- eventListVO.setTargetPoints(targetPointsStr);
|
|
|
- eventListVO.setEventType((int) messageType);
|
|
|
- eventListService.save(eventListVO);
|
|
|
-
|
|
|
-
|
|
|
-// // 向前端发送数据
|
|
|
- JSONArray targetPointOne = targetPointArray.getJSONArray(0);
|
|
|
- BigDecimal x = targetPointOne.getBigDecimal(0);
|
|
|
- BigDecimal y = targetPointOne.getBigDecimal(1);
|
|
|
-// JSONObject msg = new JSONObject();
|
|
|
-// msg.put("target_points", targetPointArray);
|
|
|
-// msg.put("x", x);
|
|
|
-// msg.put("y", y);
|
|
|
-// msg.put("zt", pose);
|
|
|
-// msg.put("clientId", clientId);
|
|
|
-// msg.put("event", event);
|
|
|
-// msg.put("msgType", "event");
|
|
|
-// msg.put("eventListId", String.valueOf(eventListVO.getEventListId()));
|
|
|
-// // 发送socket
|
|
|
-// mqttClient.sendMessage(String.format("/mps/%s/event", clientId), msg.toString());
|
|
|
-
|
|
|
- // 整理需要接收消息的人员列表
|
|
|
- log.info("mqttutil--有跌倒事件");
|
|
|
- List<SendMsgUserDto> sendList = new ArrayList<>();
|
|
|
- String devName = dev.getDevName();
|
|
|
- String devId = dev.getClientId();
|
|
|
- Long userId = dev.getUserId();
|
|
|
-
|
|
|
- // 需要发送提示的 有 当前设备拥有者, 被分享者, 以及 对当前设备 具有管理权限的 web管理用户
|
|
|
- // 小程序拥有者
|
|
|
- if (userId != null) {
|
|
|
- UserInfo userInfo = userService.queryById(userId);
|
|
|
- SendMsgUserDto msgUserDto = new SendMsgUserDto();
|
|
|
- msgUserDto.setUserId(userId);
|
|
|
- msgUserDto.setPhone(userInfo.getPhone());
|
|
|
- msgUserDto.setUnionId(userInfo.getUnionId());
|
|
|
- msgUserDto.setMessageFlag(true);
|
|
|
- msgUserDto.setServiceNumberFlag(true);
|
|
|
- WxRelation wxRelation = wxRelationService.queryOneByUnionId(userInfo.getUnionId());
|
|
|
- if (wxRelation != null) {
|
|
|
- msgUserDto.setFwhOpenId(wxRelation.getFwhOpenId());
|
|
|
- }
|
|
|
- sendList.add(msgUserDto);
|
|
|
-
|
|
|
- // 对于 小程序拥有者,给出全局跌倒提醒,-- 被分享者是否需要
|
|
|
-
|
|
|
- JSONObject wxMsg = new JSONObject();
|
|
|
- wxMsg.put("targetPoints", targetPointArray);
|
|
|
- wxMsg.put("x", x);
|
|
|
- wxMsg.put("y", y);
|
|
|
- wxMsg.put("zt", pose);
|
|
|
- wxMsg.put("clientId", clientId);
|
|
|
- wxMsg.put("event", "fall_confirmed");
|
|
|
- wxMsg.put("msgType", "fall");
|
|
|
- wxMsg.put("devName", devName.toString());
|
|
|
- wxMsg.put("eventListId", String.valueOf(eventListVO.getEventListId()));
|
|
|
-
|
|
|
- log.info("发送微信跌倒主题消息:topic:{}, msg:{}", String.format(TopicConstants.TOPIC_MPS_NOTIC, RedisCacheConstant.WX_USER_PRE + userInfo.getUserId()), wxMsg.toString());
|
|
|
- mqttClient.sendMessage(String.format(TopicConstants.TOPIC_MPS_NOTIC, RedisCacheConstant.WX_USER_PRE + userInfo.getUserId()), wxMsg.toString(), 2, false);
|
|
|
-
|
|
|
- // 设备的被分享者 - 根据标志位筛选并添加到发送列表
|
|
|
- List<DevShare> shares = devShareService.queryConfirmedByDevId(dev.getDevId());
|
|
|
- if (!CollectionUtils.isEmpty(shares)) {
|
|
|
- for (DevShare share : shares) {
|
|
|
- // 发送微信跌倒主题消息
|
|
|
- log.info("发送微信跌倒主题消息:topic:{}, msg:{}", String.format(TopicConstants.TOPIC_MPS_NOTIC, RedisCacheConstant.WX_USER_PRE + share.getSharedUserId()), wxMsg.toString());
|
|
|
- mqttClient.sendMessage(String.format(TopicConstants.TOPIC_MPS_NOTIC, RedisCacheConstant.WX_USER_PRE + share.getSharedUserId()), wxMsg.toString(), 2, false);
|
|
|
-
|
|
|
- // 创建被分享者的消息用户DTO
|
|
|
- SendMsgUserDto msgUserShared = new SendMsgUserDto();
|
|
|
- msgUserShared.setUserId(share.getSharedUserId());
|
|
|
- msgUserShared.setPhone(share.getSharedPhone());
|
|
|
-
|
|
|
- // 获取完整的分享信息(包含标志位)
|
|
|
- DevShare devShare = devShareService.getById(share.getShareId());
|
|
|
- if (devShare != null) {
|
|
|
- // 将Integer类型的标志位转换为boolean类型:0-授权(true),1-拒绝(false)
|
|
|
- boolean messageFlag = devShare.getMessageFlag() != null && devShare.getMessageFlag() == 0;
|
|
|
- boolean serviceNumberFlag = devShare.getServiceNumberFlag() != null && devShare.getServiceNumberFlag() == 0;
|
|
|
-
|
|
|
- msgUserShared.setMessageFlag(messageFlag);
|
|
|
- msgUserShared.setServiceNumberFlag(serviceNumberFlag);
|
|
|
-
|
|
|
- // 根据标志位决定是否添加到发送列表
|
|
|
- // 只有当短信通知或服务号通知任一被授权时,才添加到发送列表
|
|
|
- if (messageFlag || serviceNumberFlag) {
|
|
|
- // 获取被分享者的微信关系信息
|
|
|
- UserInfo sharedUserInfo = userService.queryById(share.getSharedUserId());
|
|
|
- if (sharedUserInfo != null) {
|
|
|
- msgUserShared.setUnionId(sharedUserInfo.getUnionId());
|
|
|
- WxRelation sharedWxRelation = wxRelationService.queryOneByUnionId(sharedUserInfo.getUnionId());
|
|
|
- if (sharedWxRelation != null) {
|
|
|
- msgUserShared.setFwhOpenId(sharedWxRelation.getFwhOpenId());
|
|
|
- }
|
|
|
- sendList.add(msgUserShared);
|
|
|
- log.info("被分享者已添加到发送列表: userId={}, messageFlag={}, serviceNumberFlag={}",
|
|
|
- share.getSharedUserId(), messageFlag, serviceNumberFlag);
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.info("被分享者拒绝所有通知: userId={}, messageFlag={}, serviceNumberFlag={}",
|
|
|
- share.getSharedUserId(), messageFlag, serviceNumberFlag);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 针对跌倒事件 发送 网页 主题消息提示
|
|
|
- String tenantName = "";
|
|
|
- // 网页告警提示 需要当前设备绑定到租户,会发送到当前租户已经登录的管理员页面
|
|
|
- if (dev.getTenantId() != null) {
|
|
|
- TblTenant tblTenant = tblTenantService.getById(dev.getTenantId());
|
|
|
- tenantName = tblTenant.getTenantName();
|
|
|
-
|
|
|
- JSONObject webMsg = new JSONObject();
|
|
|
- webMsg.put("targetPoints", targetPointArray);
|
|
|
- webMsg.put("x", x);
|
|
|
- webMsg.put("y", y);
|
|
|
- webMsg.put("zt", pose);
|
|
|
- webMsg.put("clientId", clientId);
|
|
|
- webMsg.put("event", "fall_confirmed");
|
|
|
- webMsg.put("msgType", "fall");
|
|
|
- webMsg.put("devName", devName.toString());
|
|
|
- webMsg.put("tenantName", tenantName);
|
|
|
- webMsg.put("eventListId", String.valueOf(eventListVO.getEventListId()));
|
|
|
-
|
|
|
- // 查询当前需要发送的userId
|
|
|
- List<AdminUserInfo> adminUserInfos = adminUserService.queryByTenantIdAndUserType(dev.getTenantId(), null);
|
|
|
- if (!CollectionUtils.isEmpty(adminUserInfos)) {
|
|
|
- for (AdminUserInfo adminUserInfo : adminUserInfos) {
|
|
|
-
|
|
|
- // 3 对当前设备 具有管理权限的 web管理用户
|
|
|
- // todo 确定网页 管理用户 是否有 短信 服务号发送 功能
|
|
|
-// SendMsgUserDto sendDto = new SendMsgUserDto();
|
|
|
-// sendDto.setUserId(adminUserInfo.getUserId());
|
|
|
-// sendDto.setPhone(adminUserInfo.getPhone());
|
|
|
-//// sendDto.setUnionId(adminUserInfo.getUnionId());
|
|
|
-//// WxRelation wxRelation = wxRelationService.queryOneByUnionId(userInfo.getUnionId());
|
|
|
-//// if (wxRelation != null) {
|
|
|
-//// msgUserDto.setFwhOpenId(wxRelation.getFwhOpenId());
|
|
|
-//// }
|
|
|
-// sendList.add(sendDto);
|
|
|
-
|
|
|
- // 判断当前用户是否登录网页
|
|
|
- if (redisUtil.sIsMember(RedisCacheConstant.MQTT_CLIENT_USERID, RedisCacheConstant.WEB_USER_PRE + adminUserInfo.getUserId())) {
|
|
|
- log.info("发送网页跌倒主题消息:topic:{}, msg:{}", String.format(TopicConstants.TOPIC_MPS_NOTIC, RedisCacheConstant.WEB_USER_PRE + adminUserInfo.getUserId()), webMsg.toString());
|
|
|
- mqttClient.sendMessage(String.format(TopicConstants.TOPIC_MPS_NOTIC, RedisCacheConstant.WEB_USER_PRE + adminUserInfo.getUserId()), webMsg.toString(), 2, false);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //3.调用 发送短信和微信公众号通知 功能
|
|
|
-// sendMesAndWxService(sendList, devName, devId);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
* 推送设备转移消息给转移对象
|
|
|
*/
|
|
|
- public void pushDeviceTransferMsg(DevInfo devInfo, UserInfo targetUser){
|
|
|
+ public void pushDeviceTransferMsg(DevInfo devInfo, UserInfo targetUser) {
|
|
|
|
|
|
// 根据 unionId 查询服务号关系
|
|
|
List<WxRelation> wxRelations = wxRelationService.queryByUnionId(targetUser.getUnionId());
|
|
@@ -652,16 +392,17 @@ 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("发送微信公众号信息完毕");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 发送短信和微信公众号通知
|
|
|
+ *
|
|
|
* @param sendList 需要发送通知的用户列表
|
|
|
- * @param devName 设备名称
|
|
|
- * @param devId 设备ID
|
|
|
+ * @param devName 设备名称
|
|
|
+ * @param devId 设备ID
|
|
|
*/
|
|
|
private void sendMesAndWxService(List<SendMsgUserDto> sendList, String devName, String devId) {
|
|
|
if (CollectionUtils.isEmpty(sendList)) {
|
|
@@ -718,236 +459,61 @@ public class MqttSubHandle {
|
|
|
|
|
|
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");
|
|
|
- String uuid = obj.getString("plan_uuid");
|
|
|
-
|
|
|
- // 1.2 判断告警计划是否开启服务号推送
|
|
|
- AlarmPlan alarmPlan = alarmPlanService.findByUuid(uuid);
|
|
|
- if (alarmPlan.getLinkagePushWechatService() == 0) {
|
|
|
- log.info("服务号通知发送失败,当前设备告警计划未开启服务号推送: clientId={}, uuid={}", clientId, uuid);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 1.3 查找设备信息,获取主绑人的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.4 如果userId为空,则没有绑定人
|
|
|
- if (userId == null) {
|
|
|
- log.info("服务号通知发送失败,设备未绑定用户: clientId={}", clientId);
|
|
|
- return;
|
|
|
- }
|
|
|
+ JSONObject obj = JSONObject.parseObject(payload);
|
|
|
+ String eventType = obj.getString("event_type");
|
|
|
+ // 1.1 判断 消息类型是否符合 起夜异常 or 异常滞留
|
|
|
+ if (AlarmEventType.isTargetEvent(eventType)) {
|
|
|
+ String clientId = obj.getString("dev_id");
|
|
|
+ String uuid = obj.getString("plan_uuid");
|
|
|
+
|
|
|
+ // 1.2 判断告警计划是否开启服务号推送
|
|
|
+ AlarmPlan alarmPlan = alarmPlanService.findByUuid(uuid);
|
|
|
+ if (alarmPlan.getLinkagePushWechatService() == 0) {
|
|
|
+ log.info("服务号通知发送失败,当前设备告警计划未开启服务号推送: clientId={}, uuid={}", clientId, uuid);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- // 1.5 查询主绑人信息
|
|
|
- UserInfo user = userService.queryById(userId);
|
|
|
+ // 1.3 查找设备信息,获取主绑人的userId
|
|
|
+ DevInfo dev = devInfoService.queryByClientId(clientId);
|
|
|
|
|
|
- // 1.6 获取用户微信服务号OpenId
|
|
|
- WxRelation wxRelations = wxRelationService.queryOneByUnionId(user.getUnionId());
|
|
|
+ if (dev == null) {
|
|
|
+ log.info("服务号通知发送失败,当前设备不存在: clientId={}", clientId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (wxRelations == null) {
|
|
|
- log.info("服务号通知发送失败,用户未绑定微信服务号: userId={}", userId);
|
|
|
- return;
|
|
|
- }
|
|
|
- String fwhOpenId = wxRelations.getFwhOpenId();
|
|
|
+ Long userId = dev.getUserId();
|
|
|
+ String devName = dev.getDevName();
|
|
|
+ String devId = dev.getClientId();
|
|
|
|
|
|
- log.info("mqttutil--当前useropenid=" + user.getOpenid() + ", fwhopenId=" + fwhOpenId);
|
|
|
- log.info("发送微信公众号信息:devName=" + devName + ", phoneNo=" + user.getPhone() + "fwhOpenId=" + fwhOpenId);
|
|
|
|
|
|
- // 1.7 发送微信公告号消息
|
|
|
- wxOfficeAccountClient.sendMsg(devId, devName, user.getPhone(), fwhOpenId, "设备运行检测到告警异常,请前往小程序查看");
|
|
|
- log.info("发送微信公众号消息发完了");
|
|
|
+ // 1.4 如果userId为空,则没有绑定人
|
|
|
+ if (userId == null) {
|
|
|
+ log.info("服务号通知发送失败,设备未绑定用户: clientId={}", clientId);
|
|
|
return;
|
|
|
}
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
- // 2. 如果为旧逻辑 走下面流程
|
|
|
- JSONObject obj = JSONObject.parseObject(payload);
|
|
|
- String clientId = obj.getString("dev_id");
|
|
|
+ // 1.5 查询主绑人信息
|
|
|
+ UserInfo user = userService.queryById(userId);
|
|
|
|
|
|
- DevInfo dev = devInfoService.queryByClientId(clientId);
|
|
|
- List<Long> userIds = new ArrayList<>();
|
|
|
- StringBuilder devName = new StringBuilder();
|
|
|
- String devId = "";
|
|
|
- // 设备拥有者openid
|
|
|
- if (dev != null) {
|
|
|
- userIds.add(dev.getUserId());
|
|
|
- devName.append(dev.getDevName());
|
|
|
- devId = dev.getClientId();
|
|
|
- }
|
|
|
+ // 1.6 获取用户微信服务号OpenId
|
|
|
+ WxRelation wxRelations = wxRelationService.queryOneByUnionId(user.getUnionId());
|
|
|
|
|
|
- if (!userIds.isEmpty()) {
|
|
|
- // 拥有者和被分享者phone
|
|
|
- List<UserInfo> userInfos = userService.listByIds(userIds);
|
|
|
- for (int i = 0; i < userInfos.size(); i++) {
|
|
|
- UserInfo user = userInfos.get(i);
|
|
|
-
|
|
|
- // 发送微信公众号消息
|
|
|
- List<WxRelation> wxRelations = wxRelationService.queryByUnionId(user.getUnionId());
|
|
|
- String fwhOpenId = "";
|
|
|
- if (wxRelations != null && !wxRelations.isEmpty()) {
|
|
|
- fwhOpenId = wxRelations.get(0).getFwhOpenId();
|
|
|
- }
|
|
|
- log.info("mqttutil--当前useropenid=" + user.getOpenid() + ", fwhopenId=" + fwhOpenId);
|
|
|
- log.info("发送微信公众号信息:devName=" + devName.toString() + ", phoneNo=" + user.getPhone() + "fwhOpenId=" + fwhOpenId);
|
|
|
- // 发送微信公告号消息
|
|
|
- if (StringUtils.contains(devName.toString(), "卫生间")) {
|
|
|
- wxOfficeAccountClient.sendMsg(devId, devName.toString(), user.getPhone(), fwhOpenId, "设备运行检测到告警异常,请前往小程序查看");
|
|
|
- log.info("发送微信公众号消息发完了");
|
|
|
- }
|
|
|
+ if (wxRelations == null) {
|
|
|
+ log.info("服务号通知发送失败,用户未绑定微信服务号: userId={}", userId);
|
|
|
+ return;
|
|
|
}
|
|
|
+ String fwhOpenId = wxRelations.getFwhOpenId();
|
|
|
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void subDasRealtimePos(String topic, String payload) {
|
|
|
+ log.info("mqttutil--当前useropenid=" + user.getOpenid() + ", fwhopenId=" + fwhOpenId);
|
|
|
+ log.info("发送微信公众号信息:devName=" + devName + ", phoneNo=" + user.getPhone() + "fwhOpenId=" + fwhOpenId);
|
|
|
|
|
|
- JSONObject obj = JSONObject.parseObject(payload);
|
|
|
- String clientId = obj.getString("dev_id");
|
|
|
- byte messageType = obj.getByteValue("message_type");
|
|
|
- byte pose = obj.getByteValue("pose");
|
|
|
- JSONArray targetPointArray = obj.getJSONArray("target_point");
|
|
|
- if (targetPointArray == null || targetPointArray.isEmpty()) {
|
|
|
- log.info("Received device message: topic={}, payload={}", topic, payload);
|
|
|
- log.info("mqttsub target_point is Empty, do nothing");
|
|
|
+ // 1.7 发送微信公告号消息
|
|
|
+ wxOfficeAccountClient.sendMsg(devId, devName, user.getPhone(), fwhOpenId, "设备运行检测到告警异常,请前往小程序查看");
|
|
|
+ log.info("发送微信公众号消息发完了");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- JSONArray targetPointOne = targetPointArray.getJSONArray(0);
|
|
|
- BigDecimal x = targetPointOne.getBigDecimal(0);
|
|
|
- BigDecimal y = targetPointOne.getBigDecimal(1);
|
|
|
- BigDecimal z = targetPointOne.getBigDecimal(2);
|
|
|
-
|
|
|
- BigDecimal[][] targetPoints = new BigDecimal[targetPointArray.size()][3];
|
|
|
- for (int i = 0; i < targetPointArray.size(); i++) {
|
|
|
-
|
|
|
- JSONArray targetPoint = targetPointArray.getJSONArray(i);
|
|
|
- targetPoints[i] = new BigDecimal[]{targetPoint.getBigDecimal(0), targetPoint.getBigDecimal(1), targetPoint.getBigDecimal(2)};
|
|
|
- }
|
|
|
-
|
|
|
- //向前端发送数据
|
|
|
- JSONObject msg = new JSONObject();
|
|
|
- msg.put("targetPoints", targetPointArray);
|
|
|
- msg.put("x", x);
|
|
|
- msg.put("y", y);
|
|
|
- msg.put("zt", pose);
|
|
|
- msg.put("clientId", clientId);
|
|
|
- msg.put("msgType", "target_point");
|
|
|
-
|
|
|
- // todo websocket 发送msg
|
|
|
-// PushMsgWebSocket.sendMessageTo(msg.toString(), dev_id);
|
|
|
- mqttClient.sendMessage(String.format(TopicConstants.TOPIC_MPS_REALTIME_POS, clientId), msg.toString());
|
|
|
- }
|
|
|
-
|
|
|
- public void subDasDevStatus(String topic, String payload)
|
|
|
- {
|
|
|
-
|
|
|
- log.info("Received device message: topic={}, payload={}", topic, payload);
|
|
|
- JSONObject obj = JSONObject.parseObject(payload);
|
|
|
- String clientId = obj.getString("dev_id");
|
|
|
- String devType = obj.getString("dev_type");
|
|
|
- int online = obj.getIntValue("online");
|
|
|
- String software = obj.getString("software");
|
|
|
- String hardware = obj.getString("hardware");
|
|
|
-
|
|
|
- String networkStr = obj.getString("network");
|
|
|
- JSONObject network = JSONObject.parseObject(networkStr);
|
|
|
- String ssid = network.getString("ssid");
|
|
|
- String password = network.getString("password");
|
|
|
- String ip = network.getString("ip");
|
|
|
-
|
|
|
- String radarParamStr = obj.getString("radar_param");
|
|
|
- JSONObject radarParam = JSONObject.parseObject(radarParamStr);
|
|
|
- String mountPlain = radarParam.getString("mount_plain");
|
|
|
- BigDecimal height = radarParam.getBigDecimal("height");
|
|
|
-
|
|
|
- String trackingRegionStr = radarParam.getString("tracking_region");
|
|
|
- JSONObject trackingRegion = JSONObject.parseObject(trackingRegionStr);
|
|
|
- BigDecimal startX = trackingRegion.getBigDecimal("start_x");
|
|
|
- BigDecimal startY = trackingRegion.getBigDecimal("start_y");
|
|
|
- BigDecimal startZ = trackingRegion.getBigDecimal("start_z");
|
|
|
- BigDecimal stopX = trackingRegion.getBigDecimal("stop_x");
|
|
|
- BigDecimal stopY = trackingRegion.getBigDecimal("stop_y");
|
|
|
- BigDecimal stopZ = trackingRegion.getBigDecimal("stop_z");
|
|
|
- BigDecimal length = startX.subtract(stopX).abs();
|
|
|
- BigDecimal width = startY.subtract(stopY).abs();
|
|
|
-
|
|
|
- DevInfo vo = new DevInfo();
|
|
|
- vo.setClientId(clientId);
|
|
|
- vo.setDevType(devType);
|
|
|
- vo.setOnline(online);
|
|
|
- vo.setSoftware(software);
|
|
|
- vo.setHardware(hardware);
|
|
|
- vo.setWifiName(ssid);
|
|
|
- vo.setWifiName(password);
|
|
|
- vo.setIp(ip);
|
|
|
- vo.setMountPlain(mountPlain);
|
|
|
- vo.setXxStart(startX);
|
|
|
- vo.setYyStart(startY);
|
|
|
- vo.setZzStart(startZ);
|
|
|
- vo.setXxEnd(stopX);
|
|
|
- vo.setYyEnd(stopY);
|
|
|
- vo.setZzEnd(stopZ);
|
|
|
- vo.setHeight(height);
|
|
|
- vo.setWidth(width);
|
|
|
- vo.setLength(length);
|
|
|
-
|
|
|
- DevInfo dev = devInfoService.queryByClientId(clientId);
|
|
|
- if (dev != null) {
|
|
|
-
|
|
|
- devInfoService.update(vo, new LambdaUpdateWrapper<DevInfo>().eq(DevInfo::getClientId, clientId));
|
|
|
-
|
|
|
- // 向前端发送数据
|
|
|
- JSONObject msg = new JSONObject();
|
|
|
- msg.put("mountPlain", mountPlain);
|
|
|
- msg.put("height", height);
|
|
|
- msg.put("software", software);
|
|
|
- msg.put("startX", startX);
|
|
|
- msg.put("stopX", stopX);
|
|
|
- msg.put("startY", startY);
|
|
|
- msg.put("stopY", stopY);
|
|
|
- msg.put("startZ", startZ);
|
|
|
- msg.put("stopZ", stopZ);
|
|
|
- msg.put("devType", devType);
|
|
|
- msg.put("msgType", "dev_status");
|
|
|
-
|
|
|
- // todo websocket 发送
|
|
|
-// PushMsgWebSocket.sendMessageTo(msg.toString(), clientId);
|
|
|
- } else {
|
|
|
-
|
|
|
- devInfoService.save(vo);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void subDasExist(String topic, String payload) {
|
|
|
-
|
|
|
- log.info("Received device message: topic={}, payload={}", topic, payload);
|
|
|
- JSONObject obj = JSONObject.parseObject(payload);
|
|
|
- String clientId = obj.getString("dev_id");
|
|
|
- String event = obj.getString("event");
|
|
|
- //向前端发送数据
|
|
|
- JSONObject msg = new JSONObject();
|
|
|
- msg.put("clientId", clientId);
|
|
|
- msg.put("event", event);
|
|
|
- msg.put("msgType", "exist");
|
|
|
-
|
|
|
- // todo websocketservice
|
|
|
-// PushMsgWebSocket.sendMessageTo(msg.toString(), dev_id);
|
|
|
}
|
|
|
|
|
|
public void subMqttClientConnect(String topic, String payload) {
|