fix: [插件] 指标过滤不生效

This commit is contained in:
ulleo 2023-09-07 15:51:11 +08:00
parent 1381ebd2cd
commit baab79b29d
6 changed files with 36 additions and 29 deletions

View File

@ -1474,6 +1474,8 @@ public class ChartViewService {
List<PluginViewField> pluginViewFields = fieldMap.entrySet().stream().flatMap(entry -> entry.getValue().stream().map(field -> {
PluginViewField pluginViewField = BeanUtils.copyBean(new PluginViewField(), field);
pluginViewField.setFilter(gson.fromJson(gson.toJson(field.getFilter()), new TypeToken<List<PluginChartCustomFilterItem>>() {
}.getType()));
pluginViewField.setTypeField(entry.getKey());
return pluginViewField;
})).collect(Collectors.toList());

View File

@ -2,6 +2,7 @@ package io.dataease.service.chart;
import cn.hutool.core.util.ReflectUtil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import io.dataease.commons.model.PluginViewSetImpl;
import io.dataease.commons.utils.TableUtils;
import io.dataease.controller.request.chart.ChartExtRequest;
@ -14,6 +15,7 @@ import io.dataease.plugins.common.constants.DatasetType;
import io.dataease.plugins.common.constants.datasource.SQLConstants;
import io.dataease.plugins.common.dto.chart.ChartFieldCustomFilterDTO;
import io.dataease.plugins.common.dto.chart.ChartViewFieldDTO;
import io.dataease.plugins.common.dto.chart.ChartViewFieldFilterDTO;
import io.dataease.plugins.common.dto.sqlObj.SQLObj;
import io.dataease.plugins.common.request.chart.ChartExtFilterRequest;
import io.dataease.plugins.common.request.permission.DataSetRowPermissionsTreeDTO;
@ -247,6 +249,9 @@ public class ViewPluginBaseServiceImpl implements ViewPluginBaseService {
methodName = "getYWheres";
}
ChartViewFieldDTO chartViewFieldDTO = BeanUtils.copyBean(new ChartViewFieldDTO(), field);
chartViewFieldDTO.setFilter(gson.fromJson(gson.toJson(field.getFilter()), new TypeToken<List<ChartViewFieldFilterDTO>>() {
}.getType()));
Object execResult;
if ((execResult = execProviderMethod(queryProvider, methodName, chartViewFieldDTO, originField, fieldAlias)) != null) {
String where = (String) execResult;

View File

@ -45,7 +45,6 @@ public class ChartMixViewStatHandler implements PluginViewStatHandler {
List<PluginViewSQL> xFields = fieldSQLMap.getOrDefault("xAxis", new ArrayList<>()).stream().filter(singleField -> ObjectUtils.isNotEmpty(singleField.getField())).map(PluginSingleField::getField).collect(Collectors.toList());
List<PluginViewSQL> xOrders = fieldSQLMap.getOrDefault("xAxis", new ArrayList<>()).stream().filter(singleField -> ObjectUtils.isNotEmpty(singleField.getSort())).map(PluginSingleField::getSort).collect(Collectors.toList());
System.out.println("11111111 orders:"+new Gson().toJson(xOrders));
// List<String> xWheres = fieldSQLMap.get("xAxis").stream().map(singleField -> singleField.getWhere()).collect(Collectors.toList());
List<PluginViewSQL> yFields = fieldSQLMap.getOrDefault("yAxis", new ArrayList<>()).stream().filter(singleField -> ObjectUtils.isNotEmpty(singleField.getField())).map(PluginSingleField::getField).collect(Collectors.toList());
@ -79,7 +78,6 @@ public class ChartMixViewStatHandler implements PluginViewStatHandler {
orders.addAll(xOrders);
orders.addAll(yOrders);
System.out.println("11111111 orders: " + new Gson().toJson(orders));
List<String> aggWheres = new ArrayList<>();
aggWheres.addAll(yWheres.stream().filter(ObjectUtils::isNotEmpty).collect(Collectors.toList()));

View File

@ -49,20 +49,14 @@ public class RaceBarViewStatHandler implements PluginViewStatHandler {
}
List<PluginViewSQL> xFields = fieldSQLMap.getOrDefault("xAxis", new ArrayList<>()).stream().filter(singleField -> ObjectUtils.isNotEmpty(singleField.getField())).map(PluginSingleField::getField).collect(Collectors.toList());
List<PluginViewSQL> xFields = fieldSQLMap.get("xAxis").stream().filter(singleField -> ObjectUtils.isNotEmpty(singleField.getField())).map(singleField -> singleField.getField()).collect(Collectors.toList());
List<PluginViewSQL> xOrders = fieldSQLMap.get("xAxis").stream().filter(singleField -> ObjectUtils.isNotEmpty(singleField.getSort())).map(singleField -> singleField.getSort()).collect(Collectors.toList());
// List<String> xWheres = fieldSQLMap.get("xAxis").stream().map(singleField -> singleField.getWhere()).collect(Collectors.toList());
List<PluginViewSQL> yFields = fieldSQLMap.getOrDefault("yAxis", new ArrayList<>()).stream().filter(singleField -> ObjectUtils.isNotEmpty(singleField.getField())).map(PluginSingleField::getField).collect(Collectors.toList());
List<String> yWheres = fieldSQLMap.getOrDefault("yAxis", new ArrayList<>()).stream().filter(singleField -> ObjectUtils.isNotEmpty(singleField.getWhere())).map(PluginSingleField::getWhere).collect(Collectors.toList());
List<String> yWheres = fieldSQLMap.get("yAxis").stream().filter(singleField -> ObjectUtils.isNotEmpty(singleField.getWhere())).map(singleField -> singleField.getWhere()).collect(Collectors.toList());
/*List<PluginViewSQL> yExtFields = fieldSQLMap.getOrDefault("yAxisExt", new ArrayList<>()).stream().filter(singleField -> ObjectUtils.isNotEmpty(singleField.getField())).map(PluginSingleField::getField).collect(Collectors.toList());
List<PluginViewSQL> yExtOrders = fieldSQLMap.getOrDefault("yAxisExt", new ArrayList<>()).stream().filter(singleField -> ObjectUtils.isNotEmpty(singleField.getSort())).map(PluginSingleField::getSort).collect(Collectors.toList());
List<String> yExtWheres = fieldSQLMap.getOrDefault("yAxisExt", new ArrayList<>()).stream().filter(singleField -> ObjectUtils.isNotEmpty(singleField.getWhere())).map(PluginSingleField::getWhere).collect(Collectors.toList());
yFields.addAll(yExtFields);
yOrders.addAll(yExtOrders);
yWheres.addAll(yExtWheres);*/
// 处理视图中字段过滤
String customWheres = baseService.customWhere(dsType, pluginViewParam.getPluginChartFieldCustomFilters(), tableObj);
@ -75,9 +69,15 @@ public class RaceBarViewStatHandler implements PluginViewStatHandler {
if (customWheres != null) wheres.add(customWheres);
if (panelWheres != null) wheres.add(panelWheres);
if (permissionWhere != null) wheres.add(permissionWhere);
List<PluginViewSQL> groups = new ArrayList<>();
groups.addAll(xFields);
List<PluginViewSQL> orders = new ArrayList<>();
orders.addAll(xOrders);
// 外层再次套sql
List<String> aggWheres = new ArrayList<>();
aggWheres.addAll(yWheres.stream().filter(ObjectUtils::isNotEmpty).collect(Collectors.toList()));
@ -99,7 +99,9 @@ public class RaceBarViewStatHandler implements PluginViewStatHandler {
.tableAlias(String.format(table_alias_prefix, 1))
.build();
if (CollectionUtils.isNotEmpty(aggWheres)) st.add("filters", aggWheres);
if (CollectionUtils.isNotEmpty(orders)) st.add("orders", orders);
if (ObjectUtils.isNotEmpty(tableSQL)) st.add("table", tableSQL);
return baseService.sqlLimit(dsType, st.render(), pluginViewParam.getPluginViewLimit());
}

View File

@ -42,7 +42,7 @@ public class RaceBarService extends ViewPluginService {
static {
VIEW_STYLE_PROPERTY_INNER.put("color-selector", new String[]{"value"});
VIEW_STYLE_PROPERTY_INNER.put("label-selector", new String[]{"show", "fontSize", "color", "position"});
VIEW_STYLE_PROPERTY_INNER.put("tooltip-selector", new String[]{"show", "textStyle", });
VIEW_STYLE_PROPERTY_INNER.put("tooltip-selector", new String[]{"show", "textStyle",});
VIEW_STYLE_PROPERTY_INNER.put("title-selector", new String[]{"show", "title", "fontSize", "color", "hPosition", "vPosition", "isItalic", "isBolder"});
}
@ -107,6 +107,7 @@ public class RaceBarService extends ViewPluginService {
return null;
}
String sql = new RaceBarViewStatHandler().build(param, this);
return sql;
}
@ -143,10 +144,21 @@ public class RaceBarService extends ViewPluginService {
map.put("encode", encode);
Set<Object> xs = new HashSet<>();
Set<String> keySet = new HashSet<>();
List<String> keyList = new ArrayList<>();
data.forEach(ss -> {
xs.add(ss[encode.get("y")]);
String key = ss[(Integer) map.get("extIndex")];
if (!keySet.contains(key)) {
keySet.add(key);
keyList.add(key);
}
});
Map<String, List<String[]>> groupData = data.stream().collect(Collectors.toMap(
k -> k[(Integer) map.get("extIndex")],
v -> {
@ -160,24 +172,12 @@ public class RaceBarService extends ViewPluginService {
})
);
for (String key : groupData.keySet()) {
String finalType = type;
groupData.put(key, groupData.get(key).stream().sorted((o1, o2) -> {
if (StringUtils.equals(finalType, "LONG")) {
return Long.valueOf(o2[encode.get("x")]).compareTo(Long.valueOf(o1[encode.get("x")]));
} else if (StringUtils.equals(finalType, "DOUBLE")) {
return Double.valueOf(o2[encode.get("x")]).compareTo(Double.valueOf(o1[encode.get("x")]));
}
return o2[encode.get("x")].compareTo(o1[encode.get("x")]);
}).collect(Collectors.toList()));
}
map.put("groupData", groupData);
map.put("extXs", new ArrayList<>(groupData.keySet()).stream().sorted().collect(Collectors.toList()));
map.put("extXs", keyList);
map.put("xs", new ArrayList<>(xs).stream().sorted().collect(Collectors.toList()));
map.put("xs", xs);
return map;
}

View File

@ -65,7 +65,7 @@
/>
</el-tag>
<el-dropdown-menu slot="dropdown">
<!-- <el-dropdown-item>
<el-dropdown-item>
<el-dropdown
placement="right-start"
size="mini"
@ -78,7 +78,7 @@
<span>{{ $t('chart.sort') }}</span>
<span class="summary-span-item">({{ $t('chart.' + item.sort) }})</span>
</span>
<i class="el-icon-arrow-right el-icon&#45;&#45;right"/>
<i class="el-icon-arrow-right el-icon--right"/>
</span>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item :command="beforeSort('none')">{{ $t('chart.none') }}</el-dropdown-item>
@ -86,7 +86,7 @@
<el-dropdown-item :command="beforeSort('desc')">{{ $t('chart.desc') }}</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</el-dropdown-item>-->
</el-dropdown-item>
<el-dropdown-item
v-show="item.deType === 1"