feat(视图): 过滤器支持and、or逻辑

This commit is contained in:
junjie 2021-12-14 10:14:02 +08:00
parent def246cc54
commit 955d72cb75
12 changed files with 62 additions and 36 deletions

View File

@ -840,9 +840,11 @@ public class CKQueryProvider extends QueryProvider {
} }
List<String> strList = new ArrayList<>(); List<String> strList = new ArrayList<>();
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")"); if (CollectionUtils.isNotEmpty(list)) {
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")");
}
} }
return "(" + String.join(" AND ", res) + ")"; return CollectionUtils.isNotEmpty(res) ? "(" + String.join(" AND ", res) + ")" : null;
} }
public String transExtFilterList(SQLObj tableObj, List<ChartExtFilterRequest> requestList) { public String transExtFilterList(SQLObj tableObj, List<ChartExtFilterRequest> requestList) {
@ -922,7 +924,7 @@ public class CKQueryProvider extends QueryProvider {
} }
List<String> strList = new ArrayList<>(); List<String> strList = new ArrayList<>();
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
return "(" + String.join(" AND ", strList) + ")"; return CollectionUtils.isNotEmpty(list) ? "(" + String.join(" AND ", strList) + ")" : null;
} }
private String sqlFix(String sql) { private String sqlFix(String sql) {

View File

@ -790,9 +790,11 @@ public class Db2QueryProvider extends QueryProvider {
List<String> strList = new ArrayList<>(); List<String> strList = new ArrayList<>();
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")"); if (CollectionUtils.isNotEmpty(list)) {
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")");
}
} }
return "(" + String.join(" AND ", res) + ")"; return CollectionUtils.isNotEmpty(res) ? "(" + String.join(" AND ", res) + ")" : null;
} }
public String transExtFilterList(SQLObj tableObj, List<ChartExtFilterRequest> requestList) { public String transExtFilterList(SQLObj tableObj, List<ChartExtFilterRequest> requestList) {
@ -860,7 +862,7 @@ public class Db2QueryProvider extends QueryProvider {
} }
List<String> strList = new ArrayList<>(); List<String> strList = new ArrayList<>();
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
return "(" + String.join(" AND ", strList) + ")"; return CollectionUtils.isNotEmpty(list) ? "(" + String.join(" AND ", strList) + ")" : null;
} }
private String sqlFix(String sql) { private String sqlFix(String sql) {

View File

@ -812,9 +812,11 @@ public class DorisQueryProvider extends QueryProvider {
List<String> strList = new ArrayList<>(); List<String> strList = new ArrayList<>();
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")"); if (CollectionUtils.isNotEmpty(list)) {
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")");
}
} }
return "(" + String.join(" AND ", res) + ")"; return CollectionUtils.isNotEmpty(res) ? "(" + String.join(" AND ", res) + ")" : null;
} }
public String transExtFilterList(SQLObj tableObj, List<ChartExtFilterRequest> requestList) { public String transExtFilterList(SQLObj tableObj, List<ChartExtFilterRequest> requestList) {
@ -884,7 +886,7 @@ public class DorisQueryProvider extends QueryProvider {
} }
List<String> strList = new ArrayList<>(); List<String> strList = new ArrayList<>();
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
return "(" + String.join(" AND ", strList) + ")"; return CollectionUtils.isNotEmpty(list) ? "(" + String.join(" AND ", strList) + ")" : null;
} }
private String transDateFormat(String dateStyle, String datePattern) { private String transDateFormat(String dateStyle, String datePattern) {

View File

@ -759,9 +759,11 @@ public class EsQueryProvider extends QueryProvider {
List<String> strList = new ArrayList<>(); List<String> strList = new ArrayList<>();
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")"); if (CollectionUtils.isNotEmpty(list)) {
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")");
}
} }
return "(" + String.join(" AND ", res) + ")"; return CollectionUtils.isNotEmpty(res) ? "(" + String.join(" AND ", res) + ")" : null;
} }
public String transExtFilterList(SQLObj tableObj, List<ChartExtFilterRequest> requestList) { public String transExtFilterList(SQLObj tableObj, List<ChartExtFilterRequest> requestList) {
@ -828,7 +830,7 @@ public class EsQueryProvider extends QueryProvider {
} }
List<String> strList = new ArrayList<>(); List<String> strList = new ArrayList<>();
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
return "(" + String.join(" AND ", strList) + ")"; return CollectionUtils.isNotEmpty(list) ? "(" + String.join(" AND ", strList) + ")" : null;
} }
private String sqlFix(String sql) { private String sqlFix(String sql) {

View File

@ -786,9 +786,11 @@ public class HiveQueryProvider extends QueryProvider {
List<String> strList = new ArrayList<>(); List<String> strList = new ArrayList<>();
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")"); if (CollectionUtils.isNotEmpty(list)) {
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")");
}
} }
return "(" + String.join(" AND ", res) + ")"; return CollectionUtils.isNotEmpty(res) ? "(" + String.join(" AND ", res) + ")" : null;
} }
public String transExtFilterList(SQLObj tableObj, List<ChartExtFilterRequest> requestList) { public String transExtFilterList(SQLObj tableObj, List<ChartExtFilterRequest> requestList) {
@ -855,7 +857,7 @@ public class HiveQueryProvider extends QueryProvider {
} }
List<String> strList = new ArrayList<>(); List<String> strList = new ArrayList<>();
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
return "(" + String.join(" AND ", strList) + ")"; return CollectionUtils.isNotEmpty(list) ? "(" + String.join(" AND ", strList) + ")" : null;
} }
private String sqlFix(String sql) { private String sqlFix(String sql) {

View File

@ -752,9 +752,11 @@ public class MongoQueryProvider extends QueryProvider {
List<String> strList = new ArrayList<>(); List<String> strList = new ArrayList<>();
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")"); if (CollectionUtils.isNotEmpty(list)) {
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")");
}
} }
return "(" + String.join(" AND ", res) + ")"; return CollectionUtils.isNotEmpty(res) ? "(" + String.join(" AND ", res) + ")" : null;
} }
public String transExtFilterList(SQLObj tableObj, List<ChartExtFilterRequest> requestList) { public String transExtFilterList(SQLObj tableObj, List<ChartExtFilterRequest> requestList) {
@ -807,7 +809,7 @@ public class MongoQueryProvider extends QueryProvider {
} }
List<String> strList = new ArrayList<>(); List<String> strList = new ArrayList<>();
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
return "(" + String.join(" AND ", strList) + ")"; return CollectionUtils.isNotEmpty(list) ? "(" + String.join(" AND ", strList) + ")" : null;
} }
private String sqlFix(String sql) { private String sqlFix(String sql) {

View File

@ -789,9 +789,11 @@ public class MysqlQueryProvider extends QueryProvider {
} }
List<String> strList = new ArrayList<>(); List<String> strList = new ArrayList<>();
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")"); if (CollectionUtils.isNotEmpty(list)) {
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")");
}
} }
return "(" + String.join(" AND ", res) + ")"; return CollectionUtils.isNotEmpty(res) ? "(" + String.join(" AND ", res) + ")" : null;
} }
public String transExtFilterList(SQLObj tableObj, List<ChartExtFilterRequest> requestList) { public String transExtFilterList(SQLObj tableObj, List<ChartExtFilterRequest> requestList) {
@ -858,7 +860,7 @@ public class MysqlQueryProvider extends QueryProvider {
} }
List<String> strList = new ArrayList<>(); List<String> strList = new ArrayList<>();
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
return "(" + String.join(" AND ", strList) + ")"; return CollectionUtils.isNotEmpty(list) ? "(" + String.join(" AND ", strList) + ")" : null;
} }
private String sqlFix(String sql) { private String sqlFix(String sql) {

View File

@ -847,9 +847,11 @@ public class OracleQueryProvider extends QueryProvider {
List<String> strList = new ArrayList<>(); List<String> strList = new ArrayList<>();
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")"); if (CollectionUtils.isNotEmpty(list)) {
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")");
}
} }
return "(" + String.join(" AND ", res) + ")"; return CollectionUtils.isNotEmpty(res) ? "(" + String.join(" AND ", res) + ")" : null;
} }
public String transExtFilterList(SQLObj tableObj, List<ChartExtFilterRequest> requestList) { public String transExtFilterList(SQLObj tableObj, List<ChartExtFilterRequest> requestList) {
@ -917,7 +919,7 @@ public class OracleQueryProvider extends QueryProvider {
} }
List<String> strList = new ArrayList<>(); List<String> strList = new ArrayList<>();
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
return "(" + String.join(" AND ", strList) + ")"; return CollectionUtils.isNotEmpty(list) ? "(" + String.join(" AND ", strList) + ")" : null;
} }
private String sqlFix(String sql) { private String sqlFix(String sql) {

View File

@ -817,9 +817,11 @@ public class PgQueryProvider extends QueryProvider {
List<String> strList = new ArrayList<>(); List<String> strList = new ArrayList<>();
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")"); if (CollectionUtils.isNotEmpty(list)) {
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")");
}
} }
return "(" + String.join(" AND ", res) + ")"; return CollectionUtils.isNotEmpty(res) ? "(" + String.join(" AND ", res) + ")" : null;
} }
public String transExtFilterList(SQLObj tableObj, List<ChartExtFilterRequest> requestList) { public String transExtFilterList(SQLObj tableObj, List<ChartExtFilterRequest> requestList) {
@ -885,7 +887,7 @@ public class PgQueryProvider extends QueryProvider {
} }
List<String> strList = new ArrayList<>(); List<String> strList = new ArrayList<>();
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
return "(" + String.join(" AND ", strList) + ")"; return CollectionUtils.isNotEmpty(list) ? "(" + String.join(" AND ", strList) + ")" : null;
} }
private String sqlFix(String sql) { private String sqlFix(String sql) {

View File

@ -754,9 +754,11 @@ public class RedshiftQueryProvider extends QueryProvider {
List<String> strList = new ArrayList<>(); List<String> strList = new ArrayList<>();
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")"); if (CollectionUtils.isNotEmpty(list)) {
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")");
}
} }
return "(" + String.join(" AND ", res) + ")"; return CollectionUtils.isNotEmpty(res) ? "(" + String.join(" AND ", res) + ")" : null;
} }
public String transExtFilterList(SQLObj tableObj, List<ChartExtFilterRequest> requestList) { public String transExtFilterList(SQLObj tableObj, List<ChartExtFilterRequest> requestList) {
@ -822,7 +824,7 @@ public class RedshiftQueryProvider extends QueryProvider {
} }
List<String> strList = new ArrayList<>(); List<String> strList = new ArrayList<>();
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
return "(" + String.join(" AND ", strList) + ")"; return CollectionUtils.isNotEmpty(list) ? "(" + String.join(" AND ", strList) + ")" : null;
} }
private String sqlFix(String sql) { private String sqlFix(String sql) {

View File

@ -851,9 +851,11 @@ public class SqlserverQueryProvider extends QueryProvider {
List<String> strList = new ArrayList<>(); List<String> strList = new ArrayList<>();
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")"); if (CollectionUtils.isNotEmpty(list)) {
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")");
}
} }
return "(" + String.join(" AND ", res) + ")"; return CollectionUtils.isNotEmpty(res) ? "(" + String.join(" AND ", res) + ")" : null;
} }
public String transExtFilterList(SQLObj tableObj, List<ChartExtFilterRequest> requestList) { public String transExtFilterList(SQLObj tableObj, List<ChartExtFilterRequest> requestList) {
@ -920,7 +922,7 @@ public class SqlserverQueryProvider extends QueryProvider {
} }
List<String> strList = new ArrayList<>(); List<String> strList = new ArrayList<>();
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
return "(" + String.join(" AND ", strList) + ")"; return CollectionUtils.isNotEmpty(list) ? "(" + String.join(" AND ", strList) + ")" : null;
} }
private String sqlFix(String sql) { private String sqlFix(String sql) {

View File

@ -4,6 +4,7 @@ package io.dataease.service.dataset;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson; import com.google.gson.Gson;
import io.dataease.auth.api.dto.CurrentRoleDto; import io.dataease.auth.api.dto.CurrentRoleDto;
import io.dataease.auth.api.dto.CurrentUserDto;
import io.dataease.base.domain.*; import io.dataease.base.domain.*;
import io.dataease.base.mapper.*; import io.dataease.base.mapper.*;
import io.dataease.base.mapper.ext.ExtDataSetGroupMapper; import io.dataease.base.mapper.ext.ExtDataSetGroupMapper;
@ -447,9 +448,12 @@ public class DataSetTableService {
return new ArrayList<>(); return new ArrayList<>();
} }
RowPermissionService rowPermissionService = SpringContextUtil.getBean(RowPermissionService.class); RowPermissionService rowPermissionService = SpringContextUtil.getBean(RowPermissionService.class);
datasetRowPermissions.addAll(rowPermissionService.listDatasetRowPermissions(datasetId, Collections.singletonList(AuthUtils.getUser().getUserId()), "user")); CurrentUserDto user = AuthUtils.getUser();
datasetRowPermissions.addAll(rowPermissionService.listDatasetRowPermissions(datasetId, AuthUtils.getUser().getRoles().stream().map(CurrentRoleDto::getId).collect(Collectors.toList()), "role")); if (user != null) {
datasetRowPermissions.addAll(rowPermissionService.listDatasetRowPermissions(datasetId, Collections.singletonList(AuthUtils.getUser().getDeptId()), "dept")); datasetRowPermissions.addAll(rowPermissionService.listDatasetRowPermissions(datasetId, Collections.singletonList(user.getUserId()), "user"));
datasetRowPermissions.addAll(rowPermissionService.listDatasetRowPermissions(datasetId, user.getRoles().stream().map(CurrentRoleDto::getId).collect(Collectors.toList()), "role"));
datasetRowPermissions.addAll(rowPermissionService.listDatasetRowPermissions(datasetId, Collections.singletonList(user.getDeptId()), "dept"));
}
return datasetRowPermissions; return datasetRowPermissions;
} }