22
33
44import cn .hutool .core .bean .BeanUtil ;
5+ import cn .hutool .core .util .StrUtil ;
56import com .alibaba .fastjson2 .JSONArray ;
67import com .chery .gb .realtime .algorithm .bo .RuleConditionBO ;
78import com .chery .gb .realtime .algorithm .bo .RuleDetailBO ;
89import com .chery .gb .realtime .algorithm .bo .RuleValidateWorkFlowBO ;
910import com .chery .gb .realtime .algorithm .enums .NewGbRuleCodeEnum ;
1011import com .chery .gb .realtime .algorithm .exception .GbException ;
12+ import com .chery .gb .realtime .algorithm .rule .config .BaseRuleConfig ;
13+ import com .chery .gb .realtime .algorithm .rule .factory .RuleConfigFactory ;
1114import com .chery .gb .realtime .algorithm .rule .factory .RuleValidatorFactory ;
1215import com .chery .gb .realtime .algorithm .rule .validator .BaseRuleValidator ;
1316import com .chery .gb .realtime .algorithm .util .check .GbRuleCheckUtil ;
2528 */
2629public class RuleValidateWorkFlowUtil {
2730
28-
2931 /**
3032 * 运行工作流
3133 *
@@ -54,12 +56,40 @@ static void run(Map<String, Object> signalMap, Map<String, Map<String, List<Rule
5456 s .append ("=" );
5557 }
5658 System .out .println ("====================执行工作流:" + workFlow .getCode () + ":" + workFlowName + s );
59+ //校验规则
60+ List <NewGbRuleCodeEnum > ruleCodeList = workFlow .getRuleCodeList ();
61+ if (CollectionUtils .isNotEmpty (ruleCodeList )) {
62+ for (NewGbRuleCodeEnum newGbRuleCodeEnum : ruleCodeList ) {
63+ String ruleCode = newGbRuleCodeEnum .getCode ();
64+ BaseRuleValidator ruleValidate = RuleValidatorFactory .getRuleValidate (ruleCode );
65+ boolean flag ;
66+ if (ruleValidate != null ) {
67+ flag = ruleValidate .validate (signalMap , ruleMap , retData );
68+ } else {
69+ flag = GbRuleCheckUtil .checkByRuleCode (signalMap , ruleMap , retData , ruleCode );
70+ }
71+ if (flag ) {
72+ BaseRuleConfig config = RuleConfigFactory .getConfig (ruleCode , ruleMap );
73+ if (config != null && config .getConditionBO () != null ) {
74+ System .out .println ("触发规则:" + ruleCode + ":" + config .getConditionBO ().getDesc ());
75+ }
76+ }
77+ // result = result || flag;
78+ if (flag && workFlow .isReturn ()) {
79+ throw new GbException (workFlowName );
80+ }
81+ }
82+ }
83+ //运行判断
5784 boolean result = false ;
5885 RuleValidateWorkFlowBO subWorkFlow = workFlow .getSubWorkFlow ();
5986 RuleConditionBO ruleCondition = workFlow .getRuleCondition ();
60- //运行判断
6187 if (ruleCondition != null ) {
6288 result = GbRuleCheckUtil .checkByCondition (signalMap , ruleCondition .getConditions (), retData , ruleCondition .getRuleCode ());
89+ String desc = ruleCondition .getDesc ();
90+ if (result && StrUtil .isNotBlank (desc )) {
91+ System .out .println (desc );
92+ }
6393 //如果条件判断结果为true,需要返回时,抛出异常
6494 if (result && (ruleCondition .isReturn () || workFlow .isReturn ())) {
6595 throw new GbException (workFlowName );
@@ -69,22 +99,6 @@ static void run(Map<String, Object> signalMap, Map<String, Map<String, List<Rule
6999 run (signalMap , ruleMap , retData , subWorkFlow );
70100 }
71101 }
72- //校验规则
73- List <NewGbRuleCodeEnum > ruleCodeList = workFlow .getRuleCodeList ();
74- if (CollectionUtils .isNotEmpty (ruleCodeList )) {
75- for (NewGbRuleCodeEnum newGbRuleCodeEnum : ruleCodeList ) {
76- String ruleCode = newGbRuleCodeEnum .getCode ();
77- BaseRuleValidator ruleValidate = RuleValidatorFactory .getRuleValidate (ruleCode );
78- if (ruleValidate != null ) {
79- result = result || ruleValidate .validate (signalMap , ruleMap , retData );
80- if (result && workFlow .isReturn ()) {
81- throw new GbException (workFlowName );
82- }
83- } else {
84- result = result || GbRuleCheckUtil .checkByRuleCode (signalMap , ruleMap , retData , ruleCode );
85- }
86- }
87- }
88102 //运行支流
89103 if (ruleCondition == null && subWorkFlow != null ) {
90104 run (signalMap , ruleMap , retData , subWorkFlow );
0 commit comments