Skip to content

Commit 8a0ad99

Browse files
committed
feat: Migration Judge Node
1 parent 6d1dbce commit 8a0ad99

26 files changed

Lines changed: 620 additions & 1 deletion
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# coding=utf-8
2+
"""
3+
@project: maxkb
4+
@Author:虎
5+
@file: __init__.py.py
6+
@date:2024/6/7 14:43
7+
@desc:
8+
"""
9+
from typing import List
10+
11+
from .contain_compare import ContainCompare
12+
from .end_with import EndWithCompare
13+
from .equal_compare import EqualCompare
14+
from .ge_compare import GECompare
15+
from .gt_compare import GTCompare
16+
from .is_not_null_compare import IsNotNullCompare
17+
from .is_not_true import IsNotTrueCompare
18+
from .is_null_compare import IsNullCompare
19+
from .is_true import IsTrueCompare
20+
from .le_compare import LECompare
21+
from .len_equal_compare import LenEqualCompare
22+
from .len_ge_compare import LenGECompare
23+
from .len_gt_compare import LenGTCompare
24+
from .len_le_compare import LenLECompare
25+
from .len_lt_compare import LenLTCompare
26+
from .lt_compare import LTCompare
27+
from .not_contain_compare import NotContainCompare
28+
from .not_equal_compare import NotEqualCompare
29+
from .regex_compare import RegexCompare
30+
from .start_with import StartWithCompare
31+
from .wildcard_compare import WildcardCompare
32+
33+
_compare_handler_dict = {
34+
'is_null': IsNullCompare(),
35+
'is_not_null': IsNotNullCompare(),
36+
'contain': ContainCompare(),
37+
'not_contain': NotContainCompare(),
38+
'eq': EqualCompare(),
39+
'not_eq': NotEqualCompare(),
40+
'ge': GECompare(),
41+
'gt': GTCompare(),
42+
'le': LECompare(),
43+
'lt': LTCompare(),
44+
'len_eq': LenEqualCompare(),
45+
'len_ge': LenGECompare(),
46+
'len_gt': LenGTCompare(),
47+
'len_le': LenLECompare(),
48+
'len_lt': LenLTCompare(),
49+
'is_true': IsTrueCompare(),
50+
'is_not_true': IsNotTrueCompare(),
51+
'start_with': StartWithCompare(),
52+
'end_with': EndWithCompare(),
53+
'regex': RegexCompare(),
54+
'wildcard': WildcardCompare(),
55+
}
56+
57+
58+
def _compare(source_value, compare, target_value):
59+
compare_handler = _compare_handler_dict.get(compare)
60+
if compare_handler is None:
61+
raise RuntimeError(f"Unknown compare handler '{compare}'")
62+
return compare_handler.compare(source_value, compare, target_value)
63+
64+
65+
def _assertion(workflow_manage, field_list: List[str], compare: str, value):
66+
try:
67+
value = workflow_manage.generate_prompt(value)
68+
except Exception:
69+
pass
70+
field_value = None
71+
try:
72+
field_value = workflow_manage.get_reference_field(field_list[0], field_list[1:])
73+
except Exception:
74+
pass
75+
return _compare(field_value, compare, value)
76+
77+
78+
def do_assertion(workflow_manage, condition, condition_list):
79+
b = False if condition == 'and' else True
80+
for row in condition_list:
81+
if _assertion(workflow_manage, row.get('field'), row.get('compare'), row.get('value')) is b:
82+
return b
83+
return not b
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# coding=utf-8
2+
"""
3+
@project: maxkb
4+
@Author:虎
5+
@file: compare.py
6+
@date:2024/6/7 14:37
7+
@desc:
8+
"""
9+
from abc import abstractmethod
10+
11+
class Compare:
12+
13+
@abstractmethod
14+
def compare(self, source_value, compare, target_value):
15+
pass
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# coding=utf-8
2+
"""
3+
@project: maxkb
4+
@Author:虎
5+
@file: contain_compare.py
6+
@date:2024/6/11 10:02
7+
@desc:
8+
"""
9+
from .compare import Compare
10+
11+
12+
class ContainCompare(Compare):
13+
14+
def compare(self, source_value, compare, target_value):
15+
target_value = str(target_value)
16+
17+
if isinstance(source_value, str):
18+
return target_value in source_value
19+
elif isinstance(source_value, list):
20+
for item in source_value:
21+
if str(item) == target_value:
22+
return True
23+
return False
24+
else:
25+
return target_value in str(source_value)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# coding=utf-8
2+
"""
3+
@project: MaxKB
4+
@Author:虎虎
5+
@file: start_with.py
6+
@date:2025/10/20 10:37
7+
@desc:
8+
"""
9+
from .compare import Compare
10+
11+
12+
class EndWithCompare(Compare):
13+
14+
def compare(self, source_value, compare, target_value):
15+
source_value = str(source_value)
16+
return source_value.endswith(str(target_value))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# coding=utf-8
2+
"""
3+
@project: maxkb
4+
@Author:虎
5+
@file: equal_compare.py
6+
@date:2024/6/7 14:44
7+
@desc:
8+
"""
9+
from .compare import Compare
10+
11+
12+
class EqualCompare(Compare):
13+
14+
def compare(self, source_value, compare, target_value):
15+
return str(source_value) == str(target_value)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# coding=utf-8
2+
"""
3+
@project: maxkb
4+
@Author:虎
5+
@file: lt_compare.py
6+
@date:2024/6/11 9:52
7+
@desc: 大于比较器
8+
"""
9+
from .compare import Compare
10+
11+
12+
class GECompare(Compare):
13+
14+
def compare(self, source_value, compare, target_value):
15+
if source_value is None:
16+
return target_value is None
17+
18+
try:
19+
return float(source_value) >= float(target_value)
20+
except Exception:
21+
try:
22+
return str(source_value) >= str(target_value)
23+
except Exception:
24+
pass
25+
return False
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# coding=utf-8
2+
"""
3+
@project: maxkb
4+
@Author:虎
5+
@file: lt_compare.py
6+
@date:2024/6/11 9:52
7+
@desc: 大于比较器
8+
"""
9+
from .compare import Compare
10+
11+
12+
class GTCompare(Compare):
13+
14+
def compare(self, source_value, compare, target_value):
15+
if source_value is None:
16+
return False
17+
18+
try:
19+
return float(source_value) > float(target_value)
20+
except Exception:
21+
try:
22+
return str(source_value) > str(target_value)
23+
except Exception:
24+
pass
25+
return False
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# coding=utf-8
2+
"""
3+
@project: maxkb
4+
@Author:虎
5+
@file: is_not_null_compare.py
6+
@date:2024/6/28 10:45
7+
@desc:
8+
"""
9+
from .compare import Compare
10+
11+
12+
class IsNotNullCompare(Compare):
13+
14+
def compare(self, source_value, compare, target_value):
15+
try:
16+
return source_value is not None and len(source_value) > 0
17+
except Exception:
18+
return True
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# coding=utf-8
2+
"""
3+
@project: MaxKB
4+
@Author:虎
5+
@file: is_not_true.py
6+
@date:2025/4/7 13:44
7+
@desc:
8+
"""
9+
from .compare import Compare
10+
11+
12+
class IsNotTrueCompare(Compare):
13+
14+
def compare(self, source_value, compare, target_value):
15+
try:
16+
return source_value is False
17+
except Exception:
18+
return False
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# coding=utf-8
2+
"""
3+
@project: maxkb
4+
@Author:虎
5+
@file: is_null_compare.py
6+
@date:2024/6/28 10:45
7+
@desc:
8+
"""
9+
from .compare import Compare
10+
11+
12+
class IsNullCompare(Compare):
13+
14+
def compare(self, source_value, compare, target_value):
15+
try:
16+
return source_value is None or len(source_value) == 0
17+
except Exception:
18+
return False

0 commit comments

Comments
 (0)