fix: tree搜索

This commit is contained in:
junjie 2021-07-31 16:13:20 +08:00
parent 8bd6a1a298
commit 4c5290d87b
12 changed files with 139 additions and 17 deletions

View File

@ -37,6 +37,12 @@
<if test="createTime != null"> <if test="createTime != null">
and chart_group.create_time = #{createTime,jdbcType=BIGINT} and chart_group.create_time = #{createTime,jdbcType=BIGINT}
</if> </if>
<if test="ids != null and ids.size() > 0">
and id in
<foreach collection="ids" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
</where> </where>
<if test="sort != null"> <if test="sort != null">
order by ${sort} order by ${sort}

View File

@ -39,6 +39,9 @@
<if test="sceneId != null"> <if test="sceneId != null">
and scene_id = #{sceneId,jdbcType=VARCHAR} and scene_id = #{sceneId,jdbcType=VARCHAR}
</if> </if>
<if test="name != null">
and name like CONCAT('%', #{name},'%')
</if>
</where> </where>
<if test="sort != null"> <if test="sort != null">
order by ${sort} order by ${sort}

View File

@ -37,6 +37,12 @@
<if test="createTime != null"> <if test="createTime != null">
and dataset_group.create_time = #{createTime,jdbcType=BIGINT} and dataset_group.create_time = #{createTime,jdbcType=BIGINT}
</if> </if>
<if test="ids != null and ids.size() > 0">
and id in
<foreach collection="ids" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
</where> </where>
<if test="sort != null"> <if test="sort != null">
order by ${sort} order by ${sort}

View File

@ -45,6 +45,9 @@
<if test="sceneId != null"> <if test="sceneId != null">
and scene_id = #{sceneId,jdbcType=VARCHAR} and scene_id = #{sceneId,jdbcType=VARCHAR}
</if> </if>
<if test="name != null">
and name like CONCAT('%', #{name},'%')
</if>
<if test="mode != null"> <if test="mode != null">
and mode = #{mode,jdbcType=INTEGER} and mode = #{mode,jdbcType=INTEGER}
</if> </if>

View File

@ -4,7 +4,9 @@ import io.dataease.base.domain.ChartViewWithBLOBs;
import io.dataease.commons.utils.AuthUtils; import io.dataease.commons.utils.AuthUtils;
import io.dataease.controller.request.chart.ChartExtRequest; import io.dataease.controller.request.chart.ChartExtRequest;
import io.dataease.controller.request.chart.ChartViewRequest; import io.dataease.controller.request.chart.ChartViewRequest;
import io.dataease.controller.request.dataset.DataSetTableRequest;
import io.dataease.dto.chart.ChartViewDTO; import io.dataease.dto.chart.ChartViewDTO;
import io.dataease.dto.dataset.DataSetTableDTO;
import io.dataease.service.chart.ChartViewService; import io.dataease.service.chart.ChartViewService;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -63,7 +65,7 @@ public class ChartViewController {
} }
@GetMapping("searchAdviceSceneId/{panelId}") @GetMapping("searchAdviceSceneId/{panelId}")
public String searchAdviceSceneId(@PathVariable String panelId){ public String searchAdviceSceneId(@PathVariable String panelId) {
return chartViewService.searchAdviceSceneId(panelId); return chartViewService.searchAdviceSceneId(panelId);
} }
@ -71,10 +73,16 @@ public class ChartViewController {
public ChartViewDTO getOneWithPermission(@PathVariable String id, @RequestBody ChartExtRequest requestList) throws Exception { public ChartViewDTO getOneWithPermission(@PathVariable String id, @RequestBody ChartExtRequest requestList) throws Exception {
//如果能获取用户 则添加对应的权限 //如果能获取用户 则添加对应的权限
ChartViewDTO dto = chartViewService.getData(id, requestList); ChartViewDTO dto = chartViewService.getData(id, requestList);
if(dto!=null && AuthUtils.getUser()!=null){ if (dto != null && AuthUtils.getUser() != null) {
ChartViewDTO permissionDto = chartViewService.getOneWithPermission(dto.getId()); ChartViewDTO permissionDto = chartViewService.getOneWithPermission(dto.getId());
dto.setPrivileges(permissionDto.getPrivileges()); dto.setPrivileges(permissionDto.getPrivileges());
} }
return dto; return dto;
} }
@PostMapping("search")
public List<ChartViewDTO> search(@RequestBody ChartViewRequest chartViewRequest) {
return chartViewService.search(chartViewRequest);
}
} }

View File

@ -108,4 +108,9 @@ public class DataSetTableController {
public Boolean checkDorisTableIsExists(@PathVariable String id) throws Exception { public Boolean checkDorisTableIsExists(@PathVariable String id) throws Exception {
return dataSetTableService.checkDorisTableIsExists(id); return dataSetTableService.checkDorisTableIsExists(id);
} }
@PostMapping("search")
public List<DataSetTableDTO> search(@RequestBody DataSetTableRequest dataSetTableRequest) {
return dataSetTableService.search(dataSetTableRequest);
}
} }

View File

@ -3,9 +3,12 @@ package io.dataease.controller.request.chart;
import io.dataease.base.domain.ChartGroup; import io.dataease.base.domain.ChartGroup;
import lombok.Data; import lombok.Data;
import java.util.Set;
@Data @Data
public class ChartGroupRequest extends ChartGroup { public class ChartGroupRequest extends ChartGroup {
private String sort; private String sort;
private String userId; private String userId;
private Set<String> ids;
} }

View File

@ -3,6 +3,9 @@ package io.dataease.controller.request.dataset;
import io.dataease.base.domain.DatasetGroup; import io.dataease.base.domain.DatasetGroup;
import lombok.Data; import lombok.Data;
import java.util.List;
import java.util.Set;
/** /**
* @Author gin * @Author gin
* @Date 2021/2/22 1:30 下午 * @Date 2021/2/22 1:30 下午
@ -12,4 +15,6 @@ public class DataSetGroupRequest extends DatasetGroup {
private String sort; private String sort;
private String userId; private String userId;
private Set<String> ids;
} }

View File

@ -15,11 +15,15 @@ import io.dataease.controller.request.chart.ChartExtFilterRequest;
import io.dataease.controller.request.chart.ChartExtRequest; import io.dataease.controller.request.chart.ChartExtRequest;
import io.dataease.controller.request.chart.ChartGroupRequest; import io.dataease.controller.request.chart.ChartGroupRequest;
import io.dataease.controller.request.chart.ChartViewRequest; import io.dataease.controller.request.chart.ChartViewRequest;
import io.dataease.controller.request.dataset.DataSetGroupRequest;
import io.dataease.controller.request.dataset.DataSetTableRequest;
import io.dataease.datasource.provider.DatasourceProvider; import io.dataease.datasource.provider.DatasourceProvider;
import io.dataease.datasource.provider.ProviderFactory; import io.dataease.datasource.provider.ProviderFactory;
import io.dataease.datasource.request.DatasourceRequest; import io.dataease.datasource.request.DatasourceRequest;
import io.dataease.datasource.service.DatasourceService; import io.dataease.datasource.service.DatasourceService;
import io.dataease.dto.chart.*; import io.dataease.dto.chart.*;
import io.dataease.dto.dataset.DataSetGroupDTO;
import io.dataease.dto.dataset.DataSetTableDTO;
import io.dataease.dto.dataset.DataSetTableUnionDTO; import io.dataease.dto.dataset.DataSetTableUnionDTO;
import io.dataease.dto.dataset.DataTableInfoDTO; import io.dataease.dto.dataset.DataTableInfoDTO;
import io.dataease.i18n.Translator; import io.dataease.i18n.Translator;
@ -110,6 +114,41 @@ public class ChartViewService {
return group; return group;
} }
public List<ChartViewDTO> search(ChartViewRequest chartViewRequest) {
String userId = String.valueOf(AuthUtils.getUser().getUserId());
chartViewRequest.setUserId(userId);
List<ChartViewDTO> ds = extChartViewMapper.search(chartViewRequest);
if (CollectionUtils.isEmpty(ds)) {
return ds;
}
TreeSet<String> ids = new TreeSet<>();
ds.forEach(ele -> {
ele.setIsLeaf(true);
ele.setPid(ele.getSceneId());
ids.add(ele.getPid());
});
ChartGroupRequest chartGroupRequest = new ChartGroupRequest();
chartGroupRequest.setUserId(userId);
chartGroupRequest.setIds(ids);
List<ChartGroupDTO> search = extChartGroupMapper.search(chartGroupRequest);
while (CollectionUtils.isNotEmpty(search)) {
ids.clear();
search.forEach(ele -> {
ChartViewDTO dto = new ChartViewDTO();
BeanUtils.copyBean(dto, ele);
dto.setIsLeaf(false);
dto.setType("group");
ds.add(dto);
ids.add(ele.getPid());
});
chartGroupRequest.setIds(ids);
search = extChartGroupMapper.search(chartGroupRequest);
}
return ds;
}
public ChartViewWithBLOBs get(String id) { public ChartViewWithBLOBs get(String id) {
return chartViewMapper.selectByPrimaryKey(id); return chartViewMapper.selectByPrimaryKey(id);
} }

View File

@ -12,6 +12,7 @@ import io.dataease.commons.constants.JobStatus;
import io.dataease.commons.constants.ScheduleType; import io.dataease.commons.constants.ScheduleType;
import io.dataease.commons.constants.TaskStatus; import io.dataease.commons.constants.TaskStatus;
import io.dataease.commons.utils.*; import io.dataease.commons.utils.*;
import io.dataease.controller.request.chart.ChartGroupRequest;
import io.dataease.controller.request.dataset.DataSetGroupRequest; import io.dataease.controller.request.dataset.DataSetGroupRequest;
import io.dataease.controller.request.dataset.DataSetTableRequest; import io.dataease.controller.request.dataset.DataSetTableRequest;
import io.dataease.controller.request.dataset.DataSetTaskRequest; import io.dataease.controller.request.dataset.DataSetTaskRequest;
@ -232,6 +233,41 @@ public class DataSetTableService {
return group; return group;
} }
public List<DataSetTableDTO> search(DataSetTableRequest dataSetTableRequest) {
String userId = String.valueOf(AuthUtils.getUser().getUserId());
dataSetTableRequest.setUserId(userId);
List<DataSetTableDTO> ds = extDataSetTableMapper.search(dataSetTableRequest);
if (CollectionUtils.isEmpty(ds)) {
return ds;
}
TreeSet<String> ids = new TreeSet<>();
ds.forEach(ele -> {
ele.setIsLeaf(true);
ele.setPid(ele.getSceneId());
ids.add(ele.getPid());
});
DataSetGroupRequest dataSetGroupRequest = new DataSetGroupRequest();
dataSetGroupRequest.setUserId(userId);
dataSetGroupRequest.setIds(ids);
List<DataSetGroupDTO> search = extDataSetGroupMapper.search(dataSetGroupRequest);
while (CollectionUtils.isNotEmpty(search)) {
ids.clear();
search.forEach(ele -> {
DataSetTableDTO dto = new DataSetTableDTO();
BeanUtils.copyBean(dto, ele);
dto.setIsLeaf(false);
dto.setType("group");
ds.add(dto);
ids.add(ele.getPid());
});
dataSetGroupRequest.setIds(ids);
search = extDataSetGroupMapper.search(dataSetGroupRequest);
}
return ds;
}
public DatasetTable get(String id) { public DatasetTable get(String id) {
return datasetTableMapper.selectByPrimaryKey(id); return datasetTableMapper.selectByPrimaryKey(id);
} }

View File

@ -891,14 +891,18 @@ export default {
searchTree(val) { searchTree(val) {
const queryCondition = { const queryCondition = {
withExtend: 'parent', // withExtend: 'parent',
modelType: 'chart', // modelType: 'chart',
name: val name: val
} }
authModel(queryCondition).then(res => { // authModel(queryCondition).then(res => {
// this.highlights(res.data) // // this.highlights(res.data)
// this.tData = this.buildTree(res.data)
// // console.log(this.tData)
// })
post('/chart/view/search', queryCondition).then(res => {
this.tData = this.buildTree(res.data) this.tData = this.buildTree(res.data)
// console.log(this.tData)
}) })
}, },
@ -910,8 +914,8 @@ export default {
const roots = [] const roots = []
arrs.forEach(el => { arrs.forEach(el => {
// ### // ###
el.type = el.modelInnerType // el.type = el.modelInnerType
el.isLeaf = el.leaf // el.isLeaf = el.leaf
if (el[this.treeProps.parentId] === null || el[this.treeProps.parentId] === 0 || el[this.treeProps.parentId] === '0') { if (el[this.treeProps.parentId] === null || el[this.treeProps.parentId] === 0 || el[this.treeProps.parentId] === '0') {
roots.push(el) roots.push(el)
return return

View File

@ -856,14 +856,18 @@ export default {
searchTree(val) { searchTree(val) {
const queryCondition = { const queryCondition = {
withExtend: 'parent', // withExtend: 'parent',
modelType: 'dataset', // modelType: 'dataset',
name: val name: val
} }
authModel(queryCondition).then(res => { // authModel(queryCondition).then(res => {
// this.highlights(res.data) // // this.highlights(res.data)
// this.tData = this.buildTree(res.data)
// // console.log(this.tData)
// })
post('/dataset/table/search', queryCondition).then(res => {
this.tData = this.buildTree(res.data) this.tData = this.buildTree(res.data)
// console.log(this.tData)
}) })
}, },
@ -875,8 +879,8 @@ export default {
const roots = [] const roots = []
arrs.forEach(el => { arrs.forEach(el => {
// ### // ###
el.type = el.modelInnerType // el.type = el.modelInnerType
el.isLeaf = el.leaf // el.isLeaf = el.leaf
if (el[this.treeProps.parentId] === null || el[this.treeProps.parentId] === 0 || el[this.treeProps.parentId] === '0') { if (el[this.treeProps.parentId] === null || el[this.treeProps.parentId] === 0 || el[this.treeProps.parentId] === '0') {
roots.push(el) roots.push(el)
return return