serviceimpl
@Override
public boolean updateAreaDistrict() {
List<StopSurvey> stopSurveys = baseMapper.selectList(new QueryWrapper<>());
for (int i = 0; i < stopSurveys.size(); i++) {
StopSurvey stopSurvey = stopSurveys.get(i);
if (StringUtils.isNotBlank(stopSurvey.getLat()) && StringUtils.isNotBlank(stopSurvey.getLng())){
Map<String, Object> parameter = new LinkedHashMap<>();
parameter.put("location", stopSurvey.getLng() + "," + stopSurvey.getLat());
parameter.put("key", GDKEY);
String result = HttpRequest.get("http://restapi.amap.com/v3/geocode/regeo").header("Content-Type", "application/json; charset=utf-8")
.header("Accept", "application/json; charset=utf-8").form(parameter).execute().body();
JSONObject jsonObject = JSONObject.parseObject(result);
JSONObject regeocode = jsonObject.getJSONObject("regeocode");
JSONObject addressComponent = regeocode.getJSONObject("addressComponent");
String District = addressComponent.getString("district");
String Township = addressComponent.getString("township");
String City = addressComponent.getString("city");
if (District.indexOf("区") > -1 && Township.indexOf("街道") > -1 && City.equals("深圳市")) {
//存入区
if (District.equals("龙华区")){
stopSurvey.setArea("LH(N)");
}else if (District.equals("罗湖区")){
stopSurvey.setArea("LH(S)");
}else {
char[] district = District.toCharArray();
StringBuffer pyfl1 = new StringBuffer();
for (int k = 0; k < district.length - 1; k++) {
String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(district[k]);
pyfl1.append(pinyinArray[0]);
}
stopSurvey.setArea(pyfl1.toString().toUpperCase());
}
//存入街道
if (Township.equals("光明街道")){
stopSurvey.setDistrict("GM(S)");
}else if (Township.equals("公明街道")){
stopSurvey.setDistrict("GM(N)");
}else {
char[] township = Township.toCharArray();
StringBuffer pyfl2 = new StringBuffer();
for (int j = 0; j < township.length - 2; j++) {
String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(township[j]);
pyfl2.append(pinyinArray[0]);
}
stopSurvey.setDistrict(pyfl2.toString().toUpperCase());
}
}
baseMapper.updateById(stopSurvey);
}
}
return true;
}