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

This commit is contained in:
fit2cloud-chenyw 2021-06-02 21:49:51 +08:00
parent 4108e68927
commit 7185f815e9
3 changed files with 22 additions and 11 deletions

View File

@ -7,12 +7,13 @@ import io.dataease.dto.panel.PanelSharePo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
public interface ExtPanelShareMapper {
int batchInsert(@Param("shares") List<PanelShare> shares);
List<PanelSharePo> query(GridExample example);
List<PanelSharePo> query(Map<String, Object> param);
List<PanelShare> queryWithResource(GridExample example);
}

View File

@ -16,16 +16,17 @@
</foreach>
</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
from panel_share s
left join panel_group g on g.id = s.panel_group_id
<if test="_parameter != null">
<include refid="io.dataease.base.mapper.ext.query.GridSql.gridCondition" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
where
( s.target_id = #{userId} and s.type = 0 ) or
( s.target_id = #{deptId} and s.type = 1 ) or
s.target_id in
<foreach collection="roleIds" item="roleId" open='(' separator=',' close=')'>
#{roleId}
</foreach>
<if test="orderByClause == null">
order by s.create_time desc
</if>

View File

@ -23,6 +23,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -92,7 +93,14 @@ public class ShareService {
Long deptId = user.getDeptId();
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(deptId);
targetIds.addAll(roleIds);
@ -105,14 +113,15 @@ public class ShareService {
request.setConditions(new ArrayList<ConditionEntity>(){{add(condition);}});
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());
return convertTree(dtoLists);
}
//List构建Tree
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 -> {
PanelShareDto panelShareDto = new PanelShareDto();
panelShareDto.setName(entry.getKey());