Skip to content
Merged
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
87 changes: 67 additions & 20 deletions apps/application/flow/compare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,78 @@
@date:2024/6/7 14:43
@desc:
"""
from typing import List

from .contain_compare import *
from .contain_compare import ContainCompare
from .end_with import EndWithCompare
from .equal_compare import *
from .ge_compare import *
from .gt_compare import *
from .is_not_null_compare import *
from .equal_compare import EqualCompare
from .ge_compare import GECompare
from .gt_compare import GTCompare
from .is_not_null_compare import IsNotNullCompare
from .is_not_true import IsNotTrueCompare
from .is_null_compare import *
from .is_null_compare import IsNullCompare
from .is_true import IsTrueCompare
from .le_compare import *
from .len_equal_compare import *
from .len_ge_compare import *
from .len_gt_compare import *
from .len_le_compare import *
from .len_lt_compare import *
from .lt_compare import *
from .not_contain_compare import *
from .not_equal_compare import *
from .le_compare import LECompare
from .len_equal_compare import LenEqualCompare
from .len_ge_compare import LenGECompare
from .len_gt_compare import LenGTCompare
from .len_le_compare import LenLECompare
from .len_lt_compare import LenLTCompare
from .lt_compare import LTCompare
from .not_contain_compare import NotContainCompare
from .not_equal_compare import NotEqualCompare
from .regex_compare import RegexCompare
from .start_with import StartWithCompare
from .wildcard_compare import WildcardCompare

compare_handle_list = [GECompare(), GTCompare(), ContainCompare(), EqualCompare(), LTCompare(), LECompare(),
LenLECompare(), LenGECompare(), LenEqualCompare(), LenGTCompare(), LenLTCompare(),
IsNullCompare(),
IsNotNullCompare(), NotContainCompare(), NotEqualCompare(), IsTrueCompare(), IsNotTrueCompare(), StartWithCompare(),
EndWithCompare(), RegexCompare(), WildcardCompare()]
_compare_handler_dict = {
'is_null': IsNullCompare(),
'is_not_null': IsNotNullCompare(),
'contain': ContainCompare(),
'not_contain': NotContainCompare(),
'eq': EqualCompare(),
'not_eq': NotEqualCompare(),
'ge': GECompare(),
'gt': GTCompare(),
'le': LECompare(),
'lt': LTCompare(),
'len_eq': LenEqualCompare(),
'len_ge': LenGECompare(),
'len_gt': LenGTCompare(),
'len_le': LenLECompare(),
'len_lt': LenLTCompare(),
'is_true': IsTrueCompare(),
'is_not_true': IsNotTrueCompare(),
'start_with': StartWithCompare(),
'end_with': EndWithCompare(),
'regex': RegexCompare(),
'wildcard': WildcardCompare(),
}


def _compare(source_value, compare, target_value):
compare_handler = _compare_handler_dict.get(compare)
if compare_handler is None:
raise RuntimeError(f"Unknown compare handler '{compare}'")
return compare_handler.compare(source_value, compare, target_value)

@wangliang181230 wangliang181230 Apr 28, 2026

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:处理器列表由 list 改成 dict,直接获取处理器,性能更高。



def _assertion(workflow_manage, field_list: List[str], compare: str, value):
try:
value = workflow_manage.generate_prompt(value)
except Exception:
pass
field_value = None
try:
field_value = workflow_manage.get_reference_field(field_list[0], field_list[1:])
except Exception:
pass
return _compare(field_value, compare, value)


def do_assertion(workflow_manage, condition, condition_list):
b = False if condition == 'and' else True
for row in condition_list:
if _assertion(workflow_manage, row.get('field'), row.get('compare'), row.get('value')) is b:
return b
return not b

@wangliang181230 wangliang181230 Apr 28, 2026

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.

性能提升2:不使用 allany 函数,避免所有判断条件都会执行compare,性能较差。

5 changes: 0 additions & 5 deletions apps/application/flow/compare/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@
@desc:
"""
from abc import abstractmethod
from typing import List


class Compare:
@abstractmethod
def support(self, node_id, fields: List[str], source_value, compare, target_value):
pass

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.

直接通过 dict 的 key 进行匹配获取,不再需要 support 方法,所有实现类的该方法全部删除。


@abstractmethod
def compare(self, source_value, compare, target_value):
Expand Down
8 changes: 1 addition & 7 deletions apps/application/flow/compare/contain_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@
@date:2024/6/11 10:02
@desc:
"""
from typing import List

from application.flow.compare.compare import Compare
from .compare import Compare


class ContainCompare(Compare):

def support(self, node_id, fields: List[str], source_value, compare, target_value):
if compare == 'contain':
return True

def compare(self, source_value, compare, target_value):
target_value = str(target_value)

Expand Down
8 changes: 1 addition & 7 deletions apps/application/flow/compare/end_with.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@
@date:2025/10/20 10:37
@desc:
"""
from typing import List

from application.flow.compare import Compare
from .compare import Compare


class EndWithCompare(Compare):

def support(self, node_id, fields: List[str], source_value, compare, target_value):
if compare == 'end_with':
return True

def compare(self, source_value, compare, target_value):
source_value = str(source_value)
return source_value.endswith(str(target_value))
8 changes: 1 addition & 7 deletions apps/application/flow/compare/equal_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@
@date:2024/6/7 14:44
@desc:
"""
from typing import List

from application.flow.compare import Compare
from .compare import Compare


class EqualCompare(Compare):

def support(self, node_id, fields: List[str], source_value, compare, target_value):
if compare == 'eq':
return True

def compare(self, source_value, compare, target_value):
return str(source_value) == str(target_value)
12 changes: 3 additions & 9 deletions apps/application/flow/compare/ge_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,17 @@
@date:2024/6/11 9:52
@desc: 大于比较器
"""
from typing import List

from application.flow.compare import Compare
from .compare import Compare


class GECompare(Compare):

def support(self, node_id, fields: List[str], source_value, compare, target_value):
if compare == 'ge':
return True

def compare(self, source_value, compare, target_value):
try:
return float(source_value) >= float(target_value)
except Exception as e:
except Exception:
try:
return str(source_value) >= str(target_value)
except Exception as _:
except Exception:
pass
return False
12 changes: 3 additions & 9 deletions apps/application/flow/compare/gt_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,17 @@
@date:2024/6/11 9:52
@desc: 大于比较器
"""
from typing import List

from application.flow.compare import Compare
from .compare import Compare


class GTCompare(Compare):

def support(self, node_id, fields: List[str], source_value, compare, target_value):
if compare == 'gt':
return True

def compare(self, source_value, compare, target_value):
try:
return float(source_value) > float(target_value)
except Exception as e:
except Exception:
try:
return str(source_value) > str(target_value)
except Exception as _:
except Exception:
pass
return False
8 changes: 1 addition & 7 deletions apps/application/flow/compare/is_not_null_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@
@date:2024/6/28 10:45
@desc:
"""
from typing import List

from application.flow.compare import Compare
from .compare import Compare


class IsNotNullCompare(Compare):

def support(self, node_id, fields: List[str], source_value, compare, target_value):
if compare == 'is_not_null':
return True

def compare(self, source_value, compare, target_value):
try:
return source_value is not None and len(source_value) > 0
Expand Down
10 changes: 2 additions & 8 deletions apps/application/flow/compare/is_not_true.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@
@date:2025/4/7 13:44
@desc:
"""
from typing import List

from application.flow.compare import Compare
from .compare import Compare


class IsNotTrueCompare(Compare):

def support(self, node_id, fields: List[str], source_value, compare, target_value):
if compare == 'is_not_true':
return True

def compare(self, source_value, compare, target_value):
try:
return source_value is False
except Exception as e:
except Exception:
return False
10 changes: 2 additions & 8 deletions apps/application/flow/compare/is_null_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@
@date:2024/6/28 10:45
@desc:
"""
from typing import List

from application.flow.compare import Compare
from .compare import Compare


class IsNullCompare(Compare):

def support(self, node_id, fields: List[str], source_value, compare, target_value):
if compare == 'is_null':
return True

def compare(self, source_value, compare, target_value):
try:
return source_value is None or len(source_value) == 0
except Exception as e:
except Exception:
return False
10 changes: 2 additions & 8 deletions apps/application/flow/compare/is_true.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@
@date:2025/4/7 13:38
@desc:
"""
from typing import List

from application.flow.compare import Compare
from .compare import Compare


class IsTrueCompare(Compare):

def support(self, node_id, fields: List[str], source_value, compare, target_value):
if compare == 'is_true':
return True

def compare(self, source_value, compare, target_value):
try:
return source_value is True
except Exception as e:
except Exception:
return False
12 changes: 3 additions & 9 deletions apps/application/flow/compare/le_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,17 @@
@date:2024/6/11 9:52
@desc: 小于比较器
"""
from typing import List

from application.flow.compare import Compare
from .compare import Compare


class LECompare(Compare):

def support(self, node_id, fields: List[str], source_value, compare, target_value):
if compare == 'le':
return True

def compare(self, source_value, compare, target_value):
try:
return float(source_value) <= float(target_value)
except Exception as e:
except Exception:
try:
return str(source_value) <= str(target_value)
except Exception as _:
except Exception:
pass
return False
8 changes: 1 addition & 7 deletions apps/application/flow/compare/len_equal_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@
@date:2024/6/7 14:44
@desc:
"""
from typing import List

from application.flow.compare import Compare
from .compare import Compare


class LenEqualCompare(Compare):

def support(self, node_id, fields: List[str], source_value, compare, target_value):
if compare == 'len_eq':
return True

def compare(self, source_value, compare, target_value):
try:
return len(source_value) == int(target_value)
Expand Down
10 changes: 2 additions & 8 deletions apps/application/flow/compare/len_ge_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@
@date:2024/6/11 9:52
@desc: 大于比较器
"""
from typing import List

from application.flow.compare import Compare
from .compare import Compare


class LenGECompare(Compare):

def support(self, node_id, fields: List[str], source_value, compare, target_value):
if compare == 'len_ge':
return True

def compare(self, source_value, compare, target_value):
try:
return len(source_value) >= int(target_value)
except Exception as e:
except Exception:
return False
10 changes: 2 additions & 8 deletions apps/application/flow/compare/len_gt_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@
@date:2024/6/11 9:52
@desc: 大于比较器
"""
from typing import List

from application.flow.compare import Compare
from .compare import Compare


class LenGTCompare(Compare):

def support(self, node_id, fields: List[str], source_value, compare, target_value):
if compare == 'len_gt':
return True

def compare(self, source_value, compare, target_value):
try:
return len(source_value) > int(target_value)
except Exception as e:
except Exception:
return False
Loading
Loading