From b2e861f31417071a180717b56592423e7fadb81c Mon Sep 17 00:00:00 2001 From: zhaoxiaolin Date: Sat, 29 Jul 2023 23:40:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E6=9C=8D=E5=8A=A1=E6=8B=86=E5=88=862?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/op/system/api/RemotePlanService.java | 28 +++++++++++++++ .../system/api/RemoteTechnologyService.java | 25 +++++++++++++ .../factory/RemotePlanFallbackFactory.java | 35 +++++++++++++++++++ .../RemoteTechnologyFallbackFactory.java | 32 +++++++++++++++++ ...ot.autoconfigure.AutoConfiguration.imports | 2 ++ .../core/constant/ServiceNameConstants.java | 8 +++++ 6 files changed, 130 insertions(+) create mode 100644 op-api/op-api-system/src/main/java/com/op/system/api/RemotePlanService.java create mode 100644 op-api/op-api-system/src/main/java/com/op/system/api/RemoteTechnologyService.java create mode 100644 op-api/op-api-system/src/main/java/com/op/system/api/factory/RemotePlanFallbackFactory.java create mode 100644 op-api/op-api-system/src/main/java/com/op/system/api/factory/RemoteTechnologyFallbackFactory.java diff --git a/op-api/op-api-system/src/main/java/com/op/system/api/RemotePlanService.java b/op-api/op-api-system/src/main/java/com/op/system/api/RemotePlanService.java new file mode 100644 index 000000000..267f6d41d --- /dev/null +++ b/op-api/op-api-system/src/main/java/com/op/system/api/RemotePlanService.java @@ -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 sapAddOrder(@RequestBody SapProOrder sapProOrder); + +} diff --git a/op-api/op-api-system/src/main/java/com/op/system/api/RemoteTechnologyService.java b/op-api/op-api-system/src/main/java/com/op/system/api/RemoteTechnologyService.java new file mode 100644 index 000000000..a5743e074 --- /dev/null +++ b/op-api/op-api-system/src/main/java/com/op/system/api/RemoteTechnologyService.java @@ -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 sapAddOrder(@RequestBody SapProOrder sapProOrder); + +} diff --git a/op-api/op-api-system/src/main/java/com/op/system/api/factory/RemotePlanFallbackFactory.java b/op-api/op-api-system/src/main/java/com/op/system/api/factory/RemotePlanFallbackFactory.java new file mode 100644 index 000000000..cc754b9a5 --- /dev/null +++ b/op-api/op-api-system/src/main/java/com/op/system/api/factory/RemotePlanFallbackFactory.java @@ -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 { + 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 sapAddOrder(SapProOrder sapProOrder) { + return R.fail("新增SAP订单失败:" + throwable.getMessage()); + } + + }; + } +} + diff --git a/op-api/op-api-system/src/main/java/com/op/system/api/factory/RemoteTechnologyFallbackFactory.java b/op-api/op-api-system/src/main/java/com/op/system/api/factory/RemoteTechnologyFallbackFactory.java new file mode 100644 index 000000000..68f2b4185 --- /dev/null +++ b/op-api/op-api-system/src/main/java/com/op/system/api/factory/RemoteTechnologyFallbackFactory.java @@ -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 { + 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 sapAddOrder(SapProOrder sapProOrder) { + return R.fail("新增SAP订单失败:" + throwable.getMessage()); + } + + }; + } +} + diff --git a/op-api/op-api-system/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/op-api/op-api-system/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 150bf3c36..46655f1dc 100644 --- a/op-api/op-api-system/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/op-api/op-api-system/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -2,3 +2,5 @@ com.op.system.api.factory.RemoteUserFallbackFactory com.op.system.api.factory.RemoteLogFallbackFactory com.op.system.api.factory.RemoteFileFallbackFactory com.op.system.api.factory.RemoteMesFallbackFactory +com.op.system.api.factory.RemotePlanFallbackFactory +com.op.system.api.factory.RemoteTechnologyFallbackFactory diff --git a/op-common/op-common-core/src/main/java/com/op/common/core/constant/ServiceNameConstants.java b/op-common/op-common-core/src/main/java/com/op/common/core/constant/ServiceNameConstants.java index 2a2c8e3cd..12e65b7af 100644 --- a/op-common/op-common-core/src/main/java/com/op/common/core/constant/ServiceNameConstants.java +++ b/op-common/op-common-core/src/main/java/com/op/common/core/constant/ServiceNameConstants.java @@ -35,4 +35,12 @@ public class ServiceNameConstants { * SAP模块的serviceid */ public static final String SAP_SERVICE = "op-sap"; + /** + * 计划模块的serviceid + */ + public static final String PLAN_SERVICE = "op-plan"; + /** + * 工艺模块的serviceid + */ + public static final String TECH_SERVICE = "op-technology"; }