feat(数据集): 数据库表不能重复添加到数据集
This commit is contained in:
parent
ec9cde55b6
commit
5fd3554a1d
@ -6,6 +6,7 @@ import io.dataease.base.domain.Datasource;
|
||||
import io.dataease.commons.utils.PageUtils;
|
||||
import io.dataease.commons.utils.Pager;
|
||||
import io.dataease.controller.sys.base.BaseGridRequest;
|
||||
import io.dataease.datasource.dto.DBTableDTO;
|
||||
import io.dataease.datasource.service.DatasourceService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -52,7 +53,7 @@ public class DatasourceController {
|
||||
}
|
||||
|
||||
@PostMapping("/getTables")
|
||||
public List<String> getTables(@RequestBody Datasource datasource) throws Exception {
|
||||
public List<DBTableDTO> getTables(@RequestBody Datasource datasource) throws Exception {
|
||||
return datasourceService.getTables(datasource);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
package io.dataease.datasource.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* @Author gin
|
||||
* @Date 2021/4/30 10:57 上午
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class DBTableDTO {
|
||||
private String datasourceId;
|
||||
private String name;
|
||||
private boolean enableCheck;
|
||||
private String datasetPath;
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
package io.dataease.datasource.service;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.dataease.base.domain.*;
|
||||
import io.dataease.base.mapper.*;
|
||||
import io.dataease.base.mapper.ext.ExtDataSourceMapper;
|
||||
@ -7,15 +8,19 @@ import io.dataease.base.mapper.ext.query.GridExample;
|
||||
import io.dataease.commons.exception.DEException;
|
||||
import io.dataease.commons.utils.CommonThreadPool;
|
||||
import io.dataease.controller.sys.base.BaseGridRequest;
|
||||
import io.dataease.datasource.dto.DBTableDTO;
|
||||
import io.dataease.datasource.provider.DatasourceProvider;
|
||||
import io.dataease.datasource.provider.ProviderFactory;
|
||||
import io.dataease.datasource.request.DatasourceRequest;
|
||||
import io.dataease.dto.dataset.DataTableInfoDTO;
|
||||
import io.dataease.service.dataset.DataSetGroupService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -29,6 +34,10 @@ public class DatasourceService {
|
||||
private CommonThreadPool commonThreadPool;
|
||||
@Resource
|
||||
private ExtDataSourceMapper extDataSourceMapper;
|
||||
@Resource
|
||||
private DatasetTableMapper datasetTableMapper;
|
||||
@Resource
|
||||
private DataSetGroupService dataSetGroupService;
|
||||
|
||||
public Datasource addDatasource(Datasource datasource) {
|
||||
DatasourceExample example = new DatasourceExample();
|
||||
@ -57,7 +66,7 @@ public class DatasourceService {
|
||||
return datasourceMapper.selectByExampleWithBLOBs(example);
|
||||
}
|
||||
|
||||
public List<Datasource> gridQuery(BaseGridRequest request){
|
||||
public List<Datasource> gridQuery(BaseGridRequest request) {
|
||||
GridExample gridExample = request.convertExample();
|
||||
return extDataSourceMapper.query(gridExample);
|
||||
}
|
||||
@ -79,12 +88,40 @@ public class DatasourceService {
|
||||
datasourceProvider.test(datasourceRequest);
|
||||
}
|
||||
|
||||
public List<String> getTables(Datasource datasource) throws Exception {
|
||||
public List<DBTableDTO> getTables(Datasource datasource) throws Exception {
|
||||
Datasource ds = datasourceMapper.selectByPrimaryKey(datasource.getId());
|
||||
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType());
|
||||
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
||||
datasourceRequest.setDatasource(ds);
|
||||
return datasourceProvider.getTables(datasourceRequest);
|
||||
List<String> tables = datasourceProvider.getTables(datasourceRequest);
|
||||
|
||||
// 获取当前数据源下的db类型数据集
|
||||
DatasetTableExample datasetTableExample = new DatasetTableExample();
|
||||
datasetTableExample.createCriteria().andTypeEqualTo("db").andDataSourceIdEqualTo(datasource.getId());
|
||||
List<DatasetTable> datasetTables = datasetTableMapper.selectByExampleWithBLOBs(datasetTableExample);
|
||||
List<DBTableDTO> list = new ArrayList<>();
|
||||
for (String name : tables) {
|
||||
DBTableDTO dbTableDTO = new DBTableDTO();
|
||||
dbTableDTO.setDatasourceId(datasource.getId());
|
||||
dbTableDTO.setName(name);
|
||||
dbTableDTO.setEnableCheck(true);
|
||||
dbTableDTO.setDatasetPath(null);
|
||||
for (DatasetTable datasetTable : datasetTables) {
|
||||
DataTableInfoDTO dataTableInfoDTO = new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class);
|
||||
if (StringUtils.equals(name, dataTableInfoDTO.getTable())) {
|
||||
dbTableDTO.setEnableCheck(false);
|
||||
|
||||
List<DatasetGroup> parents = dataSetGroupService.getParents(datasetTable.getSceneId());
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
parents.forEach(ele -> stringBuilder.append(ele.getName()).append("/"));
|
||||
stringBuilder.append(datasetTable.getName());
|
||||
dbTableDTO.setDatasetPath(stringBuilder.toString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
list.add(dbTableDTO);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public Datasource get(String id) {
|
||||
|
||||
@ -15,6 +15,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
@ -158,4 +159,21 @@ public class DataSetGroupService {
|
||||
throw new RuntimeException("Name can't repeat in same group.");
|
||||
}
|
||||
}
|
||||
|
||||
public List<DatasetGroup> getParents(String id) {
|
||||
List<DatasetGroup> list = new ArrayList<>();
|
||||
DatasetGroup datasetGroup = datasetGroupMapper.selectByPrimaryKey(id);
|
||||
list.add(datasetGroup);
|
||||
getParent(list, datasetGroup);
|
||||
Collections.reverse(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
public void getParent(List<DatasetGroup> list, DatasetGroup datasetGroup) {
|
||||
if (StringUtils.isNotEmpty(datasetGroup.getPid())) {
|
||||
DatasetGroup d = datasetGroupMapper.selectByPrimaryKey(datasetGroup.getPid());
|
||||
list.add(d);
|
||||
getParent(list, d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -796,7 +796,8 @@ export default {
|
||||
preview_item: '条数据',
|
||||
preview_total: '共',
|
||||
pls_input_less_9: '请输入9位以内的正整数',
|
||||
field_edit: '编辑字段'
|
||||
field_edit: '编辑字段',
|
||||
table_already_add_to: '该表已添加至'
|
||||
},
|
||||
datasource: {
|
||||
datasource: '数据源',
|
||||
|
||||
@ -45,12 +45,13 @@
|
||||
</el-row>
|
||||
<el-col style="overflow-y: auto;">
|
||||
<el-checkbox-group v-model="checkTableList" size="small">
|
||||
<el-checkbox
|
||||
v-for="t in tableData"
|
||||
:key="t"
|
||||
border
|
||||
:label="t"
|
||||
/>
|
||||
<el-tooltip v-for="t in tableData" :key="t.name" :disabled="t.enableCheck" effect="dark" :content="$t('dataset.table_already_add_to')+': '+t.datasetPath" placement="bottom">
|
||||
<el-checkbox
|
||||
border
|
||||
:label="t.name"
|
||||
:disabled="!t.enableCheck"
|
||||
/>
|
||||
</el-tooltip>
|
||||
</el-checkbox-group>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user