# easy-rule-demo **Repository Path**: YxD7/easy-rule-demo ## Basic Information - **Project Name**: easy-rule-demo - **Description**: easy-rules规则引擎框架demo - **Primary Language**: Java - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 4 - **Created**: 2022-08-16 - **Last Updated**: 2025-01-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 工程简介 easy-rule规则框架demo 1:实现两种方式的规则demo 动态创建规则:根据数据库中的满减规则进行操作 静态创建规则:根据定义的规则选择最优购物券 # 延伸阅读 #SQL建表语句 CREATE TABLE `rule` ( `rule_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '规则主键ID', `name` varchar(255) NOT NULL COMMENT '规则名称', `description` varchar(255) NOT NULL COMMENT '规则描述', `priority` int(20) NOT NULL DEFAULT '1' COMMENT '规则优先级', `conditions` text NOT NULL COMMENT '规则条件', `action` text NOT NULL COMMENT '规则操作', `is_composited` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否为复合规则(0:否1:是)', `composite_rule_Type` tinyint(1) DEFAULT NULL COMMENT '复合规则类型(1:UnitRuleGroup2:ActivationRuleGroup3:ConditionalRuleGroup)', `composite_rule_ids` varchar(255) DEFAULT NULL COMMENT '复合规则中规则ID集合,通过'',''分割', `is_enabled` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否启用(0:否1:是)', `rule_type` tinyint(1) NOT NULL DEFAULT '0' COMMENT '规则类型(0:不是子规则1:子规则2:简单规则和子规则)', PRIMARY KEY (`rule_id`) ) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4; #添加数据 INSERT INTO `rule` (`rule_id`, `name`, `description`, `priority`, `conditions`, `action`, `is_composited`, `composite_rule_Type`, `composite_rule_ids`, `is_enabled`, `rule_type`) VALUES (8, '满减规则', '满100减10', 100, 'store.totalPrice >=100', 'store.totalPrice = marketingWayService.subtract(store.totalPrice, 10);', 0, NULL, NULL, 1, 0); INSERT INTO `rule` (`rule_id`, `name`, `description`, `priority`, `conditions`, `action`, `is_composited`, `composite_rule_Type`, `composite_rule_ids`, `is_enabled`, `rule_type`) VALUES (9, '满减规则', '满200减30', 90, 'store.totalPrice >=200', 'store.totalPrice = marketingWayService.subtract(store.totalPrice, 30);', 0, NULL, NULL, 1, 0); INSERT INTO `rule` (`rule_id`, `name`, `description`, `priority`, `conditions`, `action`, `is_composited`, `composite_rule_Type`, `composite_rule_ids`, `is_enabled`, `rule_type`) VALUES (10, '满减规则', '满500减50', 80, 'store.totalPrice >= 500', 'store.totalPrice = marketingWayService.subtract(store.totalPrice, 50);', 0, NULL, NULL, 1, 2); INSERT INTO `rule` (`rule_id`, `name`, `description`, `priority`, `conditions`, `action`, `is_composited`, `composite_rule_Type`, `composite_rule_ids`, `is_enabled`, `rule_type`) VALUES (11, '赠送规则', '满500赠送优惠券', 70, 'store.totalPrice >= 500', 'marketingWayService.present(5,\"优惠卷\",store.userId);', 0, NULL, NULL, 1, 1); INSERT INTO `rule` (`rule_id`, `name`, `description`, `priority`, `conditions`, `action`, `is_composited`, `composite_rule_Type`, `composite_rule_ids`, `is_enabled`, `rule_type`) VALUES (12, '复合规则', '复合规则', 60, 'store.totalPrice >= 500', '222', 1, 1, '10,11', 1, 0); INSERT INTO `rule` (`rule_id`, `name`, `description`, `priority`, `conditions`, `action`, `is_composited`, `composite_rule_Type`, `composite_rule_ids`, `is_enabled`, `rule_type`) VALUES (13, '打折规则', '满1000打8折', 50, 'store.totalPrice >= 1000', 'store.totalPrice = marketingWayService.multiply(store.totalPrice, 0.8);', 0, NULL, NULL, 1, 0);