字典树新增接口
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package com.njcn.system.api;
|
||||
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.system.api.fallback.DictTreeFeignClientFallbackFactory;
|
||||
import com.njcn.system.pojo.po.SysDicTreePO;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* @author xuyang
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.SYSTEM, path = "/dictTree", fallbackFactory = DictTreeFeignClientFallbackFactory.class, contextId = "dictTree")
|
||||
public interface DictTreeFeignClient {
|
||||
|
||||
@PostMapping("/queryById")
|
||||
HttpResult<SysDicTreePO> queryById(@RequestParam("id") String id);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.njcn.system.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.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.api.DictTreeFeignClient;
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import com.njcn.system.pojo.po.SysDicTreePO;
|
||||
import com.njcn.system.utils.SystemEnumUtil;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2021年09月09日 15:19
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class DictTreeFeignClientFallbackFactory implements FallbackFactory<DictTreeFeignClient> {
|
||||
@Override
|
||||
public DictTreeFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if(cause.getCause() instanceof BusinessException){
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
exceptionEnum = SystemEnumUtil.getExceptionEnum(businessException.getResult());
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new DictTreeFeignClient() {
|
||||
@Override
|
||||
public HttpResult<SysDicTreePO> queryById(String id) {
|
||||
log.error("{}异常,降级处理,异常为:{}","根据字典id获取字典数据",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -365,8 +365,10 @@ public enum DicDataEnum {
|
||||
/**
|
||||
* 装置类型(治理)
|
||||
*/
|
||||
GATEWAY_DEV("网关", "Gateway_Dev"),
|
||||
CONNECT_DEV("直连设备", "Connect_Dev"),
|
||||
GATEWAY_DEV("网关", "Gateway"),
|
||||
CONNECT_DEV("直连设备", "Direct_Connected_Device"),
|
||||
DEV("装置", "Device"),
|
||||
|
||||
|
||||
/**
|
||||
* 治理数据模型
|
||||
|
||||
Reference in New Issue
Block a user