This commit is contained in:
huangzj
2023-07-13 13:41:21 +08:00
parent 55b40c0ce8
commit 595474ee10
18 changed files with 540 additions and 146 deletions

View File

@@ -0,0 +1,32 @@
package com.njcn.csdevice.api;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.csdevice.api.fallback.EquipmentFeignClientFallbackFactory;
import com.njcn.csdevice.api.fallback.RoleEngineerDevClientFallbackFactory;
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
/**
* @author xy
*/
@FeignClient(value = ServerInfo.CS_DEVICE_BOOT, path = "/roleEngineerDev", fallbackFactory = RoleEngineerDevClientFallbackFactory.class,contextId = "roleEngineerDev")
public interface RoleEngineerDevFeignClient {
@PostMapping("/getRoleengineer")
public HttpResult<List<String>> getRoleengineer();
@PostMapping("/getDevice")
public HttpResult<List<String>> getDevice();
}

View File

@@ -0,0 +1,47 @@
package com.njcn.csdevice.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.csdevice.api.EquipmentFeignClient;
import com.njcn.csdevice.api.RoleEngineerDevFeignClient;
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author xy
*/
@Slf4j
@Component
public class RoleEngineerDevClientFallbackFactory implements FallbackFactory<RoleEngineerDevFeignClient> {
@Override
public RoleEngineerDevFeignClient 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 RoleEngineerDevFeignClient() {
@Override
public HttpResult<List<String>> getRoleengineer() {
log.error("{}异常,降级处理,异常为:{}","查询角色工程异常",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<List<String>> getDevice() {
log.error("{}异常,降级处理,异常为:{}","查询角色设备异常",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}