|
@@ -7,6 +7,7 @@ import com.alibaba.fastjson2.JSONObject;
|
|
|
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.util.MsgClient;
|
|
|
import com.hfln.portal.domain.customer.util.WxOfficeAccountClient;
|
|
|
import com.hfln.portal.infrastructure.po.*;
|
|
@@ -190,22 +191,32 @@ public class MqttSubHandle {
|
|
|
msg.put("event", event);
|
|
|
msg.put("msgType", "event");
|
|
|
|
|
|
- // todo 发送socket
|
|
|
+ // 发送socket
|
|
|
mqttClient.sendMessage(String.format("/mps/%s/event", clientId), msg.toString());
|
|
|
-// PushMsgWebSocket.sendMessageTo(msg.toString(), dev_id);
|
|
|
|
|
|
// 发送短信
|
|
|
if (event.equals("fall_confirmed")) {
|
|
|
log.info("mqttutil--有跌倒事件");
|
|
|
List<Long> userIds = new ArrayList<>();
|
|
|
- StringBuffer devName = new StringBuffer("");
|
|
|
- String devId = "";
|
|
|
- // 设备拥有者openid
|
|
|
- if (dev != null) {
|
|
|
- userIds.add(dev.getUserId());
|
|
|
- devName.append(dev.getDevName());
|
|
|
- devId = dev.getClientId();
|
|
|
+ List<SendMsgUserDto> sendList = new ArrayList<>();
|
|
|
+ String devName = dev.getDevName();
|
|
|
+ String devId = dev.getClientId();
|
|
|
+ Long userId = dev.getUserId();
|
|
|
+
|
|
|
+ // 需要发送提示的 有 当前设备拥有者, 被分享者, 以及 对当前设备 具有管理权限的 web管理用户
|
|
|
+ // 1 小程序拥有者
|
|
|
+ UserInfo userInfo = userService.queryById(userId);
|
|
|
+ SendMsgUserDto msgUserDto = new SendMsgUserDto();
|
|
|
+ msgUserDto.setUserId(userId);
|
|
|
+ msgUserDto.setPhone(userInfo.getPhone());
|
|
|
+ msgUserDto.setUnionId(userInfo.getUnionId());
|
|
|
+ WxRelation wxRelation = wxRelationService.queryOneByUnionId(userInfo.getUnionId());
|
|
|
+ if (wxRelation != null) {
|
|
|
+ msgUserDto.setFwhOpenId(wxRelation.getFwhOpenId());
|
|
|
}
|
|
|
+ sendList.add(msgUserDto);
|
|
|
+
|
|
|
+ // 2 todo 被分享者
|
|
|
|
|
|
// 针对跌倒事件 发送 网页 主题消息提示
|
|
|
String tenantName = "";
|
|
@@ -229,40 +240,50 @@ 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_WEB_NOTIC, RedisCacheConstant.WEB_USER_PRE + adminUserInfo.getUserId()), webMsg.toString());
|
|
|
mqttClient.sendMessage(String.format(TopicConstants.TOPIC_MPS_WEB_NOTIC, RedisCacheConstant.WEB_USER_PRE + adminUserInfo.getUserId()), webMsg.toString(), 2, false);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (!userIds.isEmpty()) {
|
|
|
- // 拥有者和被分享者phone
|
|
|
- List<UserInfo> userInfos = userService.listByIds(userIds);
|
|
|
- for (UserInfo user : userInfos) {
|
|
|
+ if (!CollectionUtils.isEmpty(sendList)) {
|
|
|
+ for (SendMsgUserDto sendDto : sendList) {
|
|
|
// 发送跌倒短信
|
|
|
log.info("mqttutil--开始发送跌倒消息");
|
|
|
- log.info("mqttutil--sendmsg:phone{}, dev_name:{}", user.getPhone(), devName.toString());
|
|
|
- msgClient.sendNotifyMsg(user.getPhone(), devName.toString());
|
|
|
+ log.info("mqttutil--sendmsg:phone{}, dev_name:{}", sendDto.getPhone(), devName.toString());
|
|
|
+ msgClient.sendNotifyMsg(sendDto.getPhone(), devName.toString());
|
|
|
log.info("mqttUtil--消息发完了");
|
|
|
|
|
|
// 发送微信公众号消息
|
|
|
- List<WxRelation> wxRelations = wxRelationService.queryByUnionId(user.getUnionId());
|
|
|
+ List<WxRelation> wxRelations = wxRelationService.queryByUnionId(sendDto.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);
|
|
|
+// log.info("mqttutil--当前useropenid=" + sendDto.getOpenid() + ", fwhopenId=" + fwhOpenId);
|
|
|
+ log.info("发送微信公众号信息:devName=" + devName.toString() + ", phoneNo=" + sendDto.getPhone() + "fwhOpenId=" + fwhOpenId);
|
|
|
// 发送微信公告号消息
|
|
|
- wxOfficeAccountClient.sendMsg(devId, devName.toString(), user.getPhone(), fwhOpenId, "设备检测到跌倒,请前往小程序查看详细信息");
|
|
|
+ wxOfficeAccountClient.sendMsg(devId, devName.toString(), sendDto.getPhone(), fwhOpenId, "设备检测到跌倒,请前往小程序查看详细信息");
|
|
|
log.info("发送微信公众号消息发完了");
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
public void subDasAlarmEvent(String topic, String payload) {
|
|
|
|