diff --git a/backend/src/main/java/io/dataease/controller/chart/ChartViewController.java b/backend/src/main/java/io/dataease/controller/chart/ChartViewController.java index 3582444176..249b06dc4b 100644 --- a/backend/src/main/java/io/dataease/controller/chart/ChartViewController.java +++ b/backend/src/main/java/io/dataease/controller/chart/ChartViewController.java @@ -166,17 +166,17 @@ public class ChartViewController { @ApiIgnore @ApiOperation("获取字段值") - @PostMapping("/getFieldData/{id}/{panelId}/{fieldId}") - public List getFieldData(@PathVariable String id, @PathVariable String panelId, @PathVariable String fieldId, + @PostMapping("/getFieldData/{id}/{panelId}/{fieldId}/{fieldType}") + public List getFieldData(@PathVariable String id, @PathVariable String panelId, @PathVariable String fieldId, @PathVariable String fieldType, @RequestBody ChartExtRequest requestList) throws Exception { - return chartViewService.getFieldData(id, requestList, false, fieldId); + return chartViewService.getFieldData(id, requestList, false, fieldId, fieldType); } @ApiIgnore @ApiOperation("更新视图属性") @PostMapping("/viewPropsSave/{panelId}") - public void viewPropsSave(@PathVariable String panelId, @RequestBody ChartViewWithBLOBs chartViewWithBLOBs) { - chartViewService.viewPropsSave(chartViewWithBLOBs); + public void viewPropsSave(@PathVariable String panelId, @RequestBody ChartViewWithBLOBs chartViewWithBLOBs) { + chartViewService.viewPropsSave(chartViewWithBLOBs); } @ApiOperation("查询仪表板下视图选项") diff --git a/backend/src/main/java/io/dataease/service/chart/ChartViewService.java b/backend/src/main/java/io/dataease/service/chart/ChartViewService.java index 808787a8ac..ac1d72f929 100644 --- a/backend/src/main/java/io/dataease/service/chart/ChartViewService.java +++ b/backend/src/main/java/io/dataease/service/chart/ChartViewService.java @@ -966,7 +966,14 @@ public class ChartViewService { } } // 自定义排序 - data = resultCustomSort(xAxis, data); + if (StringUtils.containsIgnoreCase(view.getType(), "stack")) { + List list = new ArrayList<>(); + list.addAll(xAxis); + list.addAll(extStack); + data = resultCustomSort(list, data); + } else { + data = resultCustomSort(xAxis, data); + } // 同比/环比计算,通过对比类型和数据设置,计算出对应指标的结果,然后替换结果data数组中的对应元素 // 如果因维度变化(如时间字段缺失,时间字段的展示格式变化)导致无法计算结果的,则结果data数组中的对应元素全置为null // 根据不同图表类型,获得需要替换的指标index array @@ -1485,21 +1492,27 @@ public class ChartViewService { extChartViewMapper.initPanelChartViewCache(panelId); } - public List getFieldData(String id, ChartExtRequest requestList, boolean cache, String fieldId) throws Exception { + public List getFieldData(String id, ChartExtRequest requestList, boolean cache, String fieldId, String fieldType) throws Exception { ChartViewDTO view = getOne(id, requestList.getQueryFrom()); List sqlData = sqlData(view, requestList, cache, fieldId); - List xAxis = gson.fromJson(view.getXAxis(), new TypeToken>() { - }.getType()); + List fieldList = new ArrayList<>(); + if (StringUtils.equalsIgnoreCase(fieldType, "xAxis")) { + fieldList = gson.fromJson(view.getXAxis(), new TypeToken>() { + }.getType()); + } else if (StringUtils.equalsIgnoreCase(fieldType, "extStack")) { + fieldList = gson.fromJson(view.getExtStack(), new TypeToken>() { + }.getType()); + } DatasetTableField field = dataSetTableFieldsService.get(fieldId); List res = new ArrayList<>(); - if (ObjectUtils.isNotEmpty(field) && xAxis.size() > 0) { + if (ObjectUtils.isNotEmpty(field) && fieldList.size() > 0) { // 找到对应维度 ChartViewFieldDTO chartViewFieldDTO = null; int index = 0; int getIndex = 0; - for (int i = 0; i < xAxis.size(); i++) { - ChartViewFieldDTO item = xAxis.get(i); + for (int i = 0; i < fieldList.size(); i++) { + ChartViewFieldDTO item = fieldList.get(i); if (StringUtils.equalsIgnoreCase(item.getSort(), "custom_sort")) {// 此处与已有的自定义字段对比 chartViewFieldDTO = item; index = i; @@ -1508,7 +1521,7 @@ public class ChartViewService { getIndex = i; } } - List sortResult = resultCustomSort(xAxis, sqlData); + List sortResult = resultCustomSort(fieldList, sqlData); if (ObjectUtils.isNotEmpty(chartViewFieldDTO) && (getIndex >= index)) { // 获取自定义值与data对应列的结果 List strings = customSort(Optional.ofNullable(chartViewFieldDTO.getCustomSort()).orElse(new ArrayList<>()), sortResult, index); diff --git a/frontend/src/views/chart/components/compare/CustomSortEdit.vue b/frontend/src/views/chart/components/compare/CustomSortEdit.vue index 1dea740cdc..3a073dcb2e 100644 --- a/frontend/src/views/chart/components/compare/CustomSortEdit.vue +++ b/frontend/src/views/chart/components/compare/CustomSortEdit.vue @@ -33,6 +33,10 @@ export default { field: { type: Object, required: true + }, + fieldType: { + type: String, + required: true } }, data() { @@ -55,7 +59,7 @@ export default { }, methods: { init() { - post('/chart/view/getFieldData/' + this.chart.id + '/' + this.panelInfo.id + '/' + this.field.id, {}).then(response => { + post('/chart/view/getFieldData/' + this.chart.id + '/' + this.panelInfo.id + '/' + this.field.id + '/' + this.fieldType, {}).then(response => { this.sortList = response.data }) }, diff --git a/frontend/src/views/chart/components/drag-item/ChartDragItem.vue b/frontend/src/views/chart/components/drag-item/ChartDragItem.vue index a88470fa5a..93f286cda5 100644 --- a/frontend/src/views/chart/components/drag-item/ChartDragItem.vue +++ b/frontend/src/views/chart/components/drag-item/ChartDragItem.vue @@ -94,6 +94,7 @@ {{ $t('chart.none') }} {{ $t('chart.asc') }} {{ $t('chart.desc') }} + {{ $t('chart.custom_sort') }}... @@ -181,8 +182,18 @@ export default { } }, sort(param) { - this.item.sort = param.type - this.$emit('onItemChange', this.item) + if (param.type === 'custom_sort') { + const item = { + index: this.index, + sort: param.type + } + this.$emit('onItemCustomSort', item) + } else { + this.item.index = this.index + this.item.sort = param.type + this.item.customSort = [] + this.$emit('onItemChange', this.item) + } }, beforeSort(type) { return { diff --git a/frontend/src/views/chart/view/ChartEdit.vue b/frontend/src/views/chart/view/ChartEdit.vue index a302147ec2..e876b24dc4 100644 --- a/frontend/src/views/chart/view/ChartEdit.vue +++ b/frontend/src/views/chart/view/ChartEdit.vue @@ -603,6 +603,7 @@ :quota-data="quota" @onItemChange="stackItemChange" @onItemRemove="stackItemRemove" + @onItemCustomSort="stackItemCustomSort" /> @@ -1074,7 +1075,7 @@ - + - + + + + + + + 0) { this.$message({ @@ -2440,6 +2457,11 @@ export default { this.view.extStack.splice(item.index, 1) this.calcData(true) }, + stackItemCustomSort(item) { + this.customSortField = this.view.extStack[item.index] + this.stackCustomSort() + }, + drillItemChange(item) { this.calcData(true) }, @@ -2692,11 +2714,6 @@ export default { }, saveCustomSort() { this.view.xaxis.forEach(ele => { - // 先将所有自定义排序的维度设置为none,再对当前维度赋值 - // if (ele.sort === 'custom_sort') { - // ele.sort = 'none' - // ele.customSort = [] - // } if (ele.id === this.customSortField.id) { ele.sort = 'custom_sort' ele.customSort = this.customSortList @@ -2706,6 +2723,23 @@ export default { this.calcData(true) }, + stackCustomSort() { + this.showStackCustomSort = true + }, + closeStackCustomSort() { + this.showStackCustomSort = false + }, + saveStackCustomSort() { + this.view.extStack.forEach(ele => { + if (ele.id === this.customSortField.id) { + ele.sort = 'custom_sort' + ele.customSort = this.customSortList + } + }) + this.closeStackCustomSort() + this.calcData(true) + }, + fieldEdit(param) { switch (param.type) { case 'ds':