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/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/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')},