2021-03-08 14:31:09 +08:00
|
|
|
|
package io.dataease.service.panel;
|
|
|
|
|
|
2021-03-19 15:54:35 +08:00
|
|
|
|
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;
|
2021-04-22 14:27:08 +08:00
|
|
|
|
import io.dataease.commons.utils.AuthUtils;
|
2021-03-08 18:43:28 +08:00
|
|
|
|
import io.dataease.commons.utils.BeanUtils;
|
2021-05-24 17:28:03 +08:00
|
|
|
|
import io.dataease.commons.utils.TreeUtils;
|
2021-03-08 18:43:28 +08:00
|
|
|
|
import io.dataease.controller.request.panel.PanelGroupRequest;
|
2021-03-19 15:54:35 +08:00
|
|
|
|
import io.dataease.dto.chart.ChartViewDTO;
|
2021-03-08 18:43:28 +08:00
|
|
|
|
import io.dataease.dto.dataset.DataSetGroupDTO;
|
2021-03-19 15:54:35 +08:00
|
|
|
|
import io.dataease.dto.panel.PanelDesignDTO;
|
2021-03-08 18:43:28 +08:00
|
|
|
|
import io.dataease.dto.panel.PanelGroupDTO;
|
2021-05-24 17:28:03 +08:00
|
|
|
|
import io.dataease.i18n.Translator;
|
2021-03-19 15:54:35 +08:00
|
|
|
|
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;
|
2021-03-19 15:54:35 +08:00
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
2021-05-21 10:52:19 +08:00
|
|
|
|
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;
|
2021-03-19 15:54:35 +08:00
|
|
|
|
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 {
|
|
|
|
|
|
2021-03-19 15:54:35 +08:00
|
|
|
|
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;
|
2021-03-19 15:54:35 +08:00
|
|
|
|
@Resource
|
|
|
|
|
private ChartViewService chartViewService;
|
|
|
|
|
@Resource
|
|
|
|
|
private ChartViewMapper chartViewMapper;
|
2021-03-22 17:27:16 +08:00
|
|
|
|
@Resource
|
2021-05-21 10:52:19 +08:00
|
|
|
|
private StoreService storeService;
|
|
|
|
|
@Resource
|
|
|
|
|
private ShareService shareService;
|
|
|
|
|
@Resource
|
|
|
|
|
private PanelLinkService panelLinkService;
|
2021-05-24 17:28:03 +08:00
|
|
|
|
|
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-24 17:28:03 +08:00
|
|
|
|
List<PanelGroupDTO> result = TreeUtils.mergeTree(panelGroupDTOList,"panel_list");
|
|
|
|
|
return result;
|
2021-03-08 18:43:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-24 17:28:03 +08:00
|
|
|
|
public List<PanelGroupDTO> defaultTree(PanelGroupRequest panelGroupRequest) {
|
|
|
|
|
String userId = String.valueOf(AuthUtils.getUser().getUserId());
|
|
|
|
|
panelGroupRequest.setUserId(userId);
|
|
|
|
|
List<PanelGroupDTO> panelGroupDTOList = extPanelGroupMapper.panelGroupList(panelGroupRequest);
|
|
|
|
|
List<PanelGroupDTO> result = TreeUtils.mergeTree(panelGroupDTOList,"default_panel");
|
|
|
|
|
return result;
|
2021-03-08 18:43:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-24 17:28:03 +08:00
|
|
|
|
public PanelGroup saveOrUpdate(PanelGroupRequest request) {
|
|
|
|
|
String panelId = request.getId();
|
|
|
|
|
if (StringUtils.isEmpty(panelId)) {
|
|
|
|
|
// 新建
|
|
|
|
|
checkPanelName(request.getName(), request.getPid(), PanelConstants.OPT_TYPE_INSERT, null);
|
|
|
|
|
panelId = UUID.randomUUID().toString();
|
|
|
|
|
request.setId(panelId);
|
2021-03-08 18:43:28 +08:00
|
|
|
|
request.setCreateTime(System.currentTimeMillis());
|
2021-04-22 14:27:08 +08:00
|
|
|
|
request.setCreateBy(AuthUtils.getUser().getUsername());
|
2021-03-08 18:43:28 +08:00
|
|
|
|
panelGroupMapper.insert(request);
|
2021-05-24 17:28:03 +08:00
|
|
|
|
} else if ("toDefaultPanel".equals(request.getOptType())) {
|
|
|
|
|
panelId = UUID.randomUUID().toString();
|
2021-05-28 11:21:54 +08:00
|
|
|
|
// 转存为默认仪表板
|
2021-05-24 17:28:03 +08:00
|
|
|
|
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(panelId);
|
|
|
|
|
newDefaultPanel.setPid(PanelConstants.PANEL_GATHER_DEFAULT_PANEL);
|
|
|
|
|
newDefaultPanel.setLevel(0);
|
|
|
|
|
newDefaultPanel.setSource(request.getId());
|
|
|
|
|
checkPanelName(newDefaultPanel.getName(), newDefaultPanel.getPid(), PanelConstants.OPT_TYPE_INSERT, newDefaultPanel.getId());
|
|
|
|
|
panelGroupMapper.insertSelective(newDefaultPanel);
|
2021-03-08 18:43:28 +08:00
|
|
|
|
} else {
|
2021-05-24 17:28:03 +08:00
|
|
|
|
// 更新
|
|
|
|
|
if (StringUtils.isNotEmpty(request.getName())) {
|
|
|
|
|
checkPanelName(request.getName(), request.getPid(), PanelConstants.OPT_TYPE_UPDATE, request.getId());
|
2021-05-24 10:28:11 +08:00
|
|
|
|
}
|
2021-05-24 17:28:03 +08:00
|
|
|
|
panelGroupMapper.updateByPrimaryKeySelective(request);
|
|
|
|
|
}
|
2021-05-25 12:36:35 +08:00
|
|
|
|
|
|
|
|
|
//带有权限的返回
|
|
|
|
|
PanelGroupRequest authRequest = new PanelGroupRequest();
|
|
|
|
|
authRequest.setId(panelId);
|
|
|
|
|
authRequest.setUserId(String.valueOf(AuthUtils.getUser().getUserId()));
|
|
|
|
|
List<PanelGroupDTO> panelGroupDTOList = extPanelGroupMapper.panelGroupList(authRequest);
|
|
|
|
|
|
|
|
|
|
return panelGroupDTOList.get(0);
|
2021-05-24 17:28:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void checkPanelName(String name, String pid, String optType, String id) {
|
|
|
|
|
PanelGroupExample groupExample = new PanelGroupExample();
|
|
|
|
|
if (PanelConstants.OPT_TYPE_INSERT.equalsIgnoreCase(optType)) {
|
|
|
|
|
groupExample.createCriteria().andPidEqualTo(pid).andNameEqualTo(name);
|
|
|
|
|
} else if (PanelConstants.OPT_TYPE_UPDATE.equalsIgnoreCase(optType)) {
|
|
|
|
|
groupExample.createCriteria().andPidEqualTo(pid).andNameEqualTo(name).andIdNotEqualTo(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<PanelGroup> checkResult = panelGroupMapper.selectByExample(groupExample);
|
|
|
|
|
if (CollectionUtils.isNotEmpty(checkResult)) {
|
|
|
|
|
throw new RuntimeException(Translator.get("i18n_same_folder_can_not_repeat"));
|
2021-03-08 18:43:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-08 14:31:09 +08:00
|
|
|
|
|
|
|
|
|
|
2021-04-19 11:44:21 +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);
|
2021-05-21 10:52:19 +08:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
2021-04-19 11:44:21 +08:00
|
|
|
|
public PanelGroupWithBLOBs findOne(String panelId) {
|
|
|
|
|
return panelGroupMapper.selectByPrimaryKey(panelId);
|
2021-03-29 14:57:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-19 15:54:35 +08:00
|
|
|
|
|
2021-04-19 11:44:21 +08:00
|
|
|
|
public List<ChartViewDTO> getUsableViews(String panelId) throws Exception {
|
2021-03-19 15:54:35 +08:00
|
|
|
|
List<ChartViewDTO> chartViewDTOList = new ArrayList<>();
|
|
|
|
|
List<ChartView> allChartView = chartViewMapper.selectByExample(null);
|
|
|
|
|
Optional.ofNullable(allChartView).orElse(new ArrayList<>()).stream().forEach(chartView -> {
|
|
|
|
|
try {
|
2021-04-19 11:44:21 +08:00
|
|
|
|
chartViewDTOList.add(chartViewService.getData(chartView.getId(), null));
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
LOGGER.error("获取view详情出错:" + chartView.getId(), e);
|
2021-03-19 15:54:35 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return chartViewDTOList;
|
|
|
|
|
}
|
2021-03-08 14:31:09 +08:00
|
|
|
|
}
|