提交 7185f815 authored 作者: fit2cloud-chenyw's avatar fit2cloud-chenyw

fix: 仪表板分享过滤当前用户

上级 4108e689
...@@ -7,12 +7,13 @@ import io.dataease.dto.panel.PanelSharePo; ...@@ -7,12 +7,13 @@ import io.dataease.dto.panel.PanelSharePo;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import java.util.Map;
public interface ExtPanelShareMapper { public interface ExtPanelShareMapper {
int batchInsert(@Param("shares") List<PanelShare> shares); int batchInsert(@Param("shares") List<PanelShare> shares);
List<PanelSharePo> query(GridExample example); List<PanelSharePo> query(Map<String, Object> param);
List<PanelShare> queryWithResource(GridExample example); List<PanelShare> queryWithResource(GridExample example);
} }
...@@ -16,16 +16,17 @@ ...@@ -16,16 +16,17 @@
</foreach> </foreach>
</insert> </insert>
<select id="query" parameterType="io.dataease.base.mapper.ext.query.GridExample" resultMap="treeNodeMap"> <select id="query" resultMap="treeNodeMap">
select distinct s.panel_group_id as id, g.create_by as creator, g.name select distinct s.panel_group_id as id, g.create_by as creator, g.name
from panel_share s from panel_share s
left join panel_group g on g.id = s.panel_group_id left join panel_group g on g.id = s.panel_group_id
<if test="_parameter != null"> where
<include refid="io.dataease.base.mapper.ext.query.GridSql.gridCondition" /> ( s.target_id = #{userId} and s.type = 0 ) or
</if> ( s.target_id = #{deptId} and s.type = 1 ) or
<if test="orderByClause != null"> s.target_id in
order by ${orderByClause} <foreach collection="roleIds" item="roleId" open='(' separator=',' close=')'>
</if> #{roleId}
</foreach>
<if test="orderByClause == null"> <if test="orderByClause == null">
order by s.create_time desc order by s.create_time desc
</if> </if>
......
...@@ -23,6 +23,7 @@ import org.springframework.stereotype.Service; ...@@ -23,6 +23,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -92,7 +93,14 @@ public class ShareService { ...@@ -92,7 +93,14 @@ public class ShareService {
Long deptId = user.getDeptId(); Long deptId = user.getDeptId();
List<Long> roleIds = user.getRoles().stream().map(CurrentRoleDto::getId).collect(Collectors.toList()); List<Long> roleIds = user.getRoles().stream().map(CurrentRoleDto::getId).collect(Collectors.toList());
List<Long> targetIds = new ArrayList<>(); Map<String, Object> param = new HashMap<>();
param.put("userId", userId);
param.put("deptId", deptId);
param.put("roleIds", roleIds);
List<PanelSharePo> datas = extPanelShareMapper.query(param);
/*List<Long> targetIds = new ArrayList<>();
targetIds.add(userId); targetIds.add(userId);
targetIds.add(deptId); targetIds.add(deptId);
targetIds.addAll(roleIds); targetIds.addAll(roleIds);
...@@ -105,14 +113,15 @@ public class ShareService { ...@@ -105,14 +113,15 @@ public class ShareService {
request.setConditions(new ArrayList<ConditionEntity>(){{add(condition);}}); request.setConditions(new ArrayList<ConditionEntity>(){{add(condition);}});
GridExample example = request.convertExample(); GridExample example = request.convertExample();
List<PanelSharePo> datas = extPanelShareMapper.query(example); List<PanelSharePo> datas = extPanelShareMapper.query(example);*/
List<PanelShareDto> dtoLists = datas.stream().map(po -> BeanUtils.copyBean(new PanelShareDto(), po)).collect(Collectors.toList()); List<PanelShareDto> dtoLists = datas.stream().map(po -> BeanUtils.copyBean(new PanelShareDto(), po)).collect(Collectors.toList());
return convertTree(dtoLists); return convertTree(dtoLists);
} }
//List构建Tree //List构建Tree
private List<PanelShareDto> convertTree(List<PanelShareDto> datas){ private List<PanelShareDto> convertTree(List<PanelShareDto> datas){
Map<String, List<PanelShareDto>> map = datas.stream().filter(panelShareDto -> StringUtils.isNotEmpty(panelShareDto.getCreator())).collect(Collectors.groupingBy(PanelShareDto::getCreator)); String username = AuthUtils.getUser().getUsername();
Map<String, List<PanelShareDto>> map = datas.stream().filter(panelShareDto -> StringUtils.isNotEmpty(panelShareDto.getCreator()) && !StringUtils.equals(username, panelShareDto.getCreator())).collect(Collectors.groupingBy(PanelShareDto::getCreator));
return map.entrySet().stream().map(entry -> { return map.entrySet().stream().map(entry -> {
PanelShareDto panelShareDto = new PanelShareDto(); PanelShareDto panelShareDto = new PanelShareDto();
panelShareDto.setName(entry.getKey()); panelShareDto.setName(entry.getKey());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论