diff --git a/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java b/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java index 52a62462f4..b2ea0cf6d5 100644 --- a/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java +++ b/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java @@ -9,10 +9,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import io.dataease.api.dataset.dto.PreviewSqlDTO; import io.dataease.api.ds.DatasourceApi; -import io.dataease.api.ds.vo.ApiDefinition; -import io.dataease.api.ds.vo.CoreDatasourceTaskLogDTO; -import io.dataease.api.ds.vo.ExcelFileData; -import io.dataease.api.ds.vo.ExcelSheetData; +import io.dataease.api.ds.vo.*; import io.dataease.api.permissions.relation.api.RelationApi; import io.dataease.commons.constants.TaskStatus; import io.dataease.constant.LogOT; @@ -92,7 +89,6 @@ public class DatasourceServer implements DatasourceApi { @Resource private TaskLogExtMapper taskLogExtMapper; private static final ObjectMapper objectMapper = new ObjectMapper(); - @Resource private DataSourceManage dataSourceManage; @Resource @@ -103,61 +99,32 @@ public class DatasourceServer implements DatasourceApi { private CoreDsFinishPageMapper coreDsFinishPageMapper; @Resource private DatasetDataManage datasetDataManage; - @Resource private ScheduleManager scheduleManager; @Resource private CoreUserManage coreUserManage; - @Autowired(required = false) private PluginManageApi pluginManage; @Autowired(required = false) private RelationApi relationManage; + public enum UpdateType { + all_scope, add_scope + } + private TypeReference> listTypeReference = new TypeReference>() { + }; + @Resource + private CommonThreadPool commonThreadPool; + private boolean isUpdatingStatus = false; + private static List syncDsIds = new ArrayList<>(); + + @Override public List query(String keyWord) { return null; } - public enum UpdateType { - all_scope, add_scope - } - - private TypeReference> listTypeReference = new TypeReference>() { - }; - @Resource - private CommonThreadPool commonThreadPool; - - private boolean isUpdatingStatus = false; - - private static List syncDsIds = new ArrayList<>(); - - private void getParents(Long pid, List ids) { - CoreDatasource parent = datasourceMapper.selectById(pid);// 查找父级folder - ids.add(parent.getId()); - if (parent.getPid() != null && parent.getPid() != 0) { - getParents(parent.getPid(), ids); - } - } - - private void filterDs(List busiNodeVOS, List ids, String type, Long id) { - for (BusiNodeVO busiNodeVO : busiNodeVOS) { - if (busiNodeVO.getType() != null && busiNodeVO.getType().equalsIgnoreCase(type)) { - if (id != null) { - if (!busiNodeVO.getId().equals(id)) { - ids.add(busiNodeVO.getId()); - } - } else { - ids.add(busiNodeVO.getId()); - } - } - if (CollectionUtils.isNotEmpty(busiNodeVO.getChildren())) { - filterDs(busiNodeVO.getChildren(), ids, type, id); - } - } - } - - public boolean checkRepeat(@RequestBody DatasourceDTO dataSourceDTO) { + public boolean checkRepeat(@RequestBody BusiDsRequest dataSourceDTO) { if (Arrays.asList("API", "Excel", "folder").contains(dataSourceDTO.getType())) { return false; } @@ -211,7 +178,9 @@ public class DatasourceServer implements DatasourceApi { @DeLog(id = "#p0.id", ot = LogOT.MODIFY, st = LogST.DATASOURCE) @Transactional - public DatasourceDTO move(DatasourceDTO dataSourceDTO) { + public DatasourceDTO move(BusiDsRequest busiDsRequest) { + DatasourceDTO dataSourceDTO = new DatasourceDTO(); + BeanUtils.copyBean(dataSourceDTO, busiDsRequest); if (dataSourceDTO.getPid() == null) { DEException.throwException("目录必选!"); } @@ -230,7 +199,9 @@ public class DatasourceServer implements DatasourceApi { } @Transactional - public DatasourceDTO reName(DatasourceDTO dataSourceDTO) { + public DatasourceDTO reName(BusiDsRequest busiDsRequest) { + DatasourceDTO dataSourceDTO = new DatasourceDTO(); + BeanUtils.copyBean(dataSourceDTO, busiDsRequest); if (StringUtils.isEmpty(dataSourceDTO.getName())) { DEException.throwException("名称不能为空!"); } @@ -243,7 +214,9 @@ public class DatasourceServer implements DatasourceApi { @DeLog(id = "#p0.id", pid = "#p0.pid", ot = LogOT.CREATE, st = LogST.DATASOURCE) @Transactional - public DatasourceDTO createFolder(DatasourceDTO dataSourceDTO) { + public DatasourceDTO createFolder(BusiDsRequest busiDsRequest) { + DatasourceDTO dataSourceDTO = new DatasourceDTO(); + BeanUtils.copyBean(dataSourceDTO, busiDsRequest); dataSourceDTO.setCreateTime(System.currentTimeMillis()); dataSourceDTO.setUpdateTime(System.currentTimeMillis()); dataSourceDTO.setType(dataSourceDTO.getNodeType()); @@ -256,9 +229,11 @@ public class DatasourceServer implements DatasourceApi { @DeLog(id = "#p0.id", pid = "#p0.pid", ot = LogOT.CREATE, st = LogST.DATASOURCE) @Transactional @Override - public DatasourceDTO save(DatasourceDTO dataSourceDTO) throws DEException { + public DatasourceDTO save(BusiDsRequest busiDsRequest) throws DEException { + DatasourceDTO dataSourceDTO = new DatasourceDTO(); + BeanUtils.copyBean(dataSourceDTO, busiDsRequest); if (dataSourceDTO.getId() != null && dataSourceDTO.getId() > 0) { - return update(dataSourceDTO); + return update(busiDsRequest); } if (StringUtils.isNotEmpty(dataSourceDTO.getConfiguration())) { dataSourceDTO.setConfiguration(new String(Base64.getDecoder().decode(dataSourceDTO.getConfiguration()))); @@ -337,10 +312,12 @@ public class DatasourceServer implements DatasourceApi { @DeLog(id = "#p0.id", ot = LogOT.MODIFY, st = LogST.DATASOURCE) @Transactional @Override - public DatasourceDTO update(DatasourceDTO dataSourceDTO) throws DEException { + public DatasourceDTO update(BusiDsRequest busiDsRequest) throws DEException { + DatasourceDTO dataSourceDTO = new DatasourceDTO(); + BeanUtils.copyBean(dataSourceDTO, busiDsRequest); Long pk = null; if (ObjectUtils.isEmpty(pk = dataSourceDTO.getId())) { - return save(dataSourceDTO); + return save(busiDsRequest); } DatasourceDTO sourceData = dataSourceManage.getDs(pk); dataSourceDTO.setConfiguration(new String(Base64.getDecoder().decode(dataSourceDTO.getConfiguration()))); @@ -461,35 +438,6 @@ public class DatasourceServer implements DatasourceApi { return dataSourceDTO; } - private static void checkParams(String configurationStr) { - DatasourceConfiguration configuration = JsonUtil.parseObject(configurationStr, DatasourceConfiguration.class); - if (configuration.getInitialPoolSize() < configuration.getMinPoolSize()) { - DEException.throwException("初始连接数不能小于最小连接数!"); - } - if (configuration.getInitialPoolSize() > configuration.getMaxPoolSize()) { - DEException.throwException("初始连接数不能大于最大连接数!"); - } - if (configuration.getMaxPoolSize() < configuration.getMinPoolSize()) { - DEException.throwException("最大连接数不能小于最小连接数!"); - } - if (configuration.getQueryTimeout() < 0) { - DEException.throwException("查询超时不能小于0!"); - } - } - - private static void checkName(List tables) { - for (int i = 0; i < tables.size() - 1; i++) { - for (int j = i + 1; j < tables.size(); j++) { - if (tables.get(i).equalsIgnoreCase(tables.get(j))) { - DEException.throwException(Translator.get("i18n_table_name_repeat") + tables.get(i)); - } - } - } - } - - private String excelDataTableName(String name) { - return StringUtils.substring(name, 6, name.length() - 11); - } @Override public List datasourceTypes() { @@ -497,7 +445,9 @@ public class DatasourceServer implements DatasourceApi { } @Override - public DatasourceDTO validate(DatasourceDTO dataSourceDTO) throws DEException { + public DatasourceDTO validate(BusiDsRequest busiDsRequest) throws DEException { + DatasourceDTO dataSourceDTO = new DatasourceDTO(); + BeanUtils.copyBean(dataSourceDTO, busiDsRequest); dataSourceDTO.setConfiguration(new String(Base64.getDecoder().decode(dataSourceDTO.getConfiguration()))); CoreDatasource coreDatasource = new CoreDatasource(); BeanUtils.copyBean(coreDatasource, dataSourceDTO); @@ -509,7 +459,7 @@ public class DatasourceServer implements DatasourceApi { } @Override - public List getSchema(DatasourceDTO dataSourceDTO) throws DEException { + public List getSchema(BusiDsRequest dataSourceDTO) throws DEException { dataSourceDTO.setConfiguration(new String(Base64.getDecoder().decode(dataSourceDTO.getConfiguration()))); CoreDatasource coreDatasource = new CoreDatasource(); BeanUtils.copyBean(coreDatasource, dataSourceDTO); @@ -563,90 +513,6 @@ public class DatasourceServer implements DatasourceApi { return list; } - private DatasourceDTO getDatasourceDTOById(Long datasourceId, boolean hidePw) throws DEException { - CoreDatasource datasource = datasourceMapper.selectById(datasourceId); - if (datasource == null) { - DEException.throwException("不存在的数据源!"); - } - return convertCoreDatasource(datasourceId, hidePw, datasource); - } - - private DatasourceDTO convertCoreDatasource(Long datasourceId, boolean hidePw, CoreDatasource datasource) { - DatasourceDTO datasourceDTO = new DatasourceDTO(); - BeanUtils.copyBean(datasourceDTO, datasource); - - if (datasourceDTO.getType().equalsIgnoreCase(DatasourceConfiguration.DatasourceType.API.toString())) { - List apiDefinitionList = JsonUtil.parseList(datasourceDTO.getConfiguration(), listTypeReference); - List apiDefinitionListWithStatus = new ArrayList<>(); - List params = new ArrayList<>(); - int success = 0; - for (ApiDefinition apiDefinition : apiDefinitionList) { - String status = null; - if (StringUtils.isNotEmpty(datasourceDTO.getStatus())) { - JsonNode jsonNode = null; - try { - jsonNode = objectMapper.readTree(datasourceDTO.getStatus()); - } catch (Exception e) { - DEException.throwException(e); - } - for (JsonNode node : jsonNode) { - if (node.get("name").asText().equals(apiDefinition.getName())) { - status = node.get("status").asText(); - } - } - apiDefinition.setStatus(status); - } - if (StringUtils.isNotEmpty(status) && status.equalsIgnoreCase("Success")) { - success++; - } - CoreDatasourceTaskLog log = datasourceTaskServer.lastSyncLogForTable(datasourceId, apiDefinition.getDeTableName()); - if (log != null) { - apiDefinition.setUpdateTime(log.getStartTime()); - } - - - if (StringUtils.isEmpty(apiDefinition.getType()) || apiDefinition.getType().equalsIgnoreCase("table")) { - apiDefinitionListWithStatus.add(apiDefinition); - } else { - params.add(apiDefinition); - } - } - datasourceDTO.setApiConfigurationStr(new String(Base64.getEncoder().encode(Objects.requireNonNull(JsonUtil.toJSONString(apiDefinitionListWithStatus)).toString().getBytes()))); - datasourceDTO.setParamsStr(new String(Base64.getEncoder().encode(Objects.requireNonNull(JsonUtil.toJSONString(params)).toString().getBytes()))); - if (success == apiDefinitionList.size()) { - datasourceDTO.setStatus("Success"); - } else { - if (success > 0 && success < apiDefinitionList.size()) { - datasourceDTO.setStatus("Warning"); - } else { - datasourceDTO.setStatus("Error"); - } - } - CoreDatasourceTask coreDatasourceTask = datasourceTaskServer.selectByDSId(datasourceDTO.getId()); - TaskDTO taskDTO = new TaskDTO(); - BeanUtils.copyBean(taskDTO, coreDatasourceTask); - datasourceDTO.setSyncSetting(taskDTO); - - CoreDatasourceTask task = datasourceTaskServer.selectByDSId(datasourceDTO.getId()); - if (task != null) { - datasourceDTO.setLastSyncTime(task.getStartTime()); - } - } else { - if (hidePw) { - Provider provider = ProviderFactory.getProvider(datasourceDTO.getType()); - provider.hidePW(datasourceDTO); - } - - } - if (datasourceDTO.getType().equalsIgnoreCase(DatasourceConfiguration.DatasourceType.Excel.toString())) { - datasourceDTO.setFileName(ExcelUtils.getFileName(datasource)); - datasourceDTO.setSize(ExcelUtils.getSize(datasource)); - } - datasourceDTO.setConfiguration(new String(Base64.getEncoder().encode(datasourceDTO.getConfiguration().getBytes()))); - datasourceDTO.setCreator(coreUserManage.getUserName(Long.valueOf(datasourceDTO.getCreateBy()))); - return datasourceDTO; - } - @Override public boolean perDelete(Long id) { if (LicenseUtil.licenseValid()) { @@ -758,25 +624,6 @@ public class DatasourceServer implements DatasourceApi { cron, new Date(System.currentTimeMillis()), null, new JobDataMap()); } - private DatasourceDTO validate(CoreDatasource coreDatasource) { - DatasourceDTO datasourceDTO = new DatasourceDTO(); - BeanUtils.copyBean(datasourceDTO, coreDatasource); - try { - checkDatasourceStatus(datasourceDTO); - if (!Arrays.asList("API", "Excel", "folder").contains(coreDatasource.getType())) { - calciteProvider.updateDsPoolAfterCheckStatus(datasourceDTO); - } - } catch (Exception e) { - coreDatasource.setStatus("Error"); - DEException.throwException(e.getMessage()); - } finally { - coreDatasource.setStatus(datasourceDTO.getStatus()); - dataSourceManage.innerEditStatus(coreDatasource); - } - datasourceDTO.setConfiguration(""); - return datasourceDTO; - } - @Override public List tree(BusiNodeRequest request) throws DEException { return dataSourceManage.tree(request); @@ -1044,8 +891,6 @@ public class DatasourceServer implements DatasourceApi { } public IPage listSyncRecord(int goPage, int pageSize, Long dsId) { - - QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("ds_id", dsId); wrapper.orderByDesc("start_time"); @@ -1149,4 +994,163 @@ public class DatasourceServer implements DatasourceApi { BeanUtils.copyBean(datasourceDTO, record); return datasourceDTO; } + + private void getParents(Long pid, List ids) { + CoreDatasource parent = datasourceMapper.selectById(pid);// 查找父级folder + ids.add(parent.getId()); + if (parent.getPid() != null && parent.getPid() != 0) { + getParents(parent.getPid(), ids); + } + } + + private void filterDs(List busiNodeVOS, List ids, String type, Long id) { + for (BusiNodeVO busiNodeVO : busiNodeVOS) { + if (busiNodeVO.getType() != null && busiNodeVO.getType().equalsIgnoreCase(type)) { + if (id != null) { + if (!busiNodeVO.getId().equals(id)) { + ids.add(busiNodeVO.getId()); + } + } else { + ids.add(busiNodeVO.getId()); + } + } + if (CollectionUtils.isNotEmpty(busiNodeVO.getChildren())) { + filterDs(busiNodeVO.getChildren(), ids, type, id); + } + } + } + + private static void checkParams(String configurationStr) { + DatasourceConfiguration configuration = JsonUtil.parseObject(configurationStr, DatasourceConfiguration.class); + if (configuration.getInitialPoolSize() < configuration.getMinPoolSize()) { + DEException.throwException("初始连接数不能小于最小连接数!"); + } + if (configuration.getInitialPoolSize() > configuration.getMaxPoolSize()) { + DEException.throwException("初始连接数不能大于最大连接数!"); + } + if (configuration.getMaxPoolSize() < configuration.getMinPoolSize()) { + DEException.throwException("最大连接数不能小于最小连接数!"); + } + if (configuration.getQueryTimeout() < 0) { + DEException.throwException("查询超时不能小于0!"); + } + } + + private static void checkName(List tables) { + for (int i = 0; i < tables.size() - 1; i++) { + for (int j = i + 1; j < tables.size(); j++) { + if (tables.get(i).equalsIgnoreCase(tables.get(j))) { + DEException.throwException(Translator.get("i18n_table_name_repeat") + tables.get(i)); + } + } + } + } + + private String excelDataTableName(String name) { + return StringUtils.substring(name, 6, name.length() - 11); + } + + private DatasourceDTO getDatasourceDTOById(Long datasourceId, boolean hidePw) throws DEException { + CoreDatasource datasource = datasourceMapper.selectById(datasourceId); + if (datasource == null) { + DEException.throwException("不存在的数据源!"); + } + return convertCoreDatasource(datasourceId, hidePw, datasource); + } + + private DatasourceDTO convertCoreDatasource(Long datasourceId, boolean hidePw, CoreDatasource datasource) { + DatasourceDTO datasourceDTO = new DatasourceDTO(); + BeanUtils.copyBean(datasourceDTO, datasource); + + if (datasourceDTO.getType().equalsIgnoreCase(DatasourceConfiguration.DatasourceType.API.toString())) { + List apiDefinitionList = JsonUtil.parseList(datasourceDTO.getConfiguration(), listTypeReference); + List apiDefinitionListWithStatus = new ArrayList<>(); + List params = new ArrayList<>(); + int success = 0; + for (ApiDefinition apiDefinition : apiDefinitionList) { + String status = null; + if (StringUtils.isNotEmpty(datasourceDTO.getStatus())) { + JsonNode jsonNode = null; + try { + jsonNode = objectMapper.readTree(datasourceDTO.getStatus()); + } catch (Exception e) { + DEException.throwException(e); + } + for (JsonNode node : jsonNode) { + if (node.get("name").asText().equals(apiDefinition.getName())) { + status = node.get("status").asText(); + } + } + apiDefinition.setStatus(status); + } + if (StringUtils.isNotEmpty(status) && status.equalsIgnoreCase("Success")) { + success++; + } + CoreDatasourceTaskLog log = datasourceTaskServer.lastSyncLogForTable(datasourceId, apiDefinition.getDeTableName()); + if (log != null) { + apiDefinition.setUpdateTime(log.getStartTime()); + } + + + if (StringUtils.isEmpty(apiDefinition.getType()) || apiDefinition.getType().equalsIgnoreCase("table")) { + apiDefinitionListWithStatus.add(apiDefinition); + } else { + params.add(apiDefinition); + } + } + datasourceDTO.setApiConfigurationStr(new String(Base64.getEncoder().encode(Objects.requireNonNull(JsonUtil.toJSONString(apiDefinitionListWithStatus)).toString().getBytes()))); + datasourceDTO.setParamsStr(new String(Base64.getEncoder().encode(Objects.requireNonNull(JsonUtil.toJSONString(params)).toString().getBytes()))); + if (success == apiDefinitionList.size()) { + datasourceDTO.setStatus("Success"); + } else { + if (success > 0 && success < apiDefinitionList.size()) { + datasourceDTO.setStatus("Warning"); + } else { + datasourceDTO.setStatus("Error"); + } + } + CoreDatasourceTask coreDatasourceTask = datasourceTaskServer.selectByDSId(datasourceDTO.getId()); + TaskDTO taskDTO = new TaskDTO(); + BeanUtils.copyBean(taskDTO, coreDatasourceTask); + datasourceDTO.setSyncSetting(taskDTO); + + CoreDatasourceTask task = datasourceTaskServer.selectByDSId(datasourceDTO.getId()); + if (task != null) { + datasourceDTO.setLastSyncTime(task.getStartTime()); + } + } else { + if (hidePw) { + Provider provider = ProviderFactory.getProvider(datasourceDTO.getType()); + provider.hidePW(datasourceDTO); + } + + } + if (datasourceDTO.getType().equalsIgnoreCase(DatasourceConfiguration.DatasourceType.Excel.toString())) { + datasourceDTO.setFileName(ExcelUtils.getFileName(datasource)); + datasourceDTO.setSize(ExcelUtils.getSize(datasource)); + } + datasourceDTO.setConfiguration(new String(Base64.getEncoder().encode(datasourceDTO.getConfiguration().getBytes()))); + datasourceDTO.setCreator(coreUserManage.getUserName(Long.valueOf(datasourceDTO.getCreateBy()))); + return datasourceDTO; + } + + private DatasourceDTO validate(CoreDatasource coreDatasource) { + DatasourceDTO datasourceDTO = new DatasourceDTO(); + BeanUtils.copyBean(datasourceDTO, coreDatasource); + try { + checkDatasourceStatus(datasourceDTO); + if (!Arrays.asList("API", "Excel", "folder").contains(coreDatasource.getType())) { + calciteProvider.updateDsPoolAfterCheckStatus(datasourceDTO); + } + } catch (Exception e) { + coreDatasource.setStatus("Error"); + DEException.throwException(e.getMessage()); + } finally { + coreDatasource.setStatus(datasourceDTO.getStatus()); + dataSourceManage.innerEditStatus(coreDatasource); + } + datasourceDTO.setConfiguration(""); + return datasourceDTO; + } + } diff --git a/core/core-frontend/src/views/visualized/data/dataset/ExportExcel.vue b/core/core-frontend/src/views/visualized/data/dataset/ExportExcel.vue index 0f8bffbf2f..6395deeba9 100644 --- a/core/core-frontend/src/views/visualized/data/dataset/ExportExcel.vue +++ b/core/core-frontend/src/views/visualized/data/dataset/ExportExcel.vue @@ -452,6 +452,11 @@ defineExpose({ + + +