forked from github/dataease
Merge pull request #1466 from dataease/pr@dev@feat_filter_enum
feat(视图): 文本类型过滤组件支持枚举
This commit is contained in:
commit
cd4b93c487
@ -17,4 +17,6 @@ public class ChartFieldCustomFilterDTO extends ChartViewFieldBaseDTO implements
|
||||
private List<ChartCustomFilterItemDTO> filter;
|
||||
|
||||
private DatasetTableField field;
|
||||
|
||||
private List<String> enumCheckField;
|
||||
}
|
||||
|
@ -48,4 +48,6 @@ public class ChartViewFieldBaseDTO implements Serializable {
|
||||
private ChartFieldCompareDTO compareCalc;
|
||||
|
||||
private String logic;
|
||||
|
||||
private String filterType;
|
||||
}
|
||||
|
@ -735,62 +735,74 @@ public class MysqlQueryProvider extends QueryProvider {
|
||||
for (ChartFieldCustomFilterDTO request : requestList) {
|
||||
List<SQLObj> list = new ArrayList<>();
|
||||
DatasetTableField field = request.getField();
|
||||
List<ChartCustomFilterItemDTO> filter = request.getFilter();
|
||||
for (ChartCustomFilterItemDTO filterItemDTO : filter) {
|
||||
if (ObjectUtils.isEmpty(field)) {
|
||||
continue;
|
||||
|
||||
if (ObjectUtils.isEmpty(field)) {
|
||||
continue;
|
||||
}
|
||||
String whereName = "";
|
||||
String originName;
|
||||
if (ObjectUtils.isNotEmpty(field.getExtField()) && field.getExtField() == 2) {
|
||||
// 解析origin name中有关联的字段生成sql表达式
|
||||
originName = calcFieldRegex(field.getOriginName(), tableObj);
|
||||
} else if (ObjectUtils.isNotEmpty(field.getExtField()) && field.getExtField() == 1) {
|
||||
originName = String.format(MySQLConstants.KEYWORD_FIX, tableObj.getTableAlias(), field.getOriginName());
|
||||
} else {
|
||||
originName = String.format(MySQLConstants.KEYWORD_FIX, tableObj.getTableAlias(), field.getOriginName());
|
||||
}
|
||||
if (field.getDeType() == 1) {
|
||||
if (field.getDeExtractType() == 0 || field.getDeExtractType() == 5) {
|
||||
whereName = String.format(MySQLConstants.STR_TO_DATE, originName, MySQLConstants.DEFAULT_DATE_FORMAT);
|
||||
}
|
||||
String value = filterItemDTO.getValue();
|
||||
String whereName = "";
|
||||
String whereTerm = transMysqlFilterTerm(filterItemDTO.getTerm());
|
||||
String whereValue = "";
|
||||
String originName;
|
||||
if (ObjectUtils.isNotEmpty(field.getExtField()) && field.getExtField() == 2) {
|
||||
// 解析origin name中有关联的字段生成sql表达式
|
||||
originName = calcFieldRegex(field.getOriginName(), tableObj);
|
||||
} else if (ObjectUtils.isNotEmpty(field.getExtField()) && field.getExtField() == 1) {
|
||||
originName = String.format(MySQLConstants.KEYWORD_FIX, tableObj.getTableAlias(), field.getOriginName());
|
||||
} else {
|
||||
originName = String.format(MySQLConstants.KEYWORD_FIX, tableObj.getTableAlias(), field.getOriginName());
|
||||
if (field.getDeExtractType() == 2 || field.getDeExtractType() == 3 || field.getDeExtractType() == 4) {
|
||||
String cast = String.format(MySQLConstants.CAST, originName, MySQLConstants.DEFAULT_INT_FORMAT) + "/1000";
|
||||
whereName = String.format(MySQLConstants.FROM_UNIXTIME, cast, MySQLConstants.DEFAULT_DATE_FORMAT);
|
||||
}
|
||||
if (field.getDeType() == 1) {
|
||||
if (field.getDeExtractType() == 0 || field.getDeExtractType() == 5) {
|
||||
whereName = String.format(MySQLConstants.STR_TO_DATE, originName, MySQLConstants.DEFAULT_DATE_FORMAT);
|
||||
}
|
||||
if (field.getDeExtractType() == 2 || field.getDeExtractType() == 3 || field.getDeExtractType() == 4) {
|
||||
String cast = String.format(MySQLConstants.CAST, originName, MySQLConstants.DEFAULT_INT_FORMAT) + "/1000";
|
||||
whereName = String.format(MySQLConstants.FROM_UNIXTIME, cast, MySQLConstants.DEFAULT_DATE_FORMAT);
|
||||
}
|
||||
if (field.getDeExtractType() == 1) {
|
||||
whereName = originName;
|
||||
}
|
||||
} else {
|
||||
if (field.getDeExtractType() == 1) {
|
||||
whereName = originName;
|
||||
}
|
||||
if (StringUtils.equalsIgnoreCase(filterItemDTO.getTerm(), "null")) {
|
||||
whereValue = "";
|
||||
} else if (StringUtils.equalsIgnoreCase(filterItemDTO.getTerm(), "not_null")) {
|
||||
whereValue = "";
|
||||
} else if (StringUtils.equalsIgnoreCase(filterItemDTO.getTerm(), "empty")) {
|
||||
whereValue = "''";
|
||||
} else if (StringUtils.equalsIgnoreCase(filterItemDTO.getTerm(), "not_empty")) {
|
||||
whereValue = "''";
|
||||
} else if (StringUtils.containsIgnoreCase(filterItemDTO.getTerm(), "in")) {
|
||||
whereValue = "('" + StringUtils.join(value, "','") + "')";
|
||||
} else if (StringUtils.containsIgnoreCase(filterItemDTO.getTerm(), "like")) {
|
||||
whereValue = "'%" + value + "%'";
|
||||
} else {
|
||||
whereValue = String.format(MySQLConstants.WHERE_VALUE_VALUE, value);
|
||||
}
|
||||
list.add(SQLObj.builder()
|
||||
.whereField(whereName)
|
||||
.whereTermAndValue(whereTerm + whereValue)
|
||||
.build());
|
||||
} else {
|
||||
whereName = originName;
|
||||
}
|
||||
List<String> strList = new ArrayList<>();
|
||||
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")");
|
||||
|
||||
if (StringUtils.equalsIgnoreCase(request.getFilterType(), "enum")) {
|
||||
if (CollectionUtils.isNotEmpty(request.getEnumCheckField())) {
|
||||
res.add("(" + whereName + " IN ('" + String.join("','", request.getEnumCheckField()) + "'))");
|
||||
}
|
||||
} else {
|
||||
List<ChartCustomFilterItemDTO> filter = request.getFilter();
|
||||
for (ChartCustomFilterItemDTO filterItemDTO : filter) {
|
||||
if (ObjectUtils.isEmpty(field)) {
|
||||
continue;
|
||||
}
|
||||
String value = filterItemDTO.getValue();
|
||||
String whereTerm = transMysqlFilterTerm(filterItemDTO.getTerm());
|
||||
String whereValue = "";
|
||||
|
||||
if (StringUtils.equalsIgnoreCase(filterItemDTO.getTerm(), "null")) {
|
||||
whereValue = "";
|
||||
} else if (StringUtils.equalsIgnoreCase(filterItemDTO.getTerm(), "not_null")) {
|
||||
whereValue = "";
|
||||
} else if (StringUtils.equalsIgnoreCase(filterItemDTO.getTerm(), "empty")) {
|
||||
whereValue = "''";
|
||||
} else if (StringUtils.equalsIgnoreCase(filterItemDTO.getTerm(), "not_empty")) {
|
||||
whereValue = "''";
|
||||
} else if (StringUtils.containsIgnoreCase(filterItemDTO.getTerm(), "in")) {
|
||||
whereValue = "('" + StringUtils.join(value, "','") + "')";
|
||||
} else if (StringUtils.containsIgnoreCase(filterItemDTO.getTerm(), "like")) {
|
||||
whereValue = "'%" + value + "%'";
|
||||
} else {
|
||||
whereValue = String.format(MySQLConstants.WHERE_VALUE_VALUE, value);
|
||||
}
|
||||
list.add(SQLObj.builder()
|
||||
.whereField(whereName)
|
||||
.whereTermAndValue(whereTerm + whereValue)
|
||||
.build());
|
||||
}
|
||||
List<String> strList = new ArrayList<>();
|
||||
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
return CollectionUtils.isNotEmpty(res) ? "(" + String.join(" AND ", res) + ")" : null;
|
||||
|
@ -994,7 +994,11 @@ export default {
|
||||
data_percent: 'Percent',
|
||||
compare_calc_expression: 'Expression',
|
||||
and: 'And',
|
||||
or: 'Or'
|
||||
or: 'Or',
|
||||
logic_exp: 'Logic',
|
||||
enum_exp: 'Enum',
|
||||
pls_slc: 'Please Select',
|
||||
filter_exp: 'Filter Value'
|
||||
},
|
||||
dataset: {
|
||||
sheet_warn: 'There are multiple sheet pages, and the first one is extracted by default',
|
||||
|
@ -994,7 +994,11 @@ export default {
|
||||
data_percent: '差值百分比',
|
||||
compare_calc_expression: '計算公式',
|
||||
and: '與',
|
||||
or: '或'
|
||||
or: '或',
|
||||
logic_exp: '邏輯條件',
|
||||
enum_exp: '枚舉條件',
|
||||
pls_slc: '請選擇',
|
||||
filter_exp: '過濾條件'
|
||||
},
|
||||
dataset: {
|
||||
sheet_warn: '有多個 Sheet 頁,默認抽取第一個',
|
||||
|
@ -997,7 +997,11 @@ export default {
|
||||
data_percent: '差值百分比',
|
||||
compare_calc_expression: '计算公式',
|
||||
and: '与',
|
||||
or: '或'
|
||||
or: '或',
|
||||
logic_exp: '逻辑条件',
|
||||
enum_exp: '枚举条件',
|
||||
pls_slc: '请选择',
|
||||
filter_exp: '过滤条件'
|
||||
},
|
||||
dataset: {
|
||||
sheet_warn: '有多个 Sheet 页,默认抽取第一个',
|
||||
|
@ -1,52 +1,84 @@
|
||||
<template>
|
||||
<el-col>
|
||||
<div style="display: inline-block;">
|
||||
<el-button icon="el-icon-plus" circle size="mini" style="margin-bottom: 10px;" @click="addFilter" />
|
||||
<div v-if="item.deType === 0 || item.deType === 5">
|
||||
<el-radio-group
|
||||
v-model="logic"
|
||||
v-model="filterType"
|
||||
size="mini"
|
||||
style="margin-left: 10px;"
|
||||
@change="logicChange"
|
||||
style="margin-bottom: 10px;"
|
||||
@change="filterTypeChange"
|
||||
>
|
||||
<el-radio-button label="and">{{ $t('chart.and') }}</el-radio-button>
|
||||
<el-radio-button label="or">{{ $t('chart.or') }}</el-radio-button>
|
||||
<el-radio label="logic">{{ $t('chart.logic_exp') }}</el-radio>
|
||||
<el-radio label="enum">{{ $t('chart.enum_exp') }}</el-radio>
|
||||
</el-radio-group>
|
||||
</div>
|
||||
|
||||
<div style="max-height: 50vh;overflow-y: auto;">
|
||||
<el-row v-for="(f,index) in item.filter" :key="index" class="filter-item">
|
||||
<el-col :span="4">
|
||||
<span>{{ item.name }}</span>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-select v-model="f.term" size="mini">
|
||||
<el-option-group
|
||||
v-for="(group,idx) in options"
|
||||
:key="idx"
|
||||
:label="group.label"
|
||||
>
|
||||
<el-option
|
||||
v-for="opt in group.options"
|
||||
:key="opt.value"
|
||||
:label="opt.label"
|
||||
:value="opt.value"
|
||||
/>
|
||||
</el-option-group>
|
||||
</el-select>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-input v-show="!f.term.includes('null') && !f.term.includes('empty')" v-model="f.value" class="value-item" :placeholder="$t('chart.condition')" size="mini" clearable />
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-button type="text" icon="el-icon-delete" circle style="float: right" @click="removeFilter(index)" />
|
||||
</el-col>
|
||||
</el-row>
|
||||
<div v-if="((item.deType === 0 || item.deType === 5) && filterType === 'logic') || item.deType === 1 || item.deType === 2 || item.deType === 3">
|
||||
<div style="display: inline-block;">
|
||||
<el-button icon="el-icon-plus" circle size="mini" style="margin-bottom: 10px;" @click="addFilter" />
|
||||
<el-radio-group
|
||||
v-model="logic"
|
||||
size="mini"
|
||||
style="margin-left: 10px;"
|
||||
@change="logicChange"
|
||||
>
|
||||
<el-radio-button label="and">{{ $t('chart.and') }}</el-radio-button>
|
||||
<el-radio-button label="or">{{ $t('chart.or') }}</el-radio-button>
|
||||
</el-radio-group>
|
||||
</div>
|
||||
<div style="max-height: 50vh;overflow-y: auto;">
|
||||
<el-row v-for="(f,index) in item.filter" :key="index" class="filter-item">
|
||||
<el-col :span="4">
|
||||
<span>{{ item.name }}</span>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-select v-model="f.term" size="mini">
|
||||
<el-option-group
|
||||
v-for="(group,idx) in options"
|
||||
:key="idx"
|
||||
:label="group.label"
|
||||
>
|
||||
<el-option
|
||||
v-for="opt in group.options"
|
||||
:key="opt.value"
|
||||
:label="opt.label"
|
||||
:value="opt.value"
|
||||
/>
|
||||
</el-option-group>
|
||||
</el-select>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-input v-show="!f.term.includes('null') && !f.term.includes('empty')" v-model="f.value" class="value-item" :placeholder="$t('chart.condition')" size="mini" clearable />
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-button type="text" icon="el-icon-delete" circle style="float: right" @click="removeFilter(index)" />
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="(item.deType === 0 || item.deType === 5) && filterType === 'enum'">
|
||||
<span style="margin-right: 10px;">{{ $t('chart.filter_exp') }}</span>
|
||||
<el-select
|
||||
v-model="enumCheckField"
|
||||
filterable
|
||||
multiple
|
||||
:placeholder="$t('chart.pls_slc')"
|
||||
size="mini"
|
||||
@change="enumChange"
|
||||
>
|
||||
<el-option
|
||||
v-for="field in fieldOptions"
|
||||
:key="field.id"
|
||||
:label="field.text"
|
||||
:value="field.id"
|
||||
/>
|
||||
</el-select>
|
||||
</div>
|
||||
</el-col>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// import { fieldList } from '../../../../api/dataset/dataset'
|
||||
import { multFieldValues } from '@/api/dataset/dataset'
|
||||
|
||||
export default {
|
||||
name: 'ResultFilterEditor',
|
||||
@ -169,7 +201,10 @@ export default {
|
||||
}
|
||||
],
|
||||
options: [],
|
||||
logic: ''
|
||||
logic: '',
|
||||
filterType: '',
|
||||
enumCheckField: [],
|
||||
fieldOptions: []
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
@ -195,6 +230,21 @@ export default {
|
||||
},
|
||||
init() {
|
||||
this.logic = this.item.logic
|
||||
this.filterType = this.item.filterType
|
||||
this.enumCheckField = this.item.enumCheckField
|
||||
// 查找枚举的
|
||||
multFieldValues([this.item.id]).then(res => {
|
||||
this.fieldOptions = this.optionDatas(res.data)
|
||||
})
|
||||
},
|
||||
optionDatas(datas) {
|
||||
if (!datas) return null
|
||||
return datas.filter(item => !!item).map(item => {
|
||||
return {
|
||||
id: item,
|
||||
text: item
|
||||
}
|
||||
})
|
||||
},
|
||||
addFilter() {
|
||||
this.item.filter.push({
|
||||
@ -208,25 +258,31 @@ export default {
|
||||
},
|
||||
logicChange(val) {
|
||||
this.item.logic = val
|
||||
},
|
||||
filterTypeChange(val) {
|
||||
this.item.filterType = val
|
||||
},
|
||||
enumChange(val) {
|
||||
this.item.enumCheckField = this.enumCheckField
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.filter-item{
|
||||
width: 100%;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #DCDFE6;
|
||||
padding: 4px 14px;
|
||||
margin-bottom: 10px;
|
||||
display: flex;
|
||||
justify-content: left;
|
||||
align-items: center;
|
||||
}
|
||||
.form-item>>>.el-form-item__label{
|
||||
font-size: 12px;
|
||||
}
|
||||
.filter-item{
|
||||
width: 100%;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #DCDFE6;
|
||||
padding: 4px 14px;
|
||||
margin-bottom: 10px;
|
||||
display: flex;
|
||||
justify-content: left;
|
||||
align-items: center;
|
||||
}
|
||||
.form-item>>>.el-form-item__label{
|
||||
font-size: 12px;
|
||||
}
|
||||
span{
|
||||
font-size: 12px;
|
||||
}
|
||||
|
@ -1656,25 +1656,39 @@ export default {
|
||||
if (!this.filterItem.logic) {
|
||||
this.filterItem.logic = 'and'
|
||||
}
|
||||
if (!this.filterItem.filterType) {
|
||||
this.filterItem.filterType = 'logic'
|
||||
}
|
||||
if (!this.filterItem.enumCheckField) {
|
||||
this.filterItem.enumCheckField = []
|
||||
}
|
||||
this.resultFilterEdit = true
|
||||
},
|
||||
closeResultFilter() {
|
||||
this.resultFilterEdit = false
|
||||
},
|
||||
saveResultFilter() {
|
||||
for (let i = 0; i < this.filterItem.filter.length; i++) {
|
||||
const f = this.filterItem.filter[i]
|
||||
if (!f.term.includes('null') && !f.term.includes('empty') && (!f.value || f.value === '')) {
|
||||
this.$message({
|
||||
message: this.$t('chart.filter_value_can_null'),
|
||||
type: 'error',
|
||||
showClose: true
|
||||
})
|
||||
return
|
||||
if (((this.filterItem.deType === 0 || this.filterItem.deType === 5) && this.filterItem.filterType !== 'enum') ||
|
||||
this.filterItem.deType === 1 ||
|
||||
this.filterItem.deType === 2 ||
|
||||
this.filterItem.deType === 3) {
|
||||
for (let i = 0; i < this.filterItem.filter.length; i++) {
|
||||
const f = this.filterItem.filter[i]
|
||||
if (!f.term.includes('null') && !f.term.includes('empty') && (!f.value || f.value === '')) {
|
||||
this.$message({
|
||||
message: this.$t('chart.filter_value_can_null'),
|
||||
type: 'error',
|
||||
showClose: true
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.view.customFilter[this.filterItem.index].filter = this.filterItem.filter
|
||||
this.view.customFilter[this.filterItem.index].logic = this.filterItem.logic
|
||||
this.view.customFilter[this.filterItem.index].filterType = this.filterItem.filterType
|
||||
this.view.customFilter[this.filterItem.index].enumCheckField = this.filterItem.enumCheckField
|
||||
this.calcData(true)
|
||||
this.closeResultFilter()
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user