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

73 lines
2.4 KiB
Java
Raw Normal View History

2021-03-08 14:31:09 +08:00
package io.dataease.service.panel;
2021-03-08 18:43:28 +08:00
import io.dataease.base.domain.DatasetGroup;
2021-03-08 14:31:09 +08:00
import io.dataease.base.mapper.PanelGroupMapper;
2021-03-08 18:43:28 +08:00
import io.dataease.base.mapper.ext.ExtPanelGroupMapper;
import io.dataease.commons.utils.BeanUtils;
import io.dataease.controller.request.panel.PanelGroupRequest;
import io.dataease.dto.dataset.DataSetGroupDTO;
import io.dataease.dto.panel.PanelGroupDTO;
import org.apache.commons.lang3.StringUtils;
2021-03-08 14:31:09 +08:00
import org.springframework.stereotype.Service;
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-08 18:43:28 +08:00
import java.util.List;
import java.util.Optional;
import java.util.UUID;
2021-03-08 14:31:09 +08:00
/**
* Author: wangjiahao
* Date: 2021-03-05
* Description:
*/
@Service
public class PanelGroupService {
@Resource
private PanelGroupMapper panelGroupMapper;
2021-03-08 18:43:28 +08:00
@Resource
private ExtPanelGroupMapper extPanelGroupMapper;
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
}