mirror of
https://github.com/dataease/dataease.git
synced 2026-05-19 10:18:11 +08:00
feat(视图): 1.初步增加结果过滤,条件之间暂时只支持'且'逻辑;2.fix设置显示名bug;3.一些样式调整
This commit is contained in:
@@ -2,6 +2,8 @@ package io.dataease.dto.chart;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author gin
|
||||
* @Date 2021/3/11 1:18 下午
|
||||
@@ -29,4 +31,6 @@ public class ChartViewFieldDTO {
|
||||
private String summary;
|
||||
|
||||
private String sort;
|
||||
|
||||
private List<ChartViewFieldFilterDTO> filter;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package io.dataease.dto.chart;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* @Author gin
|
||||
* @Date 2021/3/25 10:31 上午
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class ChartViewFieldFilterDTO {
|
||||
private String term;
|
||||
private String value;
|
||||
}
|
||||
@@ -174,6 +174,41 @@ public class ChartViewService {
|
||||
sql = sql.substring(0, sql.length() - 1);
|
||||
}
|
||||
// 如果是对结果字段过滤,则再包裹一层sql
|
||||
return sql;
|
||||
String[] resultFilter = yAxis.stream().filter(y -> CollectionUtils.isNotEmpty(y.getFilter()) && y.getFilter().size() > 0)
|
||||
.map(y -> {
|
||||
String[] s = y.getFilter().stream().map(f -> "AND _" + y.getSummary() + "_" + y.getOriginName() + transMysqlFilterTerm(f.getTerm()) + f.getValue()).toArray(String[]::new);
|
||||
return StringUtils.join(s, " ");
|
||||
}).toArray(String[]::new);
|
||||
if (resultFilter.length == 0) {
|
||||
return sql;
|
||||
} else {
|
||||
String filterSql = MessageFormat.format("SELECT * FROM {0} WHERE 1=1 {1}",
|
||||
"(" + sql + ") AS tmp",
|
||||
StringUtils.join(resultFilter, " "));
|
||||
return filterSql;
|
||||
}
|
||||
}
|
||||
|
||||
public String transMysqlFilterTerm(String term) {
|
||||
switch (term) {
|
||||
case "eq":
|
||||
return "=";
|
||||
case "not_eq":
|
||||
return "<>";
|
||||
case "lt":
|
||||
return "<";
|
||||
case "le":
|
||||
return "<=";
|
||||
case "gt":
|
||||
return ">";
|
||||
case "ge":
|
||||
return ">=";
|
||||
case "null":
|
||||
return "IS NULL";
|
||||
case "not_null":
|
||||
return "IS NOT NULL";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user