优化 获取关注、粉丝列表
This commit is contained in:
@@ -17,10 +17,7 @@ import com.ai.da.mapper.primary.entity.*;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.enums.AutoApproved;
|
||||
import com.ai.da.model.enums.Language;
|
||||
import com.ai.da.model.vo.AccountLoginVO;
|
||||
import com.ai.da.model.vo.AccountPreLoginVO;
|
||||
import com.ai.da.model.vo.AuthPrincipalVo;
|
||||
import com.ai.da.model.vo.QuestionnaireVO;
|
||||
import com.ai.da.model.vo.*;
|
||||
import com.ai.da.service.*;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@@ -88,9 +85,13 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
|
||||
@Resource
|
||||
private MinioUtil minioUtil;
|
||||
|
||||
@Value("${minio.bucketName.users}")
|
||||
private String userBucket;
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public AccountPreLoginVO preLogin(AccountPreLoginDTO accountDTO) {
|
||||
@@ -208,8 +209,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
avatar = account.getAvatar();
|
||||
}
|
||||
response.setAvatar(minioUtil.getPreSignedUrl(avatar, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
response.setFolloweeCount(portfolioService.getFolloweeCount());
|
||||
response.setFollowerCount(portfolioService.getFollowerCount());
|
||||
response.setFolloweeCount(portfolioService.getFolloweeCount(account.getId()));
|
||||
response.setFollowerCount(portfolioService.getFollowerCount(account.getId()));
|
||||
//判断是否常用ip 不是则发邮件提示
|
||||
calculateExceptionIp(RequestInfoUtil.getIpAddress(request), account);
|
||||
return response;
|
||||
@@ -1461,4 +1462,44 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
return minioUtil.getPreSignedUrl(avatarPath, CommonConstant.MINIO_IMAGE_EXPIRE_TIME);
|
||||
}
|
||||
|
||||
public PersonalHomepageVO getPersonalHomepage(Long accountId){
|
||||
// 需要返回 用户头像 用户名 作品总量 粉丝量 关注量 主页访问量 当前用户是否被查看者关注
|
||||
Long currentUserId = UserContext.getUserHolder().getId();
|
||||
PersonalHomepageVO personalHomepageVO = new PersonalHomepageVO();
|
||||
|
||||
Account account = baseMapper.selectById(accountId);
|
||||
personalHomepageVO.setUserName(account.getUserName());
|
||||
String avatar = StringUtil.isNullOrEmpty(account.getAvatar()) ? CommonConstant.DEFAULT_AVATAR : account.getAvatar();
|
||||
personalHomepageVO.setAvatar(minioUtil.getPreSignedUrl(avatar, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
|
||||
personalHomepageVO.setPortfolioCount(portfolioService.getPortfolioCount(accountId));
|
||||
personalHomepageVO.setFolloweeCount(portfolioService.getFolloweeCount(accountId));
|
||||
personalHomepageVO.setFollowerCount(portfolioService.getFollowerCount(accountId));
|
||||
personalHomepageVO.setHomepageViewCount(viewPersonalHomepageCount(0L));
|
||||
|
||||
|
||||
if (accountId.equals(currentUserId)){
|
||||
personalHomepageVO.setIsFollow(0);
|
||||
Long viewCount = viewPersonalHomepageCount(accountId);
|
||||
// 只有本人才能看到个人主页浏览量
|
||||
personalHomepageVO.setHomepageViewCount(viewCount == null ? 0 : viewCount);
|
||||
}else {
|
||||
personalHomepageVO.setIsFollow(portfolioService.getIfFollowed(accountId, currentUserId));
|
||||
// 非本人浏览主页时增加浏览量
|
||||
viewsIncrease(accountId);
|
||||
}
|
||||
return personalHomepageVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean viewsIncrease(Long id) {
|
||||
redisUtil.increasePersonalHomepageViewCount(id);
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
private Long viewPersonalHomepageCount(Long accountId) {
|
||||
redisUtil.getPersonalHomepageViewCount(accountId);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ import com.ai.da.mapper.primary.SysNotificationReadStatusMapper;
|
||||
import com.ai.da.mapper.primary.entity.Account;
|
||||
import com.ai.da.mapper.primary.entity.Notification;
|
||||
import com.ai.da.mapper.primary.entity.SysNotificationReadStatus;
|
||||
import com.ai.da.model.vo.GetNotificationVO;
|
||||
import com.ai.da.model.dto.GetNotificationDTO;
|
||||
import com.ai.da.model.vo.NotificationVO;
|
||||
import com.ai.da.model.vo.PublishSysNotificationVO;
|
||||
import com.ai.da.model.dto.PublishSysNotificationDTO;
|
||||
import com.ai.da.service.AccountService;
|
||||
import com.ai.da.service.MessageCenterService;
|
||||
import com.ai.da.service.PortfolioService;
|
||||
@@ -67,16 +67,16 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
|
||||
|
||||
// 获取历史消息 可指定消息类型 分页查询
|
||||
@Override
|
||||
public PageBaseResponse<NotificationVO> getHistoryNotification(GetNotificationVO getNotificationVO) {
|
||||
public PageBaseResponse<NotificationVO> getHistoryNotification(GetNotificationDTO getNotificationDTO) {
|
||||
Long accountId = UserContext.getUserHolder().getId();
|
||||
QueryWrapper<Notification> queryWrapper = new QueryWrapper<>();
|
||||
if (!StringUtils.isNullOrEmpty(getNotificationVO.getType())) {
|
||||
queryWrapper.eq("type", getNotificationVO.getType());
|
||||
if (!StringUtils.isNullOrEmpty(getNotificationDTO.getType())) {
|
||||
queryWrapper.eq("type", getNotificationDTO.getType());
|
||||
}
|
||||
if (!getNotificationVO.getType().equals("system")){
|
||||
if (!getNotificationDTO.getType().equals("system")){
|
||||
queryWrapper.eq("receiver_id", accountId);
|
||||
}
|
||||
Page<Notification> notificationPage = baseMapper.selectPage(new Page<>(getNotificationVO.getPage(), getNotificationVO.getSize()), queryWrapper);
|
||||
Page<Notification> notificationPage = baseMapper.selectPage(new Page<>(getNotificationDTO.getPage(), getNotificationDTO.getSize()), queryWrapper);
|
||||
|
||||
List<Long> unreadSysNotificationIds = baseMapper.getUnreadSysNotification(accountId);
|
||||
IPage<NotificationVO> convert = notificationPage.convert(o -> {
|
||||
@@ -260,7 +260,7 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
|
||||
}
|
||||
|
||||
// 发布系统消息
|
||||
public void publishSystemNotification(PublishSysNotificationVO message) {
|
||||
public void publishSystemNotification(PublishSysNotificationDTO message) {
|
||||
Notification notification = new Notification();
|
||||
notification.setType("system");
|
||||
notification.setSenderId(UserContext.getUserHolder().getId());
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.ai.da.common.utils.MinioUtil;
|
||||
import com.ai.da.common.utils.RedisUtil;
|
||||
import com.ai.da.mapper.primary.*;
|
||||
import com.ai.da.mapper.primary.entity.*;
|
||||
import com.ai.da.mapper.primary.entity.Collection;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.enums.Position;
|
||||
import com.ai.da.model.enums.Sex;
|
||||
@@ -31,10 +32,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@@ -427,6 +425,8 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
QueryWrapper<Portfolio> qw = new QueryWrapper<>();
|
||||
if (query.getGetMyPortfolio() == 1) {
|
||||
qw.lambda().eq(Portfolio::getAccountId, userHolder.getId());
|
||||
} else if (!Objects.isNull(query.getAccountId())) {
|
||||
qw.lambda().eq(Portfolio::getAccountId, query.getAccountId());
|
||||
}
|
||||
if (query.getGetLikePortfolio() == 1) {
|
||||
List<Long> likedPortfolioIdList = redisUtil.getLikedPortfolios(userHolder.getId());
|
||||
@@ -497,14 +497,8 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
vo.setIsLike(0);
|
||||
}
|
||||
// 设置当前用户是否关注了所查看作品的作者
|
||||
QueryWrapper<UserFollow> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("followee_id", portfolio.getAccountId()).eq("follower_id", userHolder.getId());
|
||||
UserFollow userFollow = userFollowMapper.selectOne(queryWrapper);
|
||||
if (Objects.isNull(userFollow)){
|
||||
vo.setIsFollow(0);
|
||||
}else {
|
||||
vo.setIsFollow(1);
|
||||
}
|
||||
Integer ifFollowed = getIfFollowed(portfolio.getAccountId(), userHolder.getId());
|
||||
vo.setIsFollow(ifFollowed);
|
||||
avatar = StringUtil.isNullOrEmpty(account.getAvatar()) ? CommonConstant.DEFAULT_AVATAR : account.getAvatar();
|
||||
}
|
||||
vo.setAvatar(minioUtil.getPreSignedUrl(avatar, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
@@ -988,7 +982,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
}
|
||||
|
||||
// 取消关注
|
||||
public void cancelFollow(Long followeeId){
|
||||
public void cancelFollow(Long followeeId) {
|
||||
Long accountId = UserContext.getUserHolder().getId();
|
||||
// 1、确定是否关注了该用户
|
||||
QueryWrapper<UserFollow> queryWrapper = new QueryWrapper<>();
|
||||
@@ -999,47 +993,96 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
userFollowMapper.deleteById(userFollow.getId());
|
||||
// 3、逻辑删除关注消息
|
||||
messageCenterService.cancelPushMessage("follow", accountId, followeeId, null, null);
|
||||
}else {
|
||||
} else {
|
||||
throw new BusinessException("you.have.not.followed.the.current.user", 1);
|
||||
}
|
||||
}
|
||||
|
||||
public Long getFolloweeCount(){
|
||||
public Long getFolloweeCount(Long accountId) {
|
||||
QueryWrapper<UserFollow> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("follower_id", UserContext.getUserHolder().getId()).select("followee_id");
|
||||
queryWrapper.eq("follower_id", accountId).select("followee_id");
|
||||
return userFollowMapper.selectCount(queryWrapper);
|
||||
}
|
||||
|
||||
// 获取某个用户的关注列表
|
||||
public List<Account> getFolloweeList(PageQueryBaseVo pageQueryBaseVo){
|
||||
QueryWrapper<UserFollow> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("follower_id", UserContext.getUserHolder().getId()).select("followee_id");
|
||||
Page<UserFollow> followPage = userFollowMapper.selectPage(new Page<>(pageQueryBaseVo.getPage(), pageQueryBaseVo.getSize()), queryWrapper);
|
||||
// 获取某个用户的关注列表 + 按名字查询
|
||||
public List<AccountFollowVO> getFolloweeList(GetFollowListDTO getFollowListDTO) {
|
||||
Long accountId = UserContext.getUserHolder().getId();
|
||||
// 1、判断是否有按用户名查询
|
||||
List<AccountFollowVO> followeeList;
|
||||
if (!StringUtil.isNullOrEmpty(getFollowListDTO.getSearchByName())) {
|
||||
followeeList = userFollowMapper.getFolloweeListByName(getFollowListDTO.getSearchByName(), accountId);
|
||||
}else {
|
||||
// 2、查全部 分页查询
|
||||
String order = StringUtil.isNullOrEmpty(getFollowListDTO.getOrder()) ? "DESC" : getFollowListDTO.getOrder().equals("DESC") ? "DESC" : "ASC";
|
||||
Integer limit= getFollowListDTO.getSize() > 0 ? getFollowListDTO.getSize() : 20;
|
||||
Integer offset = getFollowListDTO.getPage() > 0 ? (getFollowListDTO.getPage() - 1) * getFollowListDTO.getSize() : 0;
|
||||
followeeList = userFollowMapper.getFolloweeListByFollower(accountId, limit, offset, order);
|
||||
}
|
||||
|
||||
if (!followPage.getRecords().isEmpty()){
|
||||
List<Long> followeeIds = followPage.getRecords().stream().map(UserFollow::getFolloweeId).collect(Collectors.toList());
|
||||
return accountMapper.selectBatchIds(followeeIds);
|
||||
if (!followeeList.isEmpty()){
|
||||
followeeList.forEach(followee -> {
|
||||
String avatar = StringUtil.isNullOrEmpty(followee.getAvatar()) ? CommonConstant.DEFAULT_AVATAR : followee.getAvatar();
|
||||
followee.setAvatar(minioUtil.getPreSignedUrl(avatar, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
});
|
||||
return followeeList;
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public Long getFollowerCount(){
|
||||
public Long getFollowerCount(Long accountId) {
|
||||
QueryWrapper<UserFollow> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("followee_id", UserContext.getUserHolder().getId()).select("follower_id");
|
||||
queryWrapper.eq("followee_id", accountId).select("follower_id");
|
||||
return userFollowMapper.selectCount(queryWrapper);
|
||||
}
|
||||
|
||||
// 获取某个用户的粉丝列表
|
||||
public List<Account> getFollowerList(PageQueryBaseVo pageQueryBaseVo){
|
||||
QueryWrapper<UserFollow> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("followee_id", UserContext.getUserHolder().getId()).select("follower_id");
|
||||
Page<UserFollow> followPage = userFollowMapper.selectPage(new Page<>(pageQueryBaseVo.getPage(), pageQueryBaseVo.getSize()), queryWrapper);
|
||||
// 获取某个用户的粉丝列表 + 按名字查询 需返回是否关注该粉丝
|
||||
public List<AccountFollowVO> getFollowerList(GetFollowListDTO getFollowListDTO) {
|
||||
Long accountId = UserContext.getUserHolder().getId();
|
||||
|
||||
if (!followPage.getRecords().isEmpty()){
|
||||
List<Long> followerIds = followPage.getRecords().stream().map(UserFollow::getFollowerId).collect(Collectors.toList());
|
||||
return accountMapper.selectBatchIds(followerIds);
|
||||
// 获取当前用户的所有粉丝
|
||||
QueryWrapper<UserFollow> qw = new QueryWrapper<>();
|
||||
qw.eq("follower_id", accountId).select("followee_id","create_time");
|
||||
List<UserFollow> userFollows = userFollowMapper.selectList(qw);
|
||||
Map<Long, LocalDateTime> followeeMap = userFollows.stream().collect(Collectors.toMap(UserFollow::getFolloweeId, UserFollow::getCreateTime));
|
||||
|
||||
List<AccountFollowVO> followerList;
|
||||
// 1、判断是否有按用户名查询粉丝
|
||||
if (!StringUtil.isNullOrEmpty(getFollowListDTO.getSearchByName())) {
|
||||
followerList = userFollowMapper.getFollowerListByName(getFollowListDTO.getSearchByName(), accountId);
|
||||
}else {
|
||||
// 2、查全部 分页查询
|
||||
String order = StringUtil.isNullOrEmpty(getFollowListDTO.getOrder()) ? "DESC" : getFollowListDTO.getOrder().equals("DESC") ? "DESC" : "ASC";
|
||||
Integer limit= getFollowListDTO.getSize() > 0 ? getFollowListDTO.getSize() : 20;
|
||||
Integer offset = getFollowListDTO.getPage() > 0 ? (getFollowListDTO.getPage() - 1) * getFollowListDTO.getSize() : 0;
|
||||
followerList = userFollowMapper.getFollowerListByFollowee(accountId, limit,offset, order);
|
||||
}
|
||||
|
||||
if (!followerList.isEmpty()){
|
||||
// 判断当前用户是否与粉丝互关
|
||||
followerList.forEach(follower -> {
|
||||
String avatar = StringUtil.isNullOrEmpty(follower.getAvatar()) ? CommonConstant.DEFAULT_AVATAR : follower.getAvatar();
|
||||
follower.setAvatar(minioUtil.getPreSignedUrl(avatar, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
follower.setMutualFollowing(Objects.isNull(followeeMap.get(follower.getUserId())) ? 0 : 1);
|
||||
follower.setFollowTime(followeeMap.get(follower.getUserId()));
|
||||
});
|
||||
return followerList;
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public Integer getIfFollowed(Long followeeId, Long followerId) {
|
||||
// 设置当前用户是否关注了所查看作品的作者
|
||||
QueryWrapper<UserFollow> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("followee_id", followeeId).eq("follower_id", followerId);
|
||||
UserFollow userFollow = userFollowMapper.selectOne(queryWrapper);
|
||||
return Objects.isNull(userFollow) ? 0 : 1;
|
||||
}
|
||||
|
||||
public Long getPortfolioCount(Long accountId) {
|
||||
QueryWrapper<Portfolio> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("account_id", accountId);
|
||||
|
||||
return baseMapper.selectCount(queryWrapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user