ard-work/src/main/java/com/ruoyi/call/domain/ArdCallHistory.java
@@ -24,6 +24,8 @@ /** 用户ID */ @Excel(name = "用户ID") private String userId; private String nickName; private String avatar; /** 消息类型 */ @Excel(name = "消息类型") private String type; @@ -35,7 +37,8 @@ /** 目标ID */ @Excel(name = "目标ID") private String targetId; private String targetNickName; private String targetAvatar; public void setId(String id) { this.id = id; @@ -89,6 +92,38 @@ this.targetId = targetId; } public String getNickName() { return nickName; } public void setNickName(String nickName) { this.nickName = nickName; } public String getAvatar() { return avatar; } public void setAvatar(String avatar) { this.avatar = avatar; } public String getTargetNickName() { return targetNickName; } public void setTargetNickName(String targetNickName) { this.targetNickName = targetNickName; } public String getTargetAvatar() { return targetAvatar; } public void setTargetAvatar(String targetAvatar) { this.targetAvatar = targetAvatar; } @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) ard-work/src/main/java/com/ruoyi/call/domain/ArdCallSessionUser.java
@@ -30,11 +30,13 @@ /** 当前成员id */ @Excel(name = "当前成员id") private String userId; private String nickName; private String avatar; /** 目标成员id */ @Excel(name = "目标成员id") private String targetId; private String targetNickName; private String targetAvatar; /** * 最后一条消息 */ @@ -104,4 +106,36 @@ public void setUserId(String userId) { this.userId = userId; } public String getNickName() { return nickName; } public void setNickName(String nickName) { this.nickName = nickName; } public String getAvatar() { return avatar; } public void setAvatar(String avatar) { this.avatar = avatar; } public String getTargetNickName() { return targetNickName; } public void setTargetNickName(String targetNickName) { this.targetNickName = targetNickName; } public String getTargetAvatar() { return targetAvatar; } public void setTargetAvatar(String targetAvatar) { this.targetAvatar = targetAvatar; } } ard-work/src/main/java/com/ruoyi/call/service/impl/ArdCallHistoryServiceImpl.java
@@ -7,10 +7,13 @@ import com.alibaba.fastjson2.JSONObject; import com.ruoyi.call.domain.*; 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.stereotype.Service; @@ -46,6 +49,8 @@ private ArdCallUnreadMessagesMapper ardCallUnreadMessagesMapper; @Resource private ArdCallGroupUserMapper ardCallGroupUserMapper; @Resource private IArdCallGroupService ardCallGroupService; /** * 查询会话历史 @@ -55,7 +60,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 +82,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; } /** @@ -104,13 +131,10 @@ 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)); 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 { //更新群聊用户未读消息计数 @@ -141,14 +165,10 @@ 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)); 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)); } }); ard-work/src/main/java/com/ruoyi/call/service/impl/ArdCallSessionUserServiceImpl.java
@@ -4,14 +4,15 @@ import java.util.List; import com.ruoyi.call.compare.ArdCallSessionUserComparator; import com.ruoyi.call.domain.ArdCallGroupUser; import com.ruoyi.call.domain.ArdCallHistory; import com.ruoyi.call.domain.ArdCallUnreadMessages; import com.ruoyi.call.domain.*; import com.ruoyi.call.mapper.ArdCallGroupUserMapper; import com.ruoyi.call.mapper.ArdCallHistoryMapper; import com.ruoyi.call.mapper.ArdCallUnreadMessagesMapper; 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.uuid.IdUtils; import com.ruoyi.system.service.ISysUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -21,7 +22,6 @@ import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.call.mapper.ArdCallSessionUserMapper; import com.ruoyi.call.domain.ArdCallSessionUser; import com.ruoyi.call.service.IArdCallSessionUserService; import javax.annotation.Resource; @@ -42,6 +42,8 @@ private ArdCallSessionUserComparator ardCallSessionUserComparator; @Resource private ArdCallUnreadMessagesMapper ardCallUnreadMessagesMapper; @Resource private IArdCallGroupService ardCallGroupService; /** * 查询会话用户中间表 @@ -55,10 +57,9 @@ } @Override public ArdCallSessionUser selectArdCallSessionUserBySesionId(String userId,String sessionId) { ArdCallSessionUser ardCallSessionUser = ardCallSessionUserMapper.selectArdCallSessionUserBySesionId(userId,sessionId); if(ardCallSessionUser!=null) { public ArdCallSessionUser selectArdCallSessionUserBySesionId(String userId, String sessionId) { ArdCallSessionUser ardCallSessionUser = ardCallSessionUserMapper.selectArdCallSessionUserBySesionId(userId, sessionId); if (ardCallSessionUser != null) { //获取未读数量 ArdCallUnreadMessages ardCallUnreadMessages = ardCallUnreadMessagesMapper.getUnreadMessage(ardCallSessionUser.getSessionId(), ardCallSessionUser.getUserId()); if (ardCallUnreadMessages != null) { @@ -69,6 +70,13 @@ //获取最后一条消息实体 ArdCallHistory ardCallHistory = ardCallHistoryMapper.selectLastArdCallHistory(ardCallSessionUser.getSessionId()); ardCallSessionUser.setArdCallHistory(ardCallHistory); //群聊targetNickName改为群名称 if (ardCallSessionUser.getType().equals("1")) { ArdCallGroup ardCallGroup = ardCallGroupService.selectArdCallGroupById(ardCallSessionUser.getTargetId()); if (ardCallGroup != null) { ardCallSessionUser.setTargetNickName(ardCallGroup.getName()); } } } return ardCallSessionUser; } @@ -93,6 +101,13 @@ //获取最后一条消息实体 ArdCallHistory ardCallHistory = ardCallHistoryMapper.selectLastArdCallHistory(callSessionUser.getSessionId()); callSessionUser.setArdCallHistory(ardCallHistory); //群聊targetNickName改为群名称 if (callSessionUser.getType().equals("1")) { ArdCallGroup ardCallGroup = ardCallGroupService.selectArdCallGroupById(callSessionUser.getTargetId()); if (ardCallGroup != null) { callSessionUser.setTargetNickName(ardCallGroup.getName()); } } }); //过滤掉没有历史记录的会话 ardCallSessionUsers = ardCallSessionUsers.stream().filter(obj -> obj.getArdCallHistory() != null).collect(Collectors.toList()); ard-work/src/main/resources/mapper/call/ArdCallHistoryMapper.xml
@@ -10,7 +10,11 @@ <result property="content" column="content"/> <result property="sessionId" column="session_id"/> <result property="userId" column="user_id"/> <result property="nickName" column="nick_name"/> <result property="avatar" column="avatar"/> <result property="targetId" column="target_id"/> <result property="targetNickName" column="target_nick_name"/> <result property="targetAvatar" column="target_avatar"/> <result property="createBy" column="create_by"/> <result property="createTime" column="create_time"/> <result property="updateBy" column="update_by"/> @@ -30,12 +34,32 @@ update_time from ard_call_history </sql> <sql id="selectArdCallHistoryVo1"> SELECT ach.ID, ach.TYPE, ach.CONTENT, ach.session_id, ach.user_id, ach.target_id, ach.create_by, ach.create_time, ach.update_by, ach.update_time, u.nick_name, u.avatar, u1.nick_name AS target_nick_name, u1.avatar AS target_avatar FROM ard_call_history ach LEFT JOIN sys_user u ON u.user_id = ach.user_id LEFT JOIN sys_user u1 ON u1.user_id = ach.target_id </sql> <select id="selectArdCallHistoryList" parameterType="ArdCallHistory" resultMap="ArdCallHistoryResult"> <include refid="selectArdCallHistoryVo"/> <include refid="selectArdCallHistoryVo1"/> <where> <if test="sessionId != null and sessionId != ''">and session_id= #{sessionId}</if> <if test="userId != null and userId != ''">and user_id = #{userId}</if> <if test="userId != null and userId != ''">and ach.user_id = #{userId}</if> <if test="targetId != null and targetId != ''">and target_id = #{targetId}</if> <if test="type != null and type != ''">and type = #{type}</if> <if test="content != null and content != ''">and content = #{content}</if> @@ -44,7 +68,7 @@ </select> <select id="selectArdCallHistoryById" parameterType="String" resultMap="ArdCallHistoryResult"> <include refid="selectArdCallHistoryVo"/> <include refid="selectArdCallHistoryVo1"/> where id = #{id} </select> ard-work/src/main/resources/mapper/call/ArdCallSessionUserMapper.xml
@@ -9,27 +9,46 @@ <result property="sessionId" column="session_id"/> <result property="type" column="type"/> <result property="userId" column="user_id"/> <result property="nickName" column="nick_name"/> <result property="avatar" column="avatar"/> <result property="targetId" column="target_id"/> <result property="targetNickName" column="target_nick_name"/> <result property="targetAvatar" column="target_avatar"/> </resultMap> <sql id="selectArdCallSessionUserVo"> select id, session_id, type, user_id,target_id from ard_call_session_user </sql> <sql id="selectArdCallSessionUserVo1"> SELECT acsu.ID, acsu.session_id, acsu.TYPE, acsu.user_id, acsu.target_id, u.nick_name, u.avatar, u1.nick_name AS target_nick_name, u1.avatar AS target_avatar FROM ard_call_session_user acsu LEFT JOIN sys_user u ON u.user_id = acsu.user_id LEFT JOIN sys_user u1 ON u1.user_id = acsu.target_id </sql> <select id="selectArdCallSessionUserList" parameterType="ArdCallSessionUser" resultMap="ArdCallSessionUserResult"> <include refid="selectArdCallSessionUserVo"/> <include refid="selectArdCallSessionUserVo1"/> <where> <if test="sessionId != null and sessionId != ''">and session_id = #{sessionId}</if> <if test="type != null and type != ''">and type = #{type}</if> <if test="userId != null and userId != ''">and user_id = #{userId}</if> <if test="userId != null and userId != ''">and acsu.user_id = #{userId}</if> <if test="targetId != null and targetId != ''">and target_id = #{targetId}</if> </where> </select> <select id="selectArdCallSessionUserBySesionId" parameterType="String" resultMap="ArdCallSessionUserResult"> <include refid="selectArdCallSessionUserVo"/> where session_id = #{sessionId} and user_id = #{userId} <include refid="selectArdCallSessionUserVo1"/> where session_id = #{sessionId} and acsu.user_id = #{userId} </select> <select id="selectArdCallSessionUserById" parameterType="String" resultMap="ArdCallSessionUserResult"> <include refid="selectArdCallSessionUserVo"/>