|
@@ -1,5 +1,7 @@
|
1
|
1
|
package com.huiju.estateagents.service.impl;
|
2
|
2
|
|
|
3
|
+import com.alibaba.fastjson.JSONObject;
|
|
4
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
3
|
5
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
4
|
6
|
import com.huiju.estateagents.entity.TdCity;
|
5
|
7
|
import com.huiju.estateagents.mapper.TaOrgCityMapper;
|
|
@@ -7,6 +9,7 @@ import com.huiju.estateagents.mapper.TdCityMapper;
|
7
|
9
|
import com.huiju.estateagents.service.ITdCityService;
|
8
|
10
|
import org.springframework.beans.factory.annotation.Autowired;
|
9
|
11
|
import org.springframework.stereotype.Service;
|
|
12
|
+import org.springframework.web.client.RestTemplate;
|
10
|
13
|
|
11
|
14
|
import java.util.List;
|
12
|
15
|
|
|
@@ -33,5 +36,31 @@ public class TdCityServiceImpl extends ServiceImpl<TdCityMapper, TdCity> impleme
|
33
|
36
|
List<TdCity> tdCityList= tdCityMapper.selectWxCity(orgId);
|
34
|
37
|
return tdCityList;
|
35
|
38
|
}
|
36
|
|
-
|
|
39
|
+
|
|
40
|
+ /**
|
|
41
|
+ * 根据经纬度获取城市详情信息
|
|
42
|
+ *
|
|
43
|
+ * @param location
|
|
44
|
+ * @return
|
|
45
|
+ */
|
|
46
|
+ @Override
|
|
47
|
+ public TdCity getLocationCity(String location) {
|
|
48
|
+ //获取高德地图的坐标
|
|
49
|
+ String amapString = "https://restapi.amap.com/v3/geocode/regeo?location="+location+"&key=14f05ce59c26364fd0674014dc0d8b1b";
|
|
50
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
51
|
+ String forObject = restTemplate.getForObject(amapString, String.class);
|
|
52
|
+ JSONObject jsonObject = JSONObject.parseObject(forObject);
|
|
53
|
+ //返回城市信息
|
|
54
|
+ if (jsonObject.getString("status").equals("1")){
|
|
55
|
+ JSONObject addressComponent = jsonObject.getJSONObject("regeocode").getJSONObject("addressComponent");
|
|
56
|
+ String citycode = addressComponent.getString("citycode");
|
|
57
|
+ QueryWrapper<TdCity> queryWrapper = new QueryWrapper<>();
|
|
58
|
+ queryWrapper.eq("citycode",citycode);
|
|
59
|
+ queryWrapper.eq("leveltype",2);
|
|
60
|
+ TdCity tdCity = tdCityMapper.selectOne(queryWrapper);
|
|
61
|
+ return tdCity;
|
|
62
|
+ }
|
|
63
|
+ return null;
|
|
64
|
+ }
|
|
65
|
+
|
37
|
66
|
}
|