用能代码提交
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package com.njcn.energy.pojo.api;
|
||||
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.energy.pojo.api.fallback.EleOnlineRateFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
|
||||
/**
|
||||
* pqs
|
||||
*
|
||||
* @author cdf
|
||||
* @date 2022/4/22
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.ENERGY,path = "/energyJob",fallbackFactory = EleOnlineRateFallbackFactory.class)
|
||||
public interface EnergyStatisticFeignClient {
|
||||
|
||||
/**
|
||||
* 获取策略下的监测点
|
||||
* @author cdf
|
||||
* @date 2022/4/22
|
||||
*/
|
||||
@GetMapping("electricCalJob")
|
||||
HttpResult<Boolean> electricCalJob();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.njcn.energy.pojo.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.energy.pojo.api.EleAirStrategyFeignClient;
|
||||
import com.njcn.energy.pojo.api.EnergyStatisticFeignClient;
|
||||
import com.njcn.energy.pojo.utils.EnergyEnumUtil;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2022/4/20 15:09
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class EnergyStatisticFallbackFactory implements FallbackFactory<EnergyStatisticFeignClient> {
|
||||
|
||||
|
||||
@Override
|
||||
public EnergyStatisticFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if(cause.getCause() instanceof BusinessException){
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
exceptionEnum = EnergyEnumUtil.getExceptionEnum(businessException.getResult());
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new EnergyStatisticFeignClient() {
|
||||
@Override
|
||||
public HttpResult<Boolean> electricCalJob() {
|
||||
log.error("{}异常,降级处理,异常为:{}","调度统计电量增量",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user