定位功能 显示好友距离 APP实现



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 list = this.tanHuaService.queryNearUser(gender, distance);

return ResponseEntity.ok(list);

} catch (Exception e) {

e.printStackTrace();

}

return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();

}




=======================================================



APP 端 显示定位距离 service



public List queryNearUser(String gender, String distance) {

//查询当前用户的位置

User user = UserThreadLocal.get();

UserLocationVo userLocationVo = this.userLocationApi.queryByUserId(user.getId());

if(ObjectUtil.isEmpty(userLocationVo)){

return ListUtil.empty();

}

PageInfo pageInfo = this.userLocationApi.queryUserFromLocation(userLocationVo.getLongitude(),

userLocationVo.getLatitude(),

Convert.toDouble(distance),

1,

50

);

List records = pageInfo.getRecords();

if(CollUtil.isEmpty(records)){

return ListUtil.empty();

}

//构造筛选条件

List userIdList = CollUtil.getFieldValues(records, "userId");

QueryWrapper queryWrapper = new 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 userInfoList = this.userInfoService.queryUserInfoList(queryWrapper);

List result = new ArrayList<>();

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 条评论) “”
   
验证码:

相关文章

推荐文章