Commit 94cd9e42 by 段启岩

获取他人基本信息接口添加是否关注该用户的字段

parent 9e3871e5
......@@ -19,6 +19,7 @@ import cn.meteor.beyondclouds.modules.user.form.*;
import cn.meteor.beyondclouds.modules.user.service.IUserBlacklistService;
import cn.meteor.beyondclouds.modules.user.service.IUserFollowService;
import cn.meteor.beyondclouds.modules.user.service.IUserService;
import cn.meteor.beyondclouds.modules.user.vo.UserInfoWithFollowedVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -190,8 +191,8 @@ public class UserApi {
@Anonymous
@ApiOperation(("获取他人基本信息"))
@GetMapping("/user/{userId}/baseinfo")
public Response<UserInfoDTO> updateOtherBaseInfo(@PathVariable(name = "userId") String userId ,
@CollectAccessInfo(type = ParamType.USER_STATISTICS, paramName = "userId") AccessInfo accessInfo){
public Response<UserInfoWithFollowedVO> updateOtherBaseInfo(@PathVariable(name = "userId") String userId ,
@CollectAccessInfo(type = ParamType.USER_STATISTICS, paramName = "userId") AccessInfo accessInfo){
boolean updateVisited = false;
if (null != accessInfo.getFieldVisitCount() && accessInfo.getFieldVisitCount() == 0) {
......@@ -208,8 +209,12 @@ public class UserApi {
userInfoDTO.setQqNumber(null);
userInfoDTO.setWxNumber(null);
UserInfoWithFollowedVO userInfoWithFollowedVO = new UserInfoWithFollowedVO();
BeanUtils.copyProperties(userInfoDTO, userInfoWithFollowedVO);
Boolean followedUser = userFollowService.hasFollowedUser(userId, userInfoDTO.getUserId());
userInfoWithFollowedVO.setFollowedUser(followedUser);
// 返回结果
return Response.success(userInfoDTO);
return Response.success(userInfoWithFollowedVO);
} catch (UserServiceException e) {
e.printStackTrace();
return Response.error(e);
......
......@@ -105,6 +105,7 @@ public class UserStatisticsListener implements DataItemChangeListener {
// 更新被关注用户的粉丝量
QueryWrapper<UserFollow> followedUserFansNumQueryWrapper = new QueryWrapper<>();
followedUserFansNumQueryWrapper.eq("followed_id", userFollow.getFollowedId());
followedUserFansNumQueryWrapper.eq("follow_status", 0);
long followedUserFansNum = userFollowService.count(followedUserFansNumQueryWrapper);
updateUserStatisticValue(userFollow.getFollowedId(), "fans_num", followedUserFansNum);
// 发送被关注用户统计信息修改的消息
......@@ -114,6 +115,7 @@ public class UserStatisticsListener implements DataItemChangeListener {
// 更新关注者的关注量
QueryWrapper<UserFollow> followerUserFollowedNumQueryWrapper = new QueryWrapper<>();
followerUserFollowedNumQueryWrapper.eq("follower_id", userFollow.getFollowerId());
followerUserFollowedNumQueryWrapper.eq("follow_status", 0);
long followerUserFollowedNum = userFollowService.count(followerUserFollowedNumQueryWrapper);
updateUserStatisticValue(userFollow.getFollowerId(), "followed_num", followerUserFollowedNum);
// 发送关注者统计信息修改的消息
......
......@@ -58,4 +58,11 @@ public interface IUserFollowService extends IService<UserFollow> {
*/
Set<String> getCurrentUserFollowedUserIds(String userId);
/**
* 查看当前用户是否关注了目标用户
* @param currentUserId
* @param userId
* @return
*/
Boolean hasFollowedUser(String currentUserId, String userId);
}
......@@ -20,6 +20,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.Set;
......@@ -193,6 +194,21 @@ public class UserFollowServiceImpl extends ServiceImpl<UserFollowMapper, UserFol
public Set<String> getCurrentUserFollowedUserIds(String userId) {
return redisHelper.setGet(RedisKey.USER_FOLLOWED(userId));
}
@Override
public Boolean hasFollowedUser(String currentUserId, String userId) {
// 如果是自己,直接返回true
if (currentUserId.equals(userId)) {
return true;
}
Set<String> currentUserFollowedUserIds = getCurrentUserFollowedUserIds(currentUserId);
if (!CollectionUtils.isEmpty(currentUserFollowedUserIds)) {
return currentUserFollowedUserIds.contains(userId);
}
return null;
}
}
package cn.meteor.beyondclouds.modules.user.vo;
import cn.meteor.beyondclouds.modules.user.entity.UserStatistics;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* 用户信息
* @author 段启岩
*/
@Data
public class UserInfoWithFollowedVO {
private String userId;
@ApiModelProperty(value = "用户昵称")
private String nickName;
@ApiModelProperty(value = "用户头像")
private String userAvatar;
@ApiModelProperty(value = "性别")
private Integer gender;
@ApiModelProperty(value = "个性签名")
private String signature;
@ApiModelProperty(value = "手机号")
private String mobile;
@ApiModelProperty(value = "邮箱")
private String email;
@ApiModelProperty(value = "微信号")
private String wxNumber;
@ApiModelProperty(value = "QQ号")
private String qqNumber;
private Date createTime;
private Date updateTime;
/**
* 是否关注该用户
*/
private Boolean followedUser;
private UserStatistics statistics;
}
......@@ -4,7 +4,7 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/beyond_clouds?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: 2018006709
password: 100Centa30821%mysql
# 邮箱
mail:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment