From d9b30bafb753fffe9b35165df1268c7a70c7c947 Mon Sep 17 00:00:00 2001 From: ulleo Date: Fri, 21 Jul 2023 15:38:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8F=92=E4=BB=B6=E8=A7=86=E5=9B=BE?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8F=82=E6=95=B0=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/chart/ChartViewService.java | 18 ++++++++++++------ .../chart/ViewPluginBaseServiceImpl.java | 8 ++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) 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 1b7384fd61..abd95116f2 100644 --- a/backend/src/main/java/io/dataease/service/chart/ChartViewService.java +++ b/backend/src/main/java/io/dataease/service/chart/ChartViewService.java @@ -448,7 +448,7 @@ public class ChartViewService { fieldMap.put("yAxis", yAxis); fieldMap.put("extStack", extStack); fieldMap.put("extBubble", extBubble); - PluginViewParam pluginViewParam = buildPluginParam(fieldMap, fieldCustomFilter, extFilterList, ds, table, view, rowPermissionsTree); + PluginViewParam pluginViewParam = buildPluginParam(fieldMap, fieldCustomFilter, extFilterList, ds, table, view, rowPermissionsTree, requestList); String sql = pluginViewSql(pluginViewParam, view); if (StringUtils.isBlank(sql)) { return new ArrayList(); @@ -982,7 +982,7 @@ public class ChartViewService { fieldMap.put("extBubble", extBubble); fieldMap.put("xAxis", xAxis); fieldMap.put("yAxis", yAxis); - PluginViewParam pluginViewParam = buildPluginParam(fieldMap, fieldCustomFilter, extFilterList, ds, table, view, rowPermissionsTree); + PluginViewParam pluginViewParam = buildPluginParam(fieldMap, fieldCustomFilter, extFilterList, ds, table, view, rowPermissionsTree, chartExtRequest); String sql = pluginViewSql(pluginViewParam, view); if (StringUtils.isBlank(sql)) { return emptyChartViewDTO(view); @@ -1441,12 +1441,13 @@ public class ChartViewService { return dto; } - private PluginViewParam buildPluginParam(Map> fieldMap, List customFilters, List extFilters, Datasource ds, DatasetTable table, ChartViewDTO view, List rowPermissionsTree) { + private PluginViewParam buildPluginParam(Map> fieldMap, List customFilters, List extFilters, Datasource ds, DatasetTable table, ChartViewDTO view, List rowPermissionsTree, ChartExtRequest chartExtRequest) { PluginViewParam pluginViewParam = new PluginViewParam(); PluginViewSetImpl pluginViewSet = BeanUtils.copyBean(new PluginViewSetImpl(), table); pluginViewSet.setDsType(ds.getType()); pluginViewSet.setTableId(table.getId()); pluginViewSet.setDs(ds); + pluginViewSet.setChartExtRequest(gson.toJson(chartExtRequest)); PluginViewLimit pluginViewLimit = BeanUtils.copyBean(new PluginViewLimit(), view); @@ -1851,8 +1852,8 @@ public class ChartViewService { chartViewMapper.updateByPrimaryKeySelective(chartView); } - private String handleVariable(String sql, ChartExtRequest requestList, QueryProvider qp, DataSetTableDTO table, Datasource ds) throws Exception { - List sqlVariables = new Gson().fromJson(table.getSqlVariableDetails(), new TypeToken>() { + public String preHandleVariable(String sql, ChartExtRequest requestList, QueryProvider qp, DataSetTableDTO table) { + List sqlVariables = gson.fromJson(table.getSqlVariableDetails(), new TypeToken>() { }.getType()); if (requestList != null && CollectionUtils.isNotEmpty(requestList.getFilter())) { for (ChartExtFilterRequest chartExtFilterRequest : requestList.getFilter()) { @@ -1863,7 +1864,7 @@ public class ChartViewService { continue; } - Boolean isEndParam = false; + boolean isEndParam = false; for (String parameter : chartExtFilterRequest.getParameters()) { if (parameter.contains("|DE|")) { String[] parameterArray = parameter.split("\\|DE\\|"); @@ -1902,6 +1903,11 @@ public class ChartViewService { } } } + return sql; + } + + private String handleVariable(String sql, ChartExtRequest requestList, QueryProvider qp, DataSetTableDTO table, Datasource ds) throws Exception { + sql = preHandleVariable(sql, requestList, qp, table); sql = dataSetTableService.handleVariableDefaultValue(sql, null, ds.getType(), false); return sql; } diff --git a/backend/src/main/java/io/dataease/service/chart/ViewPluginBaseServiceImpl.java b/backend/src/main/java/io/dataease/service/chart/ViewPluginBaseServiceImpl.java index a8707f05fd..97b44fe33f 100644 --- a/backend/src/main/java/io/dataease/service/chart/ViewPluginBaseServiceImpl.java +++ b/backend/src/main/java/io/dataease/service/chart/ViewPluginBaseServiceImpl.java @@ -4,6 +4,7 @@ import cn.hutool.core.util.ReflectUtil; import com.google.gson.Gson; import io.dataease.commons.model.PluginViewSetImpl; import io.dataease.commons.utils.TableUtils; +import io.dataease.controller.request.chart.ChartExtRequest; import io.dataease.dto.dataset.DataSetTableUnionDTO; import io.dataease.dto.dataset.DataTableInfoDTO; import io.dataease.plugins.common.base.domain.ChartViewWithBLOBs; @@ -47,6 +48,9 @@ public class ViewPluginBaseServiceImpl implements ViewPluginBaseService { @Resource private DataSetTableService dataSetTableService; + @Resource + private ChartViewService chartViewService; + @Override public PluginSingleField buildField(String dsType, PluginViewField pluginViewField, PluginViewSQL tableObj, int index) { @@ -122,6 +126,10 @@ public class ViewPluginBaseServiceImpl implements ViewPluginBaseService { break; case SQL: String sql = dataTableInfoDTO.isBase64Encryption() ? new String(java.util.Base64.getDecoder().decode(dataTableInfoDTO.getSql())) : dataTableInfoDTO.getSql(); + if (StringUtils.isNotBlank(pluginViewSet.getChartExtRequest())) { + ChartExtRequest chartExtRequest = gson.fromJson(pluginViewSet.getChartExtRequest(), ChartExtRequest.class); + sql = chartViewService.preHandleVariable(sql, chartExtRequest, ProviderFactory.getQueryProvider(pluginViewSet.getDsType()), dataSetTableService.getWithPermission(pluginViewSet.getTableId(), chartExtRequest.getUser())); + } tableName = dataSetTableService.handleVariableDefaultValue(sql, null, pluginViewSet.getDsType(), false); tableName = "(" + sqlFix(tableName) + ")"; break;