| | |
| | | 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.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; |
| | |
| | | private ArdCallGroupUserMapper ardCallGroupUserMapper; |
| | | @Resource |
| | | private IArdCallGroupService ardCallGroupService; |
| | | @Autowired |
| | | private ApplicationEventPublisher eventPublisher; |
| | | |
| | | /** |
| | | * æ¥è¯¢ä¼è¯åå² |
| | |
| | | */ |
| | | @Override |
| | | public int insertArdCallHistory(ArdCallHistory ardCallHistory) { |
| | | |
| | | ardCallHistory.setId(IdUtils.simpleUUID()); |
| | | ardCallHistory.setCreateTime(DateUtils.getNowDate()); |
| | | ArdCallSession ardCallSession = ardCallSessionMapper.selectArdCallSessionById(ardCallHistory.getSessionId()); |
| | |
| | | ardCallUnreadMessagesMapper.updateArdCallUnreadMessages(ardCallUnreadMessages); |
| | | } |
| | | //websocketåéç»targetId |
| | | // æå»ºæ£åè¡¨è¾¾å¼æ¨¡å¼ |
| | | 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(); |
| | |
| | | ardCallUnreadMessagesMapper.updateArdCallUnreadMessages(ardCallUnreadMessages); |
| | | } |
| | | //websocketåéç»targetId |
| | | // æå»ºæ£åè¡¨è¾¾å¼æ¨¡å¼ |
| | | 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); |
| | | } |