Commit 698b272f authored by zhouxudong's avatar zhouxudong

添加调用经纬度接口

parent bb10ffac
......@@ -2,11 +2,18 @@ package com.lyy.admin.common.utils;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import java.time.Duration;
import java.util.List;
import java.util.Map;
/**
......@@ -17,22 +24,64 @@ import java.util.Map;
@Component
@Slf4j
public class BusinessService {
@Autowired
private WebClient webClient;
@Autowired private WebClient webClient;
@Value("${business.url.thread}")
private String url;
// 地理/逆地理编码
@Value("${business.url.geocode}")
private String geocode;
public AjaxResult savThread(Map<String,Object> params) {
public AjaxResult savThread(Map<String, Object> params) {
AjaxResult block =
this.webClient
.post()
.uri(url)
.bodyValue(params)
.bodyValue(params)
.retrieve()
.bodyToMono(AjaxResult.class)
.block();
log.info("注册保存线索信息:参数:{},结果:{}",params, JSONUtil.toJsonStr(block));
log.info("注册保存线索信息:参数:{},结果:{}", params, JSONUtil.toJsonStr(block));
return block;
}
/**
* @description: 返回格式 116.225202,39.897665
* @date: 2023/12/17 15:56
* @param: [address, city]
* @return: java.lang.String
*/
public String getUserIdetify(String address, String city) {
String url = this.geocode + address;
if (StringUtils.isNotBlank(city)) {
url = url + "&city=" + city;
}
Map result =
this.webClient
.get()
.uri(url)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.retrieve()
.bodyToMono(String.class)
.timeout(Duration.ofSeconds(4))
.onErrorResume(
e -> {
log.error("调用高德接口换取经纬度标识失败:", e);
log.error("调用高德接口换取经纬度标识:{}", address);
return Mono.empty();
})
.map(str -> JSONUtil.toBean(str, Map.class))
.block();
log.info("调用经纬度返回参数:{}", result);
if (ObjectUtils.isNotEmpty(result)
&& result.get("status").equals("1")
&& result.get("infocode").equals("10000")) {
String geocodes = JSONUtil.toJsonStr(result.get("geocodes"));
List<Map> maps = JSONUtil.toList(geocodes, Map.class);
Map map = maps.get(0);
return map.get("location").toString();
}
return null;
}
}
......@@ -75,11 +75,15 @@ huaweiObs:
sk: uZIdUJIwO0sKGVY0hltF9I6IbHEmjwCRco5JV7aM
bucketName: cfld-hw-obs-01
geocode:
key: 34182f92976cdab1bb4059352fc9e4a8
business:
url:
thread: localhost:8087/lyy/api/threadInfo/v1.0/save
geocode: https://restapi.amap.com/v3/geocode/geo?key=${geocode.key}&address=
mybatis-plus:
configuration:
# 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
\ No newline at end of file
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
......@@ -74,6 +74,10 @@ huaweiObs:
sk: uZIdUJIwO0sKGVY0hltF9I6IbHEmjwCRco5JV7aM
bucketName: cfld-hw-obs-01
geocode:
key: 34182f92976cdab1bb4059352fc9e4a8
business:
url:
thread: localhost:8087/lyy/api/threadInfo/v1.0/save
\ No newline at end of file
thread: localhost:8087/lyy/api/threadInfo/v1.0/save
geocode: https://restapi.amap.com/v3/geocode/geo?key=${geocode.key}&address=
......@@ -77,9 +77,13 @@ huaweiObs:
swagger:
enabled: false
geocode:
key: 34182f92976cdab1bb4059352fc9e4a8
business:
url:
thread: localhost:8087/lyy/api/threadInfo/v1.0/save
geocode: https://restapi.amap.com/v3/geocode/geo?key=${geocode.key}&address=
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl
\ No newline at end of file
log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl
......@@ -74,9 +74,15 @@ huaweiObs:
sk: uZIdUJIwO0sKGVY0hltF9I6IbHEmjwCRco5JV7aM
bucketName: cfld-hw-obs-01
geocode:
key: 34182f92976cdab1bb4059352fc9e4a8
business:
url:
thread: http://test.api.liyeyun.com/lyy/api/threadInfo/v1.0/save
geocode: https://restapi.amap.com/v3/geocode/geo?key=${geocode.key}&address=
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl
\ No newline at end of file
log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment