parent
ea5dd49c7a
commit
dffb2aa293
@ -0,0 +1,18 @@
|
||||
package com.xjs.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 高德秘钥
|
||||
* @author xiejs
|
||||
* @since 2022-01-16
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "gaode.open")
|
||||
@Component
|
||||
public class GaodeProperties {
|
||||
|
||||
private String key;
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.xjs.common.client.api.gaode;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xjs.annotation.ApiLog;
|
||||
import com.xjs.common.client.factory.GaodeWeatherFeignFactory;
|
||||
import com.xjs.weather.domain.RequestBody;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.cloud.openfeign.SpringQueryMap;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import static com.xjs.consts.ApiConst.GAODE_WEATHER;
|
||||
import static com.xjs.consts.ApiConst.GAODE_WEATHER_URL;
|
||||
|
||||
/**
|
||||
* 高德天气预报api feign
|
||||
* @author xiejs
|
||||
* @since 2022-01-16
|
||||
*/
|
||||
@FeignClient(name = "gaodeWeather", url = GAODE_WEATHER, fallbackFactory = GaodeWeatherFeignFactory.class)
|
||||
public interface GaodeWeatherFeignClient {
|
||||
|
||||
@GetMapping()
|
||||
@ApiLog(name = GAODE_WEATHER,
|
||||
url = GAODE_WEATHER_URL,
|
||||
method = "Get")
|
||||
JSONObject WeatherApi(@SpringQueryMap RequestBody requestBody);
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.xjs.common.client.factory;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.xjs.common.client.api.gaode.GaodeWeatherFeignClient;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* 高德天气预报api 降级处理
|
||||
* @author xiejs
|
||||
* @since 2022-01-16
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class GaodeWeatherFeignFactory implements FallbackFactory<GaodeWeatherFeignClient> {
|
||||
|
||||
@Override
|
||||
public GaodeWeatherFeignClient create(Throwable cause) {
|
||||
log.error("api模块高德天气预报服务调用失败:{},执行降级处理", cause.getMessage());
|
||||
return requestBody -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||
return jsonObject;
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.xjs.weather.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 预报天气某天数据
|
||||
* @author xiejs
|
||||
* @since 2022-01-16
|
||||
*/
|
||||
@Data
|
||||
public class Casts {
|
||||
|
||||
/**
|
||||
*日期
|
||||
*/
|
||||
private String date;
|
||||
|
||||
/**
|
||||
*星期几
|
||||
*/
|
||||
private String week;
|
||||
|
||||
/**
|
||||
*白天天气现象
|
||||
*/
|
||||
private String dayweather;
|
||||
|
||||
/**
|
||||
*晚上天气现象
|
||||
*/
|
||||
private String nightweather;
|
||||
|
||||
/**
|
||||
*白天温度
|
||||
*/
|
||||
private String daytemp;
|
||||
|
||||
/**
|
||||
*晚上温度
|
||||
*/
|
||||
private String nighttemp;
|
||||
|
||||
/**
|
||||
*白天风向
|
||||
*/
|
||||
private String daywind;
|
||||
|
||||
/**
|
||||
*晚上风向
|
||||
*/
|
||||
private String nightwind;
|
||||
|
||||
/**
|
||||
*白天风力
|
||||
*/
|
||||
private String daypower;
|
||||
|
||||
/**
|
||||
*晚上风力
|
||||
*/
|
||||
private String nightpower;
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.xjs.weather.factory;
|
||||
|
||||
/**
|
||||
* 天气api工厂接口
|
||||
* @author xiejs
|
||||
* @since 2022-01-16
|
||||
*/
|
||||
public interface WeatherFactory<T> {
|
||||
|
||||
|
||||
/**
|
||||
* 获取天气api工厂方法
|
||||
* @return T
|
||||
*/
|
||||
T weatherApi();
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.xjs.weather.factory.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xjs.common.client.api.gaode.GaodeWeatherFeignClient;
|
||||
import com.xjs.config.GaodeProperties;
|
||||
import com.xjs.weather.domain.IPInfoVo;
|
||||
import com.xjs.weather.domain.NowWeather;
|
||||
import com.xjs.weather.domain.RequestBody;
|
||||
import com.xjs.weather.factory.WeatherFactory;
|
||||
import com.xjs.weather.service.IPService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.GAODE_EXTENSIONS_BASE;
|
||||
|
||||
/**
|
||||
* 高德实时天气工厂实现
|
||||
* @author xiejs
|
||||
* @since 2022-01-16
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class GaodeNowWeatherFactory implements WeatherFactory<NowWeather> {
|
||||
|
||||
@Autowired
|
||||
private GaodeProperties gaodeProperties;
|
||||
@Autowired
|
||||
private GaodeWeatherFeignClient gaodeWeatherFeignClient;
|
||||
@Autowired
|
||||
private IPService ipService;
|
||||
|
||||
|
||||
@Override
|
||||
public NowWeather weatherApi() {
|
||||
RequestBody requestBody = new RequestBody();
|
||||
//获取城市编码
|
||||
IPInfoVo ipApiData = ipService.getIPApiData();
|
||||
requestBody.setKey(gaodeProperties.getKey())
|
||||
.setCity(ipApiData.getCityId())
|
||||
.setExtensions(GAODE_EXTENSIONS_BASE);
|
||||
JSONObject jsonObject = gaodeWeatherFeignClient.WeatherApi(requestBody);
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue