mirror of
https://github.com/dataease/dataease.git
synced 2025-02-24 11:32:57 +08:00
feat(数据源): 数据源删除、移动报错
This commit is contained in:
parent
8826051ce0
commit
b53206a2b5
@ -1,6 +1,7 @@
|
||||
package io.dataease.datasource.dao.ext.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import io.dataease.datasource.dao.ext.po.DsItem;
|
||||
import io.dataease.datasource.dto.DatasourceNodePO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@ -17,4 +18,7 @@ public interface CoreDatasourceExtMapper {
|
||||
""")
|
||||
List<DatasourceNodePO> query(@Param("ew") QueryWrapper queryWrapper);
|
||||
|
||||
|
||||
@Select("select id, pid from core_datasource where id = #{id}")
|
||||
DsItem queryItem(@Param("id") Long id);
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
package io.dataease.datasource.dao.ext.po;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class DsItem implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 370886385725258461L;
|
||||
|
||||
private Long id;
|
||||
|
||||
private Long pid;
|
||||
}
|
@ -7,8 +7,10 @@ import io.dataease.commons.constants.TaskStatus;
|
||||
import io.dataease.constant.DataSourceType;
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDatasource;
|
||||
import io.dataease.datasource.dao.auto.mapper.CoreDatasourceMapper;
|
||||
import io.dataease.datasource.dao.ext.mapper.CoreDatasourceExtMapper;
|
||||
import io.dataease.datasource.dao.ext.mapper.DataSourceExtMapper;
|
||||
import io.dataease.datasource.dao.ext.po.DataSourceNodePO;
|
||||
import io.dataease.datasource.dao.ext.po.DsItem;
|
||||
import io.dataease.datasource.dto.DatasourceNodeBO;
|
||||
import io.dataease.exception.DEException;
|
||||
import io.dataease.extensions.datasource.dto.DatasourceDTO;
|
||||
@ -29,6 +31,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
@Component
|
||||
public class DataSourceManage {
|
||||
@ -43,6 +46,9 @@ public class DataSourceManage {
|
||||
@Resource
|
||||
private CoreOptRecentManage coreOptRecentManage;
|
||||
|
||||
@Resource
|
||||
private CoreDatasourceExtMapper coreDatasourceExtMapper;
|
||||
|
||||
private DatasourceNodeBO rootNode() {
|
||||
return new DatasourceNodeBO(0L, "root", false, 7, -1L, 0, "mysql");
|
||||
}
|
||||
@ -168,6 +174,31 @@ public class DataSourceManage {
|
||||
return coreDatasourceMapper.selectById(id);
|
||||
}
|
||||
|
||||
public List<Long> getPidList(Long pid) {
|
||||
if (ObjectUtils.isEmpty(pid) || pid.equals(0L)) {
|
||||
return null;
|
||||
}
|
||||
List<Long> result = new ArrayList<>();
|
||||
Stack<Long> stack = new Stack<>();
|
||||
stack.push(pid);
|
||||
while (!stack.isEmpty()) {
|
||||
Long cid = stack.pop();
|
||||
DsItem item = coreDatasourceExtMapper.queryItem(cid);
|
||||
if (ObjectUtils.isNotEmpty(item)) {
|
||||
result.add(cid);
|
||||
Long cpid = null;
|
||||
if (ObjectUtils.isNotEmpty(cpid = item.getPid()) && !cpid.equals(0L)) {
|
||||
stack.add(cpid);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public CoreDatasource getDatasource(Long id) {
|
||||
return getCoreDatasource(id);
|
||||
}
|
||||
|
||||
public DatasourceDTO getDs(Long id) {
|
||||
CoreDatasource coreDatasource = getCoreDatasource(id);
|
||||
DatasourceDTO dto = new DatasourceDTO();
|
||||
|
@ -189,9 +189,8 @@ public class DatasourceServer implements DatasourceApi {
|
||||
DEException.throwException(Translator.get("i18n_pid_not_eq_id"));
|
||||
}
|
||||
if (dataSourceDTO.getPid() != 0) {
|
||||
List<Long> ids = new ArrayList<>();
|
||||
getParents(dataSourceDTO.getPid(), ids);
|
||||
if (ids.contains(dataSourceDTO.getId())) {
|
||||
List<Long> pidList = dataSourceManage.getPidList(dataSourceDTO.getPid());
|
||||
if (pidList.contains(dataSourceDTO.getId())) {
|
||||
DEException.throwException(Translator.get("i18n_pid_not_eq_id"));
|
||||
}
|
||||
}
|
||||
@ -571,7 +570,7 @@ public class DatasourceServer implements DatasourceApi {
|
||||
}
|
||||
|
||||
public void recursionDel(Long datasourceId) throws DEException {
|
||||
CoreDatasource coreDatasource = dataSourceManage.getCoreDatasource(datasourceId);
|
||||
CoreDatasource coreDatasource = dataSourceManage.getDatasource(datasourceId);
|
||||
if (ObjectUtils.isEmpty(coreDatasource)) {
|
||||
return;
|
||||
}
|
||||
@ -1065,13 +1064,6 @@ public class DatasourceServer implements DatasourceApi {
|
||||
return datasourceDTO;
|
||||
}
|
||||
|
||||
private void getParents(Long pid, List<Long> ids) {
|
||||
CoreDatasource parent = dataSourceManage.getCoreDatasource(pid);// 查找父级folder
|
||||
ids.add(parent.getId());
|
||||
if (parent.getPid() != null && parent.getPid() != 0) {
|
||||
getParents(parent.getPid(), ids);
|
||||
}
|
||||
}
|
||||
|
||||
private void filterDs(List<BusiNodeVO> busiNodeVOS, List<Long> ids, String type, Long id) {
|
||||
for (BusiNodeVO busiNodeVO : busiNodeVOS) {
|
||||
|
Loading…
Reference in New Issue
Block a user