优化 获取关注、粉丝列表
This commit is contained in:
@@ -216,4 +216,17 @@ public class RedisUtil {
|
||||
return redisTemplate.opsForValue().increment(key, 0);
|
||||
}
|
||||
|
||||
public final static String PERSONAL_HOMEPAGE_VIEW_KEY = "PersonalHomepage:view:";
|
||||
|
||||
public void increasePersonalHomepageViewCount(Long accountId) {
|
||||
String key = PERSONAL_HOMEPAGE_VIEW_KEY + accountId;
|
||||
redisTemplate.opsForValue().increment(key);
|
||||
}
|
||||
|
||||
public Long getPersonalHomepageViewCount(Long accountId) {
|
||||
String key = PERSONAL_HOMEPAGE_VIEW_KEY + accountId;
|
||||
return redisTemplate.opsForValue().increment(key, 0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.ai.da.mapper.primary.entity.TrialOrder;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.AccountLoginVO;
|
||||
import com.ai.da.model.vo.AccountPreLoginVO;
|
||||
import com.ai.da.model.vo.PersonalHomepageVO;
|
||||
import com.ai.da.service.AccountService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -199,11 +200,23 @@ public class AccountController {
|
||||
|
||||
// 用户上传头像
|
||||
@ApiOperation(value = "上传头像")
|
||||
@PostMapping(path = "/uploadAvatar"/*, consumes = MediaType.MULTIPART_FORM_DATA_VALUE*/)
|
||||
@PostMapping(path = "/uploadAvatar")
|
||||
public Response<String> uploadAvatar(@RequestParam("file") MultipartFile file) {
|
||||
if (null == file || StringUtils.isEmpty(file.getOriginalFilename())) {
|
||||
throw new BusinessException("file.cannot.be.empty");
|
||||
}
|
||||
return Response.success(accountService.uploadAvatar(file));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "个人主页浏览量增加")
|
||||
@GetMapping("/viewsIncrease")
|
||||
public Response<Boolean> viewsGet(@RequestParam("id") Long id) {
|
||||
return Response.success(accountService.viewsIncrease(id));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取个人主页信息")
|
||||
@GetMapping("/personalHomepage")
|
||||
public Response<PersonalHomepageVO> getPersonalHomepage(@RequestParam("id") Long id){
|
||||
return Response.success(accountService.getPersonalHomepage(id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ package com.ai.da.controller;
|
||||
|
||||
import com.ai.da.common.response.PageBaseResponse;
|
||||
import com.ai.da.common.response.Response;
|
||||
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.MessageCenterService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -35,8 +35,8 @@ public class MessageCenterController {
|
||||
// 获取历史消息
|
||||
@ApiOperation(value = "获取历史消息")
|
||||
@PostMapping("/getHistoryNotification")
|
||||
public Response<PageBaseResponse<NotificationVO>> getHistoryNotification(@Valid @RequestBody GetNotificationVO getNotificationVO) {
|
||||
return Response.success(messageCenterService.getHistoryNotification(getNotificationVO));
|
||||
public Response<PageBaseResponse<NotificationVO>> getHistoryNotification(@Valid @RequestBody GetNotificationDTO getNotificationDTO) {
|
||||
return Response.success(messageCenterService.getHistoryNotification(getNotificationDTO));
|
||||
}
|
||||
|
||||
// 已读消息
|
||||
@@ -49,7 +49,7 @@ public class MessageCenterController {
|
||||
// 发布系统消息
|
||||
@ApiOperation(value = "发布系统消息")
|
||||
@PostMapping("/publishSysMessage")
|
||||
public Response<String> publishSysMessage(@Valid @RequestBody PublishSysNotificationVO message) {
|
||||
public Response<String> publishSysMessage(@Valid @RequestBody PublishSysNotificationDTO message) {
|
||||
messageCenterService.publishSystemNotification(message);
|
||||
return Response.success("success");
|
||||
}
|
||||
|
||||
@@ -134,14 +134,14 @@ public class PortfolioController {
|
||||
|
||||
@ApiOperation(value = "获取关注列表")
|
||||
@PostMapping("/getFolloweeList")
|
||||
public Response<List<Account>> getFolloweeList(@Valid @RequestBody PageQueryBaseVo pageQueryBaseVo) {
|
||||
return Response.success(portfolioService.getFolloweeList(pageQueryBaseVo));
|
||||
public Response<List<AccountFollowVO>> getFolloweeList(@Valid @RequestBody GetFollowListDTO getFollowListDTO) {
|
||||
return Response.success(portfolioService.getFolloweeList(getFollowListDTO));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取粉丝列表")
|
||||
@PostMapping("/getFollowerList")
|
||||
public Response<List<Account>> getFollowerList(@Valid @RequestBody PageQueryBaseVo pageQueryBaseVo) {
|
||||
return Response.success(portfolioService.getFollowerList(pageQueryBaseVo));
|
||||
public Response<List<AccountFollowVO>> getFollowerList(@Valid @RequestBody GetFollowListDTO getFollowListDTO) {
|
||||
return Response.success(portfolioService.getFollowerList(getFollowListDTO));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,8 +2,18 @@ package com.ai.da.mapper.primary;
|
||||
|
||||
import com.ai.da.common.config.mybatis.plus.CommonMapper;
|
||||
import com.ai.da.mapper.primary.entity.UserFollow;
|
||||
import com.ai.da.model.vo.AccountFollowVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface UserFollowMapper extends CommonMapper<UserFollow> {
|
||||
List<AccountFollowVO> getFolloweeListByFollower(Long followerAccountId, Integer limit, Integer offset, String order);
|
||||
|
||||
List<AccountFollowVO> getFollowerListByFollowee(Long followeeAccountId, Integer limit, Integer offset, String order);
|
||||
|
||||
List<AccountFollowVO> getFolloweeListByName(String name, Long followerId);
|
||||
|
||||
List<AccountFollowVO> getFollowerListByName(String name, Long followeeId);
|
||||
|
||||
}
|
||||
|
||||
19
src/main/java/com/ai/da/model/dto/GetFollowListDTO.java
Normal file
19
src/main/java/com/ai/da/model/dto/GetFollowListDTO.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.ai.da.model.dto;
|
||||
|
||||
import com.ai.da.model.vo.PageQueryBaseVo;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@ApiModel("按条件分页查询关注列表")
|
||||
public class GetFollowListDTO extends PageQueryBaseVo {
|
||||
|
||||
@ApiModelProperty("查找指定用户名")
|
||||
private String searchByName;
|
||||
|
||||
@ApiModelProperty("按关注时间排序 DESC 降序 || ASC 升序")
|
||||
private String order;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ai.da.model.vo;
|
||||
package com.ai.da.model.dto;
|
||||
|
||||
import com.ai.da.model.vo.PageQueryBaseVo;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
@@ -8,7 +9,7 @@ import lombok.EqualsAndHashCode;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel
|
||||
@Data
|
||||
public class GetNotificationVO extends PageQueryBaseVo{
|
||||
public class GetNotificationDTO extends PageQueryBaseVo {
|
||||
|
||||
@ApiModelProperty("system/like/comment/follow")
|
||||
private String type;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.ai.da.model.vo;
|
||||
package com.ai.da.model.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
@@ -6,7 +6,7 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
@ApiModel("发布系统消息")
|
||||
public class PublishSysNotificationVO {
|
||||
public class PublishSysNotificationDTO {
|
||||
|
||||
@ApiModelProperty("系统消息标题")
|
||||
private String title;
|
||||
@@ -14,4 +14,6 @@ public class QueryPortfolioPageDTO extends PageQueryBaseVo {
|
||||
private Integer getMyPortfolio;
|
||||
|
||||
private Integer getLikePortfolio;
|
||||
|
||||
private Long accountId;
|
||||
}
|
||||
|
||||
24
src/main/java/com/ai/da/model/vo/AccountFollowVO.java
Normal file
24
src/main/java/com/ai/da/model/vo/AccountFollowVO.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.ai.da.model.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AccountFollowVO {
|
||||
private Long userId;
|
||||
|
||||
private String userName;
|
||||
|
||||
private String avatar;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
|
||||
private LocalDateTime followTime;
|
||||
|
||||
private Integer mutualFollowing;
|
||||
}
|
||||
@@ -16,4 +16,6 @@ public class NotificationVO extends Notification {
|
||||
|
||||
private String senderAvatar;
|
||||
|
||||
private Integer isFollow;
|
||||
|
||||
}
|
||||
|
||||
31
src/main/java/com/ai/da/model/vo/PersonalHomepageVO.java
Normal file
31
src/main/java/com/ai/da/model/vo/PersonalHomepageVO.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.ai.da.model.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@ApiModel("个人主页返回信息")
|
||||
public class PersonalHomepageVO {
|
||||
|
||||
@ApiModelProperty("用户名")
|
||||
private String userName;
|
||||
|
||||
@ApiModelProperty("用户头像")
|
||||
private String avatar;
|
||||
|
||||
@ApiModelProperty("用户作品总数")
|
||||
private Long portfolioCount;
|
||||
|
||||
@ApiModelProperty("粉丝总数")
|
||||
private Long followerCount;
|
||||
|
||||
@ApiModelProperty("关注者总数")
|
||||
private Long followeeCount;
|
||||
|
||||
@ApiModelProperty("个人主页总浏览量")
|
||||
private Long homepageViewCount;
|
||||
|
||||
@ApiModelProperty("是否关注了主页用户")
|
||||
private Integer isFollow;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.ai.da.mapper.primary.entity.TrialOrder;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.AccountLoginVO;
|
||||
import com.ai.da.model.vo.AccountPreLoginVO;
|
||||
import com.ai.da.model.vo.PersonalHomepageVO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -160,4 +161,8 @@ public interface AccountService extends IService<Account> {
|
||||
List<Account> getByIds(List<Long> ids);
|
||||
|
||||
String uploadAvatar(MultipartFile file);
|
||||
|
||||
PersonalHomepageVO getPersonalHomepage(Long accountId);
|
||||
|
||||
Boolean viewsIncrease(Long id);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ package com.ai.da.service;
|
||||
|
||||
import com.ai.da.common.response.PageBaseResponse;
|
||||
import com.ai.da.mapper.primary.entity.Notification;
|
||||
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.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
@@ -14,7 +14,7 @@ public interface MessageCenterService extends IService<Notification> {
|
||||
|
||||
Map<String, Long> getAllTypeMessageUnreadCount();
|
||||
|
||||
PageBaseResponse<NotificationVO> getHistoryNotification(GetNotificationVO getNotificationVO);
|
||||
PageBaseResponse<NotificationVO> getHistoryNotification(GetNotificationDTO getNotificationDTO);
|
||||
|
||||
void prePushMessage(Notification notification);
|
||||
|
||||
@@ -24,5 +24,5 @@ public interface MessageCenterService extends IService<Notification> {
|
||||
|
||||
void setReadAll(String type);
|
||||
|
||||
void publishSystemNotification(PublishSysNotificationVO message);
|
||||
void publishSystemNotification(PublishSysNotificationDTO message);
|
||||
}
|
||||
|
||||
@@ -4,10 +4,7 @@ import com.ai.da.common.response.PageBaseResponse;
|
||||
import com.ai.da.mapper.primary.entity.Account;
|
||||
import com.ai.da.mapper.primary.entity.Portfolio;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.CommentVO;
|
||||
import com.ai.da.model.vo.PageQueryBaseVo;
|
||||
import com.ai.da.model.vo.PortfolioVO;
|
||||
import com.ai.da.model.vo.UserLikeChooseVO;
|
||||
import com.ai.da.model.vo.*;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@@ -50,11 +47,15 @@ public interface PortfolioService extends IService<Portfolio> {
|
||||
|
||||
void cancelFollow(Long followeeId);
|
||||
|
||||
Long getFolloweeCount();
|
||||
Long getFolloweeCount(Long accountId);
|
||||
|
||||
List<Account> getFolloweeList(PageQueryBaseVo pageQueryBaseVo);
|
||||
List<AccountFollowVO> getFolloweeList(GetFollowListDTO getFollowListDTO);
|
||||
|
||||
Long getFollowerCount();
|
||||
Long getFollowerCount(Long accountId);
|
||||
|
||||
List<Account> getFollowerList(PageQueryBaseVo pageQueryBaseVo);
|
||||
List<AccountFollowVO> getFollowerList(GetFollowListDTO getFollowListDTO);
|
||||
|
||||
Integer getIfFollowed(Long followeeId, Long followerId);
|
||||
|
||||
Long getPortfolioCount(Long accountId);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
55
src/main/resources/mapper/primary/UserFollowMapper.xml
Normal file
55
src/main/resources/mapper/primary/UserFollowMapper.xml
Normal file
@@ -0,0 +1,55 @@
|
||||
<?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="com.ai.da.mapper.primary.UserFollowMapper">
|
||||
<select id="getFolloweeListByFollower" resultType="com.ai.da.model.vo.AccountFollowVO">
|
||||
SELECT a.id as user_id, a.user_name AS user_name, a.avatar AS avatar, b.create_time AS follow_time
|
||||
FROM t_account a
|
||||
INNER JOIN t_user_follow b ON a.id = b.followee_id
|
||||
WHERE b.follower_id = #{followerAccountId}
|
||||
<if test="order != null and order != ''">
|
||||
ORDER BY b.create_time ${order}
|
||||
</if>
|
||||
LIMIT #{limit} OFFSET #{offset}
|
||||
</select>
|
||||
<select id="getFollowerListByFollowee" resultType="com.ai.da.model.vo.AccountFollowVO">
|
||||
SELECT a.id as user_id, a.user_name AS user_name, a.avatar AS avatar, b.create_time AS follow_time
|
||||
FROM t_account a
|
||||
INNER JOIN t_user_follow b ON a.id = b.follower_id
|
||||
WHERE b.followee_id = #{followeeAccountId}
|
||||
<if test="order != null and order != ''">
|
||||
ORDER BY b.create_time ${order}
|
||||
</if>
|
||||
LIMIT #{limit} OFFSET #{offset}
|
||||
</select>
|
||||
|
||||
<select id="getFolloweeListByName" resultType="com.ai.da.model.vo.AccountFollowVO">
|
||||
SELECT a.id as user_id, a.user_name, a.avatar, b.create_time as follow_time
|
||||
FROM t_account a
|
||||
INNER JOIN t_user_follow b ON a.id = b.followee_id
|
||||
WHERE b.follower_id = #{followerId}
|
||||
AND b.followee_id in (
|
||||
SELECT id
|
||||
FROM t_account
|
||||
WHERE user_name = #{name} OR user_email = #{name}
|
||||
)
|
||||
GROUP BY a.user_email;
|
||||
|
||||
</select>
|
||||
|
||||
<select id="getFollowerListByName" resultType="com.ai.da.model.vo.AccountFollowVO">
|
||||
SELECT a.id as user_id, a.user_name, a.avatar, b.create_time as follow_time
|
||||
FROM t_account a
|
||||
INNER JOIN t_user_follow b ON a.id = b.follower_id
|
||||
WHERE b.followee_id = #{followeeId}
|
||||
AND b.follower_id in (
|
||||
SELECT id
|
||||
FROM t_account
|
||||
WHERE user_name = #{name} OR user_email = #{name}
|
||||
)
|
||||
GROUP BY a.user_email;
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user