代码调整
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
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.UploadGwDataFallbackFactory;
|
||||
import com.njcn.harmonic.pojo.param.UploadParam;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* @author xuyang
|
||||
*/
|
||||
@FeignClient(
|
||||
value = ServerInfo.HARMONIC,
|
||||
path = "/upload",
|
||||
fallbackFactory = UploadGwDataFallbackFactory.class,
|
||||
contextId = "upload")
|
||||
public interface UploadGwDataFeignClient {
|
||||
|
||||
@PostMapping("/uploadPointStatisticalData")
|
||||
HttpResult<String> uploadPointStatisticalData(@RequestBody UploadParam param);
|
||||
|
||||
@PostMapping("/uploadSubstationStatisticalData")
|
||||
HttpResult<String> uploadSubstationStatisticalData(@RequestBody UploadParam param);
|
||||
|
||||
@PostMapping("/uploadEvaluationData")
|
||||
HttpResult<String> uploadEvaluationData(@RequestBody UploadParam param);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
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.harmonic.api.UploadGwDataFeignClient;
|
||||
import com.njcn.harmonic.pojo.param.UploadParam;
|
||||
import com.njcn.harmonic.utils.HarmonicEnumUtil;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @date 2023年12月15日 13:50
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class UploadGwDataFallbackFactory implements FallbackFactory<UploadGwDataFeignClient> {
|
||||
@Override
|
||||
public UploadGwDataFeignClient create(Throwable throwable) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (throwable.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) throwable.getCause();
|
||||
exceptionEnum = HarmonicEnumUtil.getExceptionEnum(businessException.getResult());
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new UploadGwDataFeignClient() {
|
||||
@Override
|
||||
public HttpResult<String> uploadPointStatisticalData(UploadParam param) {
|
||||
log.error("{}异常,降级处理,异常为:{}", "国网上送-主配网监测点统计数据", throwable.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<String> uploadSubstationStatisticalData(UploadParam param) {
|
||||
log.error("{}异常,降级处理,异常为:{}", "国网上送-变电站监测统计数据", throwable.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<String> uploadEvaluationData(UploadParam param) {
|
||||
log.error("{}异常,降级处理,异常为:{}", "国网上送-母线基准水平评估数据", throwable.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user