parent
bd518bb866
commit
e4836b53e8
@ -0,0 +1,23 @@
|
|||||||
|
package com.xjs.common.client.api.lq;
|
||||||
|
|
||||||
|
import com.xjs.annotation.ApiLog;
|
||||||
|
import com.xjs.common.client.factory.LqAWordFeignFactory;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
||||||
|
import static com.xjs.consts.ApiConst.LQ_A_WORD;
|
||||||
|
import static com.xjs.consts.ApiConst.LQ_A_WORD_URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 零七平台 一言 feign
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-02-14
|
||||||
|
*/
|
||||||
|
@FeignClient(name = "lqAWord", url = LQ_A_WORD_URL, fallbackFactory = LqAWordFeignFactory.class)
|
||||||
|
public interface LqAWordFeignClient {
|
||||||
|
@GetMapping( headers ={ "Accept-Encoding=''"})//解决响应乱码
|
||||||
|
@ApiLog(name = LQ_A_WORD,
|
||||||
|
url = LQ_A_WORD_URL,
|
||||||
|
method = "Get")
|
||||||
|
String aWordApi();
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.xjs.common.client.factory;
|
||||||
|
|
||||||
|
import com.xjs.common.client.api.lq.LqAWordFeignClient;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-02-14
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Log4j2
|
||||||
|
public class LqAWordFeignFactory implements FallbackFactory<LqAWordFeignClient> {
|
||||||
|
@Override
|
||||||
|
public LqAWordFeignClient create(Throwable cause) {
|
||||||
|
log.error("api模块零七-一言服务调用失败:{},执行降级处理", cause.getMessage());
|
||||||
|
return () -> "";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.xjs.copywriting.factory.impl;
|
||||||
|
|
||||||
|
import com.xjs.common.client.api.lq.LqAWordFeignClient;
|
||||||
|
import com.xjs.consts.TianXingConst;
|
||||||
|
import com.xjs.copywriting.domain.CopyWriting;
|
||||||
|
import com.xjs.copywriting.domain.RequestBody;
|
||||||
|
import com.xjs.copywriting.factory.CopyWritingFactory;
|
||||||
|
import com.xjs.copywriting.service.CopyWritingService;
|
||||||
|
import com.xjs.exception.ApiException;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-02-14
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Log4j2
|
||||||
|
public class LqAWordCopyWritingFactory implements CopyWritingFactory {
|
||||||
|
@Autowired
|
||||||
|
private CopyWritingService copyWritingService;
|
||||||
|
@Autowired
|
||||||
|
private LqAWordFeignClient lqAWordFeignClient;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CopyWriting productCopyWriting(RequestBody requestBody) {
|
||||||
|
String data = lqAWordFeignClient.aWordApi();
|
||||||
|
if (StringUtils.isEmpty(data)) {
|
||||||
|
throw new ApiException("零七-一言接口调用异常");
|
||||||
|
}
|
||||||
|
CopyWriting copyWriting = new CopyWriting();
|
||||||
|
copyWriting.setContent(data);
|
||||||
|
copyWriting.setSource("一言");
|
||||||
|
copyWriting.setType(TianXingConst.YY);
|
||||||
|
copyWritingService.save(copyWriting);
|
||||||
|
return copyWriting;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue