diff --git a/core/backend/src/main/java/io/dataease/controller/chart/ChartViewController.java b/core/backend/src/main/java/io/dataease/controller/chart/ChartViewController.java index aaf9e57638..1b6066b0b4 100644 --- a/core/backend/src/main/java/io/dataease/controller/chart/ChartViewController.java +++ b/core/backend/src/main/java/io/dataease/controller/chart/ChartViewController.java @@ -179,6 +179,14 @@ public class ChartViewController { return chartViewService.getFieldData(id, requestList, false, fieldId, fieldType); } + @ApiIgnore + @ApiOperation("获取下钻字段值") + @PostMapping("/getDrillFieldData/{id}/{panelId}/{fieldId}") + public List getDrillFieldData(@PathVariable String id, @PathVariable String panelId, @PathVariable String fieldId, + @RequestBody ChartExtRequest requestList) throws Exception { + return chartViewService.getDrillFieldData(id, requestList, false, fieldId); + } + @ApiIgnore @ApiOperation("更新视图属性") @PostMapping("/viewPropsSave/{panelId}") diff --git a/core/backend/src/main/java/io/dataease/service/chart/ChartViewService.java b/core/backend/src/main/java/io/dataease/service/chart/ChartViewService.java index fff8e054c7..01778077fe 100644 --- a/core/backend/src/main/java/io/dataease/service/chart/ChartViewService.java +++ b/core/backend/src/main/java/io/dataease/service/chart/ChartViewService.java @@ -443,9 +443,6 @@ public class ChartViewService { } List extFilterList = new ArrayList<>(); - List filters = new ArrayList<>(); - List drillFilters = new ArrayList<>(); - boolean isDrill = false; // 判断连接方式,直连或者定时抽取 table.mode DatasourceRequest datasourceRequest = new DatasourceRequest(); @@ -984,7 +981,6 @@ public class ChartViewService { ChartViewFieldDTO nextDrillField = drill.get(i + 1); if (!checkDrillExist(xAxis, extStack, nextDrillField.getId(), view)) { // get drill list first element's sort,then assign to nextDrillField - nextDrillField.setSort(getDrillSort(xAxis, drill.get(0))); nextDrillField.setDrill(true); if (isAntVScatterNumberXAxis) { @@ -2530,4 +2526,27 @@ public class ChartViewService { result.setDatasourceType(null); } } + + public List getDrillFieldData(String id, ChartExtRequest requestList, boolean cache, String fieldId) throws Exception { + ChartViewDTO view = getOne(id, requestList.getQueryFrom()); + Type tokenType = new TypeToken>() { + }.getType(); + List drillField = gson.fromJson(view.getDrillFields(), tokenType); + ChartViewFieldDTO targetField = null; + for (int i = 0; i < drillField.size(); i++) { + ChartViewFieldDTO tmp = drillField.get(i); + if (tmp.getId().equalsIgnoreCase(fieldId)) { + targetField = tmp; + break; + } + } + if (targetField == null) { + return Collections.emptyList(); + } + view.setXAxis(gson.toJson(Collections.singleton(targetField))); + + List sqlData = sqlData(view, requestList, cache, fieldId); + List result = customSort(Optional.ofNullable(targetField.getCustomSort()).orElse(new ArrayList<>()), sqlData, 0); + return result.stream().map(i -> i[0]).distinct().collect(Collectors.toList()); + } } diff --git a/core/frontend/src/views/chart/components/compare/CustomSortEdit.vue b/core/frontend/src/views/chart/components/compare/CustomSortEdit.vue index 82584e3107..231ef017dc 100644 --- a/core/frontend/src/views/chart/components/compare/CustomSortEdit.vue +++ b/core/frontend/src/views/chart/components/compare/CustomSortEdit.vue @@ -92,10 +92,17 @@ export default { }, methods: { init() { - post('/chart/view/getFieldData/' + this.chart.id + '/' + this.panelInfo.id + '/' + this.field.id + '/' + this.fieldType, {}).then(response => { - this.sortList = response.data - this.onUpdate() - }) + if (this.fieldType === 'drillFields') { + post('/chart/view/getDrillFieldData/' + this.chart.id + '/' + this.panelInfo.id + '/' + this.field.id, {}).then(response => { + this.sortList = response.data + this.onUpdate() + }) + } else { + post('/chart/view/getFieldData/' + this.chart.id + '/' + this.panelInfo.id + '/' + this.field.id + '/' + this.fieldType, {}).then(response => { + this.sortList = response.data + this.onUpdate() + }) + } }, moveToTop(index, item) { let targetIndex = index diff --git a/core/frontend/src/views/chart/components/dragItem/DrillItem.vue b/core/frontend/src/views/chart/components/dragItem/DrillItem.vue index 1e151bae30..f00e8422f5 100644 --- a/core/frontend/src/views/chart/components/dragItem/DrillItem.vue +++ b/core/frontend/src/views/chart/components/dragItem/DrillItem.vue @@ -59,6 +59,33 @@ /> + + + + + + {{ $t('chart.sort') }} + ({{ item.sort ? $t('chart.' + item.sort) : $t('chart.none') }}) + + + + + {{ $t('chart.none') }} + {{ $t('chart.asc') }} + {{ $t('chart.desc') }} + + {{ $t('chart.custom_sort') }}... + + + + @@ -161,6 +188,10 @@ export default { quotaData: { type: Array, required: true + }, + chart: { + type: Object, + required: true } }, data() { @@ -168,6 +199,18 @@ export default { tagType: 'success' } }, + computed: { + showDateExt() { + return ( + this.chart.datasourceType === 'mysql' || + this.chart.datasourceType === 'ds_doris' || + this.chart.datasourceType === 'StarRocks' || + this.chart.datasourceType === 'ck' || + this.chart.datasourceType === 'oracle' || + this.chart.datasetMode === 1) && + this.chart.type !== 'bar-time-range' + } + }, watch: { dimensionData: function() { this.getItemTagType() @@ -228,6 +271,25 @@ export default { return { type: type } + }, + beforeSort(type) { + return { + type: type + } + }, + sort(param) { + if (param.type === 'custom_sort') { + const item = { + index: this.index, + sort: param.type + } + this.$emit('onCustomSort', item) + } else { + this.item.index = this.index + this.item.sort = param.type + this.item.customSort = [] + this.$emit('onDimensionItemChange', this.item) + } } } } diff --git a/core/frontend/src/views/chart/view/ChartEdit.vue b/core/frontend/src/views/chart/view/ChartEdit.vue index e29d85a402..a78498f7d4 100644 --- a/core/frontend/src/views/chart/view/ChartEdit.vue +++ b/core/frontend/src/views/chart/view/ChartEdit.vue @@ -1183,8 +1183,10 @@ :item="item" :dimension-data="dimension" :quota-data="quota" + :chart="chart" @onDimensionItemChange="drillItemChange" @onDimensionItemRemove="drillItemRemove" + @onCustomSort="item => onCustomSort(item, 'drillFields')" /> @@ -2934,7 +2936,7 @@ export default { }, customSort(args) { const { item, axis } = JSON.parse(JSON.stringify(args)) - this.onCustomSort(item, axis); + this.onCustomSort(item, axis) }, onCustomSort(item, axis) { this.customSortFieldType = axis