Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/application/flow/compare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from .len_gt_compare import LenGTCompare
from .len_le_compare import LenLECompare
from .len_lt_compare import LenLTCompare
from .len_not_equal_compare import LenNotEqualCompare
from .lt_compare import LTCompare
from .not_contain_compare import NotContainCompare
from .not_equal_compare import NotEqualCompare
Expand All @@ -42,6 +43,7 @@
'le': LECompare(),
'lt': LTCompare(),
'len_eq': LenEqualCompare(),
'len_not_eq': LenNotEqualCompare(),
'len_ge': LenGECompare(),
'len_gt': LenGTCompare(),
'len_le': LenLECompare(),
Expand Down
5 changes: 1 addition & 4 deletions apps/application/flow/compare/is_not_true.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,4 @@
class IsNotTrueCompare(Compare):

def compare(self, source_value, compare, target_value):
try:
return source_value is False
except Exception:
return False
return source_value is False
5 changes: 1 addition & 4 deletions apps/application/flow/compare/is_true.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,4 @@
class IsTrueCompare(Compare):

def compare(self, source_value, compare, target_value):
try:
return source_value is True
except Exception:
return False
return source_value is True
36 changes: 33 additions & 3 deletions apps/application/flow/compare/len_equal_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,45 @@
@Author:虎
@file: equal_compare.py
@date:2024/6/7 14:44
@desc:
@desc: 长度等于比较器
"""
from .compare import Compare


def compute_length(source_value, target_length) -> list:
"""
计算长度

Args:
source_value: 引用变量
target_length: 目标长度字符串

Raises:
ValueError: 当 target_value 不是数字 或 小于0时,抛出该异常
"""
# 获取target_value的长度
target_length = int(target_length) if target_length else 0
if target_length < 0:
raise ValueError("The target length must be greater than or equal to 0")

# 获取source_value的长度
try:
source_length = len(source_value) if source_value is not None else 0
except Exception:
# 可计算数字长度
source_length = len(str(source_value))

return [source_length, target_length]


class LenEqualCompare(Compare):

def compare(self, source_value, compare, target_value):
try:
return len(source_value) == int(target_value)
except Exception as e:
# 计算长度
source_length, target_length = compute_length(source_value, target_value)

# 长度等于 比较
return source_length == target_length
except Exception:
return False
9 changes: 7 additions & 2 deletions apps/application/flow/compare/len_ge_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
@Author:虎
@file: lt_compare.py
@date:2024/6/11 9:52
@desc: 大于比较器
@desc: 长度大于等于比较器
"""
from .compare import Compare
from .len_equal_compare import compute_length


class LenGECompare(Compare):

def compare(self, source_value, compare, target_value):
try:
return len(source_value) >= int(target_value)
# 计算长度
source_length, target_length = compute_length(source_value, target_value)

# 长度大于等于 比较
return source_length >= target_length
except Exception:
return False
9 changes: 7 additions & 2 deletions apps/application/flow/compare/len_gt_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
@Author:虎
@file: lt_compare.py
@date:2024/6/11 9:52
@desc: 大于比较器
@desc: 长度大于比较器
"""
from .compare import Compare
from .len_equal_compare import compute_length


class LenGTCompare(Compare):

def compare(self, source_value, compare, target_value):
try:
return len(source_value) > int(target_value)
# 计算长度
source_length, target_length = compute_length(source_value, target_value)

# 长度大于 比较
return source_length > target_length
except Exception:
return False
9 changes: 7 additions & 2 deletions apps/application/flow/compare/len_le_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
@Author:虎
@file: lt_compare.py
@date:2024/6/11 9:52
@desc: 小于比较器
@desc: 长度小于等于比较器
"""
from .compare import Compare
from .len_equal_compare import compute_length


class LenLECompare(Compare):

def compare(self, source_value, compare, target_value):
try:
return len(source_value) <= int(target_value)
# 计算长度
source_length, target_length = compute_length(source_value, target_value)

# 长度小于等于 比较
return source_length <= target_length
except Exception:
return False
9 changes: 7 additions & 2 deletions apps/application/flow/compare/len_lt_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
@Author:虎
@file: lt_compare.py
@date:2024/6/11 9:52
@desc: 小于比较器
@desc: 长度小于比较器
"""
from .compare import Compare
from .len_equal_compare import compute_length


class LenLTCompare(Compare):

def compare(self, source_value, compare, target_value):
try:
return len(source_value) < int(target_value)
# 计算长度
source_length, target_length = compute_length(source_value, target_value)

# 长度小于 比较
return source_length < target_length
except Exception:
return False
23 changes: 23 additions & 0 deletions apps/application/flow/compare/len_not_equal_compare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# coding=utf-8
"""
@project: maxkb
@Author:wangliang181230
@file: len_not_equal_compare.py
@date:2026/4/28 20:17
@desc: 长度不等于比较器
"""
from .compare import Compare
from .len_equal_compare import compute_length


class LenNotEqualCompare(Compare):

def compare(self, source_value, compare, target_value):
try:
# 计算长度
source_length, target_length = compute_length(source_value, target_value)

# 长度不等于 比较
return source_length != target_length
except Exception:
return False
10 changes: 5 additions & 5 deletions apps/application/flow/compare/wildcard_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
from .compare import Compare
from common.cache.mem_cache import MemCache


match_cache = MemCache('wildcard_to_regex', {
'TIMEOUT': 3600, # 缓存有效期为 1 小时
'TIMEOUT': 3600, # 缓存有效期为 1 小时
'OPTIONS': {
'MAX_ENTRIES': 500, # 最多缓存 500 个条目
'CULL_FREQUENCY': 10, # 达到上限时,删除约 1/10 的缓存
'MAX_ENTRIES': 500, # 最多缓存 500 个条目
'CULL_FREQUENCY': 10, # 达到上限时,删除约 1/10 的缓存
},
})

Expand All @@ -26,10 +25,11 @@ def translate_and_compile_and_cache(wildcard):
match = match_cache.get(wildcard)
if not match:
regex = fnmatch.translate(wildcard)
match = re.compile(regex).match
match = re.compile(regex).fullmatch
match_cache.set(wildcard, match)
return match


class WildcardCompare(Compare):

def compare(self, source_value, compare, target_value):
Expand Down
1 change: 1 addition & 0 deletions ui/src/locales/lang/en-US/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ You are a master of problem optimization, adept at accurately inferring user int
le: 'Less than or equal to',
lt: 'Less than',
len_eq: 'Length equal to',
len_not_eq: 'Length not equal to',
len_ge: 'Length greater than or equal to',
len_gt: 'Length greater than',
len_le: 'Length less than or equal to',
Expand Down
1 change: 1 addition & 0 deletions ui/src/locales/lang/zh-CN/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ export default {
le: '小于等于',
lt: '小于',
len_eq: '长度等于',
len_not_eq: '长度不等于',
len_ge: '长度大于等于',
len_gt: '长度大于',
len_le: '长度小于等于',
Expand Down
1 change: 1 addition & 0 deletions ui/src/locales/lang/zh-Hant/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ export default {
le: '小於等於',
lt: '小於',
len_eq: '長度等於',
len_not_eq: '長度不等於',
len_ge: '長度大於等於',
len_gt: '長度大於',
len_le: '長度小於等於',
Expand Down
1 change: 1 addition & 0 deletions ui/src/workflow/common/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,7 @@ export const compareList = [
{value: 'le', label: t('workflow.compare.le')},
{value: 'lt', label: t('workflow.compare.lt')},
{value: 'len_eq', label: t('workflow.compare.len_eq')},
{value: 'len_not_eq', label: t('workflow.compare.len_not_eq')},
{value: 'len_ge', label: t('workflow.compare.len_ge')},
{value: 'len_gt', label: t('workflow.compare.len_gt')},
{value: 'len_le', label: t('workflow.compare.len_le')},
Expand Down
Loading