parent
e4836b53e8
commit
8f08381625
@ -0,0 +1,29 @@
|
|||||||
|
package com.xjs.common.client.api.uomg;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xjs.annotation.ApiLog;
|
||||||
|
import com.xjs.common.client.factory.UomgEarthLoveFeignFactory;
|
||||||
|
import com.xjs.copywriting.domain.RequestBody;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.cloud.openfeign.SpringQueryMap;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
||||||
|
import static com.xjs.consts.ApiConst.UOMG_EARTH_LOVE;
|
||||||
|
import static com.xjs.consts.ApiConst.UOMG_EARTH_LOVE_URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uomg平台 土味情话 feign
|
||||||
|
*
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-02-14
|
||||||
|
*/
|
||||||
|
@FeignClient(name = "uomgEarthLove", url = UOMG_EARTH_LOVE_URL, fallbackFactory = UomgEarthLoveFeignFactory.class)
|
||||||
|
@Deprecated
|
||||||
|
public interface UomgEarthLoveFeignClient {
|
||||||
|
@PostMapping(headers = {"Content-Type=text/html;charset=UTF-8"})
|
||||||
|
@ApiLog(name = UOMG_EARTH_LOVE,
|
||||||
|
url = UOMG_EARTH_LOVE_URL,
|
||||||
|
method = "Get")
|
||||||
|
@Deprecated
|
||||||
|
JSONObject earthLoveApi(@SpringQueryMap RequestBody requestBody);
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.xjs.common.client.factory;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.xjs.common.client.api.uomg.UomgEarthLoveFeignClient;
|
||||||
|
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-02-14
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Log4j2
|
||||||
|
public class UomgEarthLoveFeignFactory implements FallbackFactory<UomgEarthLoveFeignClient> {
|
||||||
|
@Override
|
||||||
|
public UomgEarthLoveFeignClient create(Throwable cause) {
|
||||||
|
log.error("api模块Uomg-土味情话服务调用失败:{},执行降级处理", cause.getMessage());
|
||||||
|
return (req) -> {
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||||
|
return jsonObject;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package com.xjs.copywriting.factory.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xjs.common.client.api.uomg.UomgEarthLoveFeignClient;
|
||||||
|
import com.xjs.consts.CopyWritingConst;
|
||||||
|
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 org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uomg平台 土味情话 api工厂实现
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-02-14
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Deprecated
|
||||||
|
public class UomgEarthLoveCopyWritingFactory implements CopyWritingFactory {
|
||||||
|
@Autowired
|
||||||
|
private CopyWritingService copyWritingService;
|
||||||
|
@Autowired
|
||||||
|
private UomgEarthLoveFeignClient uomgEarthLoveFeignClient;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public CopyWriting productCopyWriting(RequestBody requestBody) {
|
||||||
|
requestBody.setFormat("json");
|
||||||
|
JSONObject jsonObject = uomgEarthLoveFeignClient.earthLoveApi(requestBody);
|
||||||
|
if (jsonObject.containsKey(DEMOTE_ERROR)) {
|
||||||
|
throw new ApiException("Uomg平台 土味情话接口调用异常");
|
||||||
|
}
|
||||||
|
String content = jsonObject.getString("content");
|
||||||
|
CopyWriting copyWriting = new CopyWriting();
|
||||||
|
copyWriting.setContent(content);
|
||||||
|
copyWriting.setSource("土味情话");
|
||||||
|
copyWriting.setType(CopyWritingConst.TWQH);
|
||||||
|
copyWritingService.save(copyWriting);
|
||||||
|
return copyWriting;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue