List indexNearbyUserResponseList = userResults.getContent().stream() .map(p -> { String pid = p.getContent().getName(); //将自己排除 if (Integer.valueOf(pid).equals(userId)) { return null; } //从缓存中获取用户信息 User user = userService.getUserFromCache(pid); if (user == null) { //如果缓存中不存在,则从数据库中获取 user = userService.getById(pid); if (user == null) { //如果数据库中也不存在,则返回null return null; } //将用户信息存入缓存 userService.setUserToCache(user); } //筛选用户 if((sex == 1 && user.getSex() == 2) || (sex == 2 && user.getSex() == 1))return null; if (StringUtils.isNotEmpty(user.getAvatar())) { IndexNearbyUserResponse indexNearbyUserResponse = new IndexNearbyUserResponse(); BeanUtils.copyProperties(user, indexNearbyUserResponse); indexNearbyUserResponse.setDistance(p.getDistance().getValue()); return indexNearbyUserResponse; } return null; }) .filter(e -> !ObjectUtils.isEmpty(e)) .toList();


原文地址: https://www.cveoy.top/t/topic/bI2Y 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录