parent
b6be46b880
commit
790200a947
|
|
@ -0,0 +1,31 @@
|
|||
package com.xjs.business.english.api;
|
||||
|
||||
import com.ruoyi.common.core.constant.ServiceNameConstants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.system.api.domain.SysFile;
|
||||
import com.ruoyi.system.api.factory.RemoteFileFallbackFactory;
|
||||
import com.xjs.business.english.api.domain.CopyWriting;
|
||||
import com.xjs.business.english.api.factory.RemoteCopyWritingFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc RPC远程调用文案接口服务
|
||||
* @create 2021-12-27
|
||||
*/
|
||||
@FeignClient(contextId = "remoteCopyWritingFeign", value = ServiceNameConstants.BUSINESS_ENGLISH_SERVICE, fallbackFactory = RemoteCopyWritingFactory.class)
|
||||
public interface RemoteCopyWritingFeign {
|
||||
/**
|
||||
* 获取文案
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
@GetMapping(value = "/copyWriting/forPRC")
|
||||
R<CopyWriting> copyWriting();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package com.xjs.business.english.api.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc 文案实体类
|
||||
* @create 2021-12-27
|
||||
*/
|
||||
public class CopyWriting implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
||||
|
||||
/** 文案内容 */
|
||||
private String content;
|
||||
|
||||
/** 文案来源 */
|
||||
private String source;
|
||||
|
||||
private String createTime;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(String source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public String getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(String createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package com.xjs.business.english.api.factory;
|
||||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.system.api.factory.RemoteFileFallbackFactory;
|
||||
import com.xjs.business.english.api.RemoteCopyWritingFeign;
|
||||
import com.xjs.business.english.api.domain.CopyWriting;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc 文案rpc降级服务处理
|
||||
* @create 2021-12-27
|
||||
*/
|
||||
@Component
|
||||
public class RemoteCopyWritingFactory implements FallbackFactory<RemoteCopyWritingFeign> {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(RemoteFileFallbackFactory.class);
|
||||
|
||||
@Override
|
||||
public RemoteCopyWritingFeign create(Throwable cause) {
|
||||
log.error("英语模块文案服务调用失败:{}", cause.getMessage());
|
||||
return () -> R.fail("文案服务调用失败" + cause.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
@ -21,4 +21,9 @@ public class ServiceNameConstants
|
|||
* 文件服务的serviceid
|
||||
*/
|
||||
public static final String FILE_SERVICE = "ruoyi-file";
|
||||
|
||||
/**
|
||||
* 英语业务服务的serviceid
|
||||
*/
|
||||
public static final String BUSINESS_ENGLISH_SERVICE= "xjs-english" ;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import java.lang.annotation.RetentionPolicy;
|
|||
import java.lang.annotation.Target;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.mybatis.spring.annotation.MapperScans;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
|
@ -26,6 +27,8 @@ import com.ruoyi.common.security.feign.FeignAutoConfiguration;
|
|||
@EnableAsync
|
||||
// 自动加载类
|
||||
@Import({ ApplicationConfig.class, FeignAutoConfiguration.class })
|
||||
//自定义bean扫描,添加xjs路径下的bean
|
||||
@ComponentScan(basePackages = {"com.ruoyi","com.xjs"})
|
||||
public @interface EnableCustomConfig
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
package com.xjs.common.job;
|
||||
|
||||
import com.xjs.copywriting.factory.CopyWritingFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc 获取文案定时任务
|
||||
* @create 2021-12-27
|
||||
*/
|
||||
@Component
|
||||
public class CopyWritingJob {
|
||||
|
||||
@Autowired
|
||||
private CopyWritingFactory tianXingcopyWritingFactory;
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package com.xjs.copywriting;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.security.annotation.RequiresLogin;
|
||||
|
|
@ -17,6 +18,7 @@ import org.springframework.validation.annotation.Validated;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
|
|
@ -37,15 +39,40 @@ public class CopyWritingController {
|
|||
@Log(title = "文案管理")
|
||||
@RequiresLogin
|
||||
@RequiresPermissions("english:translation:api")
|
||||
public AjaxResult translation(@Validated RequestBody requestBody) {
|
||||
public AjaxResult copyWriting(@Validated RequestBody requestBody) {
|
||||
requestBody = Optional.ofNullable(requestBody).orElseGet(RequestBody::new);
|
||||
ArrayList<CopyWritingFactory> factories = new ArrayList<>();
|
||||
//添加了新接口只需要在这add接口进去
|
||||
factories.add(tianXingcopyWritingFactory);
|
||||
//随机调用集合中的接口
|
||||
CopyWritingFactory copyWritingFactory = RandomUtil.randomEle(factories);
|
||||
CopyWritingFactory copyWritingFactory = this.randomApi();
|
||||
CopyWriting copyWriting = copyWritingFactory.productCopyWriting(requestBody);
|
||||
return AjaxResult.success(copyWriting);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("forPRC")
|
||||
@ApiOperation("供定时任务服务RPC远程调用")
|
||||
public R<CopyWriting> copyWriting() {
|
||||
CopyWritingFactory copyWritingFactory = this.randomApi();
|
||||
return R.ok(copyWritingFactory.productCopyWriting(new RequestBody()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 封装随机调用api
|
||||
* @return 文案工厂
|
||||
*/
|
||||
private CopyWritingFactory randomApi() {
|
||||
ArrayList<CopyWritingFactory> factories = new ArrayList<>();
|
||||
//添加了新接口只需要在这add接口进去
|
||||
factories.add(tianXingcopyWritingFactory);
|
||||
//--------add----------------------------;-
|
||||
//随机调用集合中的接口
|
||||
return RandomUtil.randomEle(factories);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue