fix: 【数据源】数据源新增对远程 Excel/CSV 的支持 #14681

This commit is contained in:
taojinlong
2025-03-05 15:03:06 +08:00
committed by taojinlong
parent 5cb31d140e
commit 8d4922d88a
2 changed files with 11 additions and 13 deletions

View File

@@ -115,6 +115,8 @@ public class DatasourceServer implements DatasourceApi {
all_scope, add_scope
}
public static final List<String> notFullDs = List.of("folder", "Excel", "API");
private TypeReference<List<ApiDefinition>> listTypeReference = new TypeReference<List<ApiDefinition>>() {
};
@Resource
@@ -152,7 +154,7 @@ public class DatasourceServer implements DatasourceApi {
DatasourceConfiguration configuration = JsonUtil.parseObject(dataSourceDTO.getConfiguration(), DatasourceConfiguration.class);
boolean hasRepeat = false;
for (CoreDatasource datasource : datasources) {
if (Arrays.asList("API", "Excel", "folder").contains(datasource.getType())) {
if (notFullDs.stream().anyMatch(e -> datasource.getType().contains(e))) {
continue;
}
if (StringUtils.isEmpty(datasource.getConfiguration())) {
@@ -699,9 +701,8 @@ public class DatasourceServer implements DatasourceApi {
datasourceTaskServer.deleteByDSId(datasourceId);
}
datasourceMapper.deleteById(datasourceId);
if (!Arrays.asList("API", "Excel", "folder", "APILark", "ExcelRemote").contains(coreDatasource.getType())) {
if (notFullDs.stream().allMatch(e -> !coreDatasource.getType().contains(e))) {
calciteProvider.delete(coreDatasource);
}

View File

@@ -67,6 +67,7 @@ public class HttpClientUtil {
throw new DEException(SYSTEM_INNER_ERROR.code(), "HttpClient查询失败: " + e.getMessage());
}
}
private static CloseableHttpClient buildHttpClient(boolean ssl) {
try {
if (ssl) {
@@ -381,17 +382,13 @@ public class HttpClientUtil {
String tranName = UUID.randomUUID().toString() + "." + suffix;
name.put("fileName", fileName);
name.put("tranName", tranName);
try {
FileOutputStream outputStream = new FileOutputStream(path + tranName);
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = response.getEntity().getContent().read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
} finally {
File localFile = new File(path + tranName);
FileOutputStream outputStream = new FileOutputStream(localFile);
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = response.getEntity().getContent().read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
} catch (Exception e) {
logger.error("HttpClient查询失败", e);
throw new RuntimeException("HttpClient查询失败: " + e.getMessage(), e);