添加关注、取消关注、获取关注列表、粉丝列表相关接口
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
package com.ai.da.service;
|
||||
|
||||
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.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PortfolioService extends IService<Portfolio> {
|
||||
Boolean publish(MultipartFile canvas, String data);
|
||||
|
||||
@@ -41,4 +45,12 @@ public interface PortfolioService extends IService<Portfolio> {
|
||||
Boolean delete(Long id);
|
||||
|
||||
Portfolio getByIdAll(Long originalPortfolioId);
|
||||
|
||||
void follow(Long followeeId);
|
||||
|
||||
void cancelFollow(Long followeeId);
|
||||
|
||||
List<Account> getFolloweeList(PageQueryBaseVo pageQueryBaseVo);
|
||||
|
||||
List<Account> getFollowerList(PageQueryBaseVo pageQueryBaseVo);
|
||||
}
|
||||
|
||||
@@ -67,21 +67,33 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
|
||||
// 获取历史消息 可指定消息类型 分页查询
|
||||
@Override
|
||||
public PageBaseResponse<NotificationVO> getHistoryNotification(GetNotificationVO getNotificationVO) {
|
||||
Long accountId = UserContext.getUserHolder().getId();
|
||||
QueryWrapper<Notification> queryWrapper = new QueryWrapper<>();
|
||||
if (!StringUtils.isNullOrEmpty(getNotificationVO.getType())) {
|
||||
queryWrapper.eq("type", getNotificationVO.getType());
|
||||
}
|
||||
queryWrapper.eq("receiver_id", UserContext.getUserHolder().getId());
|
||||
if (!getNotificationVO.getType().equals("system")){
|
||||
queryWrapper.eq("receiver_id", accountId);
|
||||
}
|
||||
Page<Notification> notificationPage = baseMapper.selectPage(new Page<>(getNotificationVO.getPage(), getNotificationVO.getSize()), queryWrapper);
|
||||
|
||||
List<Long> unreadSysNotificationIds = baseMapper.getUnreadSysNotification(accountId);
|
||||
IPage<NotificationVO> convert = notificationPage.convert(o -> {
|
||||
NotificationVO notificationVO = CopyUtil.copyObject(o, NotificationVO.class);
|
||||
Account account = accountService.getById(notificationVO.getSenderId());
|
||||
notificationVO.setSenderUserName(account.getUserName());
|
||||
notificationVO.setSenderUserAvatar(StringUtils.isNullOrEmpty(account.getAvatar()) ? null : minioUtil.getPreSignedUrl(account.getAvatar(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
notificationVO.setPortfolioName(portfolioService.getById(notificationVO.getPortfolioId()).getPortfolioName());
|
||||
notificationVO.setPortfolioName(Objects.isNull(notificationVO.getPortfolioId()) ? null : portfolioService.getById(notificationVO.getPortfolioId()).getPortfolioName());
|
||||
// 设置单个人 系统消息是否已读
|
||||
if (notificationVO.getType().equals("system")){
|
||||
if (unreadSysNotificationIds.contains(notificationVO.getId())){
|
||||
notificationVO.setIsRead(0);
|
||||
}else {
|
||||
notificationVO.setIsRead(1);
|
||||
}
|
||||
}
|
||||
return notificationVO;
|
||||
});
|
||||
|
||||
return PageBaseResponse.success(convert);
|
||||
}
|
||||
|
||||
@@ -195,7 +207,7 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
|
||||
Long readCount = sysNotificationReadStatusMapper.selectCount(wrapper);
|
||||
|
||||
// 计算差
|
||||
return totalSysCount - readCount;
|
||||
return totalSysCount - readCount > 0 ? totalSysCount - readCount : 0;
|
||||
}
|
||||
|
||||
// 设置个人消息的已读状态 (允许一次已读多条个人消息)
|
||||
@@ -212,8 +224,8 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
|
||||
|
||||
baseMapper.update(null, updateWrapper);
|
||||
}
|
||||
pushMessage(type, UserContext.getUserHolder().getId());
|
||||
return Boolean.TRUE;
|
||||
|
||||
}
|
||||
|
||||
// 设置系统消息的已读状态 (允许一次已读多条系统消息)
|
||||
|
||||
@@ -33,6 +33,7 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio> implements PortfolioService {
|
||||
@@ -59,8 +60,8 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
|
||||
@Resource
|
||||
private UserLikeMapper userLikeMapper;
|
||||
|
||||
@Resource
|
||||
|
||||
@Resource
|
||||
private TDesignPythonOutfitMapper designPythonOutfitMapper;
|
||||
|
||||
@Resource
|
||||
@@ -75,7 +76,6 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
@Resource
|
||||
private DesignItemDetailPrintMapper designItemDetailPrintMapper;
|
||||
|
||||
|
||||
@Resource
|
||||
private MinioUtil minioUtil;
|
||||
|
||||
@@ -109,6 +109,9 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
@Resource
|
||||
private WorkspaceRelStyleMapper workspaceRelStyleMapper;
|
||||
|
||||
@Resource
|
||||
private UserFollowMapper userFollowMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean publish(MultipartFile file, String data) {
|
||||
@@ -169,7 +172,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
portfolio.setOriginal(0);
|
||||
portfolio.setOriginalAccountId(userLikeGroup.getOriginalAccountId());
|
||||
portfolio.setOriginalPortfolioId(userLikeGroup.getOriginalPortfolioId());
|
||||
}else {
|
||||
} else {
|
||||
portfolio.setOriginal(1);
|
||||
// portfolio.setOriginalAccountId(authPrincipalVo.getId());
|
||||
}
|
||||
@@ -187,7 +190,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
portfolio.setPortfolioDes(portfolioDTO.getPortfolioDes());
|
||||
if (!CollectionUtils.isEmpty(portfolios)) {
|
||||
portfolioMapper.updateById(portfolio);
|
||||
}else {
|
||||
} else {
|
||||
portfolioMapper.insert(portfolio);
|
||||
}
|
||||
|
||||
@@ -261,7 +264,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
portfolio.setOriginal(0);
|
||||
portfolio.setOriginalAccountId(userLikeGroup.getOriginalAccountId());
|
||||
portfolio.setOriginalPortfolioId(userLikeGroup.getOriginalPortfolioId());
|
||||
}else {
|
||||
} else {
|
||||
portfolio.setOriginal(1);
|
||||
// portfolio.setOriginalAccountId(authPrincipalVo.getId());
|
||||
}
|
||||
@@ -278,7 +281,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
portfolio.setPortfolioDes(portfolioDTO.getPortfolioDes());
|
||||
if (!CollectionUtils.isEmpty(portfolios)) {
|
||||
portfolioMapper.updateById(portfolio);
|
||||
}else {
|
||||
} else {
|
||||
portfolioMapper.insert(portfolio);
|
||||
}
|
||||
}
|
||||
@@ -427,12 +430,12 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
List<Long> likedPortfolioIdList = redisUtil.getLikedPortfolios(userHolder.getId());
|
||||
if (!CollectionUtils.isEmpty(likedPortfolioIdList)) {
|
||||
qw.lambda().in(Portfolio::getId, likedPortfolioIdList);
|
||||
}else {
|
||||
} else {
|
||||
return PageBaseResponse.success(new Page<>());
|
||||
}
|
||||
}
|
||||
qw.lambda().orderByDesc(Portfolio::getUpdateDate);
|
||||
IPage<Portfolio> page = portfolioMapper.selectPage(new Page<>(query.getPage(), query.getSize()),qw);
|
||||
IPage<Portfolio> page = portfolioMapper.selectPage(new Page<>(query.getPage(), query.getSize()), qw);
|
||||
IPage<PortfolioVO> convert = page.convert((Function<Portfolio, PortfolioVO>) portfolio -> {
|
||||
if (portfolio != null) {
|
||||
PortfolioVO vo = CopyUtil.copyObject(portfolio, PortfolioVO.class);
|
||||
@@ -480,13 +483,23 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
vo.setLikeNum(redisUtil.getLikeCount(vo.getId()));
|
||||
if (userHolder == null) {
|
||||
vo.setIsLike(0);
|
||||
}else {
|
||||
vo.setIsFollow(0);
|
||||
} else {
|
||||
boolean postLikedByUser = redisUtil.isPostLikedByUser(portfolioDTO.getId(), userHolder.getId());
|
||||
if (postLikedByUser) {
|
||||
vo.setIsLike(1);
|
||||
}else {
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
redisUtil.increaseViewCount(portfolioDTO.getId());
|
||||
vo.setViewNums(redisUtil.getViewCount(portfolioDTO.getId()));
|
||||
@@ -499,7 +512,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
vo.setOriginalPortfolioName(portfolioName);
|
||||
if (byId.getIsDeleted() == 0) {
|
||||
vo.setJumpable(1);
|
||||
}else {
|
||||
} else {
|
||||
vo.setJumpable(0);
|
||||
}
|
||||
}
|
||||
@@ -507,11 +520,11 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
if (userHolder == null) {
|
||||
vo.setIsMine(0);
|
||||
vo.setSelected(0);
|
||||
}else {
|
||||
} else {
|
||||
if (Objects.equals(vo.getAccountId(), userHolder.getId()) || Objects.equals(vo.getOriginalAccountId(), userHolder.getId())) {
|
||||
vo.setIsMine(1);
|
||||
vo.setSelected(1);
|
||||
}else {
|
||||
} else {
|
||||
vo.setIsMine(0);
|
||||
QueryWrapper<UserLikeGroup> getSelectedQw = new QueryWrapper<>();
|
||||
getSelectedQw.lambda().eq(UserLikeGroup::getAccountId, userHolder.getId());
|
||||
@@ -519,7 +532,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
List<UserLikeGroup> userLikeGroups = userLikeGroupMapper.selectList(getSelectedQw);
|
||||
if (CollectionUtils.isEmpty(userLikeGroups)) {
|
||||
vo.setSelected(0);
|
||||
}else {
|
||||
} else {
|
||||
vo.setSelected(1);
|
||||
}
|
||||
}
|
||||
@@ -546,12 +559,12 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
if (portfolio.getOriginal() == 1) {
|
||||
if (Objects.equals(portfolio.getAccountId(), authPrincipalVo.getId())) {
|
||||
userLikeGroupNew.setOriginal(1);
|
||||
}else {
|
||||
} else {
|
||||
userLikeGroupNew.setOriginal(0);
|
||||
userLikeGroupNew.setOriginalAccountId(portfolio.getAccountId());
|
||||
userLikeGroupNew.setOriginalPortfolioId(portfolio.getId());
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
userLikeGroupNew.setOriginal(0);
|
||||
userLikeGroupNew.setOriginalAccountId(portfolio.getOriginalAccountId());
|
||||
userLikeGroupNew.setOriginalPortfolioId(portfolio.getId());
|
||||
@@ -571,7 +584,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
if (workspace.getSex().equals(Sex.FEMALE.getValue())) {
|
||||
design.setTemplateId(workspace.getMannequinFemaleId());
|
||||
design.setModelType(workspace.getMannequinFemaleType());
|
||||
}else {
|
||||
} else {
|
||||
design.setTemplateId(workspace.getMannequinMaleId());
|
||||
design.setModelType(workspace.getMannequinMaleType());
|
||||
}
|
||||
@@ -579,7 +592,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
if (workspace.getPosition().equals(Position.OVERALL.getValue())) {
|
||||
design.setSingleOverall("overall");
|
||||
design.setSwitchCategory("");
|
||||
}else {
|
||||
} else {
|
||||
design.setSingleOverall("single");
|
||||
design.setSwitchCategory(workspace.getPosition());
|
||||
}
|
||||
@@ -697,7 +710,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
workspaceNew.setSystemDesignerPercentage((design1.getSystemScale().multiply(BigDecimal.valueOf(100)).intValue()));
|
||||
if (design1.getSingleOverall().equals("overall")) {
|
||||
workspaceNew.setPosition("Overall");
|
||||
}else {
|
||||
} else {
|
||||
workspaceNew.setPosition(design1.getSwitchCategory());
|
||||
}
|
||||
workspaceMapper.insert(workspaceNew);
|
||||
@@ -726,7 +739,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
workspaceNew.setMannequinMaleId(anotherOne.getId());
|
||||
workspaceNew.setMannequinMaleType("System");
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
workspaceNew.setSex("Male");
|
||||
workspaceNew.setMannequinMaleId(design1.getTemplateId());
|
||||
workspaceNew.setMannequinMaleType("System");
|
||||
@@ -750,7 +763,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
workspaceNew.setMannequinFemaleType("System");
|
||||
}
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
Library library = libraryMapper.selectById(design1.getTemplateId());
|
||||
if (library.getLevel2Type().equals("Female")) {
|
||||
workspaceNew.setSex("Female");
|
||||
@@ -765,7 +778,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
workspaceNew.setMannequinMaleId(anotherOne.getId());
|
||||
workspaceNew.setMannequinMaleType("System");
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
workspaceNew.setSex("Male");
|
||||
workspaceNew.setMannequinMaleId(design1.getTemplateId());
|
||||
workspaceNew.setMannequinMaleType("Library");
|
||||
@@ -809,6 +822,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
|
||||
@Resource
|
||||
private CommentMapper commentMapper;
|
||||
|
||||
@Override
|
||||
public Boolean comment(CommentDTO commentDTO) {
|
||||
AuthPrincipalVo userHolder = UserContext.getUserHolder();
|
||||
@@ -881,9 +895,9 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
|
||||
// 获取消息接收者id(即该操作的接收者)
|
||||
Long receiverId;
|
||||
if (!comment.getParentLevel1Id().equals(0L)){
|
||||
if (!comment.getParentLevel1Id().equals(0L)) {
|
||||
receiverId = commentMapper.selectById(comment.getParentLevel1Id()).getAccountId();
|
||||
}else {
|
||||
} else {
|
||||
receiverId = portfolio.getAccountId();
|
||||
}
|
||||
|
||||
@@ -944,4 +958,69 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
||||
// }
|
||||
return resultList;
|
||||
}
|
||||
|
||||
public void follow(Long followeeId) {
|
||||
Long accountId = UserContext.getUserHolder().getId();
|
||||
// 1、不能关注自己
|
||||
if (Objects.equals(followeeId, accountId)) {
|
||||
throw new BusinessException("you.cannot.follow.yourself", 1);
|
||||
}
|
||||
// 2、不能重复关注
|
||||
QueryWrapper<UserFollow> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("followee_id", followeeId).eq("follower_id", accountId);
|
||||
UserFollow userFollow = userFollowMapper.selectOne(queryWrapper);
|
||||
if (!Objects.isNull(userFollow)) {
|
||||
throw new BusinessException("you.have.already.followed.this.user", 1);
|
||||
}
|
||||
// 3、添加新follower到关注列表
|
||||
UserFollow newFollower = new UserFollow(followeeId, accountId);
|
||||
newFollower.setCreateTime(LocalDateTime.now());
|
||||
userFollowMapper.insert(newFollower);
|
||||
// 4、推送消息
|
||||
messageCenterService.prePushMessage(new Notification("follow", accountId, followeeId));
|
||||
}
|
||||
|
||||
// 取消关注
|
||||
public void cancelFollow(Long followeeId){
|
||||
Long accountId = UserContext.getUserHolder().getId();
|
||||
// 1、确定是否关注了该用户
|
||||
QueryWrapper<UserFollow> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("followee_id", followeeId).eq("follower_id", accountId);
|
||||
UserFollow userFollow = userFollowMapper.selectOne(queryWrapper);
|
||||
// 2、删除关注记录
|
||||
if (!Objects.isNull(userFollow)) {
|
||||
userFollowMapper.deleteById(userFollow.getId());
|
||||
// 3、逻辑删除关注消息
|
||||
messageCenterService.cancelPushMessage("follow", accountId, followeeId, null, null);
|
||||
}else {
|
||||
throw new BusinessException("you.have.not.followed.the.current.user", 1);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取某个用户的关注列表
|
||||
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);
|
||||
|
||||
if (!followPage.getRecords().isEmpty()){
|
||||
List<Long> followeeIds = followPage.getRecords().stream().map(UserFollow::getFolloweeId).collect(Collectors.toList());
|
||||
return accountMapper.selectBatchIds(followeeIds);
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// 获取某个用户的粉丝列表
|
||||
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);
|
||||
|
||||
if (!followPage.getRecords().isEmpty()){
|
||||
List<Long> followerIds = followPage.getRecords().stream().map(UserFollow::getFollowerId).collect(Collectors.toList());
|
||||
return accountMapper.selectBatchIds(followerIds);
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user