public static class WTHDTO { | public static class WTHDTO { | ||||
@ApiModelProperty(value = "parm") | @ApiModelProperty(value = "parm") | ||||
private ParmDTO parm; | private ParmDTO parm; | ||||
private ParmNewDTO parmNew; | |||||
@ApiModelProperty(value = "mid") | @ApiModelProperty(value = "mid") | ||||
private Integer mid; | private Integer mid; | ||||
@ApiModelProperty(value = "deviceid") | @ApiModelProperty(value = "deviceid") | ||||
@ApiModelProperty(value = "WDIR") | @ApiModelProperty(value = "WDIR") | ||||
private Integer wdir; | private Integer wdir; | ||||
} | } | ||||
@NoArgsConstructor | |||||
@Data | |||||
public static class ParmNewDTO { | |||||
private Double hum; | |||||
private Double noise; | |||||
private Double rainfull; | |||||
private Double tmp; | |||||
private String wdirname; | |||||
private Double dew; | |||||
private Double wspd; | |||||
private Double hpa; | |||||
private Double wdir; | |||||
private Double lux; | |||||
} | |||||
} | } | ||||
@NoArgsConstructor | @NoArgsConstructor |
try { | try { | ||||
jsonResult = JacksonUtil.json2pojo(weatherStr, JsonResult.class); | jsonResult = JacksonUtil.json2pojo(weatherStr, JsonResult.class); | ||||
if (ObjectUtil.isEmpty(jsonResult) || Objects.requireNonNull(jsonResult).getCode() != 0) { | if (ObjectUtil.isEmpty(jsonResult) || Objects.requireNonNull(jsonResult).getCode() != 0) { | ||||
log.info("获取天气信息失败,返回为空或code不为0"); | |||||
log.info("获取天气信息失败,url={}", url); | |||||
log.info("获取天气信息失败,param={}", param); | |||||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "获取天气信息失败,请重试"); | throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "获取天气信息失败,请重试"); | ||||
} | } | ||||
if (ObjectUtil.isEmpty(jsonResult.getData())) { | if (ObjectUtil.isEmpty(jsonResult.getData())) { | ||||
log.info("获取天气信息,返回数据为空"); | |||||
return new AirWeatherVO(); | return new AirWeatherVO(); | ||||
} | } | ||||
return JSONObject.parseObject(JSONObject.toJSONString(jsonResult.getData()), AirWeatherVO.class); | return JSONObject.parseObject(JSONObject.toJSONString(jsonResult.getData()), AirWeatherVO.class); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
log.info("获取天气信息异常,url={}", url); | |||||
log.info("获取天气信息异常,param={}", param); | |||||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "获取天气信息失败,请重试"); | throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "获取天气信息失败,请重试"); | ||||
} | } | ||||
} | } |
if(ObjectUtil.isEmpty(airWeather) ||ObjectUtil.isEmpty(airWeather.getWth())){ | if(ObjectUtil.isEmpty(airWeather) ||ObjectUtil.isEmpty(airWeather.getWth())){ | ||||
return ""; | return ""; | ||||
} | } | ||||
return "气温:" + new BigDecimal(airWeather.getWth().getParm().getTmp()).divide(new BigDecimal(10))+"℃" | |||||
+ ";湿度:" + new BigDecimal(airWeather.getWth().getParm().getHum()).divide(new BigDecimal(10))+"RH" | |||||
+ ";风速:" + new BigDecimal(airWeather.getWth().getParm().getWspd()).divide(new BigDecimal(10))+"M/S" | |||||
+ ";风向:" + airWeather.getWth().getParm().getWdir() + "°"; | |||||
return "气温:" + airWeather.getWth().getParmNew().getTmp() + "℃" | |||||
+ ";湿度:" + airWeather.getWth().getParmNew().getHum() + "RH" | |||||
+ ";风速:" + airWeather.getWth().getParmNew().getWspd() + "M/S" | |||||
+ ";风向:" + airWeather.getWth().getParmNew().getWdirname(); | |||||
} | } | ||||
} | } |