离线数据上传入库

This commit is contained in:
guofeihu
2024-07-31 08:47:12 +08:00
parent 777abc0824
commit fde625de7e
7 changed files with 187 additions and 13 deletions

View File

@@ -0,0 +1,21 @@
package com.njcn.csharmonic.api;
import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.csharmonic.api.fallback.EventFeignClientFallbackFactory;
import com.njcn.csharmonic.pojo.po.CsEventPO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
/**
* @author gfh
*/
@FeignClient(value = ServerInfo.CS_HARMONIC_BOOT, path = "/event", fallbackFactory = EventFeignClientFallbackFactory.class,contextId = "event")
public interface EventFeignClient {
@PostMapping("/saveBatchEventList")
HttpResult<String> saveBatchEventList(@RequestBody List<CsEventPO> csEventPOS);
}

View File

@@ -0,0 +1,35 @@
package com.njcn.csharmonic.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.csharmonic.api.EventFeignClient;
import com.njcn.csharmonic.pojo.po.CsEventPO;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author gfh
*/
@Slf4j
@Component
public class EventFeignClientFallbackFactory implements FallbackFactory<EventFeignClient> {
@Override
public EventFeignClient create(Throwable cause) {
//判断抛出异常是否为解码器抛出的业务异常
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
if (cause.getCause() instanceof BusinessException) {
BusinessException businessException = (BusinessException) cause.getCause();
}
Enum<?> finalExceptionEnum = exceptionEnum;
return new EventFeignClient() {
@Override
public HttpResult<String> saveBatchEventList(List<CsEventPO> csEventPOS) {
log.error("{}异常,降级处理,异常为:{}","获取当天事件未读消息未读消息",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}