查询用户信息
This commit is contained in:
parent
822526b913
commit
ff456d7533
@ -60,4 +60,14 @@
|
||||
</foreach>
|
||||
|
||||
</select>
|
||||
<!-- <select id="getFollowedVlogerIds" resultType="com.imooc.pojo.Fans" parameterType="map">-->
|
||||
<!-- SELECT vloger_id, MAX(is_fan_friend_of_mine) AS is_fan_friend_of_mine-->
|
||||
<!-- FROM t_fans-->
|
||||
<!-- WHERE fan_id = #{currentUserId}-->
|
||||
<!-- AND vloger_id IN-->
|
||||
<!-- <foreach collection='vlogerIds' item='vlogerId' open='(' separator=',' close=')'>-->
|
||||
<!-- #{vlogerId}-->
|
||||
<!-- </foreach>-->
|
||||
<!-- GROUP BY vloger_id-->
|
||||
<!-- </select>-->
|
||||
</mapper>
|
@ -2,6 +2,7 @@ package com.imooc.service.impl;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.imooc.base.BaseInfoProperties;
|
||||
import com.imooc.bo.UpdatedUserBO;
|
||||
import com.imooc.enums.Sex;
|
||||
import com.imooc.enums.UserInfoModifyType;
|
||||
@ -9,6 +10,8 @@ import com.imooc.enums.YesOrNo;
|
||||
import com.imooc.exceptions.GraceException;
|
||||
import com.imooc.grace.result.ResponseStatusEnum;
|
||||
import com.imooc.mapper.FansMapper;
|
||||
import com.imooc.mapper.FansMapperCustom;
|
||||
import com.imooc.service.FansService;
|
||||
import com.imooc.mapper.UserMemberMapper;
|
||||
import com.imooc.mapper.UsersMapper;
|
||||
import com.imooc.mo.Token;
|
||||
@ -48,9 +51,13 @@ import static com.imooc.base.BaseInfoProperties.MOBILE_SMSCODE;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
public class UserServiceImpl extends BaseInfoProperties implements UserService {
|
||||
@Autowired
|
||||
private UsersMapper usersMapper;
|
||||
@Autowired
|
||||
private FansMapperCustom fansMapperCustom;
|
||||
@Autowired
|
||||
private FansService fansService;
|
||||
|
||||
@Resource
|
||||
private PasswordEncoder passwordEncoder;
|
||||
@ -325,6 +332,7 @@ public class UserServiceImpl implements UserService {
|
||||
try {
|
||||
PageHelper.startPage(page, pageSize);
|
||||
List<UsersVO> userList = usersMapper.searchByNickname(nickname);
|
||||
|
||||
if(currentUserId.isEmpty()){
|
||||
return userList;
|
||||
}
|
||||
@ -332,24 +340,17 @@ public class UserServiceImpl implements UserService {
|
||||
// 提取模糊查询出的用户 ID 列表
|
||||
List<String> vlogerIds = userList.stream().map(UsersVO::getId).collect(Collectors.toList());
|
||||
log.info("用户列表" + vlogerIds);
|
||||
|
||||
// 获取当前用户关注的
|
||||
List<java.util.Map<String, Object>> followedRelations = fansMapper.getFollowedVlogerIds(currentUserId, vlogerIds);
|
||||
// 构建 vlogerId 到 is_fan_friend_of_mine 的映射
|
||||
java.util.Map<String, Integer> relationMap = followedRelations.stream()
|
||||
.collect(Collectors.toMap(
|
||||
map -> (String) map.get("vloger_id"),
|
||||
map -> (Integer) map.get("is_fan_friend_of_mine")
|
||||
));
|
||||
Set<String> followedVlogerIds = relationMap.keySet();
|
||||
|
||||
// 遍历设置每个用户的关注状态及展示状态
|
||||
if (vlogerIds.isEmpty()) {
|
||||
log.info("没有查询到用户 ID,跳过关注关系查询");
|
||||
return userList;
|
||||
}
|
||||
//
|
||||
userList.forEach(usersVO -> {
|
||||
boolean isFollowed = followedVlogerIds.contains(usersVO.getId());
|
||||
usersVO.setIsFollowed(isFollowed);
|
||||
|
||||
Boolean isFollowed = fansService.queryDoIFollowVloger(currentUserId,usersVO.getId());
|
||||
if (isFollowed) {
|
||||
Integer isFanFriendOfMine = relationMap.get(usersVO.getId());
|
||||
if (isFanFriendOfMine != null && isFanFriendOfMine == 1) {
|
||||
String relationship = redis.get(REDIS_FANS_AND_VLOGGER_RELATIONSHIP + ":" + usersVO.getId() + ":" + currentUserId);
|
||||
if (StringUtils.isNotBlank(relationship) && relationship.equalsIgnoreCase("1")) {
|
||||
usersVO.setFollowStatus("互相关注"); // 假设 UsersVO 有此方法设置展示状态
|
||||
}else {
|
||||
usersVO.setFollowStatus("已关注");
|
||||
@ -358,9 +359,43 @@ public class UserServiceImpl implements UserService {
|
||||
usersVO.setFollowStatus("未关注");
|
||||
}
|
||||
});
|
||||
|
||||
log.info("用户列表" + userList);
|
||||
return userList;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// // 获取当前用户关注的
|
||||
// List<java.util.Map<String, Object>> followedRelations = fansMapper.getFollowedVlogerIds(currentUserId, vlogerIds);
|
||||
// log.info("获取当前用户关注的: {}", followedRelations);
|
||||
// // 构建 vlogerId 到 is_fan_friend_of_mine 的映射
|
||||
// java.util.Map<String, Integer> relationMap = followedRelations.stream()
|
||||
// .filter(Objects::nonNull) // 排除整个 map 为 null 的情况
|
||||
// .collect(Collectors.toMap(
|
||||
// map -> (String) map.get("vloger_id"),
|
||||
// map -> (Integer) map.get("is_fan_friend_of_mine")
|
||||
// ));
|
||||
// log.info("构造的 relationMap: {}", relationMap);
|
||||
// Set<String> followedVlogerIds = relationMap.keySet();
|
||||
//
|
||||
// // 遍历设置每个用户的关注状态及展示状态
|
||||
// userList.forEach(usersVO -> {
|
||||
// boolean isFollowed = followedVlogerIds.contains(usersVO.getId());
|
||||
// usersVO.setIsFollowed(isFollowed);
|
||||
// if (isFollowed) {
|
||||
// Integer isFanFriendOfMine = relationMap.get(usersVO.getId());
|
||||
// if (isFanFriendOfMine != null && isFanFriendOfMine == 1) {
|
||||
// usersVO.setFollowStatus("互相关注"); // 假设 UsersVO 有此方法设置展示状态
|
||||
// } else {
|
||||
// usersVO.setFollowStatus("已关注");
|
||||
// }
|
||||
// } else {
|
||||
// usersVO.setFollowStatus("未关注");
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// log.info("用户列表" + userList);
|
||||
// return userList;
|
||||
} catch (Exception e) {
|
||||
log.error("搜索用户时发生异常", e);
|
||||
throw new RuntimeException("搜索用户时发生异常", e);
|
||||
|
Loading…
x
Reference in New Issue
Block a user