parent
6ce0420d2f
commit
7a708fef7c
@ -0,0 +1,24 @@
|
||||
package com.xjs.common.client.api.lq;
|
||||
|
||||
import com.xjs.annotation.ApiLog;
|
||||
import com.xjs.common.client.factory.LqDogDiaryFeignFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import static com.xjs.consts.ApiConst.LQ_DOG_DIARY;
|
||||
import static com.xjs.consts.ApiConst.LQ_DOG_DIARY_URL;
|
||||
|
||||
/**
|
||||
* 零七平台 dog日记 feign
|
||||
* @author xiejs
|
||||
* @since 2022-02-14
|
||||
*/
|
||||
@FeignClient(name = "lqDogDiary", url = LQ_DOG_DIARY_URL, fallbackFactory = LqDogDiaryFeignFactory.class)
|
||||
public interface LqDogDiaryFeignClient {
|
||||
|
||||
@GetMapping()
|
||||
@ApiLog(name = LQ_DOG_DIARY,
|
||||
url = LQ_DOG_DIARY_URL,
|
||||
method = "Get")
|
||||
String dogDiaryApi();
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.xjs.common.client.factory;
|
||||
|
||||
import com.xjs.common.client.api.lq.LqDogDiaryFeignClient;
|
||||
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 LqDogDiaryFeignFactory implements FallbackFactory<LqDogDiaryFeignClient> {
|
||||
@Override
|
||||
public LqDogDiaryFeignClient create(Throwable cause) {
|
||||
log.error("api模块零七舔狗日记服务调用失败:{},执行降级处理", cause.getMessage());
|
||||
return () -> {
|
||||
return "";
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.xjs.copywriting.factory.impl;
|
||||
|
||||
import com.xjs.common.client.api.lq.LqDogDiaryFeignClient;
|
||||
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 LqDogDiaryCopyWritingFactory implements CopyWritingFactory {
|
||||
|
||||
@Autowired
|
||||
private CopyWritingService copyWritingService;
|
||||
@Autowired
|
||||
private LqDogDiaryFeignClient lqDogDiaryFeignClient;
|
||||
|
||||
@Override
|
||||
public CopyWriting productCopyWriting(RequestBody requestBody) {
|
||||
String data = lqDogDiaryFeignClient.dogDiaryApi();
|
||||
if (StringUtils.isEmpty(data)) {
|
||||
throw new ApiException("零七-舔狗日记接口调用异常");
|
||||
}
|
||||
CopyWriting copyWriting = new CopyWriting();
|
||||
copyWriting.setContent(data);
|
||||
copyWriting.setSource("舔狗日记");
|
||||
copyWriting.setType(TianXingConst.TGRJ);
|
||||
|
||||
copyWritingService.save(copyWriting);
|
||||
return copyWriting;
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.xjs.copywriting.factory.impl;
|
||||
|
||||
import com.xjs.XjsOpenApiApp;
|
||||
import com.xjs.copywriting.domain.RequestBody;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @since 2022-02-14
|
||||
*/
|
||||
@SpringBootTest(classes = XjsOpenApiApp.class)
|
||||
class LqDogDiaryCopyWritingFactoryTest {
|
||||
|
||||
@Autowired
|
||||
private LqDogDiaryCopyWritingFactory lqDogDiaryCopyWritingFactory;
|
||||
|
||||
@Test
|
||||
void productCopyWriting() {
|
||||
lqDogDiaryCopyWritingFactory.productCopyWriting(new RequestBody());
|
||||
}
|
||||
}
|
Loading…
Reference in new issue