diff --git a/pqs-device/pq-device/pq-device-api/src/main/java/com/njcn/device/pq/api/CvtRelationFeignClient.java b/pqs-device/pq-device/pq-device-api/src/main/java/com/njcn/device/pq/api/CvtRelationFeignClient.java new file mode 100644 index 000000000..e24180de4 --- /dev/null +++ b/pqs-device/pq-device/pq-device-api/src/main/java/com/njcn/device/pq/api/CvtRelationFeignClient.java @@ -0,0 +1,24 @@ +package com.njcn.device.pq.api; + +import com.njcn.common.pojo.constant.ServerInfo; +import com.njcn.common.pojo.response.HttpResult; +import com.njcn.device.pq.api.fallback.CvtRelationFeignClientFallbackFactory; +import com.njcn.device.pq.pojo.dto.CvtHarmonicCorrectionFactorsDTO; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import java.util.List; + +/** + * 告警管理Feign客户端 + * + * @author yzh + * @date 2022/9/19 + */ +@FeignClient(value = ServerInfo.DEVICE, path = "/cvtBind", fallbackFactory = CvtRelationFeignClientFallbackFactory.class, contextId = "cvtBind") +public interface CvtRelationFeignClient { + + @PostMapping("queryByLineId") + HttpResult queryByLineId(@RequestParam("lineId") String lineId); +} diff --git a/pqs-device/pq-device/pq-device-api/src/main/java/com/njcn/device/pq/api/fallback/CvtRelationFeignClientFallbackFactory.java b/pqs-device/pq-device/pq-device-api/src/main/java/com/njcn/device/pq/api/fallback/CvtRelationFeignClientFallbackFactory.java new file mode 100644 index 000000000..01bd4342c --- /dev/null +++ b/pqs-device/pq-device/pq-device-api/src/main/java/com/njcn/device/pq/api/fallback/CvtRelationFeignClientFallbackFactory.java @@ -0,0 +1,43 @@ +package com.njcn.device.pq.api.fallback; + +import com.njcn.common.pojo.enums.response.CommonResponseEnum; +import com.njcn.common.pojo.exception.BusinessException; +import com.njcn.common.pojo.response.HttpResult; +import com.njcn.device.biz.utils.DeviceEnumUtil; +import com.njcn.device.pq.api.CvtRelationFeignClient; +import com.njcn.device.pq.pojo.dto.CvtHarmonicCorrectionFactorsDTO; +import feign.hystrix.FallbackFactory; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * 告警管理熔断降级 + * @author yzh + * @date 2022/9/19 + */ +@Slf4j +@Component +public class CvtRelationFeignClientFallbackFactory implements FallbackFactory { + @Override + public CvtRelationFeignClient create(Throwable throwable) { + //判断抛出异常是否为解码器抛出的业务异常 + Enum exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK; + if (throwable.getCause() instanceof BusinessException) { + BusinessException businessException = (BusinessException) throwable.getCause(); + exceptionEnum = DeviceEnumUtil.getExceptionEnum(businessException.getResult()); + } + Enum finalExceptionEnum = exceptionEnum; + return new CvtRelationFeignClient() { + + + @Override + public HttpResult queryByLineId(String lineId) { + log.error("{}异常,降级处理,异常为:{}", "监测点获取Cvt系数", throwable.toString()); + throw new BusinessException(finalExceptionEnum); + } + }; + } +} +