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-03-08 18:43:28 +08:00
|
|
|
|
import io.dataease.commons.utils.BeanUtils;
|
|
|
|
|
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-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-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 PanelDesignMapper panelDesignMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private ChartViewService chartViewService;
|
|
|
|
|
@Resource
|
|
|
|
|
private ChartViewMapper chartViewMapper;
|
2021-03-22 17:27:16 +08:00
|
|
|
|
@Resource
|
|
|
|
|
private ExtPanelDesignMapper extPanelDesignMapper;
|
2021-03-08 18:43:28 +08:00
|
|
|
|
|
|
|
|
|
public List<PanelGroupDTO> tree(PanelGroupRequest panelGroupRequest) {
|
|
|
|
|
List<PanelGroupDTO> panelGroupDTOList = extPanelGroupMapper.panelGroupList(panelGroupRequest);
|
|
|
|
|
getTreeChildren(panelGroupDTOList);
|
|
|
|
|
return panelGroupDTOList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void getTreeChildren(List<PanelGroupDTO> parentPanelGroupDTO){
|
|
|
|
|
Optional.ofNullable(parentPanelGroupDTO).ifPresent(parent -> parent.forEach(panelGroupDTO -> {
|
|
|
|
|
List<PanelGroupDTO> panelGroupDTOChildren = extPanelGroupMapper.panelGroupList(new PanelGroupRequest(panelGroupDTO.getId()));
|
|
|
|
|
panelGroupDTO.setChildren(panelGroupDTOChildren);
|
|
|
|
|
getTreeChildren(panelGroupDTOChildren);
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<PanelGroupDTO> getDefaultTree(PanelGroupRequest panelGroupRequest){
|
|
|
|
|
return extPanelGroupMapper.panelGroupList(panelGroupRequest);
|
|
|
|
|
}
|
|
|
|
|
|
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());
|
|
|
|
|
panelGroupMapper.insert(request);
|
|
|
|
|
} else {
|
|
|
|
|
panelGroupMapper.updateByPrimaryKey(request);
|
|
|
|
|
}
|
|
|
|
|
PanelGroupDTO panelGroupDTO = new PanelGroupDTO();
|
|
|
|
|
BeanUtils.copyBean(panelGroupDTO, request);
|
|
|
|
|
panelGroupDTO.setLabel(request.getName());
|
|
|
|
|
return panelGroupDTO;
|
|
|
|
|
}
|
2021-03-08 14:31:09 +08:00
|
|
|
|
|
|
|
|
|
|
2021-03-08 18:43:28 +08:00
|
|
|
|
public void deleteCircle(String id){
|
|
|
|
|
Assert.notNull(id, "id cannot be null");
|
|
|
|
|
extPanelGroupMapper.deleteCircle(id);
|
|
|
|
|
}
|
2021-03-08 14:31:09 +08:00
|
|
|
|
|
|
|
|
|
|
2021-03-19 15:54:35 +08:00
|
|
|
|
public PanelGroupDTO findOne(String panelId) throws Exception{
|
|
|
|
|
PanelGroupDTO panelGroupDTO = extPanelGroupMapper.panelGroup(panelId);
|
|
|
|
|
Assert.notNull(panelGroupDTO, "未查询到仪表盘信息");
|
|
|
|
|
PanelDesignExample panelDesignExample = new PanelDesignExample();
|
|
|
|
|
panelDesignExample.createCriteria().andPanelIdEqualTo(panelId);
|
|
|
|
|
List<PanelDesign> panelDesignList = panelDesignMapper.selectByExample(panelDesignExample);
|
|
|
|
|
if(CollectionUtils.isNotEmpty(panelDesignList)){
|
|
|
|
|
List<PanelDesignDTO> panelDesignDTOList = new ArrayList<>();
|
|
|
|
|
//TODO 加载所有视图和组件的数据
|
|
|
|
|
for(PanelDesign panelDesign:panelDesignList){
|
|
|
|
|
//TODO 获取view 视图数据
|
|
|
|
|
ChartViewDTO chartViewDTO = chartViewService.getData(panelDesign.getComponentId());
|
|
|
|
|
//TODO 获取systemComponent 系统组件数据(待开发)
|
|
|
|
|
|
|
|
|
|
PanelDesignDTO panelDesignDTO = new PanelDesignDTO(chartViewDTO);
|
|
|
|
|
BeanUtils.copyBean(panelDesignDTO,panelDesign);
|
|
|
|
|
panelDesignDTO.setKeepFlag(true);
|
|
|
|
|
panelDesignDTOList.add(panelDesignDTO);
|
|
|
|
|
}
|
|
|
|
|
panelGroupDTO.setPanelDesigns(panelDesignDTOList);
|
|
|
|
|
}
|
|
|
|
|
//获取所有可用的视图
|
|
|
|
|
panelGroupDTO.setViewsUsable(getUsableViews(panelId));
|
|
|
|
|
return panelGroupDTO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()));
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
LOGGER.error("获取view详情出错:"+chartView.getId(),e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return chartViewDTOList;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-22 17:27:16 +08:00
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
|
public void saveGroupWithDesign(PanelGroupRequest request) {
|
|
|
|
|
//TODO 更新panelGroup 信息
|
|
|
|
|
if (StringUtils.isEmpty(request.getId())) {
|
|
|
|
|
request.setId(UUID.randomUUID().toString());
|
|
|
|
|
request.setCreateTime(System.currentTimeMillis());
|
|
|
|
|
panelGroupMapper.insert(request);
|
|
|
|
|
} else {
|
|
|
|
|
panelGroupMapper.updateByPrimaryKey(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TODO 更新panelDesign 信息
|
|
|
|
|
String panelId = request.getId();
|
|
|
|
|
Assert.notNull(panelId,"panelId should not be null");
|
|
|
|
|
//清理原有design
|
|
|
|
|
extPanelDesignMapper.deleteByPanelId(panelId);
|
|
|
|
|
//保存view 或者component design
|
|
|
|
|
Optional.ofNullable(request.getPanelDesigns()).orElse(new ArrayList<>()).stream().forEach(panelDesignDTO -> {
|
|
|
|
|
if(panelDesignDTO.isKeepFlag()) {
|
|
|
|
|
String componentId = "";
|
|
|
|
|
if(StringUtils.equals(PanelConstants.COMPONENT_TYPE_VIEW,panelDesignDTO.getComponentType())){
|
|
|
|
|
componentId = panelDesignDTO.getChartView().getId();
|
|
|
|
|
}else{
|
|
|
|
|
//预留 公共组件id获取
|
|
|
|
|
componentId = "";
|
|
|
|
|
}
|
|
|
|
|
panelDesignDTO.setPanelId(panelId);
|
|
|
|
|
panelDesignDTO.setComponentId(componentId);
|
|
|
|
|
panelDesignDTO.setUpdateTime(System.currentTimeMillis());
|
|
|
|
|
panelDesignMapper.insertSelective(panelDesignDTO);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-03-08 14:31:09 +08:00
|
|
|
|
}
|