Merge pull request #4448 from dataease/pr@dev@pages

feat: 修改API 数据集名称时,同步修改数据集里的表名
This commit is contained in:
taojinlong
2023-02-01 17:11:21 +08:00
committed by GitHub
3 changed files with 32 additions and 8 deletions

View File

@@ -26,5 +26,7 @@ public class ApiDefinition {
private boolean useJsonPath;
private String jsonPath;
private boolean showApiStructure;
private boolean reName = false;
private String orgName;
}

View File

@@ -284,7 +284,6 @@ public class DatasourceService {
datasource.setUpdateTime(System.currentTimeMillis());
Provider datasourceProvider = ProviderFactory.getProvider(updataDsRequest.getType());
datasourceProvider.checkConfiguration(datasource);
checkAndUpdateDatasourceStatus(datasource);
updateDatasource(updataDsRequest.getId(), datasource);
}
@@ -295,6 +294,28 @@ public class DatasourceService {
checkAndUpdateDatasourceStatus(datasource);
datasourceMapper.updateByExampleSelective(datasource, example);
handleConnectionPool(id);
if (datasource.getType().equalsIgnoreCase("api")) {
DatasetTableExample datasetTableExample = new DatasetTableExample();
datasetTableExample.createCriteria().andDataSourceIdEqualTo(id);
List<DatasetTable> datasetTables = datasetTableMapper.selectByExample(datasetTableExample);
List<ApiDefinition> apiDefinitionList = new Gson().fromJson(datasource.getConfiguration(), new TypeToken<List<ApiDefinition>>() {}.getType());
apiDefinitionList.forEach(apiDefinition -> {
if(apiDefinition.isReName()){
datasetTables.forEach(datasetTable -> {
if(new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class).getTable().equals(apiDefinition.getOrgName())){
DatasetTable record = new DatasetTable();
DataTableInfoDTO dataTableInfoDTO = new DataTableInfoDTO();
dataTableInfoDTO.setTable(apiDefinition.getName());
record.setInfo(new Gson().toJson(dataTableInfoDTO));
datasetTableExample.clear();
datasetTableExample.createCriteria().andIdEqualTo(datasetTable.getId());
datasetTableMapper.updateByExampleSelective(record, datasetTableExample);
}
});
}
});
}
}
private void handleConnectionPool(String datasourceId) {