From cd538c205628f28839323b49b7f77f33196a601f Mon Sep 17 00:00:00 2001
From: zhangnaisong <2434969829@qq.com>
Date: 星期四, 11 七月 2024 15:50:42 +0800
Subject: [PATCH] 电磁锁操控加入判断速度为0提交
---
ard-work/src/main/java/com/ruoyi/call/service/impl/ArdCallHistoryServiceImpl.java | 43 ++++++++++++++++++++++++++++++++++++++++---
1 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/call/service/impl/ArdCallHistoryServiceImpl.java b/ard-work/src/main/java/com/ruoyi/call/service/impl/ArdCallHistoryServiceImpl.java
index 8667806..82014e5 100644
--- a/ard-work/src/main/java/com/ruoyi/call/service/impl/ArdCallHistoryServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/call/service/impl/ArdCallHistoryServiceImpl.java
@@ -1,7 +1,10 @@
package com.ruoyi.call.service.impl;
+import java.util.HashMap;
import java.util.List;
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.call.domain.*;
import com.ruoyi.call.mapper.*;
import com.ruoyi.common.utils.DateUtils;
@@ -13,12 +16,17 @@
import org.springframework.stereotype.Service;
import java.util.ArrayList;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.call.service.IArdCallHistoryService;
import javax.annotation.Resource;
+import javax.websocket.Session;
import static com.ruoyi.utils.websocket.util.WebSocketUtils.ONLINE_USER_SESSIONS;
@@ -69,6 +77,8 @@
*/
@Override
public int insertArdCallHistory(ArdCallHistory ardCallHistory) {
+
+
ardCallHistory.setId(IdUtils.simpleUUID());
ardCallHistory.setCreateTime(DateUtils.getNowDate());
ArdCallSession ardCallSession = ardCallSessionMapper.selectArdCallSessionById(ardCallHistory.getSessionId());
@@ -86,7 +96,20 @@
ardCallUnreadMessagesMapper.updateArdCallUnreadMessages(ardCallUnreadMessages);
}
//websocket鍙戦�佺粰targetId
- WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(ardCallHistory.getTargetId()),ardCallHistory.getContent());
+ // 鏋勫缓姝e垯琛ㄨ揪寮忔ā寮�
+ String regex = "^" + Pattern.quote(ardCallHistory.getTargetId()) + "_\\d+$";
+ Pattern pattern = Pattern.compile(regex);
+ Map<String, Object> messageMap = new HashMap<>();
+ messageMap.put("type", "message");
+ messageMap.put("message", JSON.toJSONString(ardCallHistory));
+ ONLINE_USER_SESSIONS.entrySet().stream()
+ .filter(entry -> {
+ Matcher matcher = pattern.matcher(entry.getKey());
+ return matcher.matches();
+ })
+ .map(Map.Entry::getValue)
+ .forEach(session -> WebSocketUtils.sendMessage(session, messageMap));
+
} else {
//鏇存柊缇よ亰鐢ㄦ埛鏈娑堟伅璁℃暟
ArdCallGroupUser ardCallGroupUser = new ArdCallGroupUser();
@@ -106,9 +129,23 @@
ardCallUnreadMessages.setUnreadCount(ardCallUnreadMessages.getUnreadCount() + 1);
ardCallUnreadMessagesMapper.updateArdCallUnreadMessages(ardCallUnreadMessages);
}
+ //websocket鍙戦�佺粰targetId
+ // 鏋勫缓姝e垯琛ㄨ揪寮忔ā寮�
+ String regex = "^" + Pattern.quote(groupUser.getUserId()) + "_\\d+$";
+ Pattern pattern = Pattern.compile(regex);
+ Map<String, Object> messageMap = new HashMap<>();
+ messageMap.put("type", "message");
+ messageMap.put("message", JSON.toJSONString(ardCallHistory));
+ ONLINE_USER_SESSIONS.entrySet().stream()
+ .filter(entry ->
+ {
+ Matcher matcher = pattern.matcher(entry.getKey());
+ return matcher.matches();
+ })
+ .map(Map.Entry::getValue)
+ .forEach(session -> WebSocketUtils.sendMessage(session, messageMap));
}
- //websocket鍙戦�佺粰targetId
- WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(groupUser.getUserId()),ardCallHistory.getContent());
+
});
}
--
Gitblit v1.9.3