0 涉及架构
注意 :以下代码,都是根据一个特定规则模型:
rulemodel_03_caculator 来进行开发的
不同的规则模型,如下功能代码需要进行不同的开发
RuleModel_03 这个规则模型的特点是:
- 拥有事件间隔时间
1 规则参数结构规范
{ "ruleModelId": "3", "ruleId": "m3-r01", "ruleTrigEvent": { "eventId": "submitOrder", "attributeParams": [ { "attributeName": "pageId", "compareType": "=", "compareValue": "page001" } ], "windowStart": "", "windowEnd": "2022-08-30 12:00:00" }, "interval_time": "10000", "checkEvent": { "eventId": "payOrder", "eventAttribute": "orderId" }, "rule_match_count": 2 }
2 新规则实例发布controller开发
package cn.doitedu.rulemgmt.controller; import cn.doitedu.rtmk.common.pojo.ActionSeqParam; import cn.doitedu.rtmk.common.pojo.AttributeParam; import cn.doitedu.rtmk.common.pojo.EventParam; import cn.doitedu.rulemgmt.dao.DorisQueryDaoImpl; import cn.doitedu.rulemgmt.dao.RuleSystemMetaDaoImpl; import cn.doitedu.rulemgmt.service.*; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.jfinal.template.Engine; import com.jfinal.template.Template; import lombok.extern.slf4j.Slf4j; import org.roaringbitmap.RoaringBitmap; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.io.IOException; import java.sql.SQLException; import java.util.*; /** * 前端传入的规则定义参数json结构示例: param_jsons/rule_model_1.json */ @Slf4j @RestController public class RuleManagementController { private final ProfileConditionQueryService profileConditionQueryServiceImpl; private final ActionConditionQueryService actionConditionQueryService; private final RuleSystemMetaService ruleSystemMetaService; @Autowired public RuleManagementController( ProfileConditionQueryService profileConditionQueryServiceImpl, ActionConditionQueryService actionConditionQueryService, RuleSystemMetaService ruleSystemMetaService) { this.profileConditionQueryServiceImpl = profileConditionQueryServiceImpl; this.actionConditionQueryService = actionConditionQueryService; this.ruleSystemMetaService = ruleSystemMetaService; } @RequestMapping("/api/publish/addrule/model03") public void publishRuleModel03(@RequestBody String ruleDefineJson) throws IOException, SQLException { log.info(ruleDefineJson); JSONObject ruleDefineJsonObject = JSON.parseObject(ruleDefineJson); String ruleId = ruleDefineJsonObject.getString("ruleId"); /* * * 一、 规则的groovy运算代码处理 */ String groovyCode = ruleSystemMetaService.findRuleModelGroovyTemplate(ruleDefineJsonObject.getInteger("ruleModelId")); /** * 二、 正式发布规则,把 3类信息,放入规则平台的元数据库: * 1. 规则参数(大json) * 1. 规则运算的 groovy 代码 */ Integer ruleModelId = ruleDefineJsonObject.getInteger("ruleModelId"); String creatorName = "多易教育@深似海男人"; ruleSystemMetaService.publishRuleInstance(ruleId,ruleModelId,creatorName,1,null,ruleDefineJson,groovyCode); } // 测试: 手动调用controller的规则发布功能 public static void main(String[] args) throws IOException, SQLException { RuleManagementController controller = new RuleManagementController( new ProfileConditionQueryServiceImpl(), new ActionConditionQueryServiceImpl(new RuleSystemMetaDaoImpl(), new DorisQueryDaoImpl()),new RuleSystemMetaServiceImpl(new RuleSystemMetaDaoImpl())); String webFrontJson = "{\n" + " \"ruleId\":\"rule001\",\n" + " \"profileCondition\":[{\"tagId\":\"tg01\",\"compareType\":\"gt\",\"compareValue\":\"1\"},{\"tagId\":\"tg04\",\"compareType\":\"match\",\"compareValue\":\"汽车\"}]\n" + "}"; controller.publishRuleModel01(webFrontJson); } }
3 规则的groovy运算代码处理
4 正式发布规则,把 信息,放入规则平台的元数据库
标签:rulemodel,03,cn,new,String,规则,import,doitedu From: https://www.cnblogs.com/qiu-hua/p/18156176