- hxpwork
- 等级:
![五星会员 五星会员](/images/star5.gif)
![hxpwork的博客: hxpwork hxpwork的博客](https://www.iteye.com/images/user-logo.gif?1652290086)
- 性别:
![男](/images/icon_minigender_1.gif) - 文章: 38
- 积分: 460
- 来自: 广州
![](/images/status/offline.gif)
|
Fact 数据插入
-
- final CustomerEx a = new CustomerEx( "A",
- "Gold" );
- final CustomerEx b = new CustomerEx( "B",
- "Platinum" );
- final CustomerEx c = new CustomerEx( "C",
- "Silver" );
- final CustomerEx d = new CustomerEx( "D",
- "Silver" );
-
- final Ticket t1 = new Ticket( a );
- final Ticket t2 = new Ticket( b );
- final Ticket t3 = new Ticket( c );
- final Ticket t4 = new Ticket( d );
-
- final FactHandle fa = session.insert( a );
- final FactHandle fb = session.insert( b );
- final FactHandle fc = session.insert( c );
- final FactHandle fd = session.insert( d );
-
- final FactHandle ft1 = session.insert( t1 );
- final FactHandle ft2 = session.insert( t2 );
- final FactHandle ft3 = session.insert( t3 );
- final FactHandle ft4 = session.insert( t4 );
-
- session.fireAllRules();
-
-
-
-
- t4.setStatus( "Done" );
- session.update( ft4, t4 );
-
- try {
-
-
- System.err.println( "[[ Sleeping 5 seconds ]]" );
- Thread.sleep( 5000 );
- } catch ( final InterruptedException e ) {
- e.printStackTrace();
- }
-
- System.err.println( "[[ awake ]]" );
-
- session.dispose();
规则
- # 显示增加的门票情况
- rule "New Ticket"
- salience 10
- when
- customer : CustomerEx( )
- ticket : Ticket( customer == customer, status == "New" )
- then
- System.out.println( "New : " + ticket );
- end
-
- # 找到银卡会员,设置电影票状态
- rule "Silver Priority"
- duration 3000
- when
- customer : CustomerEx( subscription == "Silver" )
- ticket : Ticket( customer == customer, status == "New" )
- then
- ticket.setStatus( "Escalate" );
- update( ticket );
- end
-
- # 找到白金卡会员,设置电影票状态
- rule "Platinum Priority"
- when
- customer : CustomerEx( subscription == "Platinum" )
- ticket : Ticket( customer == customer, status == "New" )
- then;
- ticket.setStatus( "Escalate" );
- update( ticket );
- end
-
- # 找到金卡会员,设置电影票状态
- rule "Gold Priority"
- duration 1000
- when
- customer : CustomerEx( subscription == "Gold" )
- ticket : Ticket( customer == customer, status == "New" )
- then
- ticket.setStatus( "Escalate" );
- update( ticket );
- end
-
- # 对于被设置状态为Escalate的电影票发送邮件
- rule "Escalate"
- when
- customer : CustomerEx( )
- ticket : Ticket( customer == customer, status == "Escalate" )
- then
- sendEscalationEmail( customer, ticket );
- end
-
- # 显示状态设置为Done的电影票情况
- rule "Done"
- when
- customer : CustomerEx( )
- ticket : Ticket( customer == customer, status == "Done" )
- then
- System.out.println( "Done : " + ticket );
- end
-
- # 模拟发送邮件的函数
- function void sendEscalationEmail( CustomerEx customer, Ticket ticket ) {
- System.out.println( "Email : " + ticket );
- }
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
返回顶楼 |
|
|
- 江南白衣
- 等级:
资深会员
![江南白衣的博客: 花钱的年华 江南白衣的博客](https://www.iteye.com/upload/logo/user/19081/83725cdb-e7c6-4c6c-bcf4-0f2eb55c231d.jpg?1717536794)
- 文章: 524
- 积分: 2124
- 来自: 广州
![](/images/status/offline.gif)
|
给分,兄弟为drools4推广出力良多。
|
返回顶楼 |
|
|