mirror of
https://github.com/hpd840321/starRiverProperty.git
synced 2026-06-09 08:20:31 +08:00
fix(v0.11): 第二轮走查 P1/P2(按模块优先级)
- davinci:DavinciResult.fail/success;FileManager Feign Fallback 结构化降级;FileStorageManagerImpl 对空 Result/Response 防御 - cwos-resource:RestPortalUserServiceImpl 消除静默 null,统一 CloudwalkResult.fail 与 getDefaultPwd 空串语义 - device-manager:DeviceConstant 改为 final 工具类 - aks:AksRespCodeConstant final + 私有构造 - ninca-crk:启动入口 SLF4J、显式 Feign 扫描包、SpringApplication 写法 - ninca-qk-alarm:main 简化、收窄 @EnableFeignClients(保持 netflix 注解以兼容当前 BOM) Made-with: Cursor
This commit is contained in:
+18
@@ -42,4 +42,22 @@ public class DavinciResult<T> implements Serializable {
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/** Feign 降级或本地失败路径使用的结构化失败体(不走异常控制流)。 */
|
||||
public static <T> DavinciResult<T> fail(String code, String message) {
|
||||
DavinciResult<T> r = new DavinciResult<>();
|
||||
r.setSuccess(false);
|
||||
r.setCode(code);
|
||||
r.setMessage(message);
|
||||
return r;
|
||||
}
|
||||
|
||||
public static <T> DavinciResult<T> success(T data) {
|
||||
DavinciResult<T> r = new DavinciResult<>();
|
||||
r.setSuccess(true);
|
||||
r.setCode("0");
|
||||
r.setMessage("ok");
|
||||
r.setData(data);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
+17
-7
@@ -2,7 +2,10 @@ package cn.cloudwalk.intelligent.davinci.storage.feign;
|
||||
|
||||
import cn.cloudwalk.intelligent.davinci.common.result.DavinciResult;
|
||||
import cn.cloudwalk.intelligent.davinci.storage.bean.file.dto.FileRemoveDTO;
|
||||
import feign.Request;
|
||||
import feign.Response;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -43,39 +46,46 @@ public interface FileManagerFeign {
|
||||
@Component
|
||||
class FileManagerFeignClientFallback implements FileManagerFeign {
|
||||
|
||||
private static final String FEIGN_DOWN = "DAVINCI_FEIGN_DOWN";
|
||||
|
||||
@Override
|
||||
public DavinciResult<String> fileUpload(MultipartFile file) {
|
||||
throw new RuntimeException("调用Davinci-portal服务,模块文件上传接口异常");
|
||||
return DavinciResult.fail(FEIGN_DOWN, "调用Davinci-portal服务,模块文件上传接口降级");
|
||||
}
|
||||
|
||||
@Override
|
||||
public DavinciResult<String> fileUpload(String moduleCategory, MultipartFile file) {
|
||||
throw new RuntimeException("调用Davinci-portal服务,模块文件上传接口异常");
|
||||
return DavinciResult.fail(FEIGN_DOWN, "调用Davinci-portal服务,模块文件上传接口降级");
|
||||
}
|
||||
|
||||
@Override
|
||||
public DavinciResult<String> bigFileUpload(MultipartFile file) {
|
||||
throw new RuntimeException("调用Davinci-portal服务,大文件上传接口异常");
|
||||
return DavinciResult.fail(FEIGN_DOWN, "调用Davinci-portal服务,大文件上传接口降级");
|
||||
}
|
||||
|
||||
@Override
|
||||
public DavinciResult<String> bigFileUpload(String moduleCategory, MultipartFile file) {
|
||||
throw new RuntimeException("调用Davinci-portal服务,大文件上传接口异常");
|
||||
return DavinciResult.fail(FEIGN_DOWN, "调用Davinci-portal服务,大文件上传接口降级");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response fileDownload(String path) {
|
||||
throw new RuntimeException("调用Davinci-portal服务,获取文件流接口异常");
|
||||
return Response.builder()
|
||||
.status(503)
|
||||
.reason("Feign fallback")
|
||||
.request(Request.create(Request.HttpMethod.GET, "/", Collections.emptyMap(), null, StandardCharsets.UTF_8))
|
||||
.body("{}", StandardCharsets.UTF_8)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DavinciResult<String> getFileData(String path) {
|
||||
throw new RuntimeException("调用Davinci-portal服务,获取获取文件Base64内容接口异常");
|
||||
return DavinciResult.fail(FEIGN_DOWN, "调用Davinci-portal服务,获取文件Base64内容接口降级");
|
||||
}
|
||||
|
||||
@Override
|
||||
public DavinciResult<List<String>> remove(FileRemoveDTO dto) {
|
||||
throw new RuntimeException("调用Davinci-portal服务,删除文件接口异常");
|
||||
return DavinciResult.fail(FEIGN_DOWN, "调用Davinci-portal服务,删除文件接口降级");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+21
-1
@@ -107,6 +107,12 @@ public class FileStorageManagerImpl implements FileStorageManager {
|
||||
}
|
||||
}
|
||||
|
||||
private static void requireDavinciResult(DavinciResult<?> result, String op) throws DavinciServiceException {
|
||||
if (result == null) {
|
||||
throw new DavinciServiceException("NULL_RESULT", "Davinci-portal 返回空结果: " + op);
|
||||
}
|
||||
}
|
||||
|
||||
private static InputStream attachResponseClose(InputStream bodyStream, Response response) {
|
||||
return new FilterInputStream(bodyStream) {
|
||||
@Override
|
||||
@@ -123,6 +129,7 @@ public class FileStorageManagerImpl implements FileStorageManager {
|
||||
@Override
|
||||
public String fileUpload(MultipartFile file) throws DavinciServiceException {
|
||||
DavinciResult<String> result = this.fileManagerFeign.fileUpload(file);
|
||||
requireDavinciResult(result, "fileUpload");
|
||||
if (result.isSuccess()) {
|
||||
return result.getData();
|
||||
}
|
||||
@@ -132,6 +139,7 @@ public class FileStorageManagerImpl implements FileStorageManager {
|
||||
@Override
|
||||
public String fileUpload(String moduleCategory, MultipartFile file) throws DavinciServiceException {
|
||||
DavinciResult<String> result = this.fileManagerFeign.fileUpload(moduleCategory, file);
|
||||
requireDavinciResult(result, "fileUpload(module)");
|
||||
if (result.isSuccess()) {
|
||||
return result.getData();
|
||||
}
|
||||
@@ -141,6 +149,7 @@ public class FileStorageManagerImpl implements FileStorageManager {
|
||||
@Override
|
||||
public String bigFileUpload(MultipartFile file) throws DavinciServiceException {
|
||||
DavinciResult<String> result = this.fileManagerFeign.bigFileUpload(file);
|
||||
requireDavinciResult(result, "bigFileUpload");
|
||||
if (result.isSuccess()) {
|
||||
return result.getData();
|
||||
}
|
||||
@@ -150,6 +159,7 @@ public class FileStorageManagerImpl implements FileStorageManager {
|
||||
@Override
|
||||
public String bigFileUpload(String moduleCategory, MultipartFile file) throws DavinciServiceException {
|
||||
DavinciResult<String> result = this.fileManagerFeign.bigFileUpload(moduleCategory, file);
|
||||
requireDavinciResult(result, "bigFileUpload(module)");
|
||||
if (result.isSuccess()) {
|
||||
return result.getData();
|
||||
}
|
||||
@@ -159,6 +169,9 @@ public class FileStorageManagerImpl implements FileStorageManager {
|
||||
@Override
|
||||
public byte[] fileDownload(String path) throws DavinciServiceException {
|
||||
try (Response response = this.fileManagerFeign.fileDownload(path)) {
|
||||
if (response == null) {
|
||||
return null;
|
||||
}
|
||||
if (response.body() == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -174,13 +187,18 @@ public class FileStorageManagerImpl implements FileStorageManager {
|
||||
public InputStream fileDownloadStream(String path) throws DavinciServiceException {
|
||||
Response response = this.fileManagerFeign.fileDownload(path);
|
||||
try {
|
||||
if (response == null) {
|
||||
return null;
|
||||
}
|
||||
if (response.body() == null) {
|
||||
response.close();
|
||||
return null;
|
||||
}
|
||||
return attachResponseClose(response.body().asInputStream(), response);
|
||||
} catch (IOException e) {
|
||||
response.close();
|
||||
if (response != null) {
|
||||
response.close();
|
||||
}
|
||||
throw new DavinciServiceException("FILE_DOWNLOAD_IO", "调用Davinci-portal服务,获取文件流接口异常");
|
||||
}
|
||||
}
|
||||
@@ -191,6 +209,7 @@ public class FileStorageManagerImpl implements FileStorageManager {
|
||||
return "";
|
||||
}
|
||||
DavinciResult<String> result = this.fileManagerFeign.getFileData(path);
|
||||
requireDavinciResult(result, "getFileData");
|
||||
if (result.isSuccess()) {
|
||||
return result.getData();
|
||||
}
|
||||
@@ -200,6 +219,7 @@ public class FileStorageManagerImpl implements FileStorageManager {
|
||||
@Override
|
||||
public List<String> remove(FileRemoveDTO dto) throws DavinciServiceException {
|
||||
DavinciResult<List<String>> result = this.fileManagerRestFeign.remove(dto);
|
||||
requireDavinciResult(result, "remove");
|
||||
if (result.isSuccess()) {
|
||||
return result.getData();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user