2021-03-16 16:59:49 +08:00
|
|
|
package io.dataease.service.panel;
|
|
|
|
|
2021-03-19 13:05:14 +08:00
|
|
|
import io.dataease.auth.api.dto.CurrentRoleDto;
|
|
|
|
import io.dataease.auth.api.dto.CurrentUserDto;
|
2021-03-16 16:59:49 +08:00
|
|
|
import io.dataease.base.domain.PanelShare;
|
|
|
|
import io.dataease.base.domain.PanelShareExample;
|
2021-03-18 16:55:31 +08:00
|
|
|
import io.dataease.base.domain.SysUser;
|
2021-03-16 16:59:49 +08:00
|
|
|
import io.dataease.base.mapper.PanelShareMapper;
|
|
|
|
import io.dataease.base.mapper.ext.ExtPanelShareMapper;
|
|
|
|
import io.dataease.base.mapper.ext.query.GridExample;
|
|
|
|
import io.dataease.commons.utils.AuthUtils;
|
2021-03-18 18:30:10 +08:00
|
|
|
import io.dataease.commons.utils.BeanUtils;
|
2021-03-16 16:59:49 +08:00
|
|
|
import io.dataease.commons.utils.CommonBeanFactory;
|
|
|
|
import io.dataease.controller.request.panel.PanelShareRequest;
|
|
|
|
import io.dataease.controller.sys.base.BaseGridRequest;
|
|
|
|
import io.dataease.controller.sys.base.ConditionEntity;
|
|
|
|
import io.dataease.dto.panel.PanelShareDto;
|
2021-03-18 18:30:10 +08:00
|
|
|
import io.dataease.dto.panel.PanelSharePo;
|
2021-03-16 16:59:49 +08:00
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
2021-05-25 15:52:28 +08:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2021-03-16 16:59:49 +08:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.util.ArrayList;
|
2021-06-02 21:49:51 +08:00
|
|
|
import java.util.HashMap;
|
2021-03-16 16:59:49 +08:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
public class ShareService {
|
|
|
|
|
|
|
|
@Autowired(required = false)
|
|
|
|
private PanelShareMapper mapper;
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
private ExtPanelShareMapper extPanelShareMapper;
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
public void save(PanelShareRequest request){
|
|
|
|
|
|
|
|
//1.先根据仪表板删除所有已经分享的
|
2021-03-18 16:55:31 +08:00
|
|
|
Integer type = request.getType();
|
2021-03-16 16:59:49 +08:00
|
|
|
List<String> panelIds = request.getPanelIds();
|
2021-03-18 16:55:31 +08:00
|
|
|
List<Long> targetIds = request.getTargetIds();
|
2021-03-16 16:59:49 +08:00
|
|
|
// 使用原生对象会导致事物失效 所以这里需要使用spring代理对象
|
|
|
|
if (CollectionUtils.isNotEmpty(panelIds)){
|
|
|
|
ShareService proxy = CommonBeanFactory.getBean(ShareService.class);
|
2021-03-18 16:55:31 +08:00
|
|
|
panelIds.forEach(panelId -> {
|
|
|
|
proxy.delete(panelId, type);
|
|
|
|
});
|
2021-03-16 16:59:49 +08:00
|
|
|
}
|
2021-03-18 16:55:31 +08:00
|
|
|
if (CollectionUtils.isEmpty(targetIds)) return;
|
|
|
|
|
2021-03-16 16:59:49 +08:00
|
|
|
long now = System.currentTimeMillis();
|
|
|
|
List<PanelShare> shares = panelIds.stream().flatMap(panelId ->
|
2021-03-18 16:55:31 +08:00
|
|
|
targetIds.stream().map(targetId -> {
|
2021-03-16 16:59:49 +08:00
|
|
|
PanelShare share = new PanelShare();
|
|
|
|
share.setCreateTime(now);
|
|
|
|
share.setPanelGroupId(panelId);
|
2021-03-18 16:55:31 +08:00
|
|
|
share.setTargetId(targetId);
|
|
|
|
share.setType(type);
|
2021-03-16 16:59:49 +08:00
|
|
|
return share;
|
|
|
|
})
|
|
|
|
).collect(Collectors.toList());
|
|
|
|
if (CollectionUtils.isNotEmpty(shares)){
|
|
|
|
extPanelShareMapper.batchInsert(shares);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* panel_group_id建了索引 效率不会很差
|
|
|
|
* @param panel_group_id
|
|
|
|
*/
|
|
|
|
@Transactional
|
2021-03-18 16:55:31 +08:00
|
|
|
public void delete(String panel_group_id, Integer type){
|
2021-03-16 16:59:49 +08:00
|
|
|
PanelShareExample example = new PanelShareExample();
|
2021-05-21 10:52:19 +08:00
|
|
|
PanelShareExample.Criteria criteria = example.createCriteria();
|
|
|
|
criteria.andPanelGroupIdEqualTo(panel_group_id);
|
|
|
|
if(type != null){
|
|
|
|
criteria.andTypeEqualTo(type);
|
|
|
|
}
|
2021-03-16 16:59:49 +08:00
|
|
|
mapper.deleteByExample(example);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<PanelShareDto> queryTree(BaseGridRequest request){
|
2021-03-19 13:05:14 +08:00
|
|
|
CurrentUserDto user = AuthUtils.getUser();
|
2021-03-18 16:55:31 +08:00
|
|
|
Long userId = user.getUserId();
|
|
|
|
Long deptId = user.getDeptId();
|
2021-03-19 13:05:14 +08:00
|
|
|
List<Long> roleIds = user.getRoles().stream().map(CurrentRoleDto::getId).collect(Collectors.toList());
|
2021-03-18 16:55:31 +08:00
|
|
|
|
2021-06-02 21:49:51 +08:00
|
|
|
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<>();
|
2021-03-18 16:55:31 +08:00
|
|
|
targetIds.add(userId);
|
|
|
|
targetIds.add(deptId);
|
|
|
|
targetIds.addAll(roleIds);
|
|
|
|
|
2021-03-16 16:59:49 +08:00
|
|
|
ConditionEntity condition = new ConditionEntity();
|
2021-03-18 16:55:31 +08:00
|
|
|
condition.setField("s.target_id");
|
|
|
|
condition.setOperator("in");
|
|
|
|
condition.setValue(targetIds);
|
|
|
|
|
2021-03-16 16:59:49 +08:00
|
|
|
request.setConditions(new ArrayList<ConditionEntity>(){{add(condition);}});
|
2021-03-18 16:55:31 +08:00
|
|
|
|
2021-03-16 16:59:49 +08:00
|
|
|
GridExample example = request.convertExample();
|
2021-06-02 21:49:51 +08:00
|
|
|
List<PanelSharePo> datas = extPanelShareMapper.query(example);*/
|
2021-03-18 18:30:10 +08:00
|
|
|
List<PanelShareDto> dtoLists = datas.stream().map(po -> BeanUtils.copyBean(new PanelShareDto(), po)).collect(Collectors.toList());
|
|
|
|
return convertTree(dtoLists);
|
2021-03-16 16:59:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//List构建Tree
|
|
|
|
private List<PanelShareDto> convertTree(List<PanelShareDto> datas){
|
2021-06-02 21:49:51 +08:00
|
|
|
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));
|
2021-03-18 18:30:10 +08:00
|
|
|
return map.entrySet().stream().map(entry -> {
|
|
|
|
PanelShareDto panelShareDto = new PanelShareDto();
|
|
|
|
panelShareDto.setName(entry.getKey());
|
|
|
|
panelShareDto.setChildren(entry.getValue());
|
|
|
|
return panelShareDto;
|
|
|
|
}).collect(Collectors.toList());
|
2021-03-16 16:59:49 +08:00
|
|
|
}
|
|
|
|
|
2021-03-17 18:50:29 +08:00
|
|
|
public List<PanelShare> queryWithResource(BaseGridRequest request){
|
|
|
|
GridExample example = request.convertExample();
|
|
|
|
return extPanelShareMapper.queryWithResource(example);
|
|
|
|
}
|
|
|
|
|
2021-03-16 16:59:49 +08:00
|
|
|
|
|
|
|
}
|