diff --git a/src/main/java/com/ai/da/common/utils/RedisUtil.java b/src/main/java/com/ai/da/common/utils/RedisUtil.java index 0d5c6153..ffb0f424 100644 --- a/src/main/java/com/ai/da/common/utils/RedisUtil.java +++ b/src/main/java/com/ai/da/common/utils/RedisUtil.java @@ -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); + } + + } diff --git a/src/main/java/com/ai/da/controller/AccountController.java b/src/main/java/com/ai/da/controller/AccountController.java index 4579ae15..8cf6a5a9 100644 --- a/src/main/java/com/ai/da/controller/AccountController.java +++ b/src/main/java/com/ai/da/controller/AccountController.java @@ -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 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 viewsGet(@RequestParam("id") Long id) { + return Response.success(accountService.viewsIncrease(id)); + } + + @ApiOperation(value = "获取个人主页信息") + @GetMapping("/personalHomepage") + public Response getPersonalHomepage(@RequestParam("id") Long id){ + return Response.success(accountService.getPersonalHomepage(id)); + } } diff --git a/src/main/java/com/ai/da/controller/MessageCenterController.java b/src/main/java/com/ai/da/controller/MessageCenterController.java index 66bb764c..3f625cb8 100644 --- a/src/main/java/com/ai/da/controller/MessageCenterController.java +++ b/src/main/java/com/ai/da/controller/MessageCenterController.java @@ -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> getHistoryNotification(@Valid @RequestBody GetNotificationVO getNotificationVO) { - return Response.success(messageCenterService.getHistoryNotification(getNotificationVO)); + public Response> getHistoryNotification(@Valid @RequestBody GetNotificationDTO getNotificationDTO) { + return Response.success(messageCenterService.getHistoryNotification(getNotificationDTO)); } // 已读消息 @@ -49,7 +49,7 @@ public class MessageCenterController { // 发布系统消息 @ApiOperation(value = "发布系统消息") @PostMapping("/publishSysMessage") - public Response publishSysMessage(@Valid @RequestBody PublishSysNotificationVO message) { + public Response publishSysMessage(@Valid @RequestBody PublishSysNotificationDTO message) { messageCenterService.publishSystemNotification(message); return Response.success("success"); } diff --git a/src/main/java/com/ai/da/controller/PortfolioController.java b/src/main/java/com/ai/da/controller/PortfolioController.java index c69c7485..1ad6d81d 100644 --- a/src/main/java/com/ai/da/controller/PortfolioController.java +++ b/src/main/java/com/ai/da/controller/PortfolioController.java @@ -134,14 +134,14 @@ public class PortfolioController { @ApiOperation(value = "获取关注列表") @PostMapping("/getFolloweeList") - public Response> getFolloweeList(@Valid @RequestBody PageQueryBaseVo pageQueryBaseVo) { - return Response.success(portfolioService.getFolloweeList(pageQueryBaseVo)); + public Response> getFolloweeList(@Valid @RequestBody GetFollowListDTO getFollowListDTO) { + return Response.success(portfolioService.getFolloweeList(getFollowListDTO)); } @ApiOperation(value = "获取粉丝列表") @PostMapping("/getFollowerList") - public Response> getFollowerList(@Valid @RequestBody PageQueryBaseVo pageQueryBaseVo) { - return Response.success(portfolioService.getFollowerList(pageQueryBaseVo)); + public Response> getFollowerList(@Valid @RequestBody GetFollowListDTO getFollowListDTO) { + return Response.success(portfolioService.getFollowerList(getFollowListDTO)); } } diff --git a/src/main/java/com/ai/da/mapper/primary/UserFollowMapper.java b/src/main/java/com/ai/da/mapper/primary/UserFollowMapper.java index 77e2b6d8..ff45177c 100644 --- a/src/main/java/com/ai/da/mapper/primary/UserFollowMapper.java +++ b/src/main/java/com/ai/da/mapper/primary/UserFollowMapper.java @@ -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 { + List getFolloweeListByFollower(Long followerAccountId, Integer limit, Integer offset, String order); + + List getFollowerListByFollowee(Long followeeAccountId, Integer limit, Integer offset, String order); + + List getFolloweeListByName(String name, Long followerId); + + List getFollowerListByName(String name, Long followeeId); } diff --git a/src/main/java/com/ai/da/model/dto/GetFollowListDTO.java b/src/main/java/com/ai/da/model/dto/GetFollowListDTO.java new file mode 100644 index 00000000..c2878ecb --- /dev/null +++ b/src/main/java/com/ai/da/model/dto/GetFollowListDTO.java @@ -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; +} diff --git a/src/main/java/com/ai/da/model/vo/GetNotificationVO.java b/src/main/java/com/ai/da/model/dto/GetNotificationDTO.java similarity index 67% rename from src/main/java/com/ai/da/model/vo/GetNotificationVO.java rename to src/main/java/com/ai/da/model/dto/GetNotificationDTO.java index e241e163..781ffc59 100644 --- a/src/main/java/com/ai/da/model/vo/GetNotificationVO.java +++ b/src/main/java/com/ai/da/model/dto/GetNotificationDTO.java @@ -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; diff --git a/src/main/java/com/ai/da/model/vo/PublishSysNotificationVO.java b/src/main/java/com/ai/da/model/dto/PublishSysNotificationDTO.java similarity index 84% rename from src/main/java/com/ai/da/model/vo/PublishSysNotificationVO.java rename to src/main/java/com/ai/da/model/dto/PublishSysNotificationDTO.java index 1379aca0..11a0c56b 100644 --- a/src/main/java/com/ai/da/model/vo/PublishSysNotificationVO.java +++ b/src/main/java/com/ai/da/model/dto/PublishSysNotificationDTO.java @@ -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; diff --git a/src/main/java/com/ai/da/model/dto/QueryPortfolioPageDTO.java b/src/main/java/com/ai/da/model/dto/QueryPortfolioPageDTO.java index 8176ba00..71e2c3d3 100644 --- a/src/main/java/com/ai/da/model/dto/QueryPortfolioPageDTO.java +++ b/src/main/java/com/ai/da/model/dto/QueryPortfolioPageDTO.java @@ -14,4 +14,6 @@ public class QueryPortfolioPageDTO extends PageQueryBaseVo { private Integer getMyPortfolio; private Integer getLikePortfolio; + + private Long accountId; } diff --git a/src/main/java/com/ai/da/model/vo/AccountFollowVO.java b/src/main/java/com/ai/da/model/vo/AccountFollowVO.java new file mode 100644 index 00000000..5680ed76 --- /dev/null +++ b/src/main/java/com/ai/da/model/vo/AccountFollowVO.java @@ -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; +} diff --git a/src/main/java/com/ai/da/model/vo/NotificationVO.java b/src/main/java/com/ai/da/model/vo/NotificationVO.java index 823d53f2..cd4eaedd 100644 --- a/src/main/java/com/ai/da/model/vo/NotificationVO.java +++ b/src/main/java/com/ai/da/model/vo/NotificationVO.java @@ -16,4 +16,6 @@ public class NotificationVO extends Notification { private String senderAvatar; + private Integer isFollow; + } diff --git a/src/main/java/com/ai/da/model/vo/PersonalHomepageVO.java b/src/main/java/com/ai/da/model/vo/PersonalHomepageVO.java new file mode 100644 index 00000000..b6f0f058 --- /dev/null +++ b/src/main/java/com/ai/da/model/vo/PersonalHomepageVO.java @@ -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; +} diff --git a/src/main/java/com/ai/da/service/AccountService.java b/src/main/java/com/ai/da/service/AccountService.java index 0450042e..8d97d549 100644 --- a/src/main/java/com/ai/da/service/AccountService.java +++ b/src/main/java/com/ai/da/service/AccountService.java @@ -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 { List getByIds(List ids); String uploadAvatar(MultipartFile file); + + PersonalHomepageVO getPersonalHomepage(Long accountId); + + Boolean viewsIncrease(Long id); } diff --git a/src/main/java/com/ai/da/service/MessageCenterService.java b/src/main/java/com/ai/da/service/MessageCenterService.java index 35930a5a..84bb9cd1 100644 --- a/src/main/java/com/ai/da/service/MessageCenterService.java +++ b/src/main/java/com/ai/da/service/MessageCenterService.java @@ -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 { Map getAllTypeMessageUnreadCount(); - PageBaseResponse getHistoryNotification(GetNotificationVO getNotificationVO); + PageBaseResponse getHistoryNotification(GetNotificationDTO getNotificationDTO); void prePushMessage(Notification notification); @@ -24,5 +24,5 @@ public interface MessageCenterService extends IService { void setReadAll(String type); - void publishSystemNotification(PublishSysNotificationVO message); + void publishSystemNotification(PublishSysNotificationDTO message); } diff --git a/src/main/java/com/ai/da/service/PortfolioService.java b/src/main/java/com/ai/da/service/PortfolioService.java index f9a47ff6..a67b5e4c 100644 --- a/src/main/java/com/ai/da/service/PortfolioService.java +++ b/src/main/java/com/ai/da/service/PortfolioService.java @@ -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 { void cancelFollow(Long followeeId); - Long getFolloweeCount(); + Long getFolloweeCount(Long accountId); - List getFolloweeList(PageQueryBaseVo pageQueryBaseVo); + List getFolloweeList(GetFollowListDTO getFollowListDTO); - Long getFollowerCount(); + Long getFollowerCount(Long accountId); - List getFollowerList(PageQueryBaseVo pageQueryBaseVo); + List getFollowerList(GetFollowListDTO getFollowListDTO); + + Integer getIfFollowed(Long followeeId, Long followerId); + + Long getPortfolioCount(Long accountId); } diff --git a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java index 01b903e4..7b96b3a2 100644 --- a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java @@ -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 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 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 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; + } + } diff --git a/src/main/java/com/ai/da/service/impl/MessageCenterServiceImpl.java b/src/main/java/com/ai/da/service/impl/MessageCenterServiceImpl.java index 2f0ac1d8..e1f5638a 100644 --- a/src/main/java/com/ai/da/service/impl/MessageCenterServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/MessageCenterServiceImpl.java @@ -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 getHistoryNotification(GetNotificationVO getNotificationVO) { + public PageBaseResponse getHistoryNotification(GetNotificationDTO getNotificationDTO) { Long accountId = UserContext.getUserHolder().getId(); QueryWrapper 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 notificationPage = baseMapper.selectPage(new Page<>(getNotificationVO.getPage(), getNotificationVO.getSize()), queryWrapper); + Page notificationPage = baseMapper.selectPage(new Page<>(getNotificationDTO.getPage(), getNotificationDTO.getSize()), queryWrapper); List unreadSysNotificationIds = baseMapper.getUnreadSysNotification(accountId); IPage convert = notificationPage.convert(o -> { @@ -260,7 +260,7 @@ public class MessageCenterServiceImpl extends ServiceImpl 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 likedPortfolioIdList = redisUtil.getLikedPortfolios(userHolder.getId()); @@ -497,14 +497,8 @@ public class PortfolioServiceImpl extends ServiceImpl 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 queryWrapper = new QueryWrapper<>(); @@ -999,47 +993,96 @@ public class PortfolioServiceImpl extends ServiceImpl 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 getFolloweeList(PageQueryBaseVo pageQueryBaseVo){ - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("follower_id", UserContext.getUserHolder().getId()).select("followee_id"); - Page followPage = userFollowMapper.selectPage(new Page<>(pageQueryBaseVo.getPage(), pageQueryBaseVo.getSize()), queryWrapper); + // 获取某个用户的关注列表 + 按名字查询 + public List getFolloweeList(GetFollowListDTO getFollowListDTO) { + Long accountId = UserContext.getUserHolder().getId(); + // 1、判断是否有按用户名查询 + List 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 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 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 getFollowerList(PageQueryBaseVo pageQueryBaseVo){ - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("followee_id", UserContext.getUserHolder().getId()).select("follower_id"); - Page followPage = userFollowMapper.selectPage(new Page<>(pageQueryBaseVo.getPage(), pageQueryBaseVo.getSize()), queryWrapper); + // 获取某个用户的粉丝列表 + 按名字查询 需返回是否关注该粉丝 + public List getFollowerList(GetFollowListDTO getFollowListDTO) { + Long accountId = UserContext.getUserHolder().getId(); - if (!followPage.getRecords().isEmpty()){ - List followerIds = followPage.getRecords().stream().map(UserFollow::getFollowerId).collect(Collectors.toList()); - return accountMapper.selectBatchIds(followerIds); + // 获取当前用户的所有粉丝 + QueryWrapper qw = new QueryWrapper<>(); + qw.eq("follower_id", accountId).select("followee_id","create_time"); + List userFollows = userFollowMapper.selectList(qw); + Map followeeMap = userFollows.stream().collect(Collectors.toMap(UserFollow::getFolloweeId, UserFollow::getCreateTime)); + + List 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 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 queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("account_id", accountId); + + return baseMapper.selectCount(queryWrapper); + } + } diff --git a/src/main/resources/mapper/primary/UserFollowMapper.xml b/src/main/resources/mapper/primary/UserFollowMapper.xml new file mode 100644 index 00000000..06e40a81 --- /dev/null +++ b/src/main/resources/mapper/primary/UserFollowMapper.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + +