定位功能 显示好友距离 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;

}

郑重声明:本文内容及图片均整理自互联网,不代表本站立场,版权归原作者所有,如有侵权请联系管理员(admin#wlmqw.com)删除。
(0)
用户投稿
上一篇 2022年6月19日
下一篇 2022年6月19日

相关推荐

联系我们

联系邮箱:admin#wlmqw.com
工作时间:周一至周五,10:30-18:30,节假日休息