|
@@ -1,14 +1,16 @@
|
|
|
-package com.citu.module.menduner.reward.service;
|
|
|
+package com.citu.module.menduner.reward.service.event;
|
|
|
|
|
|
import com.citu.module.menduner.reward.controller.base.common.TreeRespVO;
|
|
|
import com.citu.module.menduner.reward.controller.base.event.EventTrackPointRespVO;
|
|
|
import com.citu.module.menduner.reward.controller.base.event.EventTrackUrlRespVO;
|
|
|
import com.citu.module.menduner.reward.convert.PointRuleConfigConvert;
|
|
|
import com.citu.module.menduner.reward.core.EasyRulesEngine;
|
|
|
-import com.citu.module.menduner.reward.core.PointRuleFact;
|
|
|
-import com.citu.module.menduner.reward.dal.dataobject.pointruleconfig.PointRuleConfigDO;
|
|
|
+import com.citu.module.menduner.reward.core.PointRule;
|
|
|
+import com.citu.module.menduner.reward.core.RuleMatch;
|
|
|
+import com.citu.module.menduner.reward.dal.dataobject.config.PointRuleConfigDO;
|
|
|
import com.citu.module.menduner.reward.rule.DynamicPointRule;
|
|
|
import com.citu.module.menduner.reward.rule.DynamicRuleAction;
|
|
|
+import com.citu.module.menduner.reward.service.config.PointRuleConfigService;
|
|
|
import com.citu.module.menduner.system.api.url.MendunerSystemUrlApi;
|
|
|
import com.citu.module.menduner.system.api.url.UrlInfoRespVO;
|
|
|
import org.jeasy.rules.api.Facts;
|
|
@@ -17,7 +19,6 @@ import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -40,7 +41,6 @@ public class EventTrackServiceImpl implements EventTrackService {
|
|
|
@Resource
|
|
|
private MendunerSystemUrlApi mendunerSystemUrlApi;
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public List<EventTrackUrlRespVO> getEventTrackList() {
|
|
|
List<PointRuleConfigDO> list = ruleConfigService.getList();
|
|
@@ -52,34 +52,41 @@ public class EventTrackServiceImpl implements EventTrackService {
|
|
|
PointRuleConfigDO config = ruleConfigService.get(id);
|
|
|
if (null == config) {
|
|
|
// 不存在
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
// redis 解析出当前操作用户的参数
|
|
|
|
|
|
+ List<String> triggerKeyList = EasyRulesEngine.extractUniqueKeys(config.getConstraintRule());
|
|
|
+
|
|
|
+ // 读取对应数据
|
|
|
+ // 赋值到 context
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- PointRuleFact fact = new PointRuleFact();
|
|
|
+ PointRule pointRule= new PointRule();
|
|
|
// 基本信息
|
|
|
- fact.setRuleId(String.valueOf(config.getId()));
|
|
|
- fact.setRuleName(config.getUrl());
|
|
|
- fact.setDescription(config.getTitle());
|
|
|
- fact.setWhenExpression(RULE_WHEN);
|
|
|
- fact.setThenExpression(RULE_THEN);
|
|
|
+ pointRule.setRuleId(String.valueOf(config.getId()));
|
|
|
+ pointRule.setRuleName(config.getUrl());
|
|
|
+ pointRule.setDescription(config.getTitle());
|
|
|
+ pointRule.setWhenExpression(RULE_WHEN);
|
|
|
+ pointRule.setThenExpression(RULE_THEN);
|
|
|
|
|
|
// 构造参数
|
|
|
- fact.setTriggerRule(EasyRulesEngine.buildWhenExpression(config.getTriggerRule()));
|
|
|
- fact.setLimitRule(EasyRulesEngine.buildThenExpression());
|
|
|
- fact.setTriggerContext(null);
|
|
|
- fact.setLimitContext(null);
|
|
|
- fact.setOperation(config.getOperation());
|
|
|
- fact.setPoint(config.getPoint());
|
|
|
+ pointRule.setTriggerRule(EasyRulesEngine.buildWhenExpression(config.getTriggerRule()));
|
|
|
+ pointRule.setLimitRule(EasyRulesEngine.buildThenExpression());
|
|
|
+ pointRule.setTriggerContext(null);
|
|
|
+ pointRule.setLimitContext(null);
|
|
|
+ pointRule.setOperation(config.getOperation());
|
|
|
+ pointRule.setPoint(config.getPoint());
|
|
|
|
|
|
|
|
|
// 解析器的上下文
|
|
|
Facts context = new Facts();
|
|
|
- context.put(RULE, new DynamicPointRule(fact));
|
|
|
+ context.put(RULE, new DynamicPointRule(pointRule));
|
|
|
context.put(RULE_CONFIG, config);
|
|
|
|
|
|
- DynamicRuleAction<PointRuleFact> action = (t) -> {
|
|
|
+ DynamicRuleAction<PointRule> action = (t) -> {
|
|
|
// 匹配成功后的逻辑
|
|
|
System.out.println("加分:" + t.getPoint());
|
|
|
};
|
|
@@ -87,7 +94,10 @@ public class EventTrackServiceImpl implements EventTrackService {
|
|
|
|
|
|
|
|
|
// 调用
|
|
|
- EasyRulesEngine.match(context, fact);
|
|
|
+ EasyRulesEngine.match(RuleMatch.builder()
|
|
|
+ .facts(context)
|
|
|
+ .ruleBase(pointRule)
|
|
|
+ .build());
|
|
|
|
|
|
return null;
|
|
|
}
|