1.谐波高级算法远程调用提交
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package com.njcn.advance.api;
|
||||
|
||||
import com.njcn.advance.api.fallback.EventWaveAnalysisFeignClientFallbackFactory;
|
||||
import com.njcn.advance.pojo.dto.waveAnalysis.EntityAdvancedData;
|
||||
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;
|
||||
|
||||
|
||||
@FeignClient(value = ServerInfo.ADVANCE_BOOT,path = "/waveAnalysis",fallbackFactory = EventWaveAnalysisFeignClientFallbackFactory.class,contextId = "waveAnalysis")
|
||||
public interface EventWaveAnalysisFeignClient {
|
||||
|
||||
|
||||
/**
|
||||
* @Description: 波形高级分析
|
||||
* @param eventIndex
|
||||
* @return: com.njcn.common.pojo.response.HttpResult<com.njcn.advance.pojo.dto.waveAnalysis.EntityAdvancedData>
|
||||
* @Author: wr
|
||||
* @Date: 2023/11/1 14:23
|
||||
*/
|
||||
@PostMapping("analysis")
|
||||
HttpResult<EntityAdvancedData> analysis(@RequestParam("eventIndex") String eventIndex);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.njcn.advance.api.fallback;
|
||||
|
||||
import com.njcn.advance.api.EventWaveAnalysisFeignClient;
|
||||
import com.njcn.advance.pojo.dto.waveAnalysis.EntityAdvancedData;
|
||||
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.event.utils.EventlEnumUtil;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class EventWaveAnalysisFeignClientFallbackFactory implements FallbackFactory<EventWaveAnalysisFeignClient> {
|
||||
@Override
|
||||
public EventWaveAnalysisFeignClient create(Throwable throwable) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (throwable.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) throwable.getCause();
|
||||
exceptionEnum = EventlEnumUtil.getExceptionEnum(businessException.getResult());
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new EventWaveAnalysisFeignClient() {
|
||||
|
||||
@Override
|
||||
public HttpResult<EntityAdvancedData> analysis(String eventIndex) {
|
||||
log.error("{}异常,降级处理,异常为:{}", "波形高级分析", throwable.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user