Skip to content
Closed
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
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))
Copy link
Copy Markdown
Contributor Author

@wangliang181230 wangliang181230 Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 优化:封装 compute_length 方法
  2. 新特性2:所有长度比较器,都支持比较数字的长度了


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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新特性1:新增长度不等于 len_not_eq 比较器

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