feat(backend):tree delete fix

This commit is contained in:
xiajunjie 2021-05-24 23:01:09 +08:00
parent d922fe1175
commit 3e6caadf16
5 changed files with 41 additions and 14 deletions

View File

@ -4,7 +4,10 @@ import io.dataease.controller.request.dataset.DataSetGroupRequest;
import io.dataease.dto.dataset.DataSetGroupDTO;
import java.util.List;
import java.util.Map;
public interface ExtDataSetGroupMapper {
List<DataSetGroupDTO> search(DataSetGroupRequest ChartGroup);
Map<String, String> searchIds(String id, String type);
}

View File

@ -41,7 +41,9 @@
<if test="sort != null">
order by ${sort}
</if>
</select>
<select id="searchIds" resultType="java.util.Map">
select GET_V_AUTH_MODEL_WITH_CHILDREN(#{id},#{type}) ids
</select>
</mapper>

View File

@ -3,6 +3,7 @@ package io.dataease.service.chart;
import io.dataease.base.domain.*;
import io.dataease.base.mapper.ChartGroupMapper;
import io.dataease.base.mapper.ext.ExtChartGroupMapper;
import io.dataease.base.mapper.ext.ExtDataSetGroupMapper;
import io.dataease.commons.utils.AuthUtils;
import io.dataease.commons.utils.BeanUtils;
import io.dataease.commons.utils.TreeUtils;
@ -11,12 +12,14 @@ import io.dataease.controller.request.dataset.DataSetTableRequest;
import io.dataease.dto.chart.ChartGroupDTO;
import io.dataease.i18n.Translator;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
@ -27,9 +30,10 @@ public class ChartGroupService {
private ChartGroupMapper chartGroupMapper;
@Resource
private ChartViewService chartViewService;
@Resource
private ExtChartGroupMapper extChartGroupMapper;
@Resource
private ExtDataSetGroupMapper extDataSetGroupMapper;
public ChartGroupDTO save(ChartGroup chartGroup) {
checkName(chartGroup);
@ -51,9 +55,14 @@ public class ChartGroupService {
ChartGroup cg = chartGroupMapper.selectByPrimaryKey(id);
ChartGroupRequest ChartGroup = new ChartGroupRequest();
BeanUtils.copyBean(ChartGroup, cg);
List<ChartGroupDTO> tree = tree(ChartGroup);
Map<String, String> stringStringMap = extDataSetGroupMapper.searchIds(id, "chart");
String[] split = stringStringMap.get("ids").split(",");
List<String> ids = new ArrayList<>();
getAllId(tree, ids);
for (String dsId : split) {
if (StringUtils.isNotEmpty(dsId)) {
ids.add(dsId);
}
}
ChartGroupExample ChartGroupExample = new ChartGroupExample();
ChartGroupExample.createCriteria().andIdIn(ids);
chartGroupMapper.deleteByExample(ChartGroupExample);
@ -104,6 +113,9 @@ public class ChartGroupService {
if (StringUtils.isNotEmpty(chartGroup.getId())) {
criteria.andIdNotEqualTo(chartGroup.getId());
}
if (ObjectUtils.isNotEmpty(chartGroup.getLevel())) {
criteria.andLevelEqualTo(chartGroup.getLevel());
}
List<ChartGroup> list = chartGroupMapper.selectByExample(chartGroupExample);
if (list.size() > 0) {
throw new RuntimeException(Translator.get("i18n_name_cant_repeat_same_group"));

View File

@ -14,15 +14,13 @@ import io.dataease.dto.dataset.DataSetGroupDTO;
import io.dataease.dto.dataset.DataSetTableDTO;
import io.dataease.i18n.Translator;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -59,9 +57,14 @@ public class DataSetGroupService {
DatasetGroup dg = datasetGroupMapper.selectByPrimaryKey(id);
DataSetGroupRequest datasetGroup = new DataSetGroupRequest();
BeanUtils.copyBean(datasetGroup, dg);
List<DataSetGroupDTO> tree = tree(datasetGroup);
Map<String, String> stringStringMap = extDataSetGroupMapper.searchIds(id, "dataset");
String[] split = stringStringMap.get("ids").split(",");
List<String> ids = new ArrayList<>();
getAllId(tree, ids);
for (String dsId : split) {
if (StringUtils.isNotEmpty(dsId)) {
ids.add(dsId);
}
}
DatasetGroupExample datasetGroupExample = new DatasetGroupExample();
datasetGroupExample.createCriteria().andIdIn(ids);
datasetGroupMapper.deleteByExample(datasetGroupExample);
@ -117,6 +120,9 @@ public class DataSetGroupService {
if (StringUtils.isNotEmpty(datasetGroup.getId())) {
criteria.andIdNotEqualTo(datasetGroup.getId());
}
if (ObjectUtils.isNotEmpty(datasetGroup.getLevel())) {
criteria.andLevelEqualTo(datasetGroup.getLevel());
}
List<DatasetGroup> list = datasetGroupMapper.selectByExample(datasetGroupExample);
if (list.size() > 0) {
throw new RuntimeException(Translator.get("i18n_name_cant_repeat_same_group"));

View File

@ -128,7 +128,11 @@ public class DataSetTableService {
dataSetTableFieldsService.deleteByTableId(id);
// 删除同步任务
dataSetTableTaskService.deleteByTableId(id);
deleteDorisTable(id);
try {
deleteDorisTable(id);
} catch (Exception e) {
}
}
private void deleteDorisTable(String datasetId) throws Exception {
@ -260,13 +264,13 @@ public class DataSetTableService {
}
} else if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "excel")) {
List<DatasetTableTaskLog> datasetTableTaskLogs = dataSetTableTaskLogService.getByTableId(datasetTable.getId());
if(CollectionUtils.isEmpty(datasetTableTaskLogs)){
if (CollectionUtils.isEmpty(datasetTableTaskLogs)) {
throw new Exception("no records");
}
if(datasetTableTaskLogs.get(0).getStatus().equalsIgnoreCase(JobStatus.Underway.name())){
if (datasetTableTaskLogs.get(0).getStatus().equalsIgnoreCase(JobStatus.Underway.name())) {
throw new Exception(Translator.get("i18n_processing_data"));
}
if(datasetTableTaskLogs.get(0).getStatus().equalsIgnoreCase(JobStatus.Error.name())){
if (datasetTableTaskLogs.get(0).getStatus().equalsIgnoreCase(JobStatus.Error.name())) {
throw new Exception("Failed to extract data: " + datasetTableTaskLogs.get(0).getInfo());
}
Datasource ds = (Datasource) CommonBeanFactory.getBean("DorisDatasource");