From cf4afcc8902efc85f1e71f26073404a0a7a4f204 Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: 星期三, 31 七月 2024 09:48:41 +0800
Subject: [PATCH] 修改:异步async指定线程池

---
 ard-work/src/main/java/com/ruoyi/call/service/impl/ArdCallHistoryServiceImpl.java |   70 ++++++++++++++++++----------------
 1 files changed, 37 insertions(+), 33 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 29b8097..979a542 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
@@ -6,13 +6,18 @@
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
 import com.ruoyi.call.domain.*;
+import com.ruoyi.call.dto.MessageEvent;
 import com.ruoyi.call.mapper.*;
+import com.ruoyi.call.service.IArdCallGroupService;
+import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.utils.DateUtils;
 
 import com.ruoyi.common.utils.MessageUtils;
 import com.ruoyi.common.utils.uuid.IdUtils;
+import com.ruoyi.system.service.ISysUserService;
 import com.ruoyi.utils.websocket.util.WebSocketUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationEventPublisher;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
@@ -46,6 +51,10 @@
     private ArdCallUnreadMessagesMapper ardCallUnreadMessagesMapper;
     @Resource
     private ArdCallGroupUserMapper ardCallGroupUserMapper;
+    @Resource
+    private IArdCallGroupService ardCallGroupService;
+    @Autowired
+    private ApplicationEventPublisher eventPublisher;
 
     /**
      * 鏌ヨ浼氳瘽鍘嗗彶
@@ -55,7 +64,18 @@
      */
     @Override
     public ArdCallHistory selectArdCallHistoryById(String id) {
-        return ardCallHistoryMapper.selectArdCallHistoryById(id);
+        ArdCallHistory ardCallHistory = ardCallHistoryMapper.selectArdCallHistoryById(id);
+        if (ardCallHistory != null) {
+            //缇よ亰鍒欏皢targetNickName鏀逛负缇ゅ悕绉�
+            ArdCallSession ardCallSession = ardCallSessionMapper.selectArdCallSessionById(ardCallHistory.getSessionId());
+            if (ardCallSession != null && ardCallSession.getType().equals("1")) {
+                ArdCallGroup ardCallGroup = ardCallGroupService.selectArdCallGroupById(ardCallHistory.getTargetId());
+                if (ardCallGroup != null) {
+                    ardCallHistory.setTargetNickName(ardCallGroup.getName());
+                }
+            }
+        }
+        return ardCallHistory;
     }
 
     /**
@@ -66,7 +86,18 @@
      */
     @Override
     public List<ArdCallHistory> selectArdCallHistoryList(ArdCallHistory ardCallHistory) {
-        return ardCallHistoryMapper.selectArdCallHistoryList(ardCallHistory);
+        List<ArdCallHistory> ardCallHistories = ardCallHistoryMapper.selectArdCallHistoryList(ardCallHistory);
+        ardCallHistories.stream().forEach(aCallHistory -> {
+            //缇よ亰鍒欏皢targetNickName鏀逛负缇ゅ悕绉�
+            ArdCallSession ardCallSession = ardCallSessionMapper.selectArdCallSessionById(aCallHistory.getSessionId());
+            if (ardCallSession != null && ardCallSession.getType().equals("1")) {
+                ArdCallGroup ardCallGroup = ardCallGroupService.selectArdCallGroupById(aCallHistory.getTargetId());
+                if (ardCallGroup != null) {
+                    aCallHistory.setTargetNickName(ardCallGroup.getName());
+                }
+            }
+        });
+        return ardCallHistories;
     }
 
     /**
@@ -77,7 +108,6 @@
      */
     @Override
     public int insertArdCallHistory(ArdCallHistory ardCallHistory) {
-
         ardCallHistory.setId(IdUtils.simpleUUID());
         ardCallHistory.setCreateTime(DateUtils.getNowDate());
         ArdCallSession ardCallSession = ardCallSessionMapper.selectArdCallSessionById(ardCallHistory.getSessionId());
@@ -98,20 +128,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();
@@ -135,24 +153,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