parent
ea5dd49c7a
commit
dffb2aa293
|
|
@ -85,7 +85,7 @@
|
|||
</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<router-link :to="'/openapi/english/collect/'" class="link-type">
|
||||
<router-link :to="'/business/english/collect/'" class="link-type">
|
||||
<el-button
|
||||
type="warning"
|
||||
plain
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -43,6 +43,8 @@ public class ApiConst {
|
|||
|
||||
public static final String ROLL_IP= "ROLL-IP信息";
|
||||
|
||||
public static final String GAODE_WEATHER= "高德-天气预报";
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -84,6 +86,51 @@ public class ApiConst {
|
|||
|
||||
public static final String ROLL_IP_URL= "https://www.mxnzp.com/api/ip/aim_ip";
|
||||
|
||||
/**
|
||||
* 接口文档:
|
||||
* https://lbs.amap.com/api/webservice/guide/api/weatherinfo
|
||||
*/
|
||||
public static final String GAODE_WEATHER_URL= "https://restapi.amap.com/v3/weather/weatherInfo";
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------api请求参数常量-----------------------------
|
||||
|
||||
/**
|
||||
* 高德Extensions请求参数条件
|
||||
*/
|
||||
public static final String GAODE_EXTENSIONS_ALL="all" ;
|
||||
public static final String GAODE_EXTENSIONS_BASE="base" ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------api响应参数-----------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* roll平台返回值code成功参数
|
||||
*/
|
||||
public static final Integer ROLL_CODE_SUCCESS=1 ;
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------------自定义相关请求响应常量----------------------------
|
||||
|
||||
/**
|
||||
* 降级返回结果key
|
||||
*/
|
||||
public static final String DEMOTE_ERROR= "error";
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -19,20 +19,11 @@ import java.util.regex.Pattern;
|
|||
public class IPUtils {
|
||||
|
||||
/**
|
||||
* 获取外网ip
|
||||
* 获取公网ip
|
||||
* @return
|
||||
*/
|
||||
public static String getV4IP() throws Exception {
|
||||
String ip = null;
|
||||
// 第一种方式
|
||||
try {
|
||||
ip = IPUtils.getNowIP1();
|
||||
ip.trim();
|
||||
} catch (Exception e) {
|
||||
System.out.println("getPublicIP - getNowIP1 failed ~ ");
|
||||
}
|
||||
if (!StringUtils.isEmpty(ip))
|
||||
return ip;
|
||||
// 第二种方式
|
||||
try {
|
||||
ip = IPUtils.getNowIP2();
|
||||
|
|
@ -40,6 +31,15 @@ public class IPUtils {
|
|||
} catch (Exception e) {
|
||||
System.out.println("getPublicIP - getNowIP2 failed ~ ");
|
||||
}
|
||||
if (!StringUtils.isEmpty(ip))
|
||||
return ip;
|
||||
// 第一种方式
|
||||
try {
|
||||
ip = IPUtils.getNowIP1();
|
||||
ip.trim();
|
||||
} catch (Exception e) {
|
||||
System.out.println("getPublicIP - getNowIP1 failed ~ ");
|
||||
}
|
||||
if (!StringUtils.isEmpty(ip))
|
||||
return ip;
|
||||
// 第三种方式
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* 天行数据平台每日一句工厂实现
|
||||
*
|
||||
|
|
@ -39,7 +41,7 @@ public class TianXingAWordFactory implements AWordFactory {
|
|||
public ApiAWord productApiAWord(RequestBody requestBody) {
|
||||
requestBody.setKey(tianXingProperties.getKey());
|
||||
JSONObject jsonObject = tianXingMMYJFeignClient.aWordApi(requestBody);
|
||||
if (jsonObject.containsKey("error")) {
|
||||
if (jsonObject.containsKey(DEMOTE_ERROR)) {
|
||||
throw new ApiException("天行每日一句接口调用异常");
|
||||
}
|
||||
if (HttpStatus.HTTP_OK == jsonObject.getInteger("code")) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -7,6 +7,8 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc 百度翻译平台服务降级处理类
|
||||
|
|
@ -20,7 +22,7 @@ public class BaiduFeignFactory implements FallbackFactory<BaiduFeignClient> {
|
|||
log.error("api模块百度翻译服务调用失败:{},执行降级处理", cause.getMessage());
|
||||
return qo -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("error", R.FAIL);
|
||||
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||
return jsonObject;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,8 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @since 2022-01-15
|
||||
|
|
@ -20,7 +22,7 @@ public class RollIPFeignFactory implements FallbackFactory<RollIPFeignClient> {
|
|||
log.error("api模块roll IP服务调用失败:{},执行降级处理", cause.getMessage());
|
||||
return requestBody -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("error", R.FAIL);
|
||||
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||
return jsonObject;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* roll每日一句降级
|
||||
* @author xiejs
|
||||
|
|
@ -20,7 +22,7 @@ public class RollMMYJFeignFactory implements FallbackFactory<RollMMYJFeignClient
|
|||
log.error("api模块roll每日一句服务调用失败:{},执行降级处理", cause.getMessage());
|
||||
return requestBody -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("error", R.FAIL);
|
||||
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||
return jsonObject;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* roll翻译降级
|
||||
* @author xiejs
|
||||
|
|
@ -20,7 +22,7 @@ public class RollTranslationFeignFactory implements FallbackFactory<RollTranslat
|
|||
log.error("api模块roll翻译服务调用失败:{},执行降级处理", cause.getMessage());
|
||||
return qo -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("error", R.FAIL);
|
||||
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||
return jsonObject;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @since 2022-01-11
|
||||
|
|
@ -20,7 +22,7 @@ public class TianXingBDRSFeignFactory implements FallbackFactory<TianXingBDRSFei
|
|||
return key -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
//构建一个异常json给下层接口处理
|
||||
jsonObject.put("error", R.FAIL);
|
||||
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||
return jsonObject;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @since 2022-01-12
|
||||
|
|
@ -19,7 +21,7 @@ public class TianXingDYRSFeignFactory implements FallbackFactory<TianXingDYRSFei
|
|||
log.error("api模块天行抖音热搜榜服务调用失败:{},执行降级处理", cause.getMessage());
|
||||
return key -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("error", R.FAIL);
|
||||
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||
return jsonObject;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc 天行数据经典台词降级处理
|
||||
|
|
@ -22,7 +24,7 @@ public class TianXingJDTCFeignFactory implements FallbackFactory<TianXingJDTCFei
|
|||
return requestBody -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
//构建一个异常json给下层接口处理
|
||||
jsonObject.put("error", R.FAIL);
|
||||
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||
return jsonObject;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc
|
||||
|
|
@ -22,7 +24,7 @@ public class TianXingMMMYFeignFactory implements FallbackFactory<TianXingMMMYFei
|
|||
return requestBody -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
//构建一个异常json给下层接口处理
|
||||
jsonObject.put("error", R.FAIL);
|
||||
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||
return jsonObject;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @since 2022-01-08
|
||||
|
|
@ -20,7 +22,7 @@ public class TianXingMMYJFeignFactory implements FallbackFactory<TianXingMMYJFei
|
|||
log.error("api模块天行每日一句服务调用失败:{},执行降级处理", cause.getMessage());
|
||||
return requestBody -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("error", R.FAIL);
|
||||
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||
return jsonObject;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc
|
||||
|
|
@ -21,7 +23,7 @@ public class TianXingOneEnglishFeignFactory implements FallbackFactory<TianXingO
|
|||
log.error("api模块英语一言服务调用失败:{},执行降级处理", cause.getMessage());
|
||||
return requestBody -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("error", R.FAIL);
|
||||
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||
return jsonObject;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc 天行数据平台朋友圈文案接口降级处理
|
||||
|
|
@ -21,7 +23,7 @@ public class TianXingPYQFeignFactory implements FallbackFactory<TianXingPYQFeign
|
|||
return requestBody -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
//构建一个异常json给下层接口处理
|
||||
jsonObject.put("error", R.FAIL);
|
||||
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||
return jsonObject;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @since 2022-01-10
|
||||
|
|
@ -20,8 +22,7 @@ public class TianXingQWRSFeignFactory implements FallbackFactory<TianXingQWRSFei
|
|||
log.error("api模块天行全网热搜榜服务调用失败:{},执行降级处理", cause.getMessage());
|
||||
return key -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
//构建一个异常json给下层接口处理
|
||||
jsonObject.put("error", R.FAIL);
|
||||
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||
return jsonObject;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc 天行api翻译字典降级处理
|
||||
|
|
@ -20,7 +22,7 @@ public class TianXingTranDictFeignFactory implements FallbackFactory<TianXingTra
|
|||
log.error("api模块翻译字典服务调用失败:{},执行降级处理", cause.getMessage());
|
||||
return requestBody -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("error", R.FAIL);
|
||||
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||
return jsonObject;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* 天行微博热搜feign降级
|
||||
* @author xiejs
|
||||
|
|
@ -21,7 +23,7 @@ public class TianXingWBRSFeignFactory implements FallbackFactory<TianXingWBRSFei
|
|||
return key -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
//构建一个异常json给下层接口处理
|
||||
jsonObject.put("error", R.FAIL);
|
||||
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||
return jsonObject;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @since 2022-01-11
|
||||
|
|
@ -20,7 +22,7 @@ public class TianXingWXRSFeignFactory implements FallbackFactory<TianXingWXRSFei
|
|||
return key -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
//构建一个异常json给下层接口处理
|
||||
jsonObject.put("error", R.FAIL);
|
||||
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||
return jsonObject;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc 天行数据平台网易云热评接口降级处理
|
||||
|
|
@ -21,7 +23,7 @@ public class TianXingWYYFeignFactory implements FallbackFactory<TianXingWYYFeign
|
|||
return requestBody -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
//构建一个异常json给下层接口处理
|
||||
jsonObject.put("error", R.FAIL);
|
||||
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||
return jsonObject;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc 有道翻译平台服务降级处理类
|
||||
|
|
@ -22,7 +24,7 @@ public class YouDaoFeignFactory implements FallbackFactory<YouDaoFeignClient> {
|
|||
return qo -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
//构建一个异常json给下层接口处理
|
||||
jsonObject.put("error", R.FAIL);
|
||||
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||
return jsonObject;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* roll平台每日一句工厂实现
|
||||
* @author xiejs
|
||||
|
|
@ -41,7 +43,7 @@ public class RollMMYJCopyWritingFactory implements CopyWritingFactory {
|
|||
requestBody.setApp_id(rollProperties.getApp_id());
|
||||
requestBody.setApp_secret(rollProperties.getApp_secret());
|
||||
JSONObject jsonObject = rollMMYJFeignClient.copyWritingApi(requestBody);
|
||||
if (jsonObject.containsKey("error")) {
|
||||
if (jsonObject.containsKey(DEMOTE_ERROR)) {
|
||||
throw new ApiException("roll每日一句接口调用异常");
|
||||
}
|
||||
JSONArray jsonArray = jsonObject.getJSONArray("data");
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc 天行数据经典台词工厂实现
|
||||
|
|
@ -51,7 +53,7 @@ public class TianXingJDTCCopyWritingFactory implements CopyWritingFactory {
|
|||
return copyWriting;
|
||||
}else {
|
||||
//调用服务失败的降级之后的处理
|
||||
if (jsonObject.containsKey("error")) {
|
||||
if (jsonObject.containsKey(DEMOTE_ERROR)) {
|
||||
return copyWritingMapper.getOneToRandom();
|
||||
}
|
||||
return new CopyWriting();
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc
|
||||
|
|
@ -51,7 +53,7 @@ public class TianXingMMMYCopyWritingFactory implements CopyWritingFactory {
|
|||
return copyWriting;
|
||||
}else {
|
||||
//调用服务失败的降级之后的处理
|
||||
if (jsonObject.containsKey("error")) {
|
||||
if (jsonObject.containsKey(DEMOTE_ERROR)) {
|
||||
return copyWritingMapper.getOneToRandom();
|
||||
}
|
||||
return new CopyWriting();
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc 天行数据朋友圈文案平台工厂实现
|
||||
|
|
@ -53,7 +55,7 @@ public class TianXingPYQCopyWritingFactory implements CopyWritingFactory {
|
|||
return copyWriting;
|
||||
}else {
|
||||
//调用服务失败的降级之后的处理
|
||||
if (jsonObject.containsKey("error")) {
|
||||
if (jsonObject.containsKey(DEMOTE_ERROR)) {
|
||||
return copyWritingMapper.getOneToRandom();
|
||||
}
|
||||
return new CopyWriting();
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc 天行数据网易云热评平台工厂实现
|
||||
|
|
@ -53,7 +55,7 @@ public class TianXingWYYCopyWritingFactory implements CopyWritingFactory {
|
|||
return copyWriting;
|
||||
}else {
|
||||
//调用服务失败的降级之后的处理
|
||||
if (jsonObject.containsKey("error")) {
|
||||
if (jsonObject.containsKey(DEMOTE_ERROR)) {
|
||||
return copyWritingMapper.getOneToRandom();
|
||||
}
|
||||
return new CopyWriting();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package com.xjs.oneenglish.factory;
|
||||
package com.xjs.oneenglish.factory.impl;
|
||||
|
||||
import cn.hutool.http.HttpStatus;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
|
|
@ -9,6 +9,7 @@ import com.xjs.config.TianXingProperties;
|
|||
import com.xjs.exception.ApiException;
|
||||
import com.xjs.oneenglish.domain.ApiEnglish;
|
||||
import com.xjs.oneenglish.domain.RequestBody;
|
||||
import com.xjs.oneenglish.factory.OneEnglishFactory;
|
||||
import com.xjs.oneenglish.mapper.ApiEnglishMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -19,6 +20,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
import static com.xjs.consts.RedisConst.ONE_ENGLISH;
|
||||
import static com.xjs.consts.RedisConst.ONE_ENGLISH_EXPIRE;
|
||||
|
||||
|
|
@ -52,7 +54,7 @@ public class TianXingOneEnglishFactory implements OneEnglishFactory {
|
|||
}
|
||||
requestBody.setKey(tianXingProperties.getKey());
|
||||
JSONObject jsonObject = tianXingOneEnglishFeignClient.oneEnglishApi(requestBody);
|
||||
if (!jsonObject.containsKey("error")) {
|
||||
if (!jsonObject.containsKey(DEMOTE_ERROR)) {
|
||||
if (jsonObject.getInteger("code") == HttpStatus.HTTP_OK) {
|
||||
JSONArray newslist = jsonObject.getJSONArray("newslist");
|
||||
JSONObject content = newslist.getJSONObject(0);
|
||||
|
|
@ -1,12 +1,10 @@
|
|||
package com.xjs.topsearch.factory.impl;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.core.constant.HttpStatus;
|
||||
import com.xjs.common.client.api.tianxing.TianXingQWRSFeignClient;
|
||||
import com.xjs.config.TianXingProperties;
|
||||
import com.xjs.exception.ApiException;
|
||||
import com.xjs.topsearch.domain.ApiTopsearchAllnetwork;
|
||||
import com.xjs.topsearch.factory.TopserachFactory;
|
||||
import com.xjs.topsearch.service.ApiTopsearchAllnetworkService;
|
||||
|
|
@ -17,9 +15,10 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* 天行全网热搜工厂实现
|
||||
*
|
||||
|
|
@ -42,7 +41,7 @@ public class TianXingTopsearchAllnetworkFactory implements TopserachFactory<ApiT
|
|||
@Transactional
|
||||
public List<ApiTopsearchAllnetwork> topSearchApi() {
|
||||
JSONObject jsonObject = tianXingQWRSFeignClient.topSearchApi(tianXingProperties.getKey());
|
||||
if (!jsonObject.containsKey("error")) {
|
||||
if (!jsonObject.containsKey(DEMOTE_ERROR)) {
|
||||
if (jsonObject.getInteger("code") == HttpStatus.SUCCESS) {
|
||||
JSONArray newslist = jsonObject.getJSONArray("newslist");
|
||||
List<ApiTopsearchAllnetwork> collect = newslist.stream().map(arrayJson -> {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* 天行百度热搜工厂实现
|
||||
*
|
||||
|
|
@ -37,7 +39,7 @@ public class TianXingTopsearchBaiduFactory implements TopserachFactory<ApiTopsea
|
|||
@Override
|
||||
public List<ApiTopsearchBaidu> topSearchApi() {
|
||||
JSONObject jsonObject = tianXingBDRSFeignClient.topSearchApi(tianXingProperties.getKey());
|
||||
if (!jsonObject.containsKey("error")) {
|
||||
if (!jsonObject.containsKey(DEMOTE_ERROR)) {
|
||||
if (jsonObject.getInteger("code") == HttpStatus.SUCCESS) {
|
||||
JSONArray newslist = jsonObject.getJSONArray("newslist");
|
||||
List<ApiTopsearchBaidu> collect = newslist.stream().map(arrayJson -> {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* 天行抖音热搜工厂实现
|
||||
*
|
||||
|
|
@ -42,7 +44,7 @@ public class TianXingTopsearchDouyinFactory implements TopserachFactory<ApiTopse
|
|||
@Override
|
||||
public List<ApiTopsearchDouyin> topSearchApi() {
|
||||
JSONObject jsonObject = tianXingDYRSFeignClient.topSearchApi(tianXingProperties.getKey());
|
||||
if (!jsonObject.containsKey("error")) {
|
||||
if (!jsonObject.containsKey(DEMOTE_ERROR)) {
|
||||
if (jsonObject.getInteger("code") == HttpStatus.SUCCESS) {
|
||||
JSONArray newslist = jsonObject.getJSONArray("newslist");
|
||||
List<ApiTopsearchDouyin> collect = newslist.stream().map(arrayJson -> {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* 微信热搜api工厂实现
|
||||
*
|
||||
|
|
@ -40,7 +42,7 @@ public class TianXingTopsearchWechatFactory implements TopserachFactory<ApiTopse
|
|||
@Transactional
|
||||
public List<ApiTopsearchWechat> topSearchApi() {
|
||||
JSONObject jsonObject = tianXingWXRSFeignClient.topSearchApi(tianXingProperties.getKey());
|
||||
if (!jsonObject.containsKey("error")) {
|
||||
if (!jsonObject.containsKey(DEMOTE_ERROR)) {
|
||||
if (jsonObject.getInteger("code") == HttpStatus.SUCCESS) {
|
||||
JSONArray newslist = jsonObject.getJSONArray("newslist");
|
||||
List<ApiTopsearchWechat> collect = newslist.stream().map(arrayJson -> {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* 微博热搜api工厂实现
|
||||
*
|
||||
|
|
@ -42,7 +44,7 @@ public class TianXingTopsearchWeiboFactory implements TopserachFactory<ApiTopsea
|
|||
@Transactional
|
||||
public List<ApiTopsearchWeibo> topSearchApi() {
|
||||
JSONObject jsonObject = tianXingWBRSFeignClient.topSearchApi(tianXingProperties.getKey());
|
||||
if (!jsonObject.containsKey("error")) {
|
||||
if (!jsonObject.containsKey(DEMOTE_ERROR)) {
|
||||
if (jsonObject.getInteger("code") == HttpStatus.SUCCESS) {
|
||||
JSONArray newslist = jsonObject.getJSONArray("newslist");
|
||||
List<ApiTopsearchWeibo> collect = newslist.stream().map(arrayJson -> {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ import org.springframework.stereotype.Service;
|
|||
|
||||
import java.util.*;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc
|
||||
|
|
@ -43,7 +45,7 @@ public class BaiDuTranslationFactory implements TranslationFactory {
|
|||
JSONObject jsonObject = baiduFeignClient.translationApi(baiDuTranslationQo);
|
||||
System.out.println(jsonObject);
|
||||
//接口内部错误以及网络错误都抛异常
|
||||
if(jsonObject.containsKey("error_code") || jsonObject.containsKey("error")){
|
||||
if(jsonObject.containsKey("error_code") || jsonObject.containsKey(DEMOTE_ERROR)){
|
||||
throw new ApiException("百度翻译接口调用异常");
|
||||
}
|
||||
TranslationVo translationVo = new TranslationVo();
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* roll翻译平台工厂实现
|
||||
*
|
||||
|
|
@ -35,7 +37,7 @@ public class RollTranslationFactory implements TranslationFactory {
|
|||
rollTranslationQo.setApp_secret(rollProperties.getApp_secret());
|
||||
rollTranslationQo.setContent(translationQo.getQ());
|
||||
JSONObject translationApi = rollTranslationFeignClient.translationApi(rollTranslationQo);
|
||||
if (translationApi.containsKey("error")) {
|
||||
if (translationApi.containsKey(DEMOTE_ERROR)) {
|
||||
throw new ApiException("ROLL翻译接口调用异常");
|
||||
}
|
||||
if (translationApi.getInteger("code") == 1) {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ import com.xjs.translation.factory.TranslationFactory;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc 天行数据平台翻译字典实现工厂
|
||||
|
|
@ -32,7 +34,7 @@ public class TianXingTranDictFactory implements TranslationFactory {
|
|||
requestBody.setKey(tianXingProperties.getKey());
|
||||
JSONObject jsonObject = tianXingTranDictClient.tranDictApi(requestBody);
|
||||
TranslationVo translationVo = new TranslationVo();
|
||||
if (!jsonObject.containsKey("error")) {
|
||||
if (!jsonObject.containsKey(DEMOTE_ERROR)) {
|
||||
//代表没进入降级类
|
||||
if (jsonObject.getInteger("code") == 250) {
|
||||
throw new ApiException("内容输入错误");
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc
|
||||
|
|
@ -32,7 +34,7 @@ public class YouDaoTranslationFactory implements TranslationFactory {
|
|||
youDaoTranslationQo.setI(translationQo.getQ());
|
||||
JSONObject translationApi = youDaoFeignClient.translationApi(youDaoTranslationQo);
|
||||
//接口内部错误以及网络错误都抛异常
|
||||
if(!"0".equals(translationApi.getString("errorCode"))|| translationApi.containsKey("error") ){
|
||||
if(!"0".equals(translationApi.getString("errorCode"))|| translationApi.containsKey(DEMOTE_ERROR) ){
|
||||
if(!"40".equals(translationApi.getString("errorCode"))){
|
||||
throw new ApiException("有道翻译接口调用异常");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,44 @@
|
|||
package com.xjs.weather.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 预报天气实体
|
||||
*
|
||||
* @author xiejs
|
||||
* @since 2022-01-16
|
||||
*/
|
||||
@Data
|
||||
public class ForecastWeather implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 城市名称
|
||||
*/
|
||||
private String city;
|
||||
|
||||
/**
|
||||
* 城市编码
|
||||
*/
|
||||
private String adcode;
|
||||
|
||||
/**
|
||||
* 省份名称
|
||||
*/
|
||||
private String province;
|
||||
|
||||
/**
|
||||
*预报发布时间
|
||||
*/
|
||||
private String reporttime;
|
||||
|
||||
/**
|
||||
* 预报数据list结构,元素cast,按顺序为当天、第二天、第三天的预报数据
|
||||
*/
|
||||
private List<Casts> CastsList;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
package com.xjs.weather.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 实时天气实体
|
||||
*
|
||||
* @author xiejs
|
||||
* @since 2022-01-16
|
||||
*/
|
||||
@Data
|
||||
@TableName("api_now_weather")
|
||||
public class NowWeather implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 省份名
|
||||
*/
|
||||
@Excel(name = "省份名")
|
||||
private String province;
|
||||
|
||||
/**
|
||||
* 城市名
|
||||
*/
|
||||
@Excel(name = "城市名")
|
||||
private String city;
|
||||
|
||||
/**
|
||||
* 城市编码
|
||||
*/
|
||||
@Excel(name = "城市编码")
|
||||
private String adcode;
|
||||
|
||||
/**
|
||||
* 天气现象(汉字描述)
|
||||
*/
|
||||
@Excel(name = "天气现象")
|
||||
private String weather;
|
||||
|
||||
/**
|
||||
* 实时气温,单位:摄氏度
|
||||
*/
|
||||
@Excel(name = "实时气温,单位:摄氏度")
|
||||
private String temperature;
|
||||
|
||||
/**
|
||||
* 风向描述
|
||||
*/
|
||||
@Excel(name = "风向描述")
|
||||
private String winddirection;
|
||||
|
||||
/**
|
||||
* 风力级别,单位:级
|
||||
*/
|
||||
@Excel(name = "风力级别,单位:级")
|
||||
private String windpower;
|
||||
|
||||
/**
|
||||
* 空气湿度
|
||||
*/
|
||||
@Excel(name = "空气湿度")
|
||||
private String humidity;
|
||||
|
||||
/**
|
||||
* 数据发布的时间
|
||||
*/
|
||||
@Excel(name = "数据发布的时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date reporttime;
|
||||
|
||||
@Excel(name = "创建时间" ,dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date create_time;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package com.xjs.weather.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 高德天气预报接口请求参数
|
||||
* @author xiejs
|
||||
* @since 2022-01-16
|
||||
*/
|
||||
@Data
|
||||
//链式调用
|
||||
@Accessors(chain = true)
|
||||
public class RequestBody {
|
||||
|
||||
/**
|
||||
* 请求服务权限标识:
|
||||
* 用户在高德地图官网申请web服务API类型KEY
|
||||
*/
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* 城市编码:
|
||||
* 输入城市的adcode,adcode信息可参考城市编码表
|
||||
*/
|
||||
private String city;
|
||||
|
||||
/**
|
||||
* 气象类型:
|
||||
* 可选值:base/all
|
||||
* base:返回实况天气
|
||||
* all:返回预报天气
|
||||
*/
|
||||
private String extensions;
|
||||
|
||||
/**
|
||||
*返回格式:
|
||||
* 可选值:JSON,XML
|
||||
*/
|
||||
private String output = "JSON";
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,8 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
import static com.xjs.consts.ApiConst.ROLL_CODE_SUCCESS;
|
||||
import static com.xjs.consts.RedisConst.IP_INFO;
|
||||
|
||||
/**
|
||||
|
|
@ -42,7 +44,7 @@ public class RollIPFactory implements IPFactory<IPInfoVo> {
|
|||
requestBody.setApp_id(rollProperties.getApp_id());
|
||||
requestBody.setApp_secret(rollProperties.getApp_secret());
|
||||
JSONObject jsonObject = rollIPFeignClient.IpApi(requestBody);
|
||||
if (!jsonObject.containsKey("error") && jsonObject.getInteger("code") == 1) {
|
||||
if (!jsonObject.containsKey(DEMOTE_ERROR) && jsonObject.getInteger("code") == ROLL_CODE_SUCCESS.intValue()) {
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
return data.toJavaObject(IPInfoVo.class);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import com.xjs.copywriting.mapper.CopyWritingMapper;
|
|||
import com.xjs.copywriting.service.CopyWritingService;
|
||||
import com.xjs.oneenglish.domain.ApiEnglish;
|
||||
import com.xjs.oneenglish.domain.RequestBody;
|
||||
import com.xjs.oneenglish.factory.impl.TianXingOneEnglishFactory;
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
<where>
|
||||
<if test="apiName != null and apiName != ''"> and api_name like concat('%', #{apiName}, '%')</if>
|
||||
</where>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
<select id="selectApiRecordById" parameterType="Long" resultMap="ApiRecordResult">
|
||||
|
|
|
|||
Loading…
Reference in New Issue