完成责任量化功能
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package com.njcn.harmonic.api;
|
||||
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.harmonic.api.fallback.HarmDataFeignClientFallbackFactory;
|
||||
import com.njcn.harmonic.pojo.param.HistoryHarmParam;
|
||||
import com.njcn.influx.pojo.dto.HarmHistoryDataDTO;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
@FeignClient(
|
||||
value = ServerInfo.HARMONIC,
|
||||
path = "/harmonic",
|
||||
fallbackFactory = HarmDataFeignClientFallbackFactory.class,
|
||||
contextId = "harmonic")
|
||||
public interface HarmDataFeignClient {
|
||||
|
||||
|
||||
/**
|
||||
* 获取监测点信息
|
||||
* @param historyHarmParam 请求查询参数
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping("/getHistoryHarmData")
|
||||
HttpResult<HarmHistoryDataDTO> getHistoryHarmData(@RequestBody HistoryHarmParam historyHarmParam);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.njcn.harmonic.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.harmonic.api.HarmDataFeignClient;
|
||||
import com.njcn.harmonic.pojo.param.HistoryHarmParam;
|
||||
import com.njcn.influx.pojo.dto.HarmHistoryDataDTO;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2023年07月21日 14:31
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class HarmDataFeignClientFallbackFactory implements FallbackFactory<HarmDataFeignClient> {
|
||||
@Override
|
||||
public HarmDataFeignClient 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 HarmDataFeignClient() {
|
||||
@Override
|
||||
public HttpResult<HarmHistoryDataDTO> getHistoryHarmData(HistoryHarmParam historyHarmParam) {
|
||||
log.error("{}异常,降级处理,异常为:{}", "获取谐波历史数据", throwable.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user