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;
}