From 7e2382e701604e97f775dca55dc00cee7c5da053 Mon Sep 17 00:00:00 2001 From: zhangnaisong <2434969829@qq.com> Date: 星期五, 09 八月 2024 08:02:16 +0800 Subject: [PATCH] 电磁锁异常停车加入临时电子围栏提交 --- 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