微服务拆分2
parent
3c4917cb28
commit
b2e861f314
@ -0,0 +1,28 @@
|
||||
package com.op.system.api;
|
||||
|
||||
import com.op.common.core.constant.ServiceNameConstants;
|
||||
import com.op.common.core.domain.BaseFileData;
|
||||
import com.op.common.core.domain.R;
|
||||
import com.op.system.api.factory.RemotePlanFallbackFactory;
|
||||
import com.op.system.api.model.SapProOrder;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户服务
|
||||
*
|
||||
* @author OP
|
||||
*/
|
||||
@FeignClient(contextId = "remotePlanService", value = ServiceNameConstants.PLAN_SERVICE, fallbackFactory = RemotePlanFallbackFactory.class)
|
||||
|
||||
|
||||
|
||||
public interface RemotePlanService {
|
||||
|
||||
@PostMapping("/order/sapAddOrder")
|
||||
public R<Boolean> sapAddOrder(@RequestBody SapProOrder sapProOrder);
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.op.system.api;
|
||||
|
||||
import com.op.common.core.constant.ServiceNameConstants;
|
||||
import com.op.common.core.domain.R;
|
||||
import com.op.system.api.factory.RemoteTechnologyFallbackFactory;
|
||||
import com.op.system.api.model.SapProOrder;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* 用户服务
|
||||
*
|
||||
* @author OP
|
||||
*/
|
||||
@FeignClient(contextId = "remoteTechnologyService", value = ServiceNameConstants.TECH_SERVICE, fallbackFactory = RemoteTechnologyFallbackFactory.class)
|
||||
|
||||
|
||||
|
||||
public interface RemoteTechnologyService {
|
||||
|
||||
@PostMapping("/order/sapAddOrder")
|
||||
public R<Boolean> sapAddOrder(@RequestBody SapProOrder sapProOrder);
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.op.system.api.factory;
|
||||
|
||||
import com.op.common.core.domain.BaseFileData;
|
||||
import com.op.common.core.domain.R;
|
||||
import com.op.system.api.RemotePlanService;
|
||||
import com.op.system.api.model.SapProOrder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户服务降级处理
|
||||
*
|
||||
* @author OP
|
||||
*/
|
||||
@Component
|
||||
public class RemotePlanFallbackFactory implements FallbackFactory<RemotePlanService> {
|
||||
private static final Logger log = LoggerFactory.getLogger(RemotePlanFallbackFactory.class);
|
||||
|
||||
@Override
|
||||
public RemotePlanService create(Throwable throwable) {
|
||||
log.error("Plan服务调用失败:{}", throwable.getMessage());
|
||||
return new RemotePlanService() {
|
||||
@Override
|
||||
public R<Boolean> sapAddOrder(SapProOrder sapProOrder) {
|
||||
return R.fail("新增SAP订单失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
package com.op.system.api.factory;
|
||||
|
||||
import com.op.common.core.domain.R;
|
||||
import com.op.system.api.RemoteTechnologyService;
|
||||
import com.op.system.api.model.SapProOrder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 用户服务降级处理
|
||||
*
|
||||
* @author OP
|
||||
*/
|
||||
@Component
|
||||
public class RemoteTechnologyFallbackFactory implements FallbackFactory<RemoteTechnologyService> {
|
||||
private static final Logger log = LoggerFactory.getLogger(RemoteTechnologyFallbackFactory.class);
|
||||
|
||||
@Override
|
||||
public RemoteTechnologyService create(Throwable throwable) {
|
||||
log.error("Technology服务调用失败:{}", throwable.getMessage());
|
||||
return new RemoteTechnologyService() {
|
||||
@Override
|
||||
public R<Boolean> sapAddOrder(SapProOrder sapProOrder) {
|
||||
return R.fail("新增SAP订单失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue