feat(数据集): 1.删除分组,场景将同时删除dataset和chart;2.数据集SQL模式可以重新编辑SQL

This commit is contained in:
junjie 2021-03-25 18:09:44 +08:00
parent 68df03d708
commit 6b51090887
6 changed files with 56 additions and 7 deletions

View File

@ -2,9 +2,12 @@ package io.dataease.service.chart;
import io.dataease.base.domain.ChartGroup; import io.dataease.base.domain.ChartGroup;
import io.dataease.base.domain.ChartGroupExample; import io.dataease.base.domain.ChartGroupExample;
import io.dataease.base.domain.DatasetGroup;
import io.dataease.base.domain.DatasetTable;
import io.dataease.base.mapper.ChartGroupMapper; import io.dataease.base.mapper.ChartGroupMapper;
import io.dataease.commons.utils.BeanUtils; import io.dataease.commons.utils.BeanUtils;
import io.dataease.controller.request.chart.ChartGroupRequest; import io.dataease.controller.request.chart.ChartGroupRequest;
import io.dataease.controller.request.dataset.DataSetTableRequest;
import io.dataease.dto.chart.ChartGroupDTO; import io.dataease.dto.chart.ChartGroupDTO;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -21,6 +24,8 @@ import java.util.stream.Collectors;
public class ChartGroupService { public class ChartGroupService {
@Resource @Resource
private ChartGroupMapper chartGroupMapper; private ChartGroupMapper chartGroupMapper;
@Resource
private ChartViewService chartViewService;
public ChartGroupDTO save(ChartGroup chartGroup) { public ChartGroupDTO save(ChartGroup chartGroup) {
if (StringUtils.isEmpty(chartGroup.getId())) { if (StringUtils.isEmpty(chartGroup.getId())) {
@ -45,6 +50,14 @@ public class ChartGroupService {
ChartGroupExample ChartGroupExample = new ChartGroupExample(); ChartGroupExample ChartGroupExample = new ChartGroupExample();
ChartGroupExample.createCriteria().andIdIn(ids); ChartGroupExample.createCriteria().andIdIn(ids);
chartGroupMapper.deleteByExample(ChartGroupExample); chartGroupMapper.deleteByExample(ChartGroupExample);
// 删除所有chart
deleteChart(ids);
}
public void deleteChart(List<String> sceneIds) {
for (String sceneId : sceneIds) {
chartViewService.deleteBySceneId(sceneId);
}
} }
public ChartGroup getScene(String id) { public ChartGroup getScene(String id) {

View File

@ -75,6 +75,12 @@ public class ChartViewService {
chartViewMapper.deleteByPrimaryKey(id); chartViewMapper.deleteByPrimaryKey(id);
} }
public void deleteBySceneId(String sceneId) {
ChartViewExample chartViewExample = new ChartViewExample();
chartViewExample.createCriteria().andSceneIdEqualTo(sceneId);
chartViewMapper.deleteByExample(chartViewExample);
}
public ChartViewDTO getData(String id) throws Exception { public ChartViewDTO getData(String id) throws Exception {
ChartViewWithBLOBs view = chartViewMapper.selectByPrimaryKey(id); ChartViewWithBLOBs view = chartViewMapper.selectByPrimaryKey(id);
List<ChartViewFieldDTO> xAxis = new Gson().fromJson(view.getXAxis(), new TypeToken<List<ChartViewFieldDTO>>() { List<ChartViewFieldDTO> xAxis = new Gson().fromJson(view.getXAxis(), new TypeToken<List<ChartViewFieldDTO>>() {

View File

@ -52,10 +52,8 @@ public class DataSetGroupService {
DatasetGroupExample datasetGroupExample = new DatasetGroupExample(); DatasetGroupExample datasetGroupExample = new DatasetGroupExample();
datasetGroupExample.createCriteria().andIdIn(ids); datasetGroupExample.createCriteria().andIdIn(ids);
datasetGroupMapper.deleteByExample(datasetGroupExample); datasetGroupMapper.deleteByExample(datasetGroupExample);
// 获取type为scene的id删除场景下的表和字段 // 删除场景下的表和字段
deleteTableAndField(tree.stream().filter(ele -> { deleteTableAndField(ids);
return StringUtils.equalsIgnoreCase(ele.getType(), "scene");
}).map(DatasetGroup::getId).collect(Collectors.toList()));
} }
public DatasetGroup getScene(String id) { public DatasetGroup getScene(String id) {

View File

@ -768,7 +768,8 @@ export default {
incremental_delete: '增量删除', incremental_delete: '增量删除',
last_update_time: '上次更新时间', last_update_time: '上次更新时间',
current_update_time: '当前更新时间', current_update_time: '当前更新时间',
param: '参数' param: '参数',
edit_sql: '编辑SQL'
}, },
datasource: { datasource: {
create: '新建数据连接', create: '新建数据连接',

View File

@ -3,7 +3,7 @@
<el-row> <el-row>
<el-row style="height: 26px;"> <el-row style="height: 26px;">
<span style="line-height: 26px;"> <span style="line-height: 26px;">
{{ $t('dataset.add_sql_table') }} {{ param.tableId?$t('dataset.edit_sql'):$t('dataset.add_sql_table') }}
</span> </span>
<el-row style="float: right"> <el-row style="float: right">
<el-button size="mini" @click="cancel"> <el-button size="mini" @click="cancel">
@ -85,6 +85,7 @@
<script> <script>
import { post, listDatasource } from '@/api/dataset/dataset' import { post, listDatasource } from '@/api/dataset/dataset'
import { codemirror } from 'vue-codemirror' import { codemirror } from 'vue-codemirror'
import { getTable } from '@/api/dataset/dataset'
// //
import 'codemirror/lib/codemirror.css' import 'codemirror/lib/codemirror.css'
// options // options
@ -145,7 +146,13 @@ export default {
return this.$refs.myCm.codemirror return this.$refs.myCm.codemirror
} }
}, },
watch: {}, watch: {
'param.tableId': {
handler: function() {
this.initTableInfo()
}
}
},
mounted() { mounted() {
window.onresize = () => { window.onresize = () => {
return (() => { return (() => {
@ -157,6 +164,8 @@ export default {
this.$refs.myCm.codemirror.on('keypress', () => { this.$refs.myCm.codemirror.on('keypress', () => {
this.$refs.myCm.codemirror.showHint() this.$refs.myCm.codemirror.showHint()
}) })
this.initTableInfo()
}, },
methods: { methods: {
initDataSource() { initDataSource() {
@ -165,6 +174,20 @@ export default {
}) })
}, },
initTableInfo() {
if (this.param.tableId) {
getTable(this.param.tableId).then(response => {
const table = response.data
this.name = table.name
this.dataSource = table.dataSourceId
this.mode = table.mode + ''
this.sql = JSON.parse(table.info.replace(/\n/g, '\\n').replace(/\r/g, '\\r')).sql
this.getSQLPreview()
})
}
},
getSQLPreview() { getSQLPreview() {
if (!this.dataSource || this.datasource === '') { if (!this.dataSource || this.datasource === '') {
this.$message({ this.$message({
@ -204,6 +227,7 @@ export default {
return return
} }
const table = { const table = {
id: this.param.tableId,
name: this.name, name: this.name,
sceneId: this.param.id, sceneId: this.param.id,
dataSourceId: this.dataSource, dataSourceId: this.dataSource,

View File

@ -7,6 +7,9 @@
{{ table.name }} {{ table.name }}
</span> </span>
<el-row style="float: right"> <el-row style="float: right">
<el-button v-if="table.type ==='sql'" size="mini" @click="editSql">
{{ $t('dataset.edit_sql') }}
</el-button>
<el-button size="mini" @click="edit"> <el-button size="mini" @click="edit">
{{ $t('dataset.edit') }} {{ $t('dataset.edit') }}
</el-button> </el-button>
@ -146,6 +149,10 @@ export default {
closeEdit() { closeEdit() {
this.editField = false this.editField = false
this.tableFields = [] this.tableFields = []
},
editSql() {
this.$emit('switchComponent', { name: 'AddSQL', param: { id: this.table.sceneId, tableId: this.table.id }})
} }
} }
} }