新增治理对外接口

This commit is contained in:
2023-04-10 15:19:45 +08:00
parent 952ccc8d10
commit ff27f42ae2
6 changed files with 102 additions and 39 deletions

View File

@@ -38,6 +38,11 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>common-microservice</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<properties>

View File

@@ -0,0 +1,21 @@
package com.njcn.algorithm.api;
import com.njcn.algorithm.api.fallback.EquipmentFeignClientFallbackFactory;
import com.njcn.algorithm.pojo.vo.CsEquipmentDeliveryVO;
import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.response.HttpResult;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author xy
*/
@FeignClient(value = ServerInfo.ALGORITHM_BOOT, path = "/EquipmentDelivery", fallbackFactory = EquipmentFeignClientFallbackFactory.class,contextId = "EquipmentDelivery")
public interface EquipmentFeignClient {
@PostMapping("/queryEquipmentByndid")
HttpResult<CsEquipmentDeliveryVO> queryEquipmentByndid(@RequestParam("ndid") String ndid);
}

View File

@@ -0,0 +1,36 @@
package com.njcn.algorithm.api.fallback;
import com.njcn.algorithm.api.EquipmentFeignClient;
import com.njcn.algorithm.pojo.vo.CsEquipmentDeliveryVO;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @author xy
*/
@Slf4j
@Component
public class EquipmentFeignClientFallbackFactory implements FallbackFactory<EquipmentFeignClient> {
@Override
public EquipmentFeignClient create(Throwable cause) {
//判断抛出异常是否为解码器抛出的业务异常
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
if (cause.getCause() instanceof BusinessException) {
BusinessException businessException = (BusinessException) cause.getCause();
// exceptionEnum = UserEnumUtil.getExceptionEnum(businessException.getResult());
}
Enum<?> finalExceptionEnum = exceptionEnum;
return new EquipmentFeignClient() {
@Override
public HttpResult<CsEquipmentDeliveryVO> queryEquipmentByndid(String ndid) {
log.error("{}异常,降级处理,异常为:{}","通过ndid查询出厂设备异常",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}