parent
adbd6075af
commit
fec2fc4391
@ -0,0 +1,47 @@
|
|||||||
|
package com.xjs.apitools.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* api汉语字典实体
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-20
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ApiChineseDict implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 原内容
|
||||||
|
*/
|
||||||
|
private String word;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 繁体
|
||||||
|
*/
|
||||||
|
private String traditional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拼音
|
||||||
|
*/
|
||||||
|
private String pinyin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 偏旁部首
|
||||||
|
*/
|
||||||
|
private String radicals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 汉字释义
|
||||||
|
*/
|
||||||
|
private String explanation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 汉字笔画数
|
||||||
|
*/
|
||||||
|
private String strokes;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
package com.xjs.apitools.factory.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xjs.apitools.domain.ApiChineseDict;
|
||||||
|
import com.xjs.apitools.domain.RequestBody;
|
||||||
|
import com.xjs.apitools.factory.ApiToolsFactory;
|
||||||
|
import com.xjs.common.client.api.roll.RollChineseDictFeignClient;
|
||||||
|
import com.xjs.config.RollProperties;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* roll平台获取汉语字典api工厂实现
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-20
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Log4j2
|
||||||
|
public class RollChineseDictFactory implements ApiToolsFactory<ApiChineseDict, RequestBody> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RollProperties rollProperties;
|
||||||
|
@Autowired
|
||||||
|
private RollChineseDictFeignClient rollChineseDictFeignClient;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ApiChineseDict apiData(RequestBody req) {
|
||||||
|
req.setApp_id(rollProperties.getApp_id());
|
||||||
|
req.setApp_secret(rollProperties.getApp_secret());
|
||||||
|
JSONObject jsonObject = rollChineseDictFeignClient.chineseDictApi(req);
|
||||||
|
if (!jsonObject.containsKey(DEMOTE_ERROR) && jsonObject.getInteger("code") == ROLL_CODE_SUCCESS.intValue()) {
|
||||||
|
JSONArray jsonArrayData = jsonObject.getJSONArray("data");
|
||||||
|
JSONObject jsonData = jsonArrayData.getJSONObject(0);
|
||||||
|
return jsonData.toJavaObject(ApiChineseDict.class);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.xjs.common.client.api.roll;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xjs.annotation.ApiLog;
|
||||||
|
import com.xjs.apitools.domain.RequestBody;
|
||||||
|
import com.xjs.common.client.factory.RollChineseDictFeignFactory;
|
||||||
|
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.ROLL_CHINESE_DICT;
|
||||||
|
import static com.xjs.consts.ApiConst.ROLL_CHINESE_DICT_URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* roll 汉语字典api接口feign远程调用
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-20
|
||||||
|
*/
|
||||||
|
@FeignClient(name = "rollChineseDict", url = ROLL_CHINESE_DICT_URL, fallbackFactory = RollChineseDictFeignFactory.class)
|
||||||
|
public interface RollChineseDictFeignClient {
|
||||||
|
|
||||||
|
@GetMapping()
|
||||||
|
@ApiLog(name = ROLL_CHINESE_DICT,
|
||||||
|
url = ROLL_CHINESE_DICT_URL,
|
||||||
|
method = "Get")
|
||||||
|
JSONObject chineseDictApi(@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.roll.RollChineseDictFeignClient;
|
||||||
|
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 汉语字典api降级处理
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-20
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Log4j2
|
||||||
|
public class RollChineseDictFeignFactory implements FallbackFactory<RollChineseDictFeignClient> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RollChineseDictFeignClient create(Throwable cause) {
|
||||||
|
log.error("api模块roll 汉语字典服务调用失败:{},执行降级处理", cause.getMessage());
|
||||||
|
return requestBody -> {
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||||
|
return jsonObject;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue