2023-07-10 23:35:24 +08:00
|
|
|
|
// SiYuan - Refactor your thinking
|
|
|
|
|
// Copyright (c) 2020-present, b3log.org
|
|
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
package av
|
|
|
|
|
|
2023-12-30 16:59:41 +08:00
|
|
|
|
import (
|
2024-03-13 23:23:52 +08:00
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
|
2024-04-17 19:39:33 +08:00
|
|
|
|
"github.com/88250/lute/ast"
|
2024-03-02 22:35:04 +08:00
|
|
|
|
"github.com/siyuan-note/siyuan/kernel/util"
|
2023-12-30 16:59:41 +08:00
|
|
|
|
)
|
|
|
|
|
|
2025-07-06 16:31:09 +08:00
|
|
|
|
// ViewFilter 描述了视图过滤规则的结构。
|
2023-07-11 19:45:27 +08:00
|
|
|
|
type ViewFilter struct {
|
2025-09-02 22:04:29 +08:00
|
|
|
|
Column string `json:"column"` // 列(字段)ID
|
|
|
|
|
Qualifier FilterQuantifier `json:"quantifier,omitempty"` // 量词
|
|
|
|
|
Operator FilterOperator `json:"operator"` // 操作符
|
|
|
|
|
Value *Value `json:"value"` // 过滤值
|
|
|
|
|
RelativeDate *RelativeDate `json:"relativeDate,omitempty"` // 相对时间
|
|
|
|
|
RelativeDate2 *RelativeDate `json:"relativeDate2,omitempty"` // 第二个相对时间,用于某些操作符,比如 FilterOperatorIsBetween
|
2024-03-01 09:08:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type RelativeDateUnit int
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
RelativeDateUnitDay = iota
|
|
|
|
|
RelativeDateUnitWeek
|
|
|
|
|
RelativeDateUnitMonth
|
|
|
|
|
RelativeDateUnitYear
|
|
|
|
|
)
|
|
|
|
|
|
2024-03-01 09:55:21 +08:00
|
|
|
|
type RelativeDateDirection int
|
|
|
|
|
|
2024-03-01 09:35:55 +08:00
|
|
|
|
const (
|
|
|
|
|
RelativeDateDirectionBefore = -1
|
|
|
|
|
RelativeDateDirectionThis = 0
|
|
|
|
|
RelativeDateDirectionAfter = 1
|
|
|
|
|
)
|
|
|
|
|
|
2024-03-01 09:08:04 +08:00
|
|
|
|
type RelativeDate struct {
|
2024-03-02 22:35:04 +08:00
|
|
|
|
Count int `json:"count"` // 数量
|
|
|
|
|
Unit RelativeDateUnit `json:"unit"` // 单位:0 天、1 周、2 月、3 年
|
2024-04-14 09:01:22 +08:00
|
|
|
|
Direction RelativeDateDirection `json:"direction"` // 方向:-1 前、0 当前、1 后
|
2023-07-10 23:35:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type FilterOperator string
|
|
|
|
|
|
|
|
|
|
const (
|
2024-03-01 09:08:04 +08:00
|
|
|
|
FilterOperatorIsEqual FilterOperator = "="
|
|
|
|
|
FilterOperatorIsNotEqual FilterOperator = "!="
|
|
|
|
|
FilterOperatorIsGreater FilterOperator = ">"
|
|
|
|
|
FilterOperatorIsGreaterOrEqual FilterOperator = ">="
|
|
|
|
|
FilterOperatorIsLess FilterOperator = "<"
|
|
|
|
|
FilterOperatorIsLessOrEqual FilterOperator = "<="
|
|
|
|
|
FilterOperatorContains FilterOperator = "Contains"
|
|
|
|
|
FilterOperatorDoesNotContain FilterOperator = "Does not contains"
|
|
|
|
|
FilterOperatorIsEmpty FilterOperator = "Is empty"
|
|
|
|
|
FilterOperatorIsNotEmpty FilterOperator = "Is not empty"
|
|
|
|
|
FilterOperatorStartsWith FilterOperator = "Starts with"
|
|
|
|
|
FilterOperatorEndsWith FilterOperator = "Ends with"
|
|
|
|
|
FilterOperatorIsBetween FilterOperator = "Is between"
|
|
|
|
|
FilterOperatorIsTrue FilterOperator = "Is true"
|
|
|
|
|
FilterOperatorIsFalse FilterOperator = "Is false"
|
2023-07-10 23:35:24 +08:00
|
|
|
|
)
|
2023-12-30 16:59:41 +08:00
|
|
|
|
|
2025-09-02 22:04:29 +08:00
|
|
|
|
type FilterQuantifier string
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
FilterQuantifierUndefined FilterQuantifier = ""
|
|
|
|
|
FilterQuantifierAny FilterQuantifier = "Any"
|
|
|
|
|
FilterQuantifierAll FilterQuantifier = "All"
|
|
|
|
|
FilterQuantifierNone FilterQuantifier = "None"
|
|
|
|
|
)
|
|
|
|
|
|
2025-09-02 18:37:27 +08:00
|
|
|
|
func Filter(viewable Viewable, attrView *AttributeView, rollupFurtherCollections map[string]Collection, cachedAttrViews map[string]*AttributeView) {
|
2025-07-05 12:11:12 +08:00
|
|
|
|
collection := viewable.(Collection)
|
|
|
|
|
filters := collection.GetFilters()
|
|
|
|
|
if 1 > len(filters) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var colIndexes []int
|
|
|
|
|
for _, f := range filters {
|
|
|
|
|
for i, c := range collection.GetFields() {
|
|
|
|
|
if c.GetID() == f.Column {
|
|
|
|
|
colIndexes = append(colIndexes, i)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var items []Item
|
|
|
|
|
for _, item := range collection.GetItems() {
|
|
|
|
|
pass := true
|
|
|
|
|
values := item.GetValues()
|
|
|
|
|
for j, index := range colIndexes {
|
|
|
|
|
operator := filters[j].Operator
|
|
|
|
|
|
|
|
|
|
if nil == values[index] {
|
|
|
|
|
if FilterOperatorIsNotEmpty == operator {
|
|
|
|
|
pass = false
|
|
|
|
|
} else if FilterOperatorIsEmpty == operator {
|
|
|
|
|
pass = true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if KeyTypeText != values[index].Type {
|
|
|
|
|
pass = false
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-02 18:37:27 +08:00
|
|
|
|
if !values[index].Filter(filters[j], attrView, item.GetID(), rollupFurtherCollections, cachedAttrViews) {
|
2025-07-05 12:11:12 +08:00
|
|
|
|
pass = false
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if pass {
|
|
|
|
|
items = append(items, item)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
collection.SetItems(items)
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-02 18:37:27 +08:00
|
|
|
|
func (value *Value) Filter(filter *ViewFilter, attrView *AttributeView, itemID string, rollupFurtherCollections map[string]Collection, cachedAttrViews map[string]*AttributeView) bool {
|
2024-03-13 23:23:52 +08:00
|
|
|
|
if nil == filter || (nil == filter.Value && nil == filter.RelativeDate) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if nil != filter.Value && value.Type != filter.Value.Type {
|
2025-07-06 16:31:09 +08:00
|
|
|
|
// 由于字段类型被用户编辑过导致和过滤规则值类型不匹配,该情况下不过滤
|
2024-03-13 23:23:52 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-26 10:38:26 +08:00
|
|
|
|
switch filter.Operator {
|
|
|
|
|
case FilterOperatorIsEmpty:
|
|
|
|
|
return value.IsEmpty()
|
|
|
|
|
case FilterOperatorIsNotEmpty:
|
|
|
|
|
return !value.IsEmpty()
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-17 11:29:46 +08:00
|
|
|
|
if nil != value.Rollup && KeyTypeRollup == value.Type && nil != filter.Value && KeyTypeRollup == filter.Value.Type &&
|
2024-03-13 23:23:52 +08:00
|
|
|
|
nil != filter.Value.Rollup && 0 < len(filter.Value.Rollup.Contents) {
|
|
|
|
|
// 单独处理汇总类型的比较
|
|
|
|
|
|
|
|
|
|
key, _ := attrView.GetKey(value.KeyID)
|
|
|
|
|
if nil == key {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
relKey, _ := attrView.GetKey(key.Rollup.RelationKeyID)
|
|
|
|
|
if nil == relKey {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-02 18:37:27 +08:00
|
|
|
|
relVal := attrView.GetValue(relKey.ID, itemID)
|
2024-03-13 23:23:52 +08:00
|
|
|
|
if nil == relVal || nil == relVal.Relation {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-02 18:37:27 +08:00
|
|
|
|
destAv := cachedAttrViews[relKey.Relation.AvID]
|
2024-10-20 10:35:49 +08:00
|
|
|
|
if nil == destAv {
|
|
|
|
|
destAv, _ = ParseAttributeView(relKey.Relation.AvID)
|
|
|
|
|
if nil != destAv {
|
2025-09-02 18:37:27 +08:00
|
|
|
|
cachedAttrViews[relKey.Relation.AvID] = destAv
|
2024-10-20 10:35:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-13 23:23:52 +08:00
|
|
|
|
if nil == destAv {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-17 19:39:33 +08:00
|
|
|
|
destKey, _ := destAv.GetKey(key.Rollup.KeyID)
|
|
|
|
|
if nil == destKey {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-02 18:37:27 +08:00
|
|
|
|
value.Rollup.BuildContents(destAv.KeyValues, destKey, relVal, key.Rollup.Calc, rollupFurtherCollections[key.ID])
|
2025-09-02 22:04:29 +08:00
|
|
|
|
|
|
|
|
|
switch filter.Qualifier {
|
|
|
|
|
case FilterQuantifierUndefined, FilterQuantifierAny:
|
|
|
|
|
for _, content := range value.Rollup.Contents {
|
|
|
|
|
switch filter.Operator {
|
|
|
|
|
case FilterOperatorContains:
|
|
|
|
|
if content.filter(filter.Value.Rollup.Contents[0], filter.RelativeDate, filter.RelativeDate2, filter.Operator) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
case FilterOperatorDoesNotContain:
|
|
|
|
|
if !content.filter(filter.Value.Rollup.Contents[0], filter.RelativeDate, filter.RelativeDate2, filter.Operator) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
if content.filter(filter.Value.Rollup.Contents[0], filter.RelativeDate, filter.RelativeDate2, filter.Operator) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
2024-05-27 20:38:05 +08:00
|
|
|
|
}
|
2025-09-02 22:04:29 +08:00
|
|
|
|
}
|
|
|
|
|
case FilterQuantifierAll:
|
|
|
|
|
for _, content := range value.Rollup.Contents {
|
|
|
|
|
if !content.filter(filter.Value.Rollup.Contents[0], filter.RelativeDate, filter.RelativeDate2, filter.Operator) {
|
2024-05-27 20:38:05 +08:00
|
|
|
|
return false
|
|
|
|
|
}
|
2025-09-02 22:04:29 +08:00
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
case FilterQuantifierNone:
|
|
|
|
|
for _, content := range value.Rollup.Contents {
|
2025-08-22 16:00:43 +08:00
|
|
|
|
if content.filter(filter.Value.Rollup.Contents[0], filter.RelativeDate, filter.RelativeDate2, filter.Operator) {
|
2025-09-02 22:04:29 +08:00
|
|
|
|
return false
|
2024-05-27 20:38:05 +08:00
|
|
|
|
}
|
2024-03-13 23:23:52 +08:00
|
|
|
|
}
|
2024-05-27 20:38:05 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
2024-03-13 23:23:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-27 20:38:05 +08:00
|
|
|
|
if nil != value.Relation && KeyTypeRelation == value.Type && nil != filter.Value && KeyTypeRelation == filter.Value.Type &&
|
2024-03-13 23:23:52 +08:00
|
|
|
|
nil != filter.Value.Relation && 0 < len(filter.Value.Relation.BlockIDs) {
|
|
|
|
|
// 单独处理关联类型的比较
|
|
|
|
|
|
|
|
|
|
for _, relationValue := range value.Relation.Contents {
|
|
|
|
|
filterValue := &Value{Type: KeyTypeBlock, Block: &ValueBlock{Content: filter.Value.Relation.BlockIDs[0]}}
|
2024-05-27 20:38:05 +08:00
|
|
|
|
|
|
|
|
|
switch filter.Operator {
|
|
|
|
|
case FilterOperatorContains:
|
|
|
|
|
if relationValue.filter(filterValue, filter.RelativeDate, filter.RelativeDate2, filter.Operator) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
case FilterOperatorDoesNotContain:
|
|
|
|
|
ret := relationValue.filter(filterValue, filter.RelativeDate, filter.RelativeDate2, filter.Operator)
|
|
|
|
|
if !ret {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
if relationValue.filter(filterValue, filter.RelativeDate, filter.RelativeDate2, filter.Operator) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
2024-03-13 23:23:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-27 20:38:05 +08:00
|
|
|
|
|
|
|
|
|
switch filter.Operator {
|
|
|
|
|
case FilterOperatorContains:
|
|
|
|
|
return false
|
|
|
|
|
case FilterOperatorDoesNotContain:
|
|
|
|
|
return true
|
|
|
|
|
default:
|
|
|
|
|
return false
|
|
|
|
|
}
|
2024-03-13 23:23:52 +08:00
|
|
|
|
}
|
|
|
|
|
return value.filter(filter.Value, filter.RelativeDate, filter.RelativeDate2, filter.Operator)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (value *Value) filter(other *Value, relativeDate, relativeDate2 *RelativeDate, operator FilterOperator) bool {
|
2025-08-26 10:38:26 +08:00
|
|
|
|
switch operator {
|
|
|
|
|
case FilterOperatorIsEmpty:
|
|
|
|
|
return value.IsEmpty()
|
|
|
|
|
case FilterOperatorIsNotEmpty:
|
|
|
|
|
return !value.IsEmpty()
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-13 23:23:52 +08:00
|
|
|
|
switch value.Type {
|
|
|
|
|
case KeyTypeBlock:
|
|
|
|
|
if nil != value.Block && nil != other && nil != other.Block {
|
2025-08-12 11:59:24 +08:00
|
|
|
|
return filterTextContent(operator, value.Block.Content, other.Block.Content)
|
2024-03-13 23:23:52 +08:00
|
|
|
|
}
|
|
|
|
|
case KeyTypeText:
|
|
|
|
|
if nil != value.Text && nil != other && nil != other.Text {
|
2025-08-12 11:59:24 +08:00
|
|
|
|
return filterTextContent(operator, value.Text.Content, other.Text.Content)
|
2024-03-13 23:23:52 +08:00
|
|
|
|
}
|
|
|
|
|
case KeyTypeNumber:
|
|
|
|
|
if nil != value.Number && nil != other && nil != other.Number {
|
2025-08-12 11:36:58 +08:00
|
|
|
|
if !other.Number.IsNotEmpty {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-13 23:23:52 +08:00
|
|
|
|
switch operator {
|
|
|
|
|
case FilterOperatorIsEqual:
|
2025-08-12 10:59:14 +08:00
|
|
|
|
return value.Number.Content == other.Number.Content && value.Number.IsNotEmpty == other.Number.IsNotEmpty
|
2024-03-13 23:23:52 +08:00
|
|
|
|
case FilterOperatorIsNotEqual:
|
2025-08-12 10:59:14 +08:00
|
|
|
|
return value.Number.Content != other.Number.Content || value.Number.IsNotEmpty != other.Number.IsNotEmpty
|
2024-03-13 23:23:52 +08:00
|
|
|
|
case FilterOperatorIsGreater:
|
|
|
|
|
return value.Number.Content > other.Number.Content
|
|
|
|
|
case FilterOperatorIsGreaterOrEqual:
|
|
|
|
|
return value.Number.Content >= other.Number.Content
|
|
|
|
|
case FilterOperatorIsLess:
|
|
|
|
|
return value.Number.Content < other.Number.Content
|
|
|
|
|
case FilterOperatorIsLessOrEqual:
|
|
|
|
|
return value.Number.Content <= other.Number.Content
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
case KeyTypeDate:
|
2025-08-28 15:35:09 +08:00
|
|
|
|
if nil != value.Date && nil != other && nil != other.Date && nil == relativeDate && !other.Date.IsNotEmpty {
|
|
|
|
|
return true
|
2025-08-12 11:50:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-13 23:23:52 +08:00
|
|
|
|
if nil != value.Date {
|
2024-04-17 11:29:46 +08:00
|
|
|
|
if !value.Date.IsNotEmpty {
|
|
|
|
|
// 空值不进行比较,直接排除
|
|
|
|
|
// Database date filter excludes empty values https://github.com/siyuan-note/siyuan/issues/11061
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-22 10:16:22 +08:00
|
|
|
|
if nil != relativeDate { // 使用相对时间比较
|
2024-09-27 10:35:00 +08:00
|
|
|
|
relativeTimeStart, relativeTimeEnd := calcRelativeTimeRegion(relativeDate.Count, relativeDate.Unit, relativeDate.Direction)
|
|
|
|
|
relativeTimeStart2, relativeTimeEnd2 := calcRelativeTimeRegion(relativeDate2.Count, relativeDate2.Unit, relativeDate2.Direction)
|
2025-02-12 18:09:20 +08:00
|
|
|
|
return filterRelativeTime(value.Date.Content, value.Date.IsNotEmpty, operator, relativeTimeStart, relativeTimeEnd, relativeDate.Direction, relativeTimeStart2, relativeTimeEnd2, relativeDate2.Direction)
|
2024-03-13 23:23:52 +08:00
|
|
|
|
} else { // 使用具体时间比较
|
|
|
|
|
if nil == other.Date {
|
|
|
|
|
return true
|
|
|
|
|
}
|
2024-04-11 16:27:58 +08:00
|
|
|
|
return filterTime(value.Date.Content, value.Date.IsNotEmpty, other.Date.Content, other.Date.Content2, operator)
|
2024-03-13 23:23:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
case KeyTypeCreated:
|
|
|
|
|
if nil != value.Created {
|
2024-09-22 10:16:22 +08:00
|
|
|
|
if nil != relativeDate { // 使用相对时间比较
|
2024-09-27 10:35:00 +08:00
|
|
|
|
relativeTimeStart, relativeTimeEnd := calcRelativeTimeRegion(relativeDate.Count, relativeDate.Unit, relativeDate.Direction)
|
|
|
|
|
relativeTimeStart2, relativeTimeEnd2 := calcRelativeTimeRegion(relativeDate2.Count, relativeDate2.Unit, relativeDate2.Direction)
|
2025-02-12 18:09:20 +08:00
|
|
|
|
return filterRelativeTime(value.Created.Content, true, operator, relativeTimeStart, relativeTimeEnd, relativeDate.Direction, relativeTimeStart2, relativeTimeEnd2, relativeDate2.Direction)
|
2024-03-13 23:23:52 +08:00
|
|
|
|
} else { // 使用具体时间比较
|
|
|
|
|
if nil == other.Created {
|
|
|
|
|
return true
|
|
|
|
|
}
|
2024-04-11 16:27:58 +08:00
|
|
|
|
return filterTime(value.Created.Content, value.Created.IsNotEmpty, other.Created.Content, other.Created.Content2, operator)
|
2024-03-13 23:23:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
case KeyTypeUpdated:
|
|
|
|
|
if nil != value.Updated {
|
2024-09-22 10:16:22 +08:00
|
|
|
|
if nil != relativeDate { // 使用相对时间比较
|
2024-09-27 10:35:00 +08:00
|
|
|
|
relativeTimeStart, relativeTimeEnd := calcRelativeTimeRegion(relativeDate.Count, relativeDate.Unit, relativeDate.Direction)
|
|
|
|
|
relativeTimeStart2, relativeTimeEnd2 := calcRelativeTimeRegion(relativeDate2.Count, relativeDate2.Unit, relativeDate2.Direction)
|
2025-02-12 18:09:20 +08:00
|
|
|
|
return filterRelativeTime(value.Updated.Content, true, operator, relativeTimeStart, relativeTimeEnd, relativeDate.Direction, relativeTimeStart2, relativeTimeEnd2, relativeDate2.Direction)
|
2024-03-13 23:23:52 +08:00
|
|
|
|
} else { // 使用具体时间比较
|
|
|
|
|
if nil == other.Updated {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-11 16:27:58 +08:00
|
|
|
|
return filterTime(value.Updated.Content, value.Updated.IsNotEmpty, other.Updated.Content, other.Updated.Content2, operator)
|
2024-03-13 23:23:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
case KeyTypeSelect, KeyTypeMSelect:
|
|
|
|
|
if nil != value.MSelect {
|
2025-08-21 10:55:31 +08:00
|
|
|
|
if 1 > len(other.MSelect) {
|
2025-08-24 15:27:04 +08:00
|
|
|
|
return true
|
2025-08-21 10:55:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-08-12 11:36:58 +08:00
|
|
|
|
switch operator {
|
|
|
|
|
case FilterOperatorIsEqual, FilterOperatorContains:
|
|
|
|
|
contains := false
|
|
|
|
|
for _, v := range value.MSelect {
|
|
|
|
|
for _, v2 := range other.MSelect {
|
|
|
|
|
if v.Content == v2.Content {
|
|
|
|
|
contains = true
|
|
|
|
|
break
|
2024-03-13 23:23:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2025-08-12 11:36:58 +08:00
|
|
|
|
}
|
|
|
|
|
return contains
|
|
|
|
|
case FilterOperatorIsNotEqual, FilterOperatorDoesNotContain:
|
|
|
|
|
contains := false
|
|
|
|
|
for _, v := range value.MSelect {
|
|
|
|
|
for _, v2 := range other.MSelect {
|
|
|
|
|
if v.Content == v2.Content {
|
|
|
|
|
contains = true
|
|
|
|
|
break
|
2024-03-13 23:23:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-08-12 11:36:58 +08:00
|
|
|
|
return !contains
|
2024-03-13 23:23:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
case KeyTypeURL:
|
|
|
|
|
if nil != value.URL && nil != other && nil != other.URL {
|
2025-08-12 11:59:24 +08:00
|
|
|
|
return filterTextContent(operator, value.URL.Content, other.URL.Content)
|
2024-03-13 23:23:52 +08:00
|
|
|
|
}
|
|
|
|
|
case KeyTypeEmail:
|
|
|
|
|
if nil != value.Email && nil != other && nil != other.Email {
|
2025-08-21 13:52:08 +08:00
|
|
|
|
return filterTextContent(operator, value.Email.Content, other.Email.Content)
|
2024-03-13 23:23:52 +08:00
|
|
|
|
}
|
|
|
|
|
case KeyTypePhone:
|
|
|
|
|
if nil != value.Phone && nil != other && nil != other.Phone {
|
2025-08-12 11:59:24 +08:00
|
|
|
|
return filterTextContent(operator, value.Phone.Content, other.Phone.Content)
|
2024-03-13 23:23:52 +08:00
|
|
|
|
}
|
|
|
|
|
case KeyTypeMAsset:
|
|
|
|
|
if nil != value.MAsset && nil != other && nil != other.MAsset && 0 < len(value.MAsset) && 0 < len(other.MAsset) {
|
|
|
|
|
switch operator {
|
|
|
|
|
case FilterOperatorIsEqual, FilterOperatorContains:
|
|
|
|
|
contains := false
|
|
|
|
|
for _, v := range value.MAsset {
|
|
|
|
|
for _, v2 := range other.MAsset {
|
|
|
|
|
if v.Content == v2.Content {
|
|
|
|
|
contains = true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return contains
|
|
|
|
|
case FilterOperatorIsNotEqual, FilterOperatorDoesNotContain:
|
|
|
|
|
contains := false
|
|
|
|
|
for _, v := range value.MAsset {
|
|
|
|
|
for _, v2 := range other.MAsset {
|
|
|
|
|
if v.Content == v2.Content {
|
|
|
|
|
contains = true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return !contains
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
case KeyTypeTemplate:
|
|
|
|
|
if nil != value.Template && nil != other && nil != other.Template {
|
|
|
|
|
switch operator {
|
|
|
|
|
case FilterOperatorIsEqual:
|
|
|
|
|
if "" == strings.TrimSpace(other.Template.Content) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return value.Template.Content == other.Template.Content
|
|
|
|
|
case FilterOperatorIsNotEqual:
|
|
|
|
|
if "" == strings.TrimSpace(other.Template.Content) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return value.Template.Content != other.Template.Content
|
|
|
|
|
case FilterOperatorIsGreater:
|
|
|
|
|
if "" == strings.TrimSpace(other.Template.Content) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return value.Template.Content > other.Template.Content
|
|
|
|
|
case FilterOperatorIsGreaterOrEqual:
|
|
|
|
|
if "" == strings.TrimSpace(other.Template.Content) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return value.Template.Content >= other.Template.Content
|
|
|
|
|
case FilterOperatorIsLess:
|
|
|
|
|
if "" == strings.TrimSpace(other.Template.Content) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return value.Template.Content < other.Template.Content
|
|
|
|
|
case FilterOperatorIsLessOrEqual:
|
|
|
|
|
if "" == strings.TrimSpace(other.Template.Content) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return value.Template.Content <= other.Template.Content
|
|
|
|
|
case FilterOperatorContains:
|
|
|
|
|
if "" == strings.TrimSpace(other.Template.Content) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return strings.Contains(value.Template.Content, other.Template.Content)
|
|
|
|
|
case FilterOperatorDoesNotContain:
|
|
|
|
|
if "" == strings.TrimSpace(other.Template.Content) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return !strings.Contains(value.Template.Content, other.Template.Content)
|
|
|
|
|
case FilterOperatorStartsWith:
|
|
|
|
|
if "" == strings.TrimSpace(other.Template.Content) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return strings.HasPrefix(value.Template.Content, other.Template.Content)
|
|
|
|
|
case FilterOperatorEndsWith:
|
|
|
|
|
if "" == strings.TrimSpace(other.Template.Content) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return strings.HasSuffix(value.Template.Content, other.Template.Content)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
case KeyTypeCheckbox:
|
|
|
|
|
if nil != value.Checkbox {
|
|
|
|
|
switch operator {
|
|
|
|
|
case FilterOperatorIsTrue:
|
|
|
|
|
return value.Checkbox.Checked
|
|
|
|
|
case FilterOperatorIsFalse:
|
|
|
|
|
return !value.Checkbox.Checked
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-12 11:59:24 +08:00
|
|
|
|
func filterTextContent(operator FilterOperator, valueContent, otherValueContent string) bool {
|
|
|
|
|
switch operator {
|
|
|
|
|
case FilterOperatorIsEqual:
|
|
|
|
|
if "" == strings.TrimSpace(otherValueContent) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return valueContent == otherValueContent
|
|
|
|
|
case FilterOperatorIsNotEqual:
|
|
|
|
|
if "" == strings.TrimSpace(otherValueContent) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return valueContent != otherValueContent
|
|
|
|
|
case FilterOperatorContains:
|
|
|
|
|
if "" == strings.TrimSpace(otherValueContent) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return strings.Contains(valueContent, otherValueContent)
|
|
|
|
|
case FilterOperatorDoesNotContain:
|
|
|
|
|
if "" == strings.TrimSpace(otherValueContent) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return !strings.Contains(valueContent, otherValueContent)
|
|
|
|
|
case FilterOperatorStartsWith:
|
|
|
|
|
if "" == strings.TrimSpace(otherValueContent) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return strings.HasPrefix(valueContent, otherValueContent)
|
|
|
|
|
case FilterOperatorEndsWith:
|
|
|
|
|
if "" == strings.TrimSpace(otherValueContent) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return strings.HasSuffix(valueContent, otherValueContent)
|
|
|
|
|
case FilterOperatorIsEmpty:
|
|
|
|
|
return "" == strings.TrimSpace(valueContent)
|
|
|
|
|
case FilterOperatorIsNotEmpty:
|
|
|
|
|
return "" != strings.TrimSpace(valueContent)
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-12 18:09:20 +08:00
|
|
|
|
func filterRelativeTime(valueMills int64, valueIsNotEmpty bool, operator FilterOperator, otherValueStart, otherValueEnd time.Time, direction RelativeDateDirection, otherValueStart2, otherValueEnd2 time.Time, direction2 RelativeDateDirection) bool {
|
2024-03-13 23:23:52 +08:00
|
|
|
|
valueTime := time.UnixMilli(valueMills)
|
2025-08-21 21:50:14 +08:00
|
|
|
|
|
2025-08-21 23:08:42 +08:00
|
|
|
|
if otherValueStart.After(otherValueStart2) && FilterOperatorIsBetween == operator {
|
2025-08-21 21:50:14 +08:00
|
|
|
|
tmpStart, tmpEnd := otherValueStart2, otherValueEnd2
|
|
|
|
|
otherValueStart2, otherValueEnd2 = otherValueStart, otherValueEnd
|
|
|
|
|
otherValueStart, otherValueEnd = tmpStart, tmpEnd
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-13 23:23:52 +08:00
|
|
|
|
switch operator {
|
|
|
|
|
case FilterOperatorIsEqual:
|
2025-09-03 08:56:30 +08:00
|
|
|
|
return (valueTime.After(otherValueStart) || valueTime.Equal(otherValueStart)) && (valueTime.Before(otherValueEnd) || valueTime.Equal(otherValueEnd))
|
2024-03-13 23:23:52 +08:00
|
|
|
|
case FilterOperatorIsNotEqual:
|
|
|
|
|
return valueTime.Before(otherValueStart) || valueTime.After(otherValueEnd)
|
|
|
|
|
case FilterOperatorIsGreater:
|
2025-09-03 08:56:30 +08:00
|
|
|
|
return valueTime.After(otherValueEnd)
|
2024-03-13 23:23:52 +08:00
|
|
|
|
case FilterOperatorIsGreaterOrEqual:
|
|
|
|
|
return valueTime.After(otherValueStart) || valueTime.Equal(otherValueStart)
|
|
|
|
|
case FilterOperatorIsLess:
|
|
|
|
|
return valueTime.Before(otherValueStart)
|
|
|
|
|
case FilterOperatorIsLessOrEqual:
|
2025-09-03 08:56:30 +08:00
|
|
|
|
return valueTime.Before(otherValueEnd) || valueTime.Equal(otherValueEnd)
|
2024-03-13 23:23:52 +08:00
|
|
|
|
case FilterOperatorIsBetween:
|
2025-02-12 18:09:20 +08:00
|
|
|
|
if RelativeDateDirectionBefore == direction {
|
2025-02-16 15:30:47 +08:00
|
|
|
|
if RelativeDateDirectionBefore == direction2 {
|
2025-02-12 18:09:20 +08:00
|
|
|
|
var leftStart, rightEnd time.Time
|
|
|
|
|
if otherValueStart.Before(otherValueStart2) {
|
|
|
|
|
leftStart = otherValueStart
|
|
|
|
|
} else {
|
|
|
|
|
leftStart = otherValueStart2
|
|
|
|
|
}
|
2025-02-16 15:30:47 +08:00
|
|
|
|
if otherValueEnd.Before(otherValueStart2) {
|
2025-02-12 18:09:20 +08:00
|
|
|
|
rightEnd = otherValueEnd
|
2025-02-16 15:30:47 +08:00
|
|
|
|
} else {
|
|
|
|
|
rightEnd = otherValueStart2
|
2025-02-12 18:09:20 +08:00
|
|
|
|
}
|
|
|
|
|
return (valueTime.After(leftStart) || valueTime.Equal(leftStart)) && (valueTime.Before(rightEnd) || valueTime.Equal(rightEnd))
|
|
|
|
|
} else if RelativeDateDirectionThis == direction2 {
|
|
|
|
|
return ((valueTime.After(otherValueStart) || valueTime.Equal(otherValueStart)) && (valueTime.Before(otherValueEnd) || valueTime.Equal(otherValueEnd))) ||
|
|
|
|
|
((valueTime.After(otherValueStart2) || valueTime.Equal(otherValueStart2)) && (valueTime.Before(otherValueEnd2) || valueTime.Equal(otherValueEnd2)))
|
2025-02-16 15:30:47 +08:00
|
|
|
|
} else if RelativeDateDirectionAfter == direction2 {
|
|
|
|
|
var leftStart, rightEnd time.Time
|
|
|
|
|
if otherValueStart.Before(otherValueStart2) {
|
|
|
|
|
leftStart = otherValueStart
|
|
|
|
|
} else {
|
|
|
|
|
leftStart = otherValueStart2
|
|
|
|
|
}
|
|
|
|
|
if otherValueEnd.Before(otherValueEnd2) {
|
|
|
|
|
rightEnd = otherValueEnd2
|
|
|
|
|
} else {
|
|
|
|
|
rightEnd = otherValueEnd
|
|
|
|
|
}
|
|
|
|
|
return (valueTime.After(leftStart) || valueTime.Equal(leftStart)) && (valueTime.Before(rightEnd) || valueTime.Equal(rightEnd))
|
2025-02-12 18:09:20 +08:00
|
|
|
|
}
|
|
|
|
|
} else if RelativeDateDirectionThis == direction {
|
|
|
|
|
return ((valueTime.After(otherValueStart) || valueTime.Equal(otherValueStart)) && (valueTime.Before(otherValueEnd) || valueTime.Equal(otherValueEnd))) ||
|
|
|
|
|
((valueTime.After(otherValueStart2) || valueTime.Equal(otherValueStart2)) && (valueTime.Before(otherValueEnd2) || valueTime.Equal(otherValueEnd2)))
|
|
|
|
|
} else if RelativeDateDirectionAfter == direction {
|
2025-02-16 15:30:47 +08:00
|
|
|
|
if RelativeDateDirectionBefore == direction2 {
|
2025-02-12 18:09:20 +08:00
|
|
|
|
var leftStart, rightEnd time.Time
|
|
|
|
|
if otherValueStart.Before(otherValueStart2) {
|
|
|
|
|
leftStart = otherValueStart
|
|
|
|
|
} else {
|
|
|
|
|
leftStart = otherValueStart2
|
|
|
|
|
}
|
|
|
|
|
if otherValueEnd.Before(otherValueEnd2) {
|
|
|
|
|
rightEnd = otherValueEnd2
|
|
|
|
|
} else {
|
|
|
|
|
rightEnd = otherValueEnd
|
|
|
|
|
}
|
|
|
|
|
return (valueTime.After(leftStart) || valueTime.Equal(leftStart)) && (valueTime.Before(rightEnd) || valueTime.Equal(rightEnd))
|
|
|
|
|
} else if RelativeDateDirectionThis == direction2 {
|
|
|
|
|
return ((valueTime.After(otherValueStart) || valueTime.Equal(otherValueStart)) && (valueTime.Before(otherValueEnd) || valueTime.Equal(otherValueEnd))) ||
|
|
|
|
|
((valueTime.After(otherValueStart2) || valueTime.Equal(otherValueStart2)) && (valueTime.Before(otherValueEnd2) || valueTime.Equal(otherValueEnd2)))
|
2025-02-16 15:30:47 +08:00
|
|
|
|
} else if RelativeDateDirectionAfter == direction2 {
|
|
|
|
|
var leftStart, rightEnd time.Time
|
2025-02-27 23:55:42 +08:00
|
|
|
|
if otherValueStart.Before(otherValueStart2) {
|
|
|
|
|
leftStart = otherValueStart
|
2025-02-16 15:30:47 +08:00
|
|
|
|
} else {
|
2025-02-27 23:55:42 +08:00
|
|
|
|
leftStart = otherValueStart2
|
2025-02-16 15:30:47 +08:00
|
|
|
|
}
|
|
|
|
|
if otherValueEnd.After(otherValueEnd2) {
|
|
|
|
|
rightEnd = otherValueEnd
|
|
|
|
|
} else {
|
|
|
|
|
rightEnd = otherValueEnd2
|
|
|
|
|
}
|
|
|
|
|
return (valueTime.After(leftStart) || valueTime.Equal(leftStart)) && (valueTime.Before(rightEnd) || valueTime.Equal(rightEnd))
|
2025-02-12 18:09:20 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
2024-03-13 23:23:52 +08:00
|
|
|
|
case FilterOperatorIsEmpty:
|
|
|
|
|
return !valueIsNotEmpty
|
|
|
|
|
case FilterOperatorIsNotEmpty:
|
|
|
|
|
return valueIsNotEmpty
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-11 16:27:58 +08:00
|
|
|
|
func filterTime(valueMills int64, valueIsNotEmpty bool, otherValueMills, otherValueMills2 int64, operator FilterOperator) bool {
|
2024-04-10 18:04:56 +08:00
|
|
|
|
valueTime := time.UnixMilli(valueMills)
|
2025-08-21 21:50:14 +08:00
|
|
|
|
|
2025-08-21 23:08:42 +08:00
|
|
|
|
if 0 != otherValueMills2 && otherValueMills > otherValueMills2 && FilterOperatorIsBetween == operator {
|
2025-08-21 21:50:14 +08:00
|
|
|
|
tmp := otherValueMills2
|
|
|
|
|
otherValueMills2 = otherValueMills
|
|
|
|
|
otherValueMills = tmp
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-11 16:27:58 +08:00
|
|
|
|
otherValueTime := time.UnixMilli(otherValueMills)
|
|
|
|
|
otherValueStart := time.Date(otherValueTime.Year(), otherValueTime.Month(), otherValueTime.Day(), 0, 0, 0, 0, otherValueTime.Location())
|
|
|
|
|
otherValueEnd := time.Date(otherValueTime.Year(), otherValueTime.Month(), otherValueTime.Day(), 23, 59, 59, 999999999, otherValueTime.Location())
|
2024-04-10 18:04:56 +08:00
|
|
|
|
switch operator {
|
|
|
|
|
case FilterOperatorIsEqual:
|
|
|
|
|
return (valueTime.After(otherValueStart) || valueTime.Equal(otherValueStart)) && valueTime.Before(otherValueEnd)
|
|
|
|
|
case FilterOperatorIsNotEqual:
|
|
|
|
|
return valueTime.Before(otherValueStart) || valueTime.After(otherValueEnd)
|
|
|
|
|
case FilterOperatorIsGreater:
|
|
|
|
|
return valueTime.After(otherValueEnd) || valueTime.Equal(otherValueEnd)
|
|
|
|
|
case FilterOperatorIsGreaterOrEqual:
|
|
|
|
|
return valueTime.After(otherValueStart) || valueTime.Equal(otherValueStart)
|
|
|
|
|
case FilterOperatorIsLess:
|
|
|
|
|
return valueTime.Before(otherValueStart)
|
|
|
|
|
case FilterOperatorIsLessOrEqual:
|
|
|
|
|
return valueTime.Before(otherValueEnd) || valueTime.Equal(otherValueEnd)
|
|
|
|
|
case FilterOperatorIsBetween:
|
2025-08-21 21:56:11 +08:00
|
|
|
|
if 0 == otherValueMills || 0 == otherValueMills2 {
|
|
|
|
|
return true
|
|
|
|
|
}
|
2024-04-11 16:27:58 +08:00
|
|
|
|
otherValueTime2 := time.UnixMilli(otherValueMills2)
|
|
|
|
|
otherValueEnd2 := time.Date(otherValueTime2.Year(), otherValueTime2.Month(), otherValueTime2.Day(), 23, 59, 59, 999999999, otherValueTime2.Location())
|
|
|
|
|
return (valueTime.After(otherValueStart) || valueTime.Equal(otherValueStart)) && (valueTime.Before(otherValueEnd2) || valueTime.Equal(otherValueEnd2))
|
2024-04-10 18:04:56 +08:00
|
|
|
|
case FilterOperatorIsEmpty:
|
|
|
|
|
return !valueIsNotEmpty
|
|
|
|
|
case FilterOperatorIsNotEmpty:
|
|
|
|
|
return valueIsNotEmpty
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-13 23:23:52 +08:00
|
|
|
|
// 根据 Count、Unit 和 Direction 计算相对当前时间的开始时间和结束时间
|
|
|
|
|
func calcRelativeTimeRegion(count int, unit RelativeDateUnit, direction RelativeDateDirection) (start, end time.Time) {
|
|
|
|
|
now := time.Now()
|
|
|
|
|
switch unit {
|
|
|
|
|
case RelativeDateUnitDay:
|
|
|
|
|
switch direction {
|
|
|
|
|
case RelativeDateDirectionBefore:
|
2024-04-14 09:01:22 +08:00
|
|
|
|
// 结束时间:今天的 0 点
|
2024-03-13 23:23:52 +08:00
|
|
|
|
end = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
2024-04-14 09:01:22 +08:00
|
|
|
|
// 开始时间:结束时间减去 count 天
|
2024-03-13 23:23:52 +08:00
|
|
|
|
start = end.AddDate(0, 0, -count)
|
|
|
|
|
case RelativeDateDirectionThis:
|
2024-04-14 09:01:22 +08:00
|
|
|
|
// 开始时间:今天的 0 点
|
2024-03-13 23:23:52 +08:00
|
|
|
|
start = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
2024-04-14 09:01:22 +08:00
|
|
|
|
// 结束时间:今天的 23:59:59.999999999
|
|
|
|
|
end = time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 999999999, now.Location())
|
2024-03-13 23:23:52 +08:00
|
|
|
|
case RelativeDateDirectionAfter:
|
2024-04-14 09:01:22 +08:00
|
|
|
|
// 开始时间:今天的 23:59:59.999999999
|
2024-03-13 23:23:52 +08:00
|
|
|
|
start = time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 999999999, now.Location())
|
2024-04-14 09:01:22 +08:00
|
|
|
|
// 结束时间:开始时间加上 count 天
|
2024-03-13 23:23:52 +08:00
|
|
|
|
end = start.AddDate(0, 0, count)
|
|
|
|
|
}
|
|
|
|
|
case RelativeDateUnitWeek:
|
|
|
|
|
weekday := int(now.Weekday())
|
|
|
|
|
if 0 == weekday {
|
|
|
|
|
weekday = 7
|
|
|
|
|
}
|
|
|
|
|
switch direction {
|
|
|
|
|
case RelativeDateDirectionBefore:
|
2024-04-14 09:01:22 +08:00
|
|
|
|
// 结束时间:本周的周一
|
|
|
|
|
end = time.Date(now.Year(), now.Month(), now.Day()-weekday+1, 0, 0, 0, 0, now.Location())
|
|
|
|
|
// 开始时间:结束时间减去 count*7 天
|
2024-03-13 23:23:52 +08:00
|
|
|
|
start = end.AddDate(0, 0, -count*7)
|
|
|
|
|
case RelativeDateDirectionThis:
|
2024-04-14 09:01:22 +08:00
|
|
|
|
// 开始时间:本周的周一
|
|
|
|
|
start = time.Date(now.Year(), now.Month(), now.Day()-weekday+1, 0, 0, 0, 0, now.Location())
|
|
|
|
|
// 结束时间:本周的周日
|
|
|
|
|
end = time.Date(now.Year(), now.Month(), now.Day()-weekday+7, 23, 59, 59, 999999999, now.Location())
|
2024-03-13 23:23:52 +08:00
|
|
|
|
case RelativeDateDirectionAfter:
|
2024-04-14 09:01:22 +08:00
|
|
|
|
// 开始时间:本周的周日
|
2024-03-13 23:23:52 +08:00
|
|
|
|
start = time.Date(now.Year(), now.Month(), now.Day()-weekday+7, 23, 59, 59, 999999999, now.Location())
|
2024-04-14 09:01:22 +08:00
|
|
|
|
// 结束时间:开始时间加上 count*7 天
|
2024-03-13 23:23:52 +08:00
|
|
|
|
end = start.AddDate(0, 0, count*7)
|
|
|
|
|
}
|
|
|
|
|
case RelativeDateUnitMonth:
|
|
|
|
|
switch direction {
|
|
|
|
|
case RelativeDateDirectionBefore:
|
2024-04-14 09:01:22 +08:00
|
|
|
|
// 结束时间:本月的 1 号
|
2024-03-13 23:23:52 +08:00
|
|
|
|
end = time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
|
2024-04-14 09:01:22 +08:00
|
|
|
|
// 开始时间:结束时间减去 count 个月
|
2024-03-13 23:23:52 +08:00
|
|
|
|
start = end.AddDate(0, -count, 0)
|
|
|
|
|
case RelativeDateDirectionThis:
|
2024-04-14 09:01:22 +08:00
|
|
|
|
// 开始时间:本月的 1 号
|
2024-03-13 23:23:52 +08:00
|
|
|
|
start = time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
|
2024-04-14 09:01:22 +08:00
|
|
|
|
// 结束时间:下个月的 1 号减去 1 纳秒
|
|
|
|
|
end = time.Date(now.Year(), now.Month()+1, 1, 0, 0, 0, 0, now.Location()).Add(-time.Nanosecond)
|
2024-03-13 23:23:52 +08:00
|
|
|
|
case RelativeDateDirectionAfter:
|
2024-04-14 09:01:22 +08:00
|
|
|
|
// 开始时间:下个月的 1 号减去 1 纳秒
|
2024-03-13 23:23:52 +08:00
|
|
|
|
start = time.Date(now.Year(), now.Month()+1, 1, 0, 0, 0, 0, now.Location()).Add(-time.Nanosecond)
|
2024-04-14 09:01:22 +08:00
|
|
|
|
// 结束时间:开始时间加上 count 个月
|
2024-03-13 23:23:52 +08:00
|
|
|
|
end = start.AddDate(0, count, 0)
|
|
|
|
|
}
|
|
|
|
|
case RelativeDateUnitYear:
|
|
|
|
|
switch direction {
|
|
|
|
|
case RelativeDateDirectionBefore:
|
2024-04-14 09:01:22 +08:00
|
|
|
|
// 结束时间:今年的 1 月 1 号
|
2024-03-13 23:23:52 +08:00
|
|
|
|
end = time.Date(now.Year(), 1, 1, 0, 0, 0, 0, now.Location())
|
2024-04-14 09:01:22 +08:00
|
|
|
|
// 开始时间:结束时间减去 count 年
|
2024-03-13 23:23:52 +08:00
|
|
|
|
start = end.AddDate(-count, 0, 0)
|
|
|
|
|
case RelativeDateDirectionThis:
|
2024-04-14 09:01:22 +08:00
|
|
|
|
// 开始时间:今年的 1 月 1 号
|
2024-03-13 23:23:52 +08:00
|
|
|
|
start = time.Date(now.Year(), 1, 1, 0, 0, 0, 0, now.Location())
|
2024-04-14 09:01:22 +08:00
|
|
|
|
// 结束时间:明年的 1 月 1 号减去 1 纳秒
|
|
|
|
|
end = time.Date(now.Year()+1, 1, 1, 0, 0, 0, 0, now.Location()).Add(-time.Nanosecond)
|
2024-03-13 23:23:52 +08:00
|
|
|
|
case RelativeDateDirectionAfter:
|
2024-04-14 09:01:22 +08:00
|
|
|
|
// 开始时间:今年的 12 月 31 号
|
|
|
|
|
start = time.Date(now.Year(), 12, 31, 23, 59, 59, 999999999, now.Location())
|
|
|
|
|
// 结束时间:开始时间加上 count 年
|
2024-03-13 23:23:52 +08:00
|
|
|
|
end = start.AddDate(count, 0, 0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-03 11:02:02 +08:00
|
|
|
|
func (filter *ViewFilter) GetAffectValue(key *Key, addingBlockID string) (ret *Value) {
|
2024-03-05 20:59:11 +08:00
|
|
|
|
if nil != filter.Value {
|
2024-03-08 10:30:41 +08:00
|
|
|
|
if KeyTypeRelation == filter.Value.Type || KeyTypeTemplate == filter.Value.Type || KeyTypeRollup == filter.Value.Type || KeyTypeUpdated == filter.Value.Type || KeyTypeCreated == filter.Value.Type {
|
|
|
|
|
// 所有生成的数据都不设置默认值
|
2024-03-05 20:54:39 +08:00
|
|
|
|
return nil
|
|
|
|
|
}
|
2024-03-03 22:44:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-05 20:59:11 +08:00
|
|
|
|
if nil == filter.Value {
|
2024-03-03 22:44:47 +08:00
|
|
|
|
return nil
|
|
|
|
|
}
|
2023-12-30 17:23:02 +08:00
|
|
|
|
|
2024-05-08 09:43:13 +08:00
|
|
|
|
if FilterOperatorIsEmpty != filter.Operator && FilterOperatorIsNotEmpty != filter.Operator {
|
2025-08-21 23:08:42 +08:00
|
|
|
|
if filter.Value.IsEmpty() && nil == filter.RelativeDate {
|
2024-05-08 09:43:13 +08:00
|
|
|
|
// 在不是过滤空值和非空值的情况下,空值不设置默认值 https://github.com/siyuan-note/siyuan/issues/11297
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-30 16:59:41 +08:00
|
|
|
|
ret = filter.Value.Clone()
|
2025-08-02 17:49:30 +08:00
|
|
|
|
ret.ID = ast.NewNodeID()
|
|
|
|
|
ret.KeyID = key.ID
|
|
|
|
|
ret.BlockID = addingBlockID
|
2024-03-06 23:25:25 +08:00
|
|
|
|
ret.CreatedAt = util.CurrentTimeMillis()
|
|
|
|
|
ret.UpdatedAt = ret.CreatedAt + 1000
|
2024-03-06 11:20:20 +08:00
|
|
|
|
|
2023-12-30 16:59:41 +08:00
|
|
|
|
switch filter.Value.Type {
|
|
|
|
|
case KeyTypeBlock:
|
|
|
|
|
switch filter.Operator {
|
|
|
|
|
case FilterOperatorIsEqual:
|
2025-08-10 11:20:53 +08:00
|
|
|
|
ret.Block = &ValueBlock{Content: filter.Value.Block.Content, Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorIsNotEqual:
|
2025-08-10 11:20:53 +08:00
|
|
|
|
ret.Block = &ValueBlock{Content: "", Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorContains:
|
2025-08-10 11:20:53 +08:00
|
|
|
|
ret.Block = &ValueBlock{Content: filter.Value.Block.Content, Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorDoesNotContain:
|
2025-08-10 11:20:53 +08:00
|
|
|
|
ret.Block = &ValueBlock{Content: "", Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorStartsWith:
|
2025-08-10 11:20:53 +08:00
|
|
|
|
ret.Block = &ValueBlock{Content: filter.Value.Block.Content, Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorEndsWith:
|
2025-08-10 11:20:53 +08:00
|
|
|
|
ret.Block = &ValueBlock{Content: filter.Value.Block.Content, Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorIsEmpty:
|
2025-08-10 11:20:53 +08:00
|
|
|
|
ret.Block = &ValueBlock{Content: "", Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorIsNotEmpty:
|
2025-08-12 10:59:14 +08:00
|
|
|
|
return nil
|
2023-12-30 16:59:41 +08:00
|
|
|
|
}
|
|
|
|
|
case KeyTypeText:
|
|
|
|
|
switch filter.Operator {
|
|
|
|
|
case FilterOperatorIsEqual:
|
|
|
|
|
ret.Text = &ValueText{Content: filter.Value.Text.Content}
|
|
|
|
|
case FilterOperatorIsNotEqual:
|
2024-03-06 11:20:20 +08:00
|
|
|
|
ret.Text = &ValueText{Content: ""}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorContains:
|
|
|
|
|
ret.Text = &ValueText{Content: filter.Value.Text.Content}
|
|
|
|
|
case FilterOperatorDoesNotContain:
|
2024-03-06 11:20:20 +08:00
|
|
|
|
ret.Text = &ValueText{Content: ""}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorStartsWith:
|
|
|
|
|
ret.Text = &ValueText{Content: filter.Value.Text.Content}
|
|
|
|
|
case FilterOperatorEndsWith:
|
|
|
|
|
ret.Text = &ValueText{Content: filter.Value.Text.Content}
|
|
|
|
|
case FilterOperatorIsEmpty:
|
|
|
|
|
ret.Text = &ValueText{Content: ""}
|
|
|
|
|
case FilterOperatorIsNotEmpty:
|
2025-08-12 10:59:14 +08:00
|
|
|
|
return nil
|
2023-12-30 16:59:41 +08:00
|
|
|
|
}
|
|
|
|
|
case KeyTypeNumber:
|
|
|
|
|
switch filter.Operator {
|
|
|
|
|
case FilterOperatorIsEqual:
|
2025-08-15 11:03:51 +08:00
|
|
|
|
ret.Number = &ValueNumber{Content: filter.Value.Number.Content, IsNotEmpty: true}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorIsNotEqual:
|
2025-08-12 10:59:14 +08:00
|
|
|
|
ret.Number = &ValueNumber{Content: 0, IsNotEmpty: false}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorIsGreater:
|
|
|
|
|
ret.Number = &ValueNumber{Content: filter.Value.Number.Content + 1, IsNotEmpty: true}
|
|
|
|
|
case FilterOperatorIsGreaterOrEqual:
|
|
|
|
|
ret.Number = &ValueNumber{Content: filter.Value.Number.Content, IsNotEmpty: true}
|
|
|
|
|
case FilterOperatorIsLess:
|
|
|
|
|
ret.Number = &ValueNumber{Content: filter.Value.Number.Content - 1, IsNotEmpty: true}
|
|
|
|
|
case FilterOperatorIsLessOrEqual:
|
|
|
|
|
ret.Number = &ValueNumber{Content: filter.Value.Number.Content, IsNotEmpty: true}
|
|
|
|
|
case FilterOperatorIsEmpty:
|
|
|
|
|
ret.Number = &ValueNumber{Content: 0, IsNotEmpty: false}
|
|
|
|
|
case FilterOperatorIsNotEmpty:
|
|
|
|
|
ret.Number = &ValueNumber{Content: 0, IsNotEmpty: true}
|
|
|
|
|
}
|
|
|
|
|
case KeyTypeDate:
|
2025-08-21 23:08:42 +08:00
|
|
|
|
start := time.Now()
|
|
|
|
|
end := start
|
|
|
|
|
if nil != filter.Value.Date {
|
|
|
|
|
start = time.UnixMilli(filter.Value.Date.Content)
|
|
|
|
|
end = time.UnixMilli(filter.Value.Date.Content2)
|
|
|
|
|
}
|
|
|
|
|
if nil != filter.RelativeDate {
|
|
|
|
|
start, end = calcRelativeTimeRegion(filter.RelativeDate.Count, filter.RelativeDate.Unit, filter.RelativeDate.Direction)
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-30 16:59:41 +08:00
|
|
|
|
switch filter.Operator {
|
|
|
|
|
case FilterOperatorIsEqual:
|
2025-08-21 23:26:55 +08:00
|
|
|
|
ret.Date = &ValueDate{Content: start.UnixMilli(), IsNotEmpty: true}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorIsGreater:
|
2025-08-21 23:26:55 +08:00
|
|
|
|
ret.Date = &ValueDate{Content: end.Add(24 * time.Hour).UnixMilli(), IsNotEmpty: true}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorIsGreaterOrEqual:
|
2025-08-21 23:08:42 +08:00
|
|
|
|
ret.Date = &ValueDate{Content: start.UnixMilli(), IsNotEmpty: true}
|
2025-08-21 23:26:55 +08:00
|
|
|
|
case FilterOperatorIsLess:
|
|
|
|
|
ret.Date = &ValueDate{Content: start.Add(-24 * time.Hour).UnixMilli(), IsNotEmpty: true}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorIsLessOrEqual:
|
2025-08-21 23:08:42 +08:00
|
|
|
|
ret.Date = &ValueDate{Content: start.UnixMilli(), IsNotEmpty: true}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorIsBetween:
|
2025-08-21 23:26:55 +08:00
|
|
|
|
start2, end2 := start, end
|
|
|
|
|
if nil != filter.RelativeDate2 {
|
|
|
|
|
start2, end2 = calcRelativeTimeRegion(filter.RelativeDate2.Count, filter.RelativeDate2.Unit, filter.RelativeDate2.Direction)
|
|
|
|
|
if start.After(start2) {
|
|
|
|
|
tmp := start
|
|
|
|
|
start = start2
|
|
|
|
|
start2 = tmp
|
|
|
|
|
}
|
2025-08-21 23:30:52 +08:00
|
|
|
|
if end.Before(end2) {
|
2025-08-21 23:26:55 +08:00
|
|
|
|
tmp := end
|
|
|
|
|
end = end2
|
|
|
|
|
end2 = tmp
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if start.After(end) {
|
|
|
|
|
tmp := start
|
|
|
|
|
start = end
|
|
|
|
|
end = tmp
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-21 23:08:42 +08:00
|
|
|
|
now := time.Now()
|
|
|
|
|
if start.Before(now) && now.Before(end) {
|
|
|
|
|
ret.Date = &ValueDate{Content: now.UnixMilli(), IsNotEmpty: true}
|
2025-08-21 22:25:41 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2025-08-21 23:08:42 +08:00
|
|
|
|
ret.Date = &ValueDate{Content: start.UnixMilli(), IsNotEmpty: true}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorIsEmpty:
|
|
|
|
|
ret.Date = &ValueDate{Content: 0, IsNotEmpty: false}
|
|
|
|
|
case FilterOperatorIsNotEmpty:
|
|
|
|
|
ret.Date = &ValueDate{Content: util.CurrentTimeMillis(), IsNotEmpty: true}
|
|
|
|
|
}
|
2024-03-06 11:20:20 +08:00
|
|
|
|
case KeyTypeSelect, KeyTypeMSelect:
|
2024-01-07 17:30:52 +08:00
|
|
|
|
switch filter.Operator {
|
|
|
|
|
case FilterOperatorIsEqual:
|
2024-03-06 11:20:20 +08:00
|
|
|
|
valueSelect := &ValueSelect{Content: "", Color: "1"}
|
2024-01-07 17:30:52 +08:00
|
|
|
|
if 0 < len(key.Options) {
|
2024-03-06 11:20:20 +08:00
|
|
|
|
valueSelect.Color = key.Options[0].Color
|
2024-01-07 17:30:52 +08:00
|
|
|
|
}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
if 0 < len(filter.Value.MSelect) {
|
2024-03-06 11:20:20 +08:00
|
|
|
|
valueSelect.Content = filter.Value.MSelect[0].Content
|
|
|
|
|
valueSelect.Color = filter.Value.MSelect[0].Color
|
2023-12-30 16:59:41 +08:00
|
|
|
|
}
|
2024-03-06 11:20:20 +08:00
|
|
|
|
ret.MSelect = []*ValueSelect{valueSelect}
|
|
|
|
|
case FilterOperatorIsNotEqual:
|
2025-08-12 11:36:58 +08:00
|
|
|
|
return nil
|
|
|
|
|
case FilterOperatorContains:
|
2023-12-30 16:59:41 +08:00
|
|
|
|
if 0 < len(filter.Value.MSelect) {
|
2025-08-12 11:36:58 +08:00
|
|
|
|
ret.MSelect = []*ValueSelect{{Content: filter.Value.MSelect[0].Content, Color: filter.Value.MSelect[0].Color}}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
}
|
2025-08-12 11:36:58 +08:00
|
|
|
|
case FilterOperatorDoesNotContain:
|
|
|
|
|
return nil
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorIsEmpty:
|
|
|
|
|
ret.MSelect = []*ValueSelect{}
|
|
|
|
|
case FilterOperatorIsNotEmpty:
|
|
|
|
|
if 0 < len(key.Options) {
|
|
|
|
|
ret.MSelect = []*ValueSelect{{Content: key.Options[0].Name, Color: key.Options[0].Color}}
|
2025-08-12 10:59:14 +08:00
|
|
|
|
} else {
|
|
|
|
|
return nil
|
2023-12-30 16:59:41 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
case KeyTypeURL:
|
|
|
|
|
switch filter.Operator {
|
|
|
|
|
case FilterOperatorIsEqual:
|
|
|
|
|
ret.URL = &ValueURL{Content: filter.Value.URL.Content}
|
|
|
|
|
case FilterOperatorIsNotEqual:
|
2025-08-12 10:59:14 +08:00
|
|
|
|
ret.URL = &ValueURL{Content: ""}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorContains:
|
|
|
|
|
ret.URL = &ValueURL{Content: filter.Value.URL.Content}
|
|
|
|
|
case FilterOperatorDoesNotContain:
|
2024-03-06 11:20:20 +08:00
|
|
|
|
ret.URL = &ValueURL{Content: ""}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorStartsWith:
|
|
|
|
|
ret.URL = &ValueURL{Content: filter.Value.URL.Content}
|
|
|
|
|
case FilterOperatorEndsWith:
|
|
|
|
|
ret.URL = &ValueURL{Content: filter.Value.URL.Content}
|
|
|
|
|
case FilterOperatorIsEmpty:
|
2025-08-12 10:59:14 +08:00
|
|
|
|
ret.URL = &ValueURL{Content: ""}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorIsNotEmpty:
|
2025-08-12 10:59:14 +08:00
|
|
|
|
return nil
|
2023-12-30 16:59:41 +08:00
|
|
|
|
}
|
|
|
|
|
case KeyTypeEmail:
|
|
|
|
|
switch filter.Operator {
|
|
|
|
|
case FilterOperatorIsEqual:
|
|
|
|
|
ret.Email = &ValueEmail{Content: filter.Value.Email.Content}
|
|
|
|
|
case FilterOperatorIsNotEqual:
|
2025-08-12 10:59:14 +08:00
|
|
|
|
ret.Email = &ValueEmail{Content: ""}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorContains:
|
|
|
|
|
ret.Email = &ValueEmail{Content: filter.Value.Email.Content}
|
|
|
|
|
case FilterOperatorDoesNotContain:
|
2024-03-06 11:20:20 +08:00
|
|
|
|
ret.Email = &ValueEmail{Content: ""}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorStartsWith:
|
|
|
|
|
ret.Email = &ValueEmail{Content: filter.Value.Email.Content}
|
|
|
|
|
case FilterOperatorEndsWith:
|
|
|
|
|
ret.Email = &ValueEmail{Content: filter.Value.Email.Content}
|
|
|
|
|
case FilterOperatorIsEmpty:
|
|
|
|
|
ret.Email = &ValueEmail{Content: ""}
|
|
|
|
|
case FilterOperatorIsNotEmpty:
|
2025-08-12 10:59:14 +08:00
|
|
|
|
return nil
|
2023-12-30 16:59:41 +08:00
|
|
|
|
}
|
|
|
|
|
case KeyTypePhone:
|
|
|
|
|
switch filter.Operator {
|
|
|
|
|
case FilterOperatorIsEqual:
|
|
|
|
|
ret.Phone = &ValuePhone{Content: filter.Value.Phone.Content}
|
|
|
|
|
case FilterOperatorIsNotEqual:
|
2025-08-12 10:59:14 +08:00
|
|
|
|
ret.Phone = &ValuePhone{Content: ""}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorContains:
|
|
|
|
|
ret.Phone = &ValuePhone{Content: filter.Value.Phone.Content}
|
|
|
|
|
case FilterOperatorDoesNotContain:
|
2024-03-06 11:20:20 +08:00
|
|
|
|
ret.Phone = &ValuePhone{Content: ""}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorStartsWith:
|
|
|
|
|
ret.Phone = &ValuePhone{Content: filter.Value.Phone.Content}
|
|
|
|
|
case FilterOperatorEndsWith:
|
|
|
|
|
ret.Phone = &ValuePhone{Content: filter.Value.Phone.Content}
|
|
|
|
|
case FilterOperatorIsEmpty:
|
|
|
|
|
ret.Phone = &ValuePhone{Content: ""}
|
|
|
|
|
case FilterOperatorIsNotEmpty:
|
2025-08-12 10:59:14 +08:00
|
|
|
|
return nil
|
2023-12-30 16:59:41 +08:00
|
|
|
|
}
|
|
|
|
|
case KeyTypeMAsset:
|
|
|
|
|
switch filter.Operator {
|
|
|
|
|
case FilterOperatorIsEqual, FilterOperatorContains:
|
|
|
|
|
if 0 < len(filter.Value.MAsset) {
|
|
|
|
|
ret.MAsset = []*ValueAsset{{Type: filter.Value.MAsset[0].Type, Name: filter.Value.MAsset[0].Name, Content: filter.Value.MAsset[0].Content}}
|
|
|
|
|
}
|
|
|
|
|
case FilterOperatorIsNotEqual, FilterOperatorDoesNotContain:
|
|
|
|
|
case FilterOperatorIsEmpty:
|
|
|
|
|
ret.MAsset = []*ValueAsset{}
|
|
|
|
|
case FilterOperatorIsNotEmpty:
|
|
|
|
|
}
|
|
|
|
|
case KeyTypeCheckbox:
|
|
|
|
|
switch filter.Operator {
|
|
|
|
|
case FilterOperatorIsTrue:
|
|
|
|
|
ret.Checkbox = &ValueCheckbox{Checked: true}
|
|
|
|
|
case FilterOperatorIsFalse:
|
|
|
|
|
ret.Checkbox = &ValueCheckbox{Checked: false}
|
|
|
|
|
}
|
|
|
|
|
case KeyTypeRelation:
|
|
|
|
|
switch filter.Operator {
|
|
|
|
|
case FilterOperatorContains:
|
|
|
|
|
if 0 < len(filter.Value.Relation.Contents) {
|
|
|
|
|
ret.Relation = &ValueRelation{Contents: filter.Value.Relation.Contents}
|
|
|
|
|
}
|
|
|
|
|
case FilterOperatorDoesNotContain:
|
|
|
|
|
case FilterOperatorIsEmpty:
|
2024-03-07 16:11:58 +08:00
|
|
|
|
ret.Relation = &ValueRelation{Contents: []*Value{}}
|
2023-12-30 16:59:41 +08:00
|
|
|
|
case FilterOperatorIsNotEmpty:
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|