From b8cb954a4a10f8c906e75daa5e79d67d287ebbdb Mon Sep 17 00:00:00 2001 From: wangdan-fit2cloud Date: Thu, 30 Apr 2026 11:25:11 +0800 Subject: [PATCH] feat: 1) support `length_not_equal` comparison; 2) All length comparators support numbers --- apps/application/flow/compare/__init__.py | 2 ++ apps/application/flow/compare/is_not_true.py | 5 +-- apps/application/flow/compare/is_true.py | 5 +-- .../flow/compare/len_equal_compare.py | 36 +++++++++++++++++-- .../flow/compare/len_ge_compare.py | 9 +++-- .../flow/compare/len_gt_compare.py | 9 +++-- .../flow/compare/len_le_compare.py | 9 +++-- .../flow/compare/len_lt_compare.py | 9 +++-- .../flow/compare/len_not_equal_compare.py | 23 ++++++++++++ .../flow/compare/wildcard_compare.py | 10 +++--- ui/src/locales/lang/en-US/workflow.ts | 1 + ui/src/locales/lang/zh-CN/workflow.ts | 1 + ui/src/locales/lang/zh-Hant/workflow.ts | 1 + ui/src/workflow/common/data.ts | 1 + 14 files changed, 97 insertions(+), 24 deletions(-) create mode 100644 apps/application/flow/compare/len_not_equal_compare.py diff --git a/apps/application/flow/compare/__init__.py b/apps/application/flow/compare/__init__.py index ce0c430e1ad..329b3e80286 100644 --- a/apps/application/flow/compare/__init__.py +++ b/apps/application/flow/compare/__init__.py @@ -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 @@ -42,6 +43,7 @@ 'le': LECompare(), 'lt': LTCompare(), 'len_eq': LenEqualCompare(), + 'len_not_eq': LenNotEqualCompare(), 'len_ge': LenGECompare(), 'len_gt': LenGTCompare(), 'len_le': LenLECompare(), diff --git a/apps/application/flow/compare/is_not_true.py b/apps/application/flow/compare/is_not_true.py index fabeec2cc41..43a42bbc726 100644 --- a/apps/application/flow/compare/is_not_true.py +++ b/apps/application/flow/compare/is_not_true.py @@ -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 diff --git a/apps/application/flow/compare/is_true.py b/apps/application/flow/compare/is_true.py index 8cb4a45a2a5..daa1479307d 100644 --- a/apps/application/flow/compare/is_true.py +++ b/apps/application/flow/compare/is_true.py @@ -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 diff --git a/apps/application/flow/compare/len_equal_compare.py b/apps/application/flow/compare/len_equal_compare.py index 98a5314a292..7479c5128ba 100644 --- a/apps/application/flow/compare/len_equal_compare.py +++ b/apps/application/flow/compare/len_equal_compare.py @@ -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 diff --git a/apps/application/flow/compare/len_ge_compare.py b/apps/application/flow/compare/len_ge_compare.py index 06dd566cf24..41227d2efa7 100644 --- a/apps/application/flow/compare/len_ge_compare.py +++ b/apps/application/flow/compare/len_ge_compare.py @@ -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 diff --git a/apps/application/flow/compare/len_gt_compare.py b/apps/application/flow/compare/len_gt_compare.py index fae2668e0ba..c11c3eb9b86 100644 --- a/apps/application/flow/compare/len_gt_compare.py +++ b/apps/application/flow/compare/len_gt_compare.py @@ -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 diff --git a/apps/application/flow/compare/len_le_compare.py b/apps/application/flow/compare/len_le_compare.py index 41b9ee9f709..0a7bef1a441 100644 --- a/apps/application/flow/compare/len_le_compare.py +++ b/apps/application/flow/compare/len_le_compare.py @@ -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 diff --git a/apps/application/flow/compare/len_lt_compare.py b/apps/application/flow/compare/len_lt_compare.py index 4a9b11654ca..0871d167464 100644 --- a/apps/application/flow/compare/len_lt_compare.py +++ b/apps/application/flow/compare/len_lt_compare.py @@ -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 diff --git a/apps/application/flow/compare/len_not_equal_compare.py b/apps/application/flow/compare/len_not_equal_compare.py new file mode 100644 index 00000000000..388791b12ae --- /dev/null +++ b/apps/application/flow/compare/len_not_equal_compare.py @@ -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 diff --git a/apps/application/flow/compare/wildcard_compare.py b/apps/application/flow/compare/wildcard_compare.py index 43c903a9360..48cbf173ab1 100644 --- a/apps/application/flow/compare/wildcard_compare.py +++ b/apps/application/flow/compare/wildcard_compare.py @@ -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 的缓存 }, }) @@ -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): diff --git a/ui/src/locales/lang/en-US/workflow.ts b/ui/src/locales/lang/en-US/workflow.ts index beb02772c5a..25d34b92ad2 100644 --- a/ui/src/locales/lang/en-US/workflow.ts +++ b/ui/src/locales/lang/en-US/workflow.ts @@ -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', diff --git a/ui/src/locales/lang/zh-CN/workflow.ts b/ui/src/locales/lang/zh-CN/workflow.ts index 6ed79e52fc9..b68c09f9ee3 100644 --- a/ui/src/locales/lang/zh-CN/workflow.ts +++ b/ui/src/locales/lang/zh-CN/workflow.ts @@ -525,6 +525,7 @@ export default { le: '小于等于', lt: '小于', len_eq: '长度等于', + len_not_eq: '长度不等于', len_ge: '长度大于等于', len_gt: '长度大于', len_le: '长度小于等于', diff --git a/ui/src/locales/lang/zh-Hant/workflow.ts b/ui/src/locales/lang/zh-Hant/workflow.ts index 0513ea1c0e4..10a443aabaf 100644 --- a/ui/src/locales/lang/zh-Hant/workflow.ts +++ b/ui/src/locales/lang/zh-Hant/workflow.ts @@ -519,6 +519,7 @@ export default { le: '小於等於', lt: '小於', len_eq: '長度等於', + len_not_eq: '長度不等於', len_ge: '長度大於等於', len_gt: '長度大於', len_le: '長度小於等於', diff --git a/ui/src/workflow/common/data.ts b/ui/src/workflow/common/data.ts index a726ae9ed5a..d1eaa637675 100644 --- a/ui/src/workflow/common/data.ts +++ b/ui/src/workflow/common/data.ts @@ -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')},