提交 27ca95ab authored 作者: 李瑞鑫's avatar 李瑞鑫

Merge remote-tracking branch 'origin/test' into test

Former-commit-id: 4dd85729
...@@ -78,13 +78,18 @@ public class TempLineWarnController { ...@@ -78,13 +78,18 @@ public class TempLineWarnController {
if (feignAddressVO.getSendAddress()!=null if (feignAddressVO.getSendAddress()!=null
&& StringUtils.isNotBlank(feignAddressVO.getSendAddress().getCityCode())){ && StringUtils.isNotBlank(feignAddressVO.getSendAddress().getCityCode())){
String weather = gdUtils.getWeather(feignAddressVO.getSendAddress().getCityCode()); String cityCode = gdUtils.getCity(feignAddressVO.getSendAddress().getLongitude(),
feignAddressVO.getSendAddress().getLatitude());
String weather = gdUtils.getWeather(cityCode);
result.put("send", weather); result.put("send", weather);
} }
if (feignAddressVO.getReceiveAddress()!=null if (feignAddressVO.getReceiveAddress()!=null
&& StringUtils.isNotBlank(feignAddressVO.getReceiveAddress().getCityCode())){ && StringUtils.isNotBlank(feignAddressVO.getReceiveAddress().getCityCode())){
String weather = gdUtils.getWeather(feignAddressVO.getReceiveAddress().getCityCode()); String cityCode = gdUtils.getCity(feignAddressVO.getReceiveAddress().getLongitude(),
feignAddressVO.getReceiveAddress().getLatitude());
String weather = gdUtils.getWeather(cityCode);
result.put("receive", weather); result.put("receive", weather);
} }
......
...@@ -72,7 +72,10 @@ public class LineWarnWeatherWarnServiceImpl implements LineWarnWeatherWarnServic ...@@ -72,7 +72,10 @@ public class LineWarnWeatherWarnServiceImpl implements LineWarnWeatherWarnServic
if (feignAddressVO.getSendAddress()!=null if (feignAddressVO.getSendAddress()!=null
&& StringUtils.isNotBlank(feignAddressVO.getSendAddress().getCityCode())){ && StringUtils.isNotBlank(feignAddressVO.getSendAddress().getCityCode())){
String weather = gdUtils.getWeather(feignAddressVO.getSendAddress().getCityCode()); String cityCode = gdUtils.getCity(feignAddressVO.getSendAddress().getLongitude(),
feignAddressVO.getSendAddress().getLatitude());
String weather = gdUtils.getWeather(cityCode);
if (weatherCheck(weather)){ if (weatherCheck(weather)){
// 更新 // 更新
lineWarnCommonService.lineWarnInfoUpdate(orderGoods, lineWarnInfo, lineWarnConfig, weather); lineWarnCommonService.lineWarnInfoUpdate(orderGoods, lineWarnInfo, lineWarnConfig, weather);
...@@ -80,7 +83,9 @@ public class LineWarnWeatherWarnServiceImpl implements LineWarnWeatherWarnServic ...@@ -80,7 +83,9 @@ public class LineWarnWeatherWarnServiceImpl implements LineWarnWeatherWarnServic
} }
if (feignAddressVO.getReceiveAddress()!=null if (feignAddressVO.getReceiveAddress()!=null
&& StringUtils.isNotBlank(feignAddressVO.getReceiveAddress().getCityCode())){ && StringUtils.isNotBlank(feignAddressVO.getReceiveAddress().getCityCode())){
String weather = gdUtils.getWeather(feignAddressVO.getReceiveAddress().getCityCode()); String cityCode = gdUtils.getCity(feignAddressVO.getReceiveAddress().getLongitude(),
feignAddressVO.getReceiveAddress().getLatitude());
String weather = gdUtils.getWeather(cityCode);
if (weatherCheck(weather)){ if (weatherCheck(weather)){
// 更新 // 更新
lineWarnCommonService.lineWarnInfoUpdate(orderGoods, lineWarnInfo, lineWarnConfig, weather); lineWarnCommonService.lineWarnInfoUpdate(orderGoods, lineWarnInfo, lineWarnConfig, weather);
......
...@@ -35,6 +35,7 @@ public class GdService { ...@@ -35,6 +35,7 @@ public class GdService {
private static final String WEATHER_API = "https://restapi.amap.com/v3/weather/weatherInfo?parameters";//天气 private static final String WEATHER_API = "https://restapi.amap.com/v3/weather/weatherInfo?parameters";//天气
private static final String CITY_API = "https://restapi.amap.com/v3/geocode/regeo?parameters";//城市
private String gaodeKey = "b2550e16bbc7bf9f6cd168e0f21709fc"; private String gaodeKey = "b2550e16bbc7bf9f6cd168e0f21709fc";
...@@ -405,4 +406,50 @@ public class GdService { ...@@ -405,4 +406,50 @@ public class GdService {
return weather; return weather;
} }
public String getCity(BigDecimal longitude, BigDecimal latitude){
return getCity(gaodeKey, longitude, latitude);
}
public static String getCity(String key, BigDecimal longitude, BigDecimal latitude) {
String url = CITY_API+"?output=json&location=" +longitude+","+latitude+"&key="+key;
String resultStr;
try {
resultStr = HttpUtils.httpGetRequest(url);
} catch (Exception e) {
throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德地理编码接口异常");
}
if (StringUtils.isBlank(resultStr)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 返回结果空");}
JSONObject retJSONObject = JSONObject.parseObject(resultStr);
if (Objects.isNull(retJSONObject)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 返回结果转换异常, result:"+resultStr);}
Integer status = retJSONObject.getInteger("status");
if (!Objects.equals(1, status)) {
if (Objects.equals(10001, status)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 无效key, result:"+resultStr);}
else if (Objects.equals(10002, status)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 没有权限使用相应的服务或者请求接口的路径拼写错误, result:"+resultStr);}
else if (Objects.equals(10003, status)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 访问已超出日访问量, result:"+resultStr);}
else if (Objects.equals(10004, status)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 单位时间内访问过于频繁, result:"+resultStr);}
else if (Objects.equals(10010, status)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, IP访问超限, result:"+resultStr);}
else if (Objects.equals(10044, status)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 账号维度日调用量超出限制, result:"+resultStr);}
else if (Objects.equals(40000, status)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 余额耗尽, result:"+resultStr);}
else if (Objects.equals(40002, status)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 购买服务到期, result:"+resultStr);}
else if (Objects.equals(20802, status)) { throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 路线计算失败, result:"+resultStr); }
else if (Objects.equals(20803, status)) { throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 起点终点距离过长, result:"+resultStr); }
else {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 状态异常, result:"+resultStr);}
}
// 解析
String adcode = retJSONObject.getJSONObject("regeocode").getJSONObject("addressComponent").getString("adcode");
if (StringUtils.isBlank(adcode)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德城市编码接口异常, result:"+resultStr);}
return adcode;
}
} }
...@@ -89,6 +89,12 @@ public class GdUtils { ...@@ -89,6 +89,12 @@ public class GdUtils {
return gdService.getWeather(city); return gdService.getWeather(city);
} }
/**
* 天气
*/
public String getCity(BigDecimal longitude, BigDecimal latitude){
return gdService.getCity(longitude,latitude);
}
/** /**
* 获取线路 * 获取线路
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论