dataease-dm/backend/src/main/java/io/dataease/service/panel/PanelGroupService.java

135 lines
5.2 KiB
Java
Raw Normal View History

2021-03-08 14:31:09 +08:00
package io.dataease.service.panel;
import io.dataease.base.domain.*;
import io.dataease.base.mapper.ChartViewMapper;
import io.dataease.base.mapper.PanelDesignMapper;
2021-03-08 14:31:09 +08:00
import io.dataease.base.mapper.PanelGroupMapper;
2021-03-22 17:27:16 +08:00
import io.dataease.base.mapper.ext.ExtPanelDesignMapper;
2021-03-08 18:43:28 +08:00
import io.dataease.base.mapper.ext.ExtPanelGroupMapper;
2021-03-22 17:27:16 +08:00
import io.dataease.commons.constants.PanelConstants;
import io.dataease.commons.utils.AuthUtils;
2021-03-08 18:43:28 +08:00
import io.dataease.commons.utils.BeanUtils;
import io.dataease.controller.request.panel.PanelGroupRequest;
import io.dataease.dto.chart.ChartViewDTO;
2021-03-08 18:43:28 +08:00
import io.dataease.dto.dataset.DataSetGroupDTO;
import io.dataease.dto.panel.PanelDesignDTO;
2021-03-08 18:43:28 +08:00
import io.dataease.dto.panel.PanelGroupDTO;
import io.dataease.service.chart.ChartViewService;
import org.apache.commons.collections4.CollectionUtils;
2021-03-08 18:43:28 +08:00
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
2021-03-08 14:31:09 +08:00
import org.springframework.stereotype.Service;
2021-03-22 17:27:16 +08:00
import org.springframework.transaction.annotation.Transactional;
2021-03-08 18:43:28 +08:00
import org.springframework.util.Assert;
2021-03-08 14:31:09 +08:00
import javax.annotation.Resource;
import java.util.ArrayList;
2021-03-08 18:43:28 +08:00
import java.util.List;
import java.util.Optional;
import java.util.UUID;
2021-03-22 17:27:16 +08:00
import java.util.stream.Collectors;
2021-03-08 14:31:09 +08:00
/**
* Author: wangjiahao
* Date: 2021-03-05
* Description:
*/
@Service
public class PanelGroupService {
private Logger LOGGER = LoggerFactory.getLogger(this.getClass());
2021-03-08 14:31:09 +08:00
@Resource
private PanelGroupMapper panelGroupMapper;
2021-03-08 18:43:28 +08:00
@Resource
private ExtPanelGroupMapper extPanelGroupMapper;
@Resource
private ChartViewService chartViewService;
@Resource
private ChartViewMapper chartViewMapper;
2021-03-22 17:27:16 +08:00
@Resource
private StoreService storeService;
@Resource
private ShareService shareService;
@Resource
private PanelLinkService panelLinkService;
2021-03-08 18:43:28 +08:00
public List<PanelGroupDTO> tree(PanelGroupRequest panelGroupRequest) {
2021-05-18 16:07:19 +08:00
String userId = String.valueOf(AuthUtils.getUser().getUserId());
panelGroupRequest.setUserId(userId);
2021-03-08 18:43:28 +08:00
List<PanelGroupDTO> panelGroupDTOList = extPanelGroupMapper.panelGroupList(panelGroupRequest);
2021-05-18 16:07:19 +08:00
getTreeChildren(panelGroupDTOList,userId);
2021-03-08 18:43:28 +08:00
return panelGroupDTOList;
}
2021-05-18 16:07:19 +08:00
public void getTreeChildren(List<PanelGroupDTO> parentPanelGroupDTO,String userId) {
2021-03-08 18:43:28 +08:00
Optional.ofNullable(parentPanelGroupDTO).ifPresent(parent -> parent.forEach(panelGroupDTO -> {
2021-05-18 16:07:19 +08:00
List<PanelGroupDTO> panelGroupDTOChildren = extPanelGroupMapper.panelGroupList(new PanelGroupRequest(panelGroupDTO.getId(),userId));
2021-03-08 18:43:28 +08:00
panelGroupDTO.setChildren(panelGroupDTOChildren);
2021-05-18 16:07:19 +08:00
getTreeChildren(panelGroupDTOChildren,userId);
2021-03-08 18:43:28 +08:00
}));
}
public List<PanelGroupDTO> getDefaultTree(PanelGroupRequest panelGroupRequest) {
return extPanelGroupMapper.panelGroupListDefault(panelGroupRequest);
2021-03-08 18:43:28 +08:00
}
2021-03-08 14:31:09 +08:00
2021-03-08 18:43:28 +08:00
public PanelGroupDTO save(PanelGroupRequest request) {
if (StringUtils.isEmpty(request.getId())) {
request.setId(UUID.randomUUID().toString());
request.setCreateTime(System.currentTimeMillis());
request.setCreateBy(AuthUtils.getUser().getUsername());
2021-03-08 18:43:28 +08:00
panelGroupMapper.insert(request);
} else {
// 复制为默认仪表盘
if("toDefaultPanel".equals(request.getOptType())){
PanelGroupWithBLOBs newDefaultPanel = panelGroupMapper.selectByPrimaryKey(request.getId());
newDefaultPanel.setPanelType(PanelConstants.PANEL_TYPE_SYSTEM);
newDefaultPanel.setNodeType(PanelConstants.PANEL_NODE_TYPE_PANEL);
newDefaultPanel.setName(request.getName());
newDefaultPanel.setId(UUID.randomUUID().toString());
newDefaultPanel.setPid(null);
newDefaultPanel.setLevel(0);
panelGroupMapper.insertSelective(newDefaultPanel);
}else{
panelGroupMapper.updateByPrimaryKeySelective(request);
}
2021-03-08 18:43:28 +08:00
}
PanelGroupDTO panelGroupDTO = new PanelGroupDTO();
BeanUtils.copyBean(panelGroupDTO, request);
panelGroupDTO.setLabel(request.getName());
return panelGroupDTO;
}
2021-03-08 14:31:09 +08:00
public void deleteCircle(String id) {
2021-03-08 18:43:28 +08:00
Assert.notNull(id, "id cannot be null");
extPanelGroupMapper.deleteCircle(id);
storeService.removeByPanelId(id);
shareService.delete(id, null);
panelLinkService.deleteByResourceId(id);
2021-03-08 18:43:28 +08:00
}
2021-03-08 14:31:09 +08:00
public PanelGroupWithBLOBs findOne(String panelId) {
return panelGroupMapper.selectByPrimaryKey(panelId);
2021-03-29 14:57:04 +08:00
}
public List<ChartViewDTO> getUsableViews(String panelId) throws Exception {
List<ChartViewDTO> chartViewDTOList = new ArrayList<>();
List<ChartView> allChartView = chartViewMapper.selectByExample(null);
Optional.ofNullable(allChartView).orElse(new ArrayList<>()).stream().forEach(chartView -> {
try {
chartViewDTOList.add(chartViewService.getData(chartView.getId(), null));
} catch (Exception e) {
LOGGER.error("获取view详情出错" + chartView.getId(), e);
}
});
return chartViewDTOList;
}
2021-03-08 14:31:09 +08:00
}