|
|
@ -1,6 +1,8 @@ |
|
|
package com.bx.implatform.service.impl; |
|
|
package com.bx.implatform.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
import com.bx.implatform.contant.RedisKey; |
|
|
import com.bx.implatform.contant.RedisKey; |
|
|
import com.bx.implatform.entity.Friend; |
|
|
import com.bx.implatform.entity.Friend; |
|
|
@ -8,14 +10,14 @@ import com.bx.implatform.entity.User; |
|
|
import com.bx.implatform.enums.ResultCode; |
|
|
import com.bx.implatform.enums.ResultCode; |
|
|
import com.bx.implatform.exception.GlobalException; |
|
|
import com.bx.implatform.exception.GlobalException; |
|
|
import com.bx.implatform.mapper.FriendMapper; |
|
|
import com.bx.implatform.mapper.FriendMapper; |
|
|
|
|
|
import com.bx.implatform.mapper.UserMapper; |
|
|
import com.bx.implatform.service.IFriendService; |
|
|
import com.bx.implatform.service.IFriendService; |
|
|
import com.bx.implatform.service.IUserService; |
|
|
|
|
|
import com.bx.implatform.session.SessionContext; |
|
|
import com.bx.implatform.session.SessionContext; |
|
|
import com.bx.implatform.session.UserSession; |
|
|
import com.bx.implatform.session.UserSession; |
|
|
import com.bx.implatform.vo.FriendVO; |
|
|
import com.bx.implatform.vo.FriendVO; |
|
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.aop.framework.AopContext; |
|
|
import org.springframework.aop.framework.AopContext; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.cache.annotation.CacheConfig; |
|
|
import org.springframework.cache.annotation.CacheConfig; |
|
|
import org.springframework.cache.annotation.CacheEvict; |
|
|
import org.springframework.cache.annotation.CacheEvict; |
|
|
import org.springframework.cache.annotation.Cacheable; |
|
|
import org.springframework.cache.annotation.Cacheable; |
|
|
@ -26,25 +28,24 @@ import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
@Slf4j |
|
|
@CacheConfig(cacheNames= RedisKey.IM_CACHE_FRIEND) |
|
|
|
|
|
@Service |
|
|
@Service |
|
|
|
|
|
@AllArgsConstructor |
|
|
|
|
|
@CacheConfig(cacheNames= RedisKey.IM_CACHE_FRIEND) |
|
|
public class FriendServiceImpl extends ServiceImpl<FriendMapper, Friend> implements IFriendService { |
|
|
public class FriendServiceImpl extends ServiceImpl<FriendMapper, Friend> implements IFriendService { |
|
|
|
|
|
|
|
|
@Autowired |
|
|
private final UserMapper userMapper; |
|
|
private IUserService userService; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 查询用户的所有好友 |
|
|
* 查询用户的所有好友 |
|
|
* |
|
|
* |
|
|
* @param userId 用户id |
|
|
* @param userId 用户id |
|
|
* @return |
|
|
* @return 好友列表 |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public List<Friend> findFriendByUserId(Long userId) { |
|
|
public List<Friend> findFriendByUserId(Long userId) { |
|
|
QueryWrapper<Friend> queryWrapper = new QueryWrapper(); |
|
|
LambdaQueryWrapper<Friend> queryWrapper = Wrappers.lambdaQuery(); |
|
|
queryWrapper.lambda().eq(Friend::getUserId,userId); |
|
|
queryWrapper.eq(Friend::getUserId,userId); |
|
|
List<Friend> friends = this.list(queryWrapper); |
|
|
return this.list(queryWrapper); |
|
|
return friends; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -52,9 +53,8 @@ public class FriendServiceImpl extends ServiceImpl<FriendMapper, Friend> impleme |
|
|
* 添加好友,互相建立好友关系 |
|
|
* 添加好友,互相建立好友关系 |
|
|
* |
|
|
* |
|
|
* @param friendId 好友的用户id |
|
|
* @param friendId 好友的用户id |
|
|
* @return |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
@Transactional |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Override |
|
|
@Override |
|
|
public void addFriend(Long friendId) { |
|
|
public void addFriend(Long friendId) { |
|
|
long userId = SessionContext.getSession().getUserId(); |
|
|
long userId = SessionContext.getSession().getUserId(); |
|
|
@ -73,9 +73,8 @@ public class FriendServiceImpl extends ServiceImpl<FriendMapper, Friend> impleme |
|
|
* 删除好友,双方都会解除好友关系 |
|
|
* 删除好友,双方都会解除好友关系 |
|
|
* |
|
|
* |
|
|
* @param friendId 好友的用户id |
|
|
* @param friendId 好友的用户id |
|
|
* @return |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
@Transactional |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Override |
|
|
@Override |
|
|
public void delFriend(Long friendId) { |
|
|
public void delFriend(Long friendId) { |
|
|
long userId = SessionContext.getSession().getUserId(); |
|
|
long userId = SessionContext.getSession().getUserId(); |
|
|
@ -92,7 +91,6 @@ public class FriendServiceImpl extends ServiceImpl<FriendMapper, Friend> impleme |
|
|
* |
|
|
* |
|
|
* @param userId1 用户1的id |
|
|
* @param userId1 用户1的id |
|
|
* @param userId2 用户2的id |
|
|
* @param userId2 用户2的id |
|
|
* @return |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
@Cacheable(key="#userId1+':'+#userId2") |
|
|
@Cacheable(key="#userId1+':'+#userId2") |
|
|
@Override |
|
|
@Override |
|
|
@ -109,7 +107,6 @@ public class FriendServiceImpl extends ServiceImpl<FriendMapper, Friend> impleme |
|
|
* 更新好友信息,主要是头像和昵称 |
|
|
* 更新好友信息,主要是头像和昵称 |
|
|
* |
|
|
* |
|
|
* @param vo 好友vo |
|
|
* @param vo 好友vo |
|
|
* @return |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public void update(FriendVO vo) { |
|
|
public void update(FriendVO vo) { |
|
|
@ -135,7 +132,6 @@ public class FriendServiceImpl extends ServiceImpl<FriendMapper, Friend> impleme |
|
|
* |
|
|
* |
|
|
* @param userId 用户id |
|
|
* @param userId 用户id |
|
|
* @param friendId 好友的用户id |
|
|
* @param friendId 好友的用户id |
|
|
* @return |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
@CacheEvict(key="#userId+':'+#friendId") |
|
|
@CacheEvict(key="#userId+':'+#friendId") |
|
|
public void bindFriend(Long userId, Long friendId) { |
|
|
public void bindFriend(Long userId, Long friendId) { |
|
|
@ -147,7 +143,7 @@ public class FriendServiceImpl extends ServiceImpl<FriendMapper, Friend> impleme |
|
|
Friend friend = new Friend(); |
|
|
Friend friend = new Friend(); |
|
|
friend.setUserId(userId); |
|
|
friend.setUserId(userId); |
|
|
friend.setFriendId(friendId); |
|
|
friend.setFriendId(friendId); |
|
|
User friendInfo = userService.getById(friendId); |
|
|
User friendInfo = userMapper.selectById(friendId); |
|
|
friend.setFriendHeadImage(friendInfo.getHeadImage()); |
|
|
friend.setFriendHeadImage(friendInfo.getHeadImage()); |
|
|
friend.setFriendNickName(friendInfo.getNickName()); |
|
|
friend.setFriendNickName(friendInfo.getNickName()); |
|
|
this.save(friend); |
|
|
this.save(friend); |
|
|
@ -160,7 +156,6 @@ public class FriendServiceImpl extends ServiceImpl<FriendMapper, Friend> impleme |
|
|
* |
|
|
* |
|
|
* @param userId 用户id |
|
|
* @param userId 用户id |
|
|
* @param friendId 好友的用户id |
|
|
* @param friendId 好友的用户id |
|
|
* @return |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
@CacheEvict(key="#userId+':'+#friendId") |
|
|
@CacheEvict(key="#userId+':'+#friendId") |
|
|
public void unbindFriend(Long userId, Long friendId) { |
|
|
public void unbindFriend(Long userId, Long friendId) { |
|
|
@ -169,9 +164,7 @@ public class FriendServiceImpl extends ServiceImpl<FriendMapper, Friend> impleme |
|
|
.eq(Friend::getUserId,userId) |
|
|
.eq(Friend::getUserId,userId) |
|
|
.eq(Friend::getFriendId,friendId); |
|
|
.eq(Friend::getFriendId,friendId); |
|
|
List<Friend> friends = this.list(queryWrapper); |
|
|
List<Friend> friends = this.list(queryWrapper); |
|
|
friends.stream().forEach(friend -> { |
|
|
friends.forEach(friend -> this.removeById(friend.getId())); |
|
|
this.removeById(friend.getId()); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -179,7 +172,7 @@ public class FriendServiceImpl extends ServiceImpl<FriendMapper, Friend> impleme |
|
|
* 查询指定的某个好友信息 |
|
|
* 查询指定的某个好友信息 |
|
|
* |
|
|
* |
|
|
* @param friendId 好友的用户id |
|
|
* @param friendId 好友的用户id |
|
|
* @return |
|
|
* @return 好友信息 |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public FriendVO findFriend(Long friendId) { |
|
|
public FriendVO findFriend(Long friendId) { |
|
|
|