行政区接口
This commit is contained in:
parent
efb1ff7f75
commit
91da9aa0de
|
|
@ -1,7 +1,11 @@
|
|||
package com.czg.controller.user;
|
||||
|
||||
import com.czg.account.service.GeoService;
|
||||
import com.czg.account.vo.DistrictVo;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
|
@ -9,6 +13,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* geo位置管理
|
||||
* @author Administrator
|
||||
|
|
@ -19,8 +25,31 @@ public class UserGeoController {
|
|||
@Resource
|
||||
private GeoService geoService;
|
||||
|
||||
/**
|
||||
* 经纬度换取位置信息
|
||||
* @param lat 经度
|
||||
* @param lng 纬度
|
||||
* @return 位置西悉尼
|
||||
*/
|
||||
@GetMapping("/geocode")
|
||||
public CzgResult<?> getAddress(@RequestParam @NotEmpty String lat, @RequestParam @NotEmpty String lng) {
|
||||
return CzgResult.success(geoService.getAddress(lat, lng));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据市换取所有下属行政区
|
||||
*/
|
||||
@GetMapping("/district")
|
||||
public CzgResult<List<DistrictVo>> district(String keywords) throws JsonProcessingException {
|
||||
String districtJson = geoService.district(keywords,null);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode jsonNode = mapper.readTree(districtJson);
|
||||
JsonNode districts = jsonNode.get("districts");
|
||||
String text = districts.toString();
|
||||
List<DistrictVo> cityInfoList = mapper.readValue(text, mapper.getTypeFactory().constructCollectionType(List.class, DistrictVo.class));
|
||||
DistrictVo allCity = new DistrictVo();
|
||||
allCity.setName("全城");
|
||||
cityInfoList.addFirst(allCity);
|
||||
return CzgResult.success(cityInfoList);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,4 +7,6 @@ import jakarta.validation.constraints.NotEmpty;
|
|||
*/
|
||||
public interface GeoService {
|
||||
Object getAddress(@NotEmpty String lat, @NotEmpty String lng);
|
||||
|
||||
String district(String keywords, String subdistrict);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
package com.czg.account.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import net.sourceforge.pinyin4j.PinyinHelper;
|
||||
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
|
||||
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
|
||||
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
|
||||
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 行政区域返回vo
|
||||
*/
|
||||
@Data
|
||||
public class DistrictVo {
|
||||
private Object citycode;
|
||||
private String adcode;
|
||||
private String name;
|
||||
private String center;
|
||||
private String level;
|
||||
private List<DistrictVo> districts;
|
||||
|
||||
public String getNameAsPY() {
|
||||
return getPinYin(name);
|
||||
}
|
||||
|
||||
public String getPinYin(String name){
|
||||
HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
|
||||
// 设置声调类型为WITH_TONE_MARK
|
||||
format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
|
||||
// 设置拼音输出的大小写格式为小写
|
||||
format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
|
||||
String pinyin = "";
|
||||
try {
|
||||
pinyin = PinyinHelper.toHanYuPinyinString(name,format , "", false);
|
||||
} catch (BadHanyuPinyinOutputFormatCombination e) {
|
||||
return pinyin;
|
||||
}
|
||||
return pinyin;
|
||||
}
|
||||
}
|
||||
|
|
@ -39,10 +39,16 @@
|
|||
<aliyun.oss.version>2.8.3</aliyun.oss.version>
|
||||
<zxing.version>3.5.3</zxing.version>
|
||||
<weixin.java.miniapp.version>3.8.0</weixin.java.miniapp.version>
|
||||
<pinyin.version>2.5.1</pinyin.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.belerweb</groupId>
|
||||
<artifactId>pinyin4j</artifactId>
|
||||
<version>${pinyin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.czg</groupId>
|
||||
<artifactId>cash-common-tools</artifactId>
|
||||
|
|
|
|||
|
|
@ -18,6 +18,10 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.belerweb</groupId>
|
||||
<artifactId >pinyin4j</artifactId>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.github.binarywang</groupId>-->
|
||||
<!-- <artifactId>weixin-java-miniapp</artifactId>-->
|
||||
|
|
|
|||
|
|
@ -1,14 +1,19 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.account.service.GeoService;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.seata.common.util.HttpClientUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
|
|
@ -40,6 +45,21 @@ public class GeoServiceImpl implements GeoService {
|
|||
}
|
||||
return jsonObject.getJSONObject("regeocode");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String district(String keywords, String subdistrict) {
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
//超掌柜生活-用户端
|
||||
param.put("key", "7a7f2e4790ea222660a027352ee3af39");
|
||||
param.put("keywords", keywords);
|
||||
param.put("subdistrict", "1");
|
||||
if (StringUtils.isNotBlank(subdistrict)) {
|
||||
param.put("subdistrict", "2");
|
||||
}
|
||||
param.put("extensions", "base");
|
||||
String s = HttpUtil.get("https://restapi.amap.com/v3/config/district", param);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue