From 38f29e38fcc668171dc05c53d40a36b895c86102 Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: 星期四, 10 十月 2024 13:34:28 +0800
Subject: [PATCH] init
---
ard-work/src/main/java/com/ruoyi/call/service/impl/ArdCallHistoryServiceImpl.java | 65 ++++++++------------------------
1 files changed, 17 insertions(+), 48 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 d7a967c..d442904 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,37 +1,23 @@
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.call.dto.MessageEvent;
+import com.ruoyi.call.mapper.ArdCallGroupUserMapper;
+import com.ruoyi.call.mapper.ArdCallHistoryMapper;
+import com.ruoyi.call.mapper.ArdCallSessionMapper;
+import com.ruoyi.call.mapper.ArdCallUnreadMessagesMapper;
import com.ruoyi.call.service.IArdCallGroupService;
-import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.call.service.IArdCallHistoryService;
import com.ruoyi.common.utils.DateUtils;
-
-import com.ruoyi.common.utils.MessageUtils;
+import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
-import com.ruoyi.system.service.ISysUserService;
-import com.ruoyi.utils.websocket.util.WebSocketUtils;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationEventPublisher;
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;
+import java.util.List;
/**
* 浼氳瘽鍘嗗彶Service涓氬姟灞傚鐞�
@@ -40,6 +26,7 @@
* @date 2024-07-03
*/
@Service
+@Slf4j(topic = "msgListener")
public class ArdCallHistoryServiceImpl implements IArdCallHistoryService {
@Resource
private ArdCallHistoryMapper ardCallHistoryMapper;
@@ -51,6 +38,8 @@
private ArdCallGroupUserMapper ardCallGroupUserMapper;
@Resource
private IArdCallGroupService ardCallGroupService;
+ @Autowired
+ private ApplicationEventPublisher eventPublisher;
/**
* 鏌ヨ浼氳瘽鍘嗗彶
@@ -104,7 +93,6 @@
*/
@Override
public int insertArdCallHistory(ArdCallHistory ardCallHistory) {
-
ardCallHistory.setId(IdUtils.simpleUUID());
ardCallHistory.setCreateTime(DateUtils.getNowDate());
ArdCallSession ardCallSession = ardCallSessionMapper.selectArdCallSessionById(ardCallHistory.getSessionId());
@@ -125,17 +113,8 @@
ardCallUnreadMessagesMapper.updateArdCallUnreadMessages(ardCallUnreadMessages);
}
//websocket鍙戦�佺粰targetId
- // 鏋勫缓姝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));
-
+ MessageEvent messageEvent = new MessageEvent(ardCallHistory.getTargetId(), ardCallHistory);
+ eventPublisher.publishEvent(messageEvent);
} else {
//鏇存柊缇よ亰鐢ㄦ埛鏈娑堟伅璁℃暟
ArdCallGroupUser ardCallGroupUser = new ArdCallGroupUser();
@@ -159,20 +138,10 @@
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));
+ MessageEvent messageEvent = new MessageEvent(groupUser.getUserId(), ardCallHistory);
+ eventPublisher.publishEvent(messageEvent);
}
-
});
-
}
return ardCallHistoryMapper.insertArdCallHistory(ardCallHistory);
}
--
Gitblit v1.9.3