APP VO 对象
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class NearUserVo {
private Long userId;
private String avatar;
private String nickname;
}
===========================================================
APP 端 显示定位距离 controller
/**
* 搜附近
*
* @param gender
* @param distance
* @return
*/
@GetMapping("search")
public ResponseEntity> queryNearUser(@RequestParam(value = "gender", required = false) String gender,
@RequestParam(value = "distance", defaultValue = "2000") String distance) {
try {
List
return ResponseEntity.ok(list);
} catch (Exception e) {
e.printStackTrace();
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
=======================================================
APP 端 显示定位距离 service
public List
//查询当前用户的位置
User user = UserThreadLocal.get();
UserLocationVo userLocationVo = this.userLocationApi.queryByUserId(user.getId());
if(ObjectUtil.isEmpty(userLocationVo)){
return ListUtil.empty();
}
PageInfo
userLocationVo.getLatitude(),
Convert.toDouble(distance),
1,
50
);
List
if(CollUtil.isEmpty(records)){
return ListUtil.empty();
}
//构造筛选条件
List
QueryWrapper
queryWrapper.in("user_id", userIdList);
if(StrUtil.equalsIgnoreCase(gender, "man")){
queryWrapper.eq("sex", SexEnum.MAN);
}else if(StrUtil.equalsIgnoreCase(gender, "woman")){
queryWrapper.eq("sex", SexEnum.WOMAN);
}
List
List
for (UserLocationVo locationVo : records) {
//排除自己
if(ObjectUtil.equals(locationVo.getUserId(), user.getId())){
continue;
}
for (UserInfo userInfo : userInfoList) {
if(ObjectUtil.equals(locationVo.getUserId(), userInfo.getUserId())){
NearUserVo nearUserVo = new NearUserVo();
nearUserVo.setUserId(userInfo.getUserId());
nearUserVo.setAvatar(userInfo.getLogo());
nearUserVo.setNickname(userInfo.getNickName());
result.add(nearUserVo);
break;
}
}
}
return result;
}
留言与评论(共有 0 条评论) “” |