diff --git a/im-client/src/main/java/com/bx/imclient/IMClient.java b/im-client/src/main/java/com/bx/imclient/IMClient.java index 4b3e6e7..fcaafcd 100644 --- a/im-client/src/main/java/com/bx/imclient/IMClient.java +++ b/im-client/src/main/java/com/bx/imclient/IMClient.java @@ -4,6 +4,7 @@ import com.bx.imclient.sender.IMSender; import com.bx.imcommon.enums.IMTerminalType; import com.bx.imcommon.model.IMGroupMessage; import com.bx.imcommon.model.IMPrivateMessage; +import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; @@ -11,9 +12,9 @@ import java.util.List; import java.util.Map; @Configuration +@AllArgsConstructor public class IMClient { - @Autowired private IMSender imSender; /** diff --git a/im-client/src/main/java/com/bx/imclient/sender/IMSender.java b/im-client/src/main/java/com/bx/imclient/sender/IMSender.java index f4d0b83..b090051 100644 --- a/im-client/src/main/java/com/bx/imclient/sender/IMSender.java +++ b/im-client/src/main/java/com/bx/imclient/sender/IMSender.java @@ -8,6 +8,7 @@ import com.bx.imcommon.enums.IMListenerType; import com.bx.imcommon.enums.IMSendCode; import com.bx.imcommon.enums.IMTerminalType; import com.bx.imcommon.model.*; +import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.data.redis.core.RedisTemplate; @@ -16,13 +17,13 @@ import org.springframework.stereotype.Service; import java.util.*; @Service +@AllArgsConstructor public class IMSender { @Autowired @Qualifier("IMRedisTemplate") private RedisTemplate redisTemplate; - @Autowired private MessageListenerMulticaster listenerMulticaster; public void sendPrivateMessage(IMPrivateMessage message) { diff --git a/im-client/src/main/java/com/bx/imclient/task/AbstractPullMessageTask.java b/im-client/src/main/java/com/bx/imclient/task/AbstractMessageResultTask.java similarity index 94% rename from im-client/src/main/java/com/bx/imclient/task/AbstractPullMessageTask.java rename to im-client/src/main/java/com/bx/imclient/task/AbstractMessageResultTask.java index a21fe14..52f437b 100644 --- a/im-client/src/main/java/com/bx/imclient/task/AbstractPullMessageTask.java +++ b/im-client/src/main/java/com/bx/imclient/task/AbstractMessageResultTask.java @@ -8,7 +8,7 @@ import javax.annotation.PreDestroy; import java.util.concurrent.*; @Slf4j -public abstract class AbstractPullMessageTask implements CommandLineRunner { +public abstract class AbstractMessageResultTask implements CommandLineRunner { private int threadNum = 8; diff --git a/im-client/src/main/java/com/bx/imclient/task/PullSendResultGroupMessageTask.java b/im-client/src/main/java/com/bx/imclient/task/GroupMessageResultResultTask.java similarity index 84% rename from im-client/src/main/java/com/bx/imclient/task/PullSendResultGroupMessageTask.java rename to im-client/src/main/java/com/bx/imclient/task/GroupMessageResultResultTask.java index 2fa6e62..67cfd8b 100644 --- a/im-client/src/main/java/com/bx/imclient/task/PullSendResultGroupMessageTask.java +++ b/im-client/src/main/java/com/bx/imclient/task/GroupMessageResultResultTask.java @@ -5,21 +5,22 @@ import com.bx.imclient.listener.MessageListenerMulticaster; import com.bx.imcommon.contant.IMRedisKey; import com.bx.imcommon.enums.IMListenerType; import com.bx.imcommon.model.IMSendResult; +import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; +import javax.annotation.Resource; import java.util.concurrent.TimeUnit; @Component -public class PullSendResultGroupMessageTask extends AbstractPullMessageTask{ +@AllArgsConstructor +public class GroupMessageResultResultTask extends AbstractMessageResultTask { - @Qualifier("IMRedisTemplate") - @Autowired + @Resource(name = "IMRedisTemplate") private RedisTemplate redisTemplate; - @Autowired private MessageListenerMulticaster listenerMulticaster; @Override diff --git a/im-client/src/main/java/com/bx/imclient/task/PullSendResultPrivateMessageTask.java b/im-client/src/main/java/com/bx/imclient/task/PrivateMessageResultResultTask.java similarity index 84% rename from im-client/src/main/java/com/bx/imclient/task/PullSendResultPrivateMessageTask.java rename to im-client/src/main/java/com/bx/imclient/task/PrivateMessageResultResultTask.java index c0fa2bb..39ee51c 100644 --- a/im-client/src/main/java/com/bx/imclient/task/PullSendResultPrivateMessageTask.java +++ b/im-client/src/main/java/com/bx/imclient/task/PrivateMessageResultResultTask.java @@ -5,26 +5,27 @@ import com.bx.imclient.listener.MessageListenerMulticaster; import com.bx.imcommon.contant.IMRedisKey; import com.bx.imcommon.enums.IMListenerType; import com.bx.imcommon.model.IMSendResult; +import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; +import javax.annotation.Resource; import java.util.concurrent.TimeUnit; ; @Slf4j @Component -public class PullSendResultPrivateMessageTask extends AbstractPullMessageTask{ +@AllArgsConstructor +public class PrivateMessageResultResultTask extends AbstractMessageResultTask { - @Qualifier("IMRedisTemplate") - @Autowired + @Resource(name = "IMRedisTemplate") private RedisTemplate redisTemplate; - @Autowired private MessageListenerMulticaster listenerMulticaster; @Override diff --git a/im-platform/src/main/java/com/bx/implatform/controller/FileController.java b/im-platform/src/main/java/com/bx/implatform/controller/FileController.java index 0d50738..55b29b3 100644 --- a/im-platform/src/main/java/com/bx/implatform/controller/FileController.java +++ b/im-platform/src/main/java/com/bx/implatform/controller/FileController.java @@ -6,6 +6,7 @@ import com.bx.implatform.service.thirdparty.FileService; import com.bx.implatform.vo.UploadImageVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; @@ -16,10 +17,9 @@ import org.springframework.web.multipart.MultipartFile; @Slf4j @RestController @Api(tags = "文件上传") +@AllArgsConstructor public class FileController { - - @Autowired private FileService fileService; @ApiOperation(value = "上传图片",notes="上传图片,上传后返回原图和缩略图的url") diff --git a/im-platform/src/main/java/com/bx/implatform/controller/FriendController.java b/im-platform/src/main/java/com/bx/implatform/controller/FriendController.java index fc4d568..e889eaa 100644 --- a/im-platform/src/main/java/com/bx/implatform/controller/FriendController.java +++ b/im-platform/src/main/java/com/bx/implatform/controller/FriendController.java @@ -8,6 +8,7 @@ import com.bx.implatform.session.SessionContext; import com.bx.implatform.vo.FriendVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -19,9 +20,9 @@ import java.util.stream.Collectors; @Api(tags = "好友") @RestController @RequestMapping("/friend") +@AllArgsConstructor public class FriendController { - @Autowired private IFriendService friendService; @GetMapping("/list") diff --git a/im-platform/src/main/java/com/bx/implatform/controller/GroupController.java b/im-platform/src/main/java/com/bx/implatform/controller/GroupController.java index 709397a..2bd9c46 100644 --- a/im-platform/src/main/java/com/bx/implatform/controller/GroupController.java +++ b/im-platform/src/main/java/com/bx/implatform/controller/GroupController.java @@ -9,6 +9,7 @@ import com.bx.implatform.vo.GroupMemberVO; import com.bx.implatform.vo.GroupVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -21,9 +22,9 @@ import java.util.List; @Api(tags = "群聊") @RestController @RequestMapping("/group") +@AllArgsConstructor public class GroupController { - @Autowired private IGroupService groupService; @ApiOperation(value = "创建群聊",notes="创建群聊") diff --git a/im-platform/src/main/java/com/bx/implatform/controller/GroupMessageController.java b/im-platform/src/main/java/com/bx/implatform/controller/GroupMessageController.java index 73abf24..38a54f1 100644 --- a/im-platform/src/main/java/com/bx/implatform/controller/GroupMessageController.java +++ b/im-platform/src/main/java/com/bx/implatform/controller/GroupMessageController.java @@ -9,6 +9,7 @@ import com.bx.implatform.dto.GroupMessageDTO; import com.bx.implatform.vo.PrivateMessageVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -20,9 +21,9 @@ import java.util.List; @Api(tags = "群聊消息") @RestController @RequestMapping("/message/group") +@AllArgsConstructor public class GroupMessageController { - @Autowired private IGroupMessageService groupMessageService; diff --git a/im-platform/src/main/java/com/bx/implatform/controller/LoginController.java b/im-platform/src/main/java/com/bx/implatform/controller/LoginController.java index 3a09fed..7bcf0df 100644 --- a/im-platform/src/main/java/com/bx/implatform/controller/LoginController.java +++ b/im-platform/src/main/java/com/bx/implatform/controller/LoginController.java @@ -10,6 +10,7 @@ import com.bx.implatform.dto.RegisterDTO; import com.bx.implatform.vo.LoginVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -19,9 +20,9 @@ import javax.validation.Valid; @Api(tags = "用户登录和注册") @RestController +@AllArgsConstructor public class LoginController { - @Autowired private IUserService userService; @PostMapping("/login") diff --git a/im-platform/src/main/java/com/bx/implatform/controller/PrivateMessageController.java b/im-platform/src/main/java/com/bx/implatform/controller/PrivateMessageController.java index ea55123..625d58b 100644 --- a/im-platform/src/main/java/com/bx/implatform/controller/PrivateMessageController.java +++ b/im-platform/src/main/java/com/bx/implatform/controller/PrivateMessageController.java @@ -8,6 +8,7 @@ import com.bx.implatform.service.IPrivateMessageService; import com.bx.implatform.dto.PrivateMessageDTO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -18,9 +19,9 @@ import java.util.List; @Api(tags = "私聊消息") @RestController @RequestMapping("/message/private") +@AllArgsConstructor public class PrivateMessageController { - - @Autowired + private IPrivateMessageService privateMessageService; @PostMapping("/send") diff --git a/im-platform/src/main/java/com/bx/implatform/controller/UserController.java b/im-platform/src/main/java/com/bx/implatform/controller/UserController.java index 1c7cf09..c5ad0c1 100644 --- a/im-platform/src/main/java/com/bx/implatform/controller/UserController.java +++ b/im-platform/src/main/java/com/bx/implatform/controller/UserController.java @@ -11,6 +11,7 @@ import com.bx.implatform.vo.OnlineTerminalVO; import com.bx.implatform.vo.UserVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -22,9 +23,9 @@ import java.util.List; @Api(tags = "用户") @RestController @RequestMapping("/user") +@AllArgsConstructor public class UserController { - @Autowired private IUserService userService; diff --git a/im-platform/src/main/java/com/bx/implatform/controller/WebrtcController.java b/im-platform/src/main/java/com/bx/implatform/controller/WebrtcController.java index 9fca97c..cb98ef9 100644 --- a/im-platform/src/main/java/com/bx/implatform/controller/WebrtcController.java +++ b/im-platform/src/main/java/com/bx/implatform/controller/WebrtcController.java @@ -6,6 +6,7 @@ import com.bx.implatform.result.ResultUtils; import com.bx.implatform.service.IWebrtcService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -14,9 +15,9 @@ import java.util.List; @Api(tags = "webrtc视频单人通话") @RestController @RequestMapping("/webrtc/private") +@AllArgsConstructor public class WebrtcController { - @Autowired private IWebrtcService webrtcService; @ApiOperation(httpMethod = "POST", value = "呼叫视频通话") diff --git a/im-platform/src/main/java/com/bx/implatform/interceptor/AuthInterceptor.java b/im-platform/src/main/java/com/bx/implatform/interceptor/AuthInterceptor.java index 92fbd7e..2201159 100644 --- a/im-platform/src/main/java/com/bx/implatform/interceptor/AuthInterceptor.java +++ b/im-platform/src/main/java/com/bx/implatform/interceptor/AuthInterceptor.java @@ -8,6 +8,7 @@ import com.bx.implatform.enums.ResultCode; import com.bx.implatform.exception.GlobalException; import com.bx.implatform.session.UserSession; import com.bx.imcommon.util.JwtUtil; +import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.method.HandlerMethod; diff --git a/im-platform/src/main/java/com/bx/implatform/listener/GroupMessageListener.java b/im-platform/src/main/java/com/bx/implatform/listener/GroupMessageListener.java index 0648a13..3527998 100644 --- a/im-platform/src/main/java/com/bx/implatform/listener/GroupMessageListener.java +++ b/im-platform/src/main/java/com/bx/implatform/listener/GroupMessageListener.java @@ -7,6 +7,7 @@ import com.bx.imcommon.enums.IMSendCode; import com.bx.implatform.vo.GroupMessageVO; import com.bx.imcommon.model.IMSendResult; import com.bx.implatform.contant.RedisKey; +import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; @@ -14,9 +15,9 @@ import org.springframework.data.redis.core.RedisTemplate; @Slf4j @IMListener(type = IMListenerType.GROUP_MESSAGE) +@AllArgsConstructor public class GroupMessageListener implements MessageListener { - - @Autowired + private RedisTemplate redisTemplate; @Override diff --git a/im-platform/src/main/java/com/bx/implatform/listener/PrivateMessageListener.java b/im-platform/src/main/java/com/bx/implatform/listener/PrivateMessageListener.java index fe82817..13a58ee 100644 --- a/im-platform/src/main/java/com/bx/implatform/listener/PrivateMessageListener.java +++ b/im-platform/src/main/java/com/bx/implatform/listener/PrivateMessageListener.java @@ -10,18 +10,20 @@ import com.bx.imcommon.model.IMSendResult; import com.bx.implatform.entity.PrivateMessage; import com.bx.implatform.enums.MessageStatus; import com.bx.implatform.service.IPrivateMessageService; +import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; @Slf4j @IMListener(type = IMListenerType.PRIVATE_MESSAGE) public class PrivateMessageListener implements MessageListener { + @Lazy @Autowired private IPrivateMessageService privateMessageService; - @Override public void process(IMSendResult result){ PrivateMessageVO messageInfo = result.getData(); diff --git a/im-platform/src/main/java/com/bx/implatform/service/IFriendService.java b/im-platform/src/main/java/com/bx/implatform/service/IFriendService.java index cfde61c..207e744 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/IFriendService.java +++ b/im-platform/src/main/java/com/bx/implatform/service/IFriendService.java @@ -9,15 +9,50 @@ import java.util.List; public interface IFriendService extends IService { + /** + * 判断用户2是否用户1的好友 + * + * @param userId1 用户1的id + * @param userId2 用户2的id + * @return true/false + */ Boolean isFriend(Long userId1, Long userId2); + + /** + * 查询用户的所有好友 + * + * @param userId 用户id + * @return 好友列表 + */ List findFriendByUserId(Long userId); + /** + * 添加好友,互相建立好友关系 + * + * @param friendId 好友的用户id + */ void addFriend(Long friendId); + /** + * 删除好友,双方都会解除好友关系 + * + * @param friendId 好友的用户id + */ void delFriend(Long friendId); + /** + * 更新好友信息,主要是头像和昵称 + * + * @param vo 好友vo + */ void update(FriendVO vo); + /** + * 查询指定的某个好友信息 + * + * @param friendId 好友的用户id + * @return 好友信息 + */ FriendVO findFriend(Long friendId); } diff --git a/im-platform/src/main/java/com/bx/implatform/service/IGroupMemberService.java b/im-platform/src/main/java/com/bx/implatform/service/IGroupMemberService.java index a4966c0..30e14f4 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/IGroupMemberService.java +++ b/im-platform/src/main/java/com/bx/implatform/service/IGroupMemberService.java @@ -9,18 +9,60 @@ import java.util.List; public interface IGroupMemberService extends IService { - + /** + * 根据群聊id和用户id查询群聊成员 + * + * @param groupId 群聊id + * @param userId 用户id + * @return 群聊成员信息 + */ GroupMember findByGroupAndUserId(Long groupId,Long userId); + /** + * 根据用户id查询群聊成员 + * + * @param userId 用户id + * @return 成员列表 + */ List findByUserId(Long userId); + /** + * 根据群聊id查询群聊成员(包括已退出) + * + * @param groupId 群聊id + * @return 群聊成员列表 + */ List findByGroupId(Long groupId); + /** + * 根据群聊id查询没有退出的群聊成员id + * + * @param groupId 群聊id + * @return 群聊成员id列表 + */ List findUserIdsByGroupId(Long groupId); + /** + * 批量添加成员 + * + * @param groupId 群聊id + * @param members 成员列表 + * @return 成功或失败 + */ boolean saveOrUpdateBatch(Long groupId,List members); + /** + * 根据群聊id删除移除成员 + * + * @param groupId 群聊id + */ void removeByGroupId(Long groupId); + /** + *根据群聊id和用户id移除成员 + * + * @param groupId 群聊id + * @param userId 用户id + */ void removeByGroupAndUserId(Long groupId,Long userId); } diff --git a/im-platform/src/main/java/com/bx/implatform/service/IGroupMessageService.java b/im-platform/src/main/java/com/bx/implatform/service/IGroupMessageService.java index 304a00c..b92ba78 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/IGroupMessageService.java +++ b/im-platform/src/main/java/com/bx/implatform/service/IGroupMessageService.java @@ -10,16 +10,49 @@ import java.util.List; public interface IGroupMessageService extends IService { - - Long sendMessage(GroupMessageDTO vo); - + /** + * 发送群聊消息(高并发接口,查询mysql接口都要进行缓存) + * + * @param dto 群聊消息 + * @return 群聊id + */ + Long sendMessage(GroupMessageDTO dto); + + /** + * 撤回消息 + * + * @param id 消息id + */ void recallMessage(Long id); + /** + * + * 异步拉取群聊消息,通过websocket异步推送 + */ void pullUnreadMessage(); + /** + * 拉取消息,只能拉取最近1个月的消息,一次拉取100条 + * + * @param minId 消息起始id + * @return 聊天消息列表 + */ List loadMessage(Long minId); + /** + * 消息已读,同步其他终端,清空未读数量 + * + * @param groupId 群聊 + */ void readedMessage(Long groupId); + /** + * 拉取历史聊天记录 + * + * @param groupId 群聊id + * @param page 页码 + * @param size 页码大小 + * @return 聊天记录列表 + */ List findHistoryMessage(Long groupId, Long page, Long size); } diff --git a/im-platform/src/main/java/com/bx/implatform/service/IGroupService.java b/im-platform/src/main/java/com/bx/implatform/service/IGroupService.java index 40fb3c3..e82ebb9 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/IGroupService.java +++ b/im-platform/src/main/java/com/bx/implatform/service/IGroupService.java @@ -11,24 +11,79 @@ import java.util.List; public interface IGroupService extends IService { - + /** + * 创建新群聊 + * + * @param vo 群聊信息 + * @return 群聊信息 + **/ GroupVO createGroup(GroupVO vo); + /** + * 修改群聊信息 + * + * @param vo 群聊信息 + * @return 群聊信息 + **/ GroupVO modifyGroup(GroupVO vo); + /** + * 删除群聊 + * + * @param groupId 群聊id + **/ void deleteGroup(Long groupId); + /** + * 退出群聊 + * + * @param groupId 群聊id + */ void quitGroup(Long groupId); + /** + * 将用户踢出群聊 + * + * @param groupId 群聊id + * @param userId 用户id + */ void kickGroup(Long groupId,Long userId); + /** + * 查询当前用户的所有群聊 + * + * @return 群聊信息列表 + **/ List findGroups(); + /** + * 邀请好友进群 + * + * @param vo 群id、好友id列表 + **/ void invite(GroupInviteVO vo); + /** + * 根据id查找群聊,并进行缓存 + * + * @param groupId 群聊id + * @return 群聊实体 + */ Group getById(Long groupId); + /** + * 根据id查找群聊 + * + * @param groupId 群聊id + * @return 群聊vo + */ GroupVO findById(Long groupId); + /** + * 查询群成员 + * + * @param groupId 群聊id + * @return List + **/ List findGroupMembers(Long groupId); } diff --git a/im-platform/src/main/java/com/bx/implatform/service/IPrivateMessageService.java b/im-platform/src/main/java/com/bx/implatform/service/IPrivateMessageService.java index f0036e0..9cfeaca 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/IPrivateMessageService.java +++ b/im-platform/src/main/java/com/bx/implatform/service/IPrivateMessageService.java @@ -10,15 +10,49 @@ import java.util.List; public interface IPrivateMessageService extends IService { - Long sendMessage(PrivateMessageDTO vo); - + /** + * 发送私聊消息(高并发接口,查询mysql接口都要进行缓存) + * + * @param dto 私聊消息 + * @return 消息id + */ + Long sendMessage(PrivateMessageDTO dto); + + + /** + * 撤回消息 + * + * @param id 消息id + */ void recallMessage(Long id); + /** + * 拉取历史聊天记录 + * + * @param friendId 好友id + * @param page 页码 + * @param size 页码大小 + * @return 聊天记录列表 + */ List findHistoryMessage(Long friendId, Long page,Long size); + /** + * 异步拉取私聊消息,通过websocket异步推送 + */ void pullUnreadMessage(); + /** + * 拉取消息,只能拉取最近1个月的消息,一次拉取100条 + * + * @param minId 消息起始id + * @return 聊天消息列表 + */ List loadMessage(Long minId); + /** + * 消息已读,将整个会话的消息都置为已读状态 + * + * @param friendId 好友id + */ void readedMessage(Long friendId); } diff --git a/im-platform/src/main/java/com/bx/implatform/service/IUserService.java b/im-platform/src/main/java/com/bx/implatform/service/IUserService.java index af22b5c..8a1c2d1 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/IUserService.java +++ b/im-platform/src/main/java/com/bx/implatform/service/IUserService.java @@ -14,22 +14,73 @@ import java.util.List; public interface IUserService extends IService { + /** + * 用户登录 + * + * @param dto 登录dto + * @return 登录token + */ LoginVO login(LoginDTO dto); + /** + * 修改用户密码 + * + * @param dto 修改密码dto + */ void modifyPassword(ModifyPwdDTO dto); + /** + * 用refreshToken换取新 token + * + * @param refreshToken 刷新token + * @return 登录token + */ LoginVO refreshToken(String refreshToken); + /** + * 用户注册 + * + * @param dto 注册dto + */ void register(RegisterDTO dto); + /** + * 根据用户名查询用户 + * + * @param username 用户名 + * @return 用户信息 + */ User findUserByUserName(String username); + /** + * 更新用户信息,好友昵称和群聊昵称等冗余信息也会更新 + * + * @param vo 用户信息vo + */ void update(UserVO vo); + /** + * 根据用户昵id查询用户以及在线状态 + * + * @param id 用户id + * @return 用户信息 + */ UserVO findUserById(Long id); + /** + * 根据用户昵称查询用户,最多返回20条数据 + * + * @param name 用户名或昵称 + * @return 用户列表 + */ List findUserByName(String name); + /** + * 获取用户在线的终端类型 + * + * @param userIds 用户id,多个用‘,’分割 + * @return 在线用户终端 + */ List getOnlineTerminals(String userIds); diff --git a/im-platform/src/main/java/com/bx/implatform/service/impl/FriendServiceImpl.java b/im-platform/src/main/java/com/bx/implatform/service/impl/FriendServiceImpl.java index 01f65fd..27c9aa8 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/impl/FriendServiceImpl.java +++ b/im-platform/src/main/java/com/bx/implatform/service/impl/FriendServiceImpl.java @@ -35,12 +35,6 @@ public class FriendServiceImpl extends ServiceImpl impleme private final UserMapper userMapper; - /** - * 查询用户的所有好友 - * - * @param userId 用户id - * @return 好友列表 - */ @Override public List findFriendByUserId(Long userId) { LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); @@ -49,11 +43,7 @@ public class FriendServiceImpl extends ServiceImpl impleme } - /** - * 添加好友,互相建立好友关系 - * - * @param friendId 好友的用户id - */ + @Transactional(rollbackFor = Exception.class) @Override public void addFriend(Long friendId) { @@ -69,11 +59,7 @@ public class FriendServiceImpl extends ServiceImpl impleme } - /** - * 删除好友,双方都会解除好友关系 - * - * @param friendId 好友的用户id - */ + @Transactional(rollbackFor = Exception.class) @Override public void delFriend(Long friendId) { @@ -86,12 +72,7 @@ public class FriendServiceImpl extends ServiceImpl impleme } - /** - * 判断用户2是否用户1的好友 - * - * @param userId1 用户1的id - * @param userId2 用户2的id - */ + @Cacheable(key="#userId1+':'+#userId2") @Override public Boolean isFriend(Long userId1, Long userId2) { @@ -103,11 +84,7 @@ public class FriendServiceImpl extends ServiceImpl impleme } - /** - * 更新好友信息,主要是头像和昵称 - * - * @param vo 好友vo - */ + @Override public void update(FriendVO vo) { long userId = SessionContext.getSession().getUserId(); @@ -168,12 +145,7 @@ public class FriendServiceImpl extends ServiceImpl impleme } - /** - * 查询指定的某个好友信息 - * - * @param friendId 好友的用户id - * @return 好友信息 - */ + @Override public FriendVO findFriend(Long friendId) { UserSession session = SessionContext.getSession(); diff --git a/im-platform/src/main/java/com/bx/implatform/service/impl/GroupMemberServiceImpl.java b/im-platform/src/main/java/com/bx/implatform/service/impl/GroupMemberServiceImpl.java index 135c282..7edda3d 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/impl/GroupMemberServiceImpl.java +++ b/im-platform/src/main/java/com/bx/implatform/service/impl/GroupMemberServiceImpl.java @@ -23,12 +23,7 @@ import java.util.stream.Collectors; public class GroupMemberServiceImpl extends ServiceImpl implements IGroupMemberService { - /** - * 添加群聊成员 - * - * @param member 成员 - * @return 成功或失败 - */ + @CacheEvict(key="#member.getGroupId()") @Override public boolean save(GroupMember member) { @@ -36,26 +31,14 @@ public class GroupMemberServiceImpl extends ServiceImpl members) { return super.saveOrUpdateBatch(members); } - /** - * 根据群聊id和用户id查询群聊成员 - * - * @param groupId 群聊id - * @param userId 用户id - * @return 群聊成员信息 - */ + @Override public GroupMember findByGroupAndUserId(Long groupId, Long userId) { QueryWrapper wrapper = new QueryWrapper<>(); @@ -64,13 +47,6 @@ public class GroupMemberServiceImpl extends ServiceImpl findByUserId(Long userId) { LambdaQueryWrapper memberWrapper = Wrappers.lambdaQuery(); @@ -79,13 +55,6 @@ public class GroupMemberServiceImpl extends ServiceImpl findByGroupId(Long groupId) { LambdaQueryWrapper memberWrapper = Wrappers.lambdaQuery(); @@ -93,13 +62,6 @@ public class GroupMemberServiceImpl extends ServiceImpl findUserIdsByGroupId(Long groupId) { @@ -110,12 +72,6 @@ public class GroupMemberServiceImpl extends ServiceImpl redisTemplate; private IMClient imClient; - /** - * 发送群聊消息(高并发接口,查询mysql接口都要进行缓存) - * - * @param dto 群聊消息 - * @return 群聊id - */ + @Override public Long sendMessage(GroupMessageDTO dto) { UserSession session = SessionContext.getSession(); @@ -92,11 +87,6 @@ public class GroupMessageServiceImpl extends ServiceImpl loadMessage(Long minId) { UserSession session = SessionContext.getSession(); @@ -243,11 +225,7 @@ public class GroupMessageServiceImpl extends ServiceImpl findHistoryMessage(Long groupId, Long page, Long size) { page = page > 0 ? page : 1; diff --git a/im-platform/src/main/java/com/bx/implatform/service/impl/GroupServiceImpl.java b/im-platform/src/main/java/com/bx/implatform/service/impl/GroupServiceImpl.java index 5f05e10..7cd737b 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/impl/GroupServiceImpl.java +++ b/im-platform/src/main/java/com/bx/implatform/service/impl/GroupServiceImpl.java @@ -49,12 +49,7 @@ public class GroupServiceImpl extends ServiceImpl implements private IFriendService friendsService; private IMClient imClient; - /** - * 创建新群聊 - * - * @param vo 群聊信息 - * @return 群聊信息 - **/ + @Override public GroupVO createGroup(GroupVO vo) { UserSession session = SessionContext.getSession(); @@ -79,12 +74,7 @@ public class GroupServiceImpl extends ServiceImpl implements return vo; } - /** - * 修改群聊信息 - * - * @param vo 群聊信息 - * @return 群聊信息 - **/ + @CacheEvict(value = "#vo.getId()") @Transactional(rollbackFor = Exception.class) @Override @@ -110,11 +100,7 @@ public class GroupServiceImpl extends ServiceImpl implements } - /** - * 删除群聊 - * - * @param groupId 群聊id - **/ + @Transactional(rollbackFor = Exception.class) @CacheEvict(value = "#groupId") @Override @@ -133,11 +119,7 @@ public class GroupServiceImpl extends ServiceImpl implements } - /** - * 退出群聊 - * - * @param groupId 群聊id - */ + @Override public void quitGroup(Long groupId) { Long userId = SessionContext.getSession().getUserId(); @@ -151,12 +133,7 @@ public class GroupServiceImpl extends ServiceImpl implements } - /** - * 将用户踢出群聊 - * - * @param groupId 群聊id - * @param userId 用户id - */ + @Override public void kickGroup(Long groupId, Long userId) { UserSession session = SessionContext.getSession(); @@ -186,12 +163,7 @@ public class GroupServiceImpl extends ServiceImpl implements return vo; } - /** - * 根据id查找群聊,并进行缓存 - * - * @param groupId 群聊id - * @return 群聊实体 - */ + @Cacheable(value = "#groupId") @Override public Group getById(Long groupId){ @@ -207,11 +179,7 @@ public class GroupServiceImpl extends ServiceImpl implements - /** - * 查询当前用户的所有群聊 - * - * @return 群聊信息列表 - **/ + @Override public List findGroups() { UserSession session = SessionContext.getSession(); @@ -235,11 +203,7 @@ public class GroupServiceImpl extends ServiceImpl implements }).collect(Collectors.toList()); } - /** - * 邀请好友进群 - * - * @Param GroupInviteVO 群id、好友id列表 - **/ + @Override public void invite(GroupInviteVO vo) { UserSession session = SessionContext.getSession(); @@ -280,12 +244,7 @@ public class GroupServiceImpl extends ServiceImpl implements log.info("邀请进入群聊,群聊id:{},群聊名称:{},被邀请用户id:{}",group.getId(),group.getName(),vo.getFriendIds()); } - /** - * 查询群成员 - * - * @Param groupId 群聊id - * @return List - **/ + @Override public List findGroupMembers(Long groupId) { List members = groupMemberService.findByGroupId(groupId); diff --git a/im-platform/src/main/java/com/bx/implatform/service/impl/PrivateMessageServiceImpl.java b/im-platform/src/main/java/com/bx/implatform/service/impl/PrivateMessageServiceImpl.java index d707be8..55ea18b 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/impl/PrivateMessageServiceImpl.java +++ b/im-platform/src/main/java/com/bx/implatform/service/impl/PrivateMessageServiceImpl.java @@ -44,12 +44,7 @@ public class PrivateMessageServiceImpl extends ServiceImpl findHistoryMessage(Long friendId, Long page, Long size) { page = page > 0 ? page : 1; @@ -149,9 +132,7 @@ public class PrivateMessageServiceImpl extends ServiceImpl loadMessage(Long minId) { UserSession session = SessionContext.getSession(); @@ -234,12 +210,8 @@ public class PrivateMessageServiceImpl extends ServiceImpl implements IU private JwtProperties jwtProperties; private IMClient imClient; - /** - * 用户登录 - * - * @param dto 登录dto - * @return 登录token - */ @Override public LoginVO login(LoginDTO dto) { @@ -81,15 +75,6 @@ public class UserServiceImpl extends ServiceImpl implements IU return vo; } - - - - /** - * 用refreshToken换取新 token - * - * @param refreshToken 刷新token - * @return 登录token - */ @Override public LoginVO refreshToken(String refreshToken) { //验证 token @@ -108,11 +93,7 @@ public class UserServiceImpl extends ServiceImpl implements IU return vo; } - /** - * 用户注册 - * - * @param dto 注册dto - */ + @Override public void register(RegisterDTO dto) { User user = this.findUserByUserName(dto.getUserName()); @@ -138,12 +119,7 @@ public class UserServiceImpl extends ServiceImpl implements IU log.info("用户修改密码,用户id:{},用户名:{},昵称:{}",user.getId(),user.getUserName(),user.getNickName()); } - /** - * 根据用户名查询用户 - * - * @param username 用户名 - * @return 用户信息 - */ + @Override public User findUserByUserName(String username) { LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); @@ -152,12 +128,8 @@ public class UserServiceImpl extends ServiceImpl implements IU } - /** - * 更新用户信息,好友昵称和群聊昵称等冗余信息也会更新 - * - * @param vo 用户信息vo - */ - @Transactional + + @Transactional(rollbackFor = Exception.class) @Override public void update(UserVO vo) { UserSession session = SessionContext.getSession(); @@ -197,12 +169,7 @@ public class UserServiceImpl extends ServiceImpl implements IU log.info("用户信息更新,用户:{}}", user); } - /** - * 根据用户昵id查询用户以及在线状态 - * - * @param id 用户id - * @return 用户信息 - */ + @Override public UserVO findUserById(Long id) { User user = this.getById(id); @@ -211,12 +178,7 @@ public class UserServiceImpl extends ServiceImpl implements IU return vo; } - /** - * 根据用户昵称查询用户,最多返回20条数据 - * - * @param name 用户名或昵称 - * @return 用户列表 - */ + @Override public List findUserByName(String name) { LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); @@ -235,13 +197,6 @@ public class UserServiceImpl extends ServiceImpl implements IU } - - /** - * 获取用户在线的终端类型 - * - * @param userIds 用户id,多个用‘,’分割 - * @return 在线用户终端 - */ @Override public List getOnlineTerminals(String userIds) { List userIdList = Arrays.stream(userIds.split(",")) diff --git a/im-platform/src/main/java/com/bx/implatform/vo/PrivateMessageVO.java b/im-platform/src/main/java/com/bx/implatform/vo/PrivateMessageVO.java index 431dc9a..c8ea8a5 100644 --- a/im-platform/src/main/java/com/bx/implatform/vo/PrivateMessageVO.java +++ b/im-platform/src/main/java/com/bx/implatform/vo/PrivateMessageVO.java @@ -13,7 +13,7 @@ import java.util.Date; public class PrivateMessageVO { @ApiModelProperty(value = " 消息id") - private long id; + private Long id; @ApiModelProperty(value = " 发送者id") private Long sendId; diff --git a/im-platform/src/main/resources/application.yml b/im-platform/src/main/resources/application.yml index 2e84bff..49acc51 100644 --- a/im-platform/src/main/resources/application.yml +++ b/im-platform/src/main/resources/application.yml @@ -3,8 +3,6 @@ server: port: 8888 #配置项目的数据源 spring: - main: - allow-circular-references: true mvc: pathmatch: matching-strategy: ant_path_matcher diff --git a/im-server/src/main/java/com/bx/imserver/config/RedisConfig.java b/im-server/src/main/java/com/bx/imserver/config/RedisConfig.java index 5ae1fbd..35c044c 100644 --- a/im-server/src/main/java/com/bx/imserver/config/RedisConfig.java +++ b/im-server/src/main/java/com/bx/imserver/config/RedisConfig.java @@ -19,10 +19,6 @@ import javax.annotation.Resource; @Configuration public class RedisConfig { - @Resource - private RedisConnectionFactory factory; - - @Bean public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) { RedisTemplate redisTemplate = new RedisTemplate(); diff --git a/im-server/src/main/java/com/bx/imserver/netty/IMServerGroup.java b/im-server/src/main/java/com/bx/imserver/netty/IMServerGroup.java index 619d770..3983239 100644 --- a/im-server/src/main/java/com/bx/imserver/netty/IMServerGroup.java +++ b/im-server/src/main/java/com/bx/imserver/netty/IMServerGroup.java @@ -1,6 +1,7 @@ package com.bx.imserver.netty; import com.bx.imcommon.contant.IMRedisKey; +import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; @@ -12,14 +13,13 @@ import java.util.List; @Slf4j @Component +@AllArgsConstructor public class IMServerGroup implements CommandLineRunner { public static volatile long serverId = 0; - @Autowired RedisTemplate redisTemplate; - @Autowired private List imServers; /*** diff --git a/im-server/src/main/java/com/bx/imserver/netty/processor/GroupMessageProcessor.java b/im-server/src/main/java/com/bx/imserver/netty/processor/GroupMessageProcessor.java index 0446f05..2e26e1b 100644 --- a/im-server/src/main/java/com/bx/imserver/netty/processor/GroupMessageProcessor.java +++ b/im-server/src/main/java/com/bx/imserver/netty/processor/GroupMessageProcessor.java @@ -9,6 +9,7 @@ import com.bx.imcommon.model.IMUserInfo; import com.bx.imcommon.model.IMSendResult; import com.bx.imserver.netty.UserChannelCtxMap; import io.netty.channel.ChannelHandlerContext; +import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; @@ -19,9 +20,9 @@ import java.util.List; @Slf4j @Component +@AllArgsConstructor public class GroupMessageProcessor extends AbstractMessageProcessor { - - @Autowired + private RedisTemplate redisTemplate; @Async diff --git a/im-server/src/main/java/com/bx/imserver/netty/processor/HeartbeatProcessor.java b/im-server/src/main/java/com/bx/imserver/netty/processor/HeartbeatProcessor.java index f24f848..b84f5d0 100644 --- a/im-server/src/main/java/com/bx/imserver/netty/processor/HeartbeatProcessor.java +++ b/im-server/src/main/java/com/bx/imserver/netty/processor/HeartbeatProcessor.java @@ -10,6 +10,7 @@ import com.bx.imserver.constant.ChannelAttrKey; import com.bx.imserver.netty.ws.WebSocketServer; import io.netty.channel.ChannelHandlerContext; import io.netty.util.AttributeKey; +import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; @@ -20,13 +21,9 @@ import java.util.concurrent.TimeUnit; @Slf4j @Component +@AllArgsConstructor public class HeartbeatProcessor extends AbstractMessageProcessor { - - @Autowired - private WebSocketServer wsServer; - - @Autowired RedisTemplate redisTemplate; @Override diff --git a/im-server/src/main/java/com/bx/imserver/netty/processor/LoginProcessor.java b/im-server/src/main/java/com/bx/imserver/netty/processor/LoginProcessor.java index fd3d3f9..e37b2ea 100644 --- a/im-server/src/main/java/com/bx/imserver/netty/processor/LoginProcessor.java +++ b/im-server/src/main/java/com/bx/imserver/netty/processor/LoginProcessor.java @@ -14,6 +14,8 @@ import com.bx.imserver.netty.IMServerGroup; import com.bx.imserver.netty.UserChannelCtxMap; import io.netty.channel.ChannelHandlerContext; import io.netty.util.AttributeKey; +import lombok.AllArgsConstructor; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -25,10 +27,10 @@ import java.util.concurrent.TimeUnit; @Slf4j @Component +@RequiredArgsConstructor public class LoginProcessor extends AbstractMessageProcessor { - @Autowired - RedisTemplate redisTemplate; + private final RedisTemplate redisTemplate; @Value("${jwt.accessToken.secret}") private String accessTokenSecret; diff --git a/im-server/src/main/java/com/bx/imserver/netty/processor/PrivateMessageProcessor.java b/im-server/src/main/java/com/bx/imserver/netty/processor/PrivateMessageProcessor.java index f65a635..6778714 100644 --- a/im-server/src/main/java/com/bx/imserver/netty/processor/PrivateMessageProcessor.java +++ b/im-server/src/main/java/com/bx/imserver/netty/processor/PrivateMessageProcessor.java @@ -9,6 +9,7 @@ import com.bx.imcommon.model.IMUserInfo; import com.bx.imcommon.model.IMSendResult; import com.bx.imserver.netty.UserChannelCtxMap; import io.netty.channel.ChannelHandlerContext; +import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; @@ -16,9 +17,9 @@ import org.springframework.stereotype.Component; @Slf4j @Component +@AllArgsConstructor public class PrivateMessageProcessor extends AbstractMessageProcessor { - @Autowired private RedisTemplate redisTemplate; @Override diff --git a/im-server/src/main/java/com/bx/imserver/task/PullUnreadGroupMessageTask.java b/im-server/src/main/java/com/bx/imserver/task/PullGroupMessageTask.java similarity index 94% rename from im-server/src/main/java/com/bx/imserver/task/PullUnreadGroupMessageTask.java rename to im-server/src/main/java/com/bx/imserver/task/PullGroupMessageTask.java index 1787b59..ef177f7 100644 --- a/im-server/src/main/java/com/bx/imserver/task/PullUnreadGroupMessageTask.java +++ b/im-server/src/main/java/com/bx/imserver/task/PullGroupMessageTask.java @@ -15,7 +15,7 @@ import java.util.concurrent.TimeUnit; @Slf4j @Component -public class PullUnreadGroupMessageTask extends AbstractPullMessageTask { +public class PullGroupMessageTask extends AbstractPullMessageTask { @Autowired private RedisTemplate redisTemplate; diff --git a/im-server/src/main/java/com/bx/imserver/task/PullUnreadPrivateMessageTask.java b/im-server/src/main/java/com/bx/imserver/task/PullPrivateMessageTask.java similarity index 94% rename from im-server/src/main/java/com/bx/imserver/task/PullUnreadPrivateMessageTask.java rename to im-server/src/main/java/com/bx/imserver/task/PullPrivateMessageTask.java index 4b70ee6..1ebe771 100644 --- a/im-server/src/main/java/com/bx/imserver/task/PullUnreadPrivateMessageTask.java +++ b/im-server/src/main/java/com/bx/imserver/task/PullPrivateMessageTask.java @@ -16,7 +16,7 @@ import java.util.concurrent.TimeUnit; @Slf4j @Component -public class PullUnreadPrivateMessageTask extends AbstractPullMessageTask { +public class PullPrivateMessageTask extends AbstractPullMessageTask { @Autowired