mirror of
https://github.com/dataease/dataease.git
synced 2026-05-21 04:08:10 +08:00
feat: 仪表板选择视图
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package io.dataease.base.mapper.ext;
|
||||
|
||||
import io.dataease.base.mapper.ext.query.GridExample;
|
||||
import io.dataease.dto.panel.po.PanelViewPo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ExtPanelViewMapper {
|
||||
|
||||
List<PanelViewPo> groups(GridExample example);
|
||||
|
||||
List<PanelViewPo> views(GridExample example);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="io.dataease.base.mapper.ext.ExtPanelViewMapper">
|
||||
|
||||
<resultMap id="treeNodeMap" type="io.dataease.dto.panel.po.PanelViewPo">
|
||||
<id column="id" property="id" />
|
||||
<result column="name" property="name" />
|
||||
<result column="pid" property="pid" />
|
||||
<result column="type" property="type" />
|
||||
</resultMap>
|
||||
|
||||
|
||||
|
||||
<select id="groups" parameterType="io.dataease.base.mapper.ext.query.GridExample" resultMap="treeNodeMap">
|
||||
select id, pid, name, `type`
|
||||
from chart_group
|
||||
<if test="_parameter != null">
|
||||
<include refid="io.dataease.base.mapper.ext.query.GridSql.gridCondition" />
|
||||
</if>
|
||||
<if test="orderByClause != null">
|
||||
order by ${orderByClause}
|
||||
</if>
|
||||
<if test="orderByClause == null">
|
||||
order by create_time desc
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="views" parameterType="io.dataease.base.mapper.ext.query.GridExample" resultMap="treeNodeMap">
|
||||
select id, scene_id as pid ,title as name, `type`
|
||||
from chart_view
|
||||
<if test="_parameter != null">
|
||||
<include refid="io.dataease.base.mapper.ext.query.GridSql.gridCondition" />
|
||||
</if>
|
||||
<if test="orderByClause != null">
|
||||
order by ${orderByClause}
|
||||
</if>
|
||||
<if test="orderByClause == null">
|
||||
order by create_time desc
|
||||
</if>
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,21 @@
|
||||
package io.dataease.controller.panel.api;
|
||||
|
||||
|
||||
import io.dataease.controller.sys.base.BaseGridRequest;
|
||||
import io.dataease.dto.panel.PanelViewDto;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Api(tags = "仪表板:视图管理")
|
||||
@RequestMapping("/api/panelView")
|
||||
public interface ViewApi {
|
||||
|
||||
|
||||
@ApiOperation("视图树")
|
||||
@PostMapping("/tree")
|
||||
List<PanelViewDto> tree(BaseGridRequest request);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package io.dataease.controller.panel.server;
|
||||
|
||||
import io.dataease.commons.utils.AuthUtils;
|
||||
import io.dataease.controller.panel.api.ViewApi;
|
||||
import io.dataease.controller.sys.base.BaseGridRequest;
|
||||
import io.dataease.controller.sys.base.ConditionEntity;
|
||||
import io.dataease.dto.panel.PanelViewDto;
|
||||
import io.dataease.dto.panel.po.PanelViewPo;
|
||||
import io.dataease.service.panel.PanelViewService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
public class ViewServer implements ViewApi {
|
||||
|
||||
@Autowired
|
||||
private PanelViewService panelViewService;
|
||||
|
||||
/**
|
||||
* 为什么查两次?
|
||||
* 因为left join 会导致全表扫描
|
||||
* 查两次在索引合理情况下 效率比查询一次高
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<PanelViewDto> tree(@RequestBody BaseGridRequest request) {
|
||||
List<ConditionEntity> conditions = new ArrayList<>();
|
||||
ConditionEntity condition = new ConditionEntity();
|
||||
condition.setField("create_by");
|
||||
condition.setOperator("eq");
|
||||
condition.setValue(AuthUtils.getUser().getUsername());
|
||||
conditions.add(condition);
|
||||
request.setConditions(conditions);
|
||||
List<PanelViewPo> groups = panelViewService.groups(request);
|
||||
List<PanelViewPo> views = panelViewService.views(request);
|
||||
List<PanelViewDto> panelViewDtos = panelViewService.buildTree(groups, views);
|
||||
return panelViewDtos;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package io.dataease.dto.panel;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Data
|
||||
public class PanelViewDto {
|
||||
|
||||
private String id;
|
||||
|
||||
private String pid;
|
||||
|
||||
private String type;
|
||||
|
||||
private String name;
|
||||
|
||||
private List<PanelViewDto> children;
|
||||
|
||||
public void addChild(PanelViewDto dto){
|
||||
children = Optional.ofNullable(children).orElse(new ArrayList<>());
|
||||
children.add(dto);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package io.dataease.dto.panel.po;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PanelViewPo {
|
||||
|
||||
private String id;
|
||||
|
||||
private String pid;
|
||||
|
||||
private String type;
|
||||
|
||||
private String name;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package io.dataease.service.panel;
|
||||
|
||||
import io.dataease.base.mapper.ext.ExtPanelViewMapper;
|
||||
import io.dataease.base.mapper.ext.query.GridExample;
|
||||
import io.dataease.commons.utils.BeanUtils;
|
||||
import io.dataease.controller.sys.base.BaseGridRequest;
|
||||
import io.dataease.dto.panel.PanelViewDto;
|
||||
import io.dataease.dto.panel.po.PanelViewPo;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class PanelViewService {
|
||||
|
||||
@Autowired(required = false)
|
||||
private ExtPanelViewMapper extPanelViewMapper;
|
||||
|
||||
private final static String SCENE_TYPE = "scene";
|
||||
|
||||
public List<PanelViewPo> groups(BaseGridRequest request){
|
||||
GridExample example = request.convertExample();
|
||||
return extPanelViewMapper.groups(example);
|
||||
}
|
||||
|
||||
public List<PanelViewPo> views(BaseGridRequest request){
|
||||
GridExample example = request.convertExample();
|
||||
return extPanelViewMapper.views(example);
|
||||
}
|
||||
|
||||
public List<PanelViewDto> buildTree(List<PanelViewPo> groups, List<PanelViewPo> views){
|
||||
|
||||
if (CollectionUtils.isEmpty(groups) || CollectionUtils.isEmpty(views)) return null;
|
||||
|
||||
Map<String, List<PanelViewPo>> viewsMap = views.stream().collect(Collectors.groupingBy(PanelViewPo::getPid));
|
||||
List<PanelViewDto> dtos = groups.stream().map(group -> BeanUtils.copyBean(new PanelViewDto(), group)).collect(Collectors.toList());
|
||||
List<PanelViewDto> roots = new ArrayList<>();
|
||||
dtos.forEach(group -> {
|
||||
// 查找跟节点
|
||||
if (ObjectUtils.isEmpty(group.getPid())){
|
||||
roots.add(group);
|
||||
}
|
||||
// 查找当前节点的子节点
|
||||
// 当前group是场景
|
||||
if (StringUtils.equals(group.getType(), SCENE_TYPE)){
|
||||
Optional.ofNullable(viewsMap.get(group.getId())).ifPresent(lists -> lists.forEach(view -> {
|
||||
PanelViewDto dto = BeanUtils.copyBean(new PanelViewDto(), view);
|
||||
group.addChild(dto);
|
||||
}));
|
||||
return;
|
||||
}
|
||||
// 当前group是分组
|
||||
dtos.forEach(item -> {
|
||||
if (StringUtils.equals(item.getPid(), group.getId())){
|
||||
group.addChild(item);
|
||||
}
|
||||
});
|
||||
});
|
||||
// 最后 没有孩子的老东西淘汰
|
||||
return roots.stream().filter(item -> CollectionUtils.isNotEmpty(item.getChildren())).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user