u
This commit is contained in:
1 parent
28678fb4df
commit
a6dbe24dd4
43 files changed
+2285
-206
No files matched your search
+49
-12
@@ -3,19 +3,11 @@ package cn.link56.im.controller;
|
||||
import cn.link56.common.BasePageVO;
|
||||
import cn.link56.common.Result;
|
||||
import cn.link56.common.context.UserContext;
|
||||
import cn.link56.im.model.dto.CreateFriendDTO;
|
||||
import cn.link56.im.model.dto.QueryFriendDTO;
|
||||
import cn.link56.im.model.dto.QueryGroupDTO;
|
||||
import cn.link56.im.model.vo.QueryFriendVO;
|
||||
import cn.link56.im.model.vo.QueryGroupVO;
|
||||
import cn.link56.im.service.ImFriendService;
|
||||
import cn.link56.im.service.ImGroupService;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import cn.link56.im.model.dto.*;
|
||||
import cn.link56.im.model.vo.*;
|
||||
import cn.link56.im.service.*;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
@@ -28,6 +20,12 @@ public class ImController {
|
||||
private ImFriendService imFriendService;
|
||||
@Resource
|
||||
private ImGroupService imGroupService;
|
||||
@Resource
|
||||
private ImPrivateMessageService imPrivateMessageService;
|
||||
@Resource
|
||||
private ImGroupUserService imGroupUserService;
|
||||
@Resource
|
||||
private ImGroupMessageService imGroupMessageService;
|
||||
|
||||
@PostMapping("/friend/create")
|
||||
public Result<Void> createFriend(@RequestBody @Validated CreateFriendDTO dto){
|
||||
@@ -52,4 +50,43 @@ public class ImController {
|
||||
BasePageVO<QueryGroupVO> basePageVO = imGroupService.queryGroup(dto);
|
||||
return Result.success(basePageVO);
|
||||
}
|
||||
|
||||
@PostMapping("/friend/message/query")
|
||||
public Result<List<QueryPrivateMessageVO>> queryPrivateMessage(@RequestBody QueryPrivateMessageDTO dto){
|
||||
List<QueryPrivateMessageVO> list = imPrivateMessageService.queryPrivateMessages(dto);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/group/message/query")
|
||||
public Result<List<QueryGroupMessageVO>> queryGroupMessage(@RequestBody QueryGroupMessageDTO dto){
|
||||
List<QueryGroupMessageVO> list = imGroupMessageService.queryGroupMessages(dto);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/group/user/query")
|
||||
public Result<List<QueryGroupUserVO>> queryGroupUser(@RequestBody QueryGroupUserDTO dto){
|
||||
List<QueryGroupUserVO> list = imGroupUserService.queryGroupUsers(dto);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/private/update/unread")
|
||||
public Result<Void> updatePrivateUnread(@RequestBody UpdatePrivateUnreadDTO dto){
|
||||
Long userId = dto.getUserId();
|
||||
Long friendId = dto.getFriendId();
|
||||
|
||||
imFriendService.decreaseUnreadCount(userId,friendId);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PostMapping("/group/update/unread")
|
||||
public Result<Void> updateGroup(@RequestBody UpdateGroupUnreadDTO dto){
|
||||
Long userId = dto.getUserId();
|
||||
Long groupId = dto.getGroupId();
|
||||
|
||||
imGroupUserService.decreaseUnreadCount(groupId,userId);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,7 +13,8 @@ public enum MessageTypeEnums {
|
||||
OFFLINE(6),
|
||||
GROUP_OFFLINE(7),
|
||||
PRIVATE(8),
|
||||
GROUP(9);
|
||||
GROUP(9),
|
||||
FRIEND_UPDATE(10);
|
||||
|
||||
private final int code;
|
||||
|
||||
|
||||
@@ -2,12 +2,22 @@ package cn.link56.im.handler;
|
||||
|
||||
import cn.link56.auth.token.model.TokenPayload;
|
||||
import cn.link56.auth.token.service.AuthTokenService;
|
||||
import cn.link56.common.utils.TimeUtils;
|
||||
import cn.link56.common.utils.snowflake.idgen.IdGenerator;
|
||||
import cn.link56.company.model.po.CompanyUser;
|
||||
import cn.link56.company.service.CompanyUserService;
|
||||
import cn.link56.im.enums.MessageTypeEnums;
|
||||
import cn.link56.im.message.MessageRequest;
|
||||
import cn.link56.im.message.MessageResponse;
|
||||
import cn.link56.im.model.dto.GroupDTO;
|
||||
import cn.link56.im.model.dto.LoginDTO;
|
||||
import cn.link56.im.model.dto.PrivateDTO;
|
||||
import cn.link56.im.model.po.ImPrivateMessage;
|
||||
import cn.link56.im.model.vo.PrivateMessageVO;
|
||||
import cn.link56.im.model.vo.QueryFriendVO;
|
||||
import cn.link56.im.service.ImFriendService;
|
||||
import cn.link56.im.service.ImGroupUserService;
|
||||
import cn.link56.im.service.ImPrivateMessageService;
|
||||
import cn.link56.im.storage.SessionManager;
|
||||
import cn.link56.im.utils.MessageDataConverter;
|
||||
import cn.link56.im.utils.MessageWriter;
|
||||
@@ -26,6 +36,10 @@ public class MessageHandler {
|
||||
private ImFriendService imFriendService;
|
||||
@Resource
|
||||
private ImGroupUserService imGroupUserService;
|
||||
@Resource
|
||||
private ImPrivateMessageService imPrivateMessageService;
|
||||
@Resource
|
||||
private CompanyUserService companyUserService;
|
||||
|
||||
// 处理消息
|
||||
public void handleMessage(Channel channel, MessageRequest request) {
|
||||
@@ -56,7 +70,6 @@ public class MessageHandler {
|
||||
}
|
||||
|
||||
private void handleLogin(Channel channel, MessageRequest request) {
|
||||
System.out.println("===LOGIN===");
|
||||
LoginDTO dto = MessageDataConverter.convert(request.getData(), LoginDTO.class);
|
||||
TokenPayload tokenPayload = authTokenService.parsePayload(dto.getToken());
|
||||
|
||||
@@ -77,8 +90,6 @@ public class MessageHandler {
|
||||
}
|
||||
|
||||
private void handleLogout(Channel channel, MessageRequest request) {
|
||||
System.out.println("===LOGOUT===");
|
||||
|
||||
Long userId = SessionManager.getUserId(channel);
|
||||
if (ObjectUtils.isNotEmpty(userId)){
|
||||
handleOffline(channel , userId);
|
||||
@@ -110,9 +121,78 @@ public class MessageHandler {
|
||||
|
||||
// 私聊逻辑
|
||||
private void handlePrivate(Channel channel, MessageRequest request) {
|
||||
Long from = request.getFrom();
|
||||
Long to = request.getTo();
|
||||
|
||||
PrivateDTO dto = MessageDataConverter.convert(request.getData(), PrivateDTO.class);
|
||||
String content = dto.getContent();
|
||||
Integer type = dto.getType();
|
||||
String tempId = dto.getTempId();
|
||||
|
||||
// 好友关系建立
|
||||
imFriendService.createFriend(to,from);
|
||||
|
||||
// 通知建立了好友关系
|
||||
if (SessionManager.isOnline(to)) {
|
||||
CompanyUser companyUser = companyUserService.getById(from);
|
||||
if (ObjectUtils.isNotEmpty(companyUser)){
|
||||
QueryFriendVO queryFriendVO = new QueryFriendVO();
|
||||
queryFriendVO.setFriendId(from);
|
||||
queryFriendVO.setFriendName(companyUser.getName());
|
||||
queryFriendVO.setFriendAvatar(companyUser.getAvatar());
|
||||
queryFriendVO.setIsOnline(true);
|
||||
|
||||
queryFriendVO.setUnreadCount(0);
|
||||
|
||||
MessageWriter.writeToUser(to,MessageResponse.success(MessageTypeEnums.FRIEND_UPDATE,from).setData(queryFriendVO));
|
||||
}
|
||||
}
|
||||
|
||||
// 保存
|
||||
Long privateMessageID = IdGenerator.nextId();
|
||||
Long sendTime = TimeUtils.getCurrentTimestampMillis();
|
||||
|
||||
ImPrivateMessage imPrivateMessage = new ImPrivateMessage();
|
||||
imPrivateMessage.setId(privateMessageID);
|
||||
imPrivateMessage.setContent(content);
|
||||
imPrivateMessage.setType(type);
|
||||
imPrivateMessage.setSenderId(from);
|
||||
imPrivateMessage.setReceiverId(to);
|
||||
imPrivateMessage.setSendTime(sendTime);
|
||||
|
||||
imPrivateMessageService.save(imPrivateMessage);
|
||||
|
||||
// 更新状态表
|
||||
imFriendService.updateLastMessageId(from,to,privateMessageID);
|
||||
imFriendService.increaseUnreadCount(to,from,privateMessageID);
|
||||
|
||||
// 构建回复消息
|
||||
PrivateMessageVO privateMessageVO = new PrivateMessageVO();
|
||||
// 通知发送人
|
||||
privateMessageVO.setTempId(tempId);
|
||||
privateMessageVO.setId(privateMessageID);
|
||||
privateMessageVO.setSenderId(from);
|
||||
privateMessageVO.setReceiverId(to);
|
||||
privateMessageVO.setContent(content);
|
||||
privateMessageVO.setType(type);
|
||||
privateMessageVO.setSendTime(sendTime);
|
||||
|
||||
MessageWriter.writeToUser(from,MessageResponse.success(MessageTypeEnums.PRIVATE,from).setData(privateMessageVO));
|
||||
|
||||
// 通知接受人
|
||||
if (SessionManager.isOnline(to)){
|
||||
MessageWriter.writeToUser(to,MessageResponse.success(MessageTypeEnums.PRIVATE,from).setData(privateMessageVO));
|
||||
}
|
||||
}
|
||||
|
||||
// 群聊逻辑
|
||||
private void handleGroup(Channel channel, MessageRequest request) {
|
||||
Long from = request.getFrom();
|
||||
Long to = request.getTo();
|
||||
|
||||
GroupDTO dto = MessageDataConverter.convert(request.getData(), GroupDTO.class);
|
||||
String content = dto.getContent();
|
||||
Integer type = dto.getType();
|
||||
String tempId = dto.getTempId();
|
||||
}
|
||||
}
|
||||
@@ -22,5 +22,16 @@ public interface ImFriendMapper extends BaseMapper<ImFriend> {
|
||||
Long selectFriendTotal(
|
||||
@Param("userId") Long userId,
|
||||
@Param("name") String name
|
||||
);
|
||||
);
|
||||
|
||||
void incrementUnreadAndUpdateLastMessage(
|
||||
@Param("userId") Long userId,
|
||||
@Param("friendId") Long friendId,
|
||||
@Param("lastMessageId") Long lastMessageId
|
||||
);
|
||||
|
||||
void decreaseUnreadCount(
|
||||
@Param("userId") Long userId,
|
||||
@Param("friendId") Long friendId
|
||||
);
|
||||
}
|
||||
+10
@@ -1,9 +1,19 @@
|
||||
package cn.link56.im.mapper;
|
||||
|
||||
import cn.link56.im.model.po.ImGroupMessage;
|
||||
import cn.link56.im.model.vo.QueryGroupMessageVO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ImGroupMessageMapper extends BaseMapper<ImGroupMessage> {
|
||||
List<QueryGroupMessageVO> selectGroupMessages(
|
||||
@Param("groupId") Long groupId,
|
||||
@Param("pageSize") Integer pageSize,
|
||||
@Param("beforeId") Long beforeId,
|
||||
@Param("beforeTimestamp") Long beforeTimestamp
|
||||
);
|
||||
}
|
||||
@@ -1,9 +1,17 @@
|
||||
package cn.link56.im.mapper;
|
||||
|
||||
import cn.link56.im.model.po.ImGroupUser;
|
||||
import cn.link56.im.model.vo.QueryGroupUserVO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ImGroupUserMapper extends BaseMapper<ImGroupUser> {
|
||||
List<QueryGroupUserVO> selectGroupUsers(
|
||||
@Param("groupId") Long groupId,
|
||||
@Param("userName") String userName
|
||||
);
|
||||
}
|
||||
+11
@@ -1,9 +1,20 @@
|
||||
package cn.link56.im.mapper;
|
||||
|
||||
import cn.link56.im.model.po.ImPrivateMessage;
|
||||
import cn.link56.im.model.vo.QueryPrivateMessageVO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ImPrivateMessageMapper extends BaseMapper<ImPrivateMessage> {
|
||||
List<QueryPrivateMessageVO> selectPrivateMessages(
|
||||
@Param("userId") Long userId,
|
||||
@Param("friendId") Long friendId,
|
||||
@Param("beforeId") Long beforeId,
|
||||
@Param("beforeTimestamp") Long beforeTimestamp,
|
||||
@Param("pageSize") Integer pageSize
|
||||
);
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import lombok.ToString;
|
||||
public class MessageRequest {
|
||||
private Integer type;
|
||||
private Long from;
|
||||
private Object to;
|
||||
private Long to;
|
||||
private Long timestamp;
|
||||
private Object data;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package cn.link56.im.model.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class GroupDTO {
|
||||
private String content;
|
||||
private Integer type;
|
||||
private String tempId;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package cn.link56.im.model.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class PrivateDTO {
|
||||
private String content;
|
||||
private Integer type;
|
||||
private String tempId;
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package cn.link56.im.model.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class QueryGroupMessageDTO {
|
||||
private Long groupId;
|
||||
private Long beforeTimestamp;
|
||||
private Long beforeId;
|
||||
private Integer pageSize;
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package cn.link56.im.model.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class QueryGroupUserDTO {
|
||||
private Long groupId;
|
||||
private String userName;
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package cn.link56.im.model.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class QueryPrivateMessageDTO {
|
||||
private Long userId;
|
||||
private Long friendId;
|
||||
private Long beforeTimestamp;
|
||||
private Long beforeId;
|
||||
private Integer pageSize;
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package cn.link56.im.model.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class UpdateGroupUnreadDTO {
|
||||
private Long groupId;
|
||||
private Long userId;
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package cn.link56.im.model.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class UpdatePrivateUnreadDTO {
|
||||
private Long userId;
|
||||
private Long friendId;
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package cn.link56.im.model.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class PrivateMessageVO extends QueryPrivateMessageVO {
|
||||
private String tempId;
|
||||
}
|
||||
@@ -17,7 +17,7 @@ public class QueryFriendVO {
|
||||
private Integer unreadCount;
|
||||
|
||||
private Long lastMessageId;
|
||||
private Long laseMessageTime;
|
||||
private Long lastMessageTime;
|
||||
private Integer lastMessageType;
|
||||
private String lastMessageContent;
|
||||
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package cn.link56.im.model.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class QueryGroupMessageVO {
|
||||
private Long id;
|
||||
private Long groupId;
|
||||
|
||||
private Long senderId;
|
||||
private String senderAvatar;
|
||||
private String senderName;
|
||||
|
||||
private String content;
|
||||
private Integer type;
|
||||
|
||||
private Long sendTime;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.link56.im.model.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class QueryGroupUserVO {
|
||||
private Long groupId;
|
||||
private Long userId;
|
||||
private String userAvatar;
|
||||
private String userName;
|
||||
private Boolean isOnline;
|
||||
}
|
||||
@@ -15,7 +15,7 @@ public class QueryGroupVO {
|
||||
private Integer unreadCount;
|
||||
|
||||
private Long lastMessageId;
|
||||
private Long laseMessageTime;
|
||||
private Long lastMessageTime;
|
||||
private Integer lastMessageType;
|
||||
private String lastMessageContent;
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package cn.link56.im.model.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class QueryPrivateMessageVO {
|
||||
private Long id;
|
||||
|
||||
private Long senderId;
|
||||
private Long receiverId;
|
||||
|
||||
private String content;
|
||||
private Integer type;
|
||||
|
||||
private Long sendTime;
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import cn.link56.im.model.po.ImFriend;
|
||||
import cn.link56.im.model.vo.QueryFriendVO;
|
||||
import cn.link56.im.storage.SessionManager;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -33,7 +34,6 @@ public class ImFriendService extends ServiceImpl<ImFriendMapper, ImFriend> {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 不存在则插入
|
||||
ImFriend imFriend = new ImFriend();
|
||||
|
||||
@@ -87,4 +87,20 @@ public class ImFriendService extends ServiceImpl<ImFriendMapper, ImFriend> {
|
||||
}
|
||||
|
||||
|
||||
public void updateLastMessageId(Long userId,Long friendId,Long lastMessageId){
|
||||
LambdaUpdateWrapper<ImFriend> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(ImFriend::getUserId,userId)
|
||||
.eq(ImFriend::getFriendId,friendId)
|
||||
.set(ImFriend::getLastMessageId,lastMessageId);
|
||||
|
||||
imFriendMapper.update(updateWrapper);
|
||||
}
|
||||
|
||||
public void increaseUnreadCount(Long userId,Long friendId,Long lastMessageId){
|
||||
imFriendMapper.incrementUnreadAndUpdateLastMessage(userId, friendId, lastMessageId);
|
||||
}
|
||||
|
||||
public void decreaseUnreadCount(Long userId,Long friendId){
|
||||
imFriendMapper.decreaseUnreadCount(userId, friendId);
|
||||
}
|
||||
}
|
||||
+16
@@ -1,11 +1,27 @@
|
||||
package cn.link56.im.service;
|
||||
|
||||
import cn.link56.im.mapper.ImGroupMessageMapper;
|
||||
import cn.link56.im.model.dto.QueryGroupMessageDTO;
|
||||
import cn.link56.im.model.po.ImGroupMessage;
|
||||
import cn.link56.im.model.vo.QueryGroupMessageVO;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ImGroupMessageService extends ServiceImpl<ImGroupMessageMapper, ImGroupMessage> {
|
||||
@Resource
|
||||
private ImGroupMessageMapper imGroupMessageMapper;
|
||||
|
||||
public List<QueryGroupMessageVO> queryGroupMessages(QueryGroupMessageDTO dto) {
|
||||
Long groupId = dto.getGroupId();
|
||||
Integer pageSize = dto.getPageSize();
|
||||
|
||||
Long beforeId = dto.getBeforeId();
|
||||
Long beforeTimestamp = dto.getBeforeTimestamp();
|
||||
|
||||
return imGroupMessageMapper.selectGroupMessages(groupId,pageSize,beforeId,beforeTimestamp);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
package cn.link56.im.service;
|
||||
|
||||
import cn.link56.im.mapper.ImGroupUserMapper;
|
||||
import cn.link56.im.model.dto.QueryGroupUserDTO;
|
||||
import cn.link56.im.model.po.ImGroupUser;
|
||||
import cn.link56.im.model.vo.QueryGroupUserVO;
|
||||
import cn.link56.im.storage.SessionManager;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -44,4 +47,27 @@ public class ImGroupUserService extends ServiceImpl<ImGroupUserMapper, ImGroupUs
|
||||
.distinct() // 去重
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void decreaseUnreadCount(Long groupId,Long userId){
|
||||
LambdaUpdateWrapper<ImGroupUser> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
|
||||
updateWrapper.eq(ImGroupUser::getGroupId,groupId)
|
||||
.eq(ImGroupUser::getUserId,userId)
|
||||
.set(ImGroupUser::getUnreadCount,0);
|
||||
|
||||
imGroupUserMapper.update(updateWrapper);
|
||||
}
|
||||
|
||||
public List<QueryGroupUserVO> queryGroupUsers(QueryGroupUserDTO dto) {
|
||||
Long groupId = dto.getGroupId();
|
||||
String userName = dto.getUserName();
|
||||
|
||||
List<QueryGroupUserVO> queryGroupUserVOS = imGroupUserMapper.selectGroupUsers(groupId, userName);
|
||||
|
||||
queryGroupUserVOS.forEach(item -> {
|
||||
item.setIsOnline(SessionManager.isOnline(item.getUserId()));
|
||||
});
|
||||
|
||||
return queryGroupUserVOS;
|
||||
}
|
||||
}
|
||||
+18
@@ -1,10 +1,28 @@
|
||||
package cn.link56.im.service;
|
||||
|
||||
import cn.link56.im.mapper.ImPrivateMessageMapper;
|
||||
import cn.link56.im.model.dto.QueryPrivateMessageDTO;
|
||||
import cn.link56.im.model.po.ImPrivateMessage;
|
||||
import cn.link56.im.model.vo.QueryPrivateMessageVO;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ImPrivateMessageService extends ServiceImpl<ImPrivateMessageMapper, ImPrivateMessage> {
|
||||
@Resource
|
||||
private ImPrivateMessageMapper imPrivateMessageMapper;
|
||||
|
||||
public List<QueryPrivateMessageVO> queryPrivateMessages(QueryPrivateMessageDTO dto) {
|
||||
Long userId = dto.getUserId();
|
||||
Long friendId = dto.getFriendId();
|
||||
Long beforeId = dto.getBeforeId();
|
||||
Long beforeTimestamp = dto.getBeforeTimestamp();
|
||||
|
||||
Integer pageSize = dto.getPageSize();
|
||||
|
||||
return imPrivateMessageMapper.selectPrivateMessages(userId,friendId,beforeId,beforeTimestamp,pageSize);
|
||||
}
|
||||
}
|
||||
@@ -46,4 +46,21 @@
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<update id="incrementUnreadAndUpdateLastMessage">
|
||||
UPDATE b_im_friend
|
||||
SET
|
||||
b_last_message_id = #{lastMessageId},
|
||||
b_unread_count = b_unread_count + 1,
|
||||
b_update_time = GETDATE()
|
||||
WHERE b_user_id = #{userId} and b_friend_id = #{friendId}
|
||||
</update>
|
||||
|
||||
<update id="decreaseUnreadCount">
|
||||
UPDATE b_im_friend
|
||||
SET
|
||||
b_unread_count = 0,
|
||||
b_update_time = GETDATE()
|
||||
WHERE b_user_id = #{userId} and b_friend_id = #{friendId}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
+16
-18
@@ -8,28 +8,25 @@
|
||||
<select id="selectGroup" resultType="cn.link56.im.model.vo.QueryGroupVO">
|
||||
SELECT *
|
||||
FROM (
|
||||
SELECT
|
||||
g.b_id AS groupId,
|
||||
g.b_name AS groupName,
|
||||
g.b_avatar AS groupAvatar,
|
||||
gu.b_unread_count AS unreadCount,
|
||||
SELECT
|
||||
g.b_id AS groupId,
|
||||
g.b_name AS groupName,
|
||||
g.b_avatar AS groupAvatar,
|
||||
gu.b_unread_count AS unreadCount,
|
||||
|
||||
m.b_id AS lastMessageId,
|
||||
m.b_send_time AS lastMessageTime,
|
||||
m.b_type AS lastMessageType,
|
||||
m.b_content AS lastMessageContent,
|
||||
m.b_id AS lastMessageId,
|
||||
m.b_send_time AS lastMessageTime,
|
||||
m.b_type AS lastMessageType,
|
||||
m.b_content AS lastMessageContent,
|
||||
|
||||
u.b_id AS lastMessageSenderId,
|
||||
u.b_name AS lastMessageSenderName,
|
||||
u.b_avatar AS lastMessageSenderAvatar,
|
||||
u.b_id AS lastMessageSenderId,
|
||||
u.b_name AS lastMessageSenderName,
|
||||
|
||||
ROW_NUMBER() OVER (
|
||||
ORDER BY
|
||||
<if test="id != null and id != 0">
|
||||
CASE WHEN g.b_id = #{id} THEN 0 ELSE 1 END,
|
||||
</if>
|
||||
ROW_NUMBER() OVER (
|
||||
ORDER BY
|
||||
CASE WHEN #{id} IS NOT NULL AND #{id} != 0 AND g.b_id = #{id} THEN 0 ELSE 1 END,
|
||||
m.b_send_time DESC
|
||||
) AS rn
|
||||
) AS rn
|
||||
FROM b_im_group g
|
||||
INNER JOIN b_im_group_user gu ON g.b_id = gu.b_group_id
|
||||
LEFT JOIN b_im_group_message m ON gu.b_last_message_id = m.b_id
|
||||
@@ -43,6 +40,7 @@
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
<select id="selectGroupTotal" resultType="java.lang.Long">
|
||||
SELECT COUNT(DISTINCT g.b_id)
|
||||
FROM b_im_group g
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="cn.link56.im.mapper.ImGroupMessageMapper">
|
||||
|
||||
<select id="selectGroupMessages" resultType="cn.link56.im.model.vo.QueryGroupMessageVO">
|
||||
SELECT TOP (#{pageSize})
|
||||
gm.b_id AS id,
|
||||
gm.b_group_id AS groupId,
|
||||
gm.b_sender_id AS senderId,
|
||||
u.b_name AS senderName,
|
||||
u.b_avatar AS senderAvatar,
|
||||
gm.b_content AS content,
|
||||
gm.b_type AS type,
|
||||
gm.b_send_time AS sendTime
|
||||
FROM b_im_group_message gm
|
||||
LEFT JOIN b_company_user u ON gm.b_sender_id = u.b_id
|
||||
WHERE gm.b_group_id = #{groupId}
|
||||
<if test="beforeTimestamp != null and beforeId != null">
|
||||
AND (
|
||||
gm.b_send_time < #{beforeTimestamp}
|
||||
OR (gm.b_send_time = #{beforeTimestamp} AND gm.b_id < #{beforeId})
|
||||
)
|
||||
</if>
|
||||
ORDER BY gm.b_send_time DESC, gm.b_id DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="cn.link56.im.mapper.ImGroupUserMapper">
|
||||
|
||||
<select id="selectGroupUsers" resultType="cn.link56.im.model.vo.QueryGroupUserVO" parameterType="map">
|
||||
SELECT
|
||||
gu.b_group_id AS groupId,
|
||||
cu.b_id AS userId,
|
||||
cu.b_avatar AS userAvatar,
|
||||
cu.b_name AS userName
|
||||
FROM
|
||||
b_im_group_user gu
|
||||
INNER JOIN
|
||||
b_company_user cu
|
||||
ON gu.b_user_id = cu.b_id
|
||||
WHERE
|
||||
gu.b_group_id = #{groupId}
|
||||
<if test="userName != null and userName != ''">
|
||||
AND cu.b_name LIKE '%' + #{userName} + '%'
|
||||
</if>
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="cn.link56.im.mapper.ImPrivateMessageMapper">
|
||||
|
||||
<select id="selectPrivateMessages" resultType="cn.link56.im.model.vo.QueryPrivateMessageVO">
|
||||
SELECT TOP (#{pageSize})
|
||||
b_id AS id,
|
||||
b_sender_id AS senderId,
|
||||
b_receiver_id AS receiverId,
|
||||
b_content AS content,
|
||||
b_type AS type,
|
||||
b_send_time AS sendTime
|
||||
FROM b_im_private_message
|
||||
WHERE
|
||||
(
|
||||
(b_sender_id = #{userId} AND b_receiver_id = #{friendId})
|
||||
OR
|
||||
(b_sender_id = #{friendId} AND b_receiver_id = #{userId})
|
||||
)
|
||||
<if test="beforeTimestamp != null and beforeId != null">
|
||||
AND (
|
||||
b_send_time < #{beforeTimestamp}
|
||||
OR (b_send_time = #{beforeTimestamp} AND b_id < #{beforeId})
|
||||
)
|
||||
</if>
|
||||
ORDER BY b_send_time DESC, b_id DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
+5
-4
@@ -23,11 +23,12 @@
|
||||
<update id="decreaseCommentCount">
|
||||
UPDATE b_post_stat
|
||||
SET
|
||||
b_comment_count = b_comment_count - #{count},
|
||||
b_comment_count = CASE
|
||||
WHEN b_comment_count - #{count} < 0 THEN 0
|
||||
ELSE b_comment_count - #{count}
|
||||
END,
|
||||
b_update_time = GETDATE()
|
||||
WHERE b_post_id = #{postId}
|
||||
AND b_comment_count >= #{count}
|
||||
</update>
|
||||
|
||||
|
||||
</mapper>
|
||||
</mapper>
|
||||
Reference in new issue
Block a user