离线数据上传第一版代码提交

This commit is contained in:
guofeihu
2024-07-23 17:31:33 +08:00
parent a630792641
commit e27667c364
71 changed files with 7958 additions and 36 deletions

View File

@@ -0,0 +1,22 @@
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.EventUserFeignClientFallbackFactory;
import com.njcn.csharmonic.offline.vo.Response;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
* @author gfh
*/
@FeignClient(value = ServerInfo.CS_HARMONIC_BOOT, path = "/offlineDataUpload", fallbackFactory = EventUserFeignClientFallbackFactory.class,contextId = "offlineDataUpload")
public interface OfflineDataUploadFeignClient {
@PostMapping(value = "/uploadAnalysis",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
HttpResult<byte[]> uploadAnalysis(@RequestPart("files") List<MultipartFile> files,@RequestParam("type") String type);
}

View File

@@ -0,0 +1,36 @@
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.OfflineDataUploadFeignClient;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
* @author gfh
*/
@Slf4j
@Component
public class OfflineDataUploadFeignClientFallbackFactory implements FallbackFactory<OfflineDataUploadFeignClient> {
@Override
public OfflineDataUploadFeignClient create(Throwable cause) {
//判断抛出异常是否为解码器抛出的业务异常
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
if (cause.getCause() instanceof BusinessException) {
BusinessException businessException = (BusinessException) cause.getCause();
}
Enum<?> finalExceptionEnum = exceptionEnum;
return new OfflineDataUploadFeignClient() {
@Override
public HttpResult<byte[]> uploadAnalysis(List<MultipartFile> files,@RequestParam("type") String type) {
log.error("{}异常,降级处理,异常为:{}",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}