35 changed files with 288 additions and 34 deletions
@ -0,0 +1,39 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved. |
||||||
|
* |
||||||
|
* Redistribution and use in source and binary forms, with or without |
||||||
|
* modification, are permitted provided that the following conditions are met: |
||||||
|
* |
||||||
|
* Redistributions of source code must retain the above copyright notice, |
||||||
|
* this list of conditions and the following disclaimer. |
||||||
|
* Redistributions in binary form must reproduce the above copyright |
||||||
|
* notice, this list of conditions and the following disclaimer in the |
||||||
|
* documentation and/or other materials provided with the distribution. |
||||||
|
* Neither the name of the dreamlu.net developer nor the names of its |
||||||
|
* contributors may be used to endorse or promote products derived from |
||||||
|
* this software without specific prior written permission. |
||||||
|
* Author: Chill 庄骞 (smallchill@163.com) |
||||||
|
*/ |
||||||
|
package com.example.demo.rule; |
||||||
|
|
||||||
|
import com.yomahub.liteflow.annotation.LiteflowComponent; |
||||||
|
import com.yomahub.liteflow.core.NodeComponent; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* A业务 |
||||||
|
* |
||||||
|
* @author Chill |
||||||
|
*/ |
||||||
|
@Slf4j |
||||||
|
@LiteflowComponent(id = "abizRule", name = "A业务") |
||||||
|
public class AbizRule extends NodeComponent { |
||||||
|
@Override |
||||||
|
public void process() throws Exception { |
||||||
|
|
||||||
|
log.info("A业务执行完毕"); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,48 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved. |
||||||
|
* |
||||||
|
* Redistribution and use in source and binary forms, with or without |
||||||
|
* modification, are permitted provided that the following conditions are met: |
||||||
|
* |
||||||
|
* Redistributions of source code must retain the above copyright notice, |
||||||
|
* this list of conditions and the following disclaimer. |
||||||
|
* Redistributions in binary form must reproduce the above copyright |
||||||
|
* notice, this list of conditions and the following disclaimer in the |
||||||
|
* documentation and/or other materials provided with the distribution. |
||||||
|
* Neither the name of the dreamlu.net developer nor the names of its |
||||||
|
* contributors may be used to endorse or promote products derived from |
||||||
|
* this software without specific prior written permission. |
||||||
|
* Author: Chill 庄骞 (smallchill@163.com) |
||||||
|
*/ |
||||||
|
package com.example.demo.rule; |
||||||
|
|
||||||
|
import com.example.demo.rule.context.BizContext; |
||||||
|
import com.yomahub.liteflow.annotation.LiteflowComponent; |
||||||
|
import com.yomahub.liteflow.core.NodeSwitchComponent; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* A业务 |
||||||
|
* |
||||||
|
* @author Chill |
||||||
|
*/ |
||||||
|
@Slf4j |
||||||
|
@LiteflowComponent(id = "bbizRule", name = "B业务") |
||||||
|
public class BbizRule extends NodeSwitchComponent { |
||||||
|
|
||||||
|
@Override |
||||||
|
public String processSwitch() throws Exception { |
||||||
|
// 获取上下文
|
||||||
|
BizContext contextBean = this.getContextBean(BizContext.class); |
||||||
|
// 获取条件
|
||||||
|
Boolean isPublish = contextBean.getIsPublish(); |
||||||
|
log.info("B业务执行判断"); |
||||||
|
// 进行节点判断
|
||||||
|
if (isPublish) { |
||||||
|
return "cbizRule"; |
||||||
|
} else { |
||||||
|
return "dbizRule"; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,44 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved. |
||||||
|
* |
||||||
|
* Redistribution and use in source and binary forms, with or without |
||||||
|
* modification, are permitted provided that the following conditions are met: |
||||||
|
* |
||||||
|
* Redistributions of source code must retain the above copyright notice, |
||||||
|
* this list of conditions and the following disclaimer. |
||||||
|
* Redistributions in binary form must reproduce the above copyright |
||||||
|
* notice, this list of conditions and the following disclaimer in the |
||||||
|
* documentation and/or other materials provided with the distribution. |
||||||
|
* Neither the name of the dreamlu.net developer nor the names of its |
||||||
|
* contributors may be used to endorse or promote products derived from |
||||||
|
* this software without specific prior written permission. |
||||||
|
* Author: Chill 庄骞 (smallchill@163.com) |
||||||
|
*/ |
||||||
|
package com.example.demo.rule; |
||||||
|
|
||||||
|
import com.example.demo.rule.context.BizContext; |
||||||
|
import com.yomahub.liteflow.annotation.LiteflowComponent; |
||||||
|
import com.yomahub.liteflow.core.NodeComponent; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* A业务 |
||||||
|
* |
||||||
|
* @author Chill |
||||||
|
*/ |
||||||
|
@Slf4j |
||||||
|
@LiteflowComponent(id = "cbizRule", name = "C业务") |
||||||
|
public class CbizRule extends NodeComponent { |
||||||
|
@Override |
||||||
|
public void process() throws Exception { |
||||||
|
// 获取上下文
|
||||||
|
BizContext contextBean = this.getContextBean(BizContext.class); |
||||||
|
// 修改上下文
|
||||||
|
contextBean.setName(contextBean.getName() + "-> C"); |
||||||
|
|
||||||
|
log.info("C业务执行完毕"); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,45 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved. |
||||||
|
* |
||||||
|
* Redistribution and use in source and binary forms, with or without |
||||||
|
* modification, are permitted provided that the following conditions are met: |
||||||
|
* |
||||||
|
* Redistributions of source code must retain the above copyright notice, |
||||||
|
* this list of conditions and the following disclaimer. |
||||||
|
* Redistributions in binary form must reproduce the above copyright |
||||||
|
* notice, this list of conditions and the following disclaimer in the |
||||||
|
* documentation and/or other materials provided with the distribution. |
||||||
|
* Neither the name of the dreamlu.net developer nor the names of its |
||||||
|
* contributors may be used to endorse or promote products derived from |
||||||
|
* this software without specific prior written permission. |
||||||
|
* Author: Chill 庄骞 (smallchill@163.com) |
||||||
|
*/ |
||||||
|
package com.example.demo.rule; |
||||||
|
|
||||||
|
import com.example.demo.rule.context.BizContext; |
||||||
|
import com.yomahub.liteflow.annotation.LiteflowComponent; |
||||||
|
import com.yomahub.liteflow.core.NodeComponent; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* A业务 |
||||||
|
* |
||||||
|
* @author Chill |
||||||
|
*/ |
||||||
|
@Slf4j |
||||||
|
@LiteflowComponent(id = "dbizRule", name = "D业务") |
||||||
|
public class DbizRule extends NodeComponent { |
||||||
|
@Override |
||||||
|
public void process() throws Exception { |
||||||
|
// 获取上下文
|
||||||
|
BizContext contextBean = this.getContextBean(BizContext.class); |
||||||
|
// 修改上下文
|
||||||
|
contextBean.setName(contextBean.getName() + "-> D"); |
||||||
|
|
||||||
|
log.info("D业务执行完毕"); |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
package com.example.demo.rule.context; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
/** |
||||||
|
* 上下文类 |
||||||
|
* |
||||||
|
* @author Chill |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class BizContext { |
||||||
|
|
||||||
|
private Long id; |
||||||
|
|
||||||
|
private String name; |
||||||
|
|
||||||
|
private Integer category; |
||||||
|
|
||||||
|
private Boolean isPublish; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,9 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<flow> |
||||||
|
<chain name="demoChain"> |
||||||
|
THEN( |
||||||
|
abizRule, |
||||||
|
SWITCH(bbizRule).TO(cbizRule, dbizRule) |
||||||
|
); |
||||||
|
</chain> |
||||||
|
</flow> |
@ -0,0 +1,44 @@ |
|||||||
|
import com.example.demo.DemoApplication; |
||||||
|
import com.example.demo.rule.context.BizContext; |
||||||
|
import com.yomahub.liteflow.core.FlowExecutor; |
||||||
|
import com.yomahub.liteflow.flow.LiteflowResponse; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
import org.junit.jupiter.api.extension.ExtendWith; |
||||||
|
import org.springblade.core.test.BladeBootTest; |
||||||
|
import org.springblade.core.test.BladeSpringExtension; |
||||||
|
import org.springblade.core.tool.jackson.JsonUtil; |
||||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
|
||||||
|
/** |
||||||
|
* LiteFlow单元测试 |
||||||
|
* |
||||||
|
* @author Chill |
||||||
|
*/ |
||||||
|
@Slf4j |
||||||
|
@ExtendWith(BladeSpringExtension.class) |
||||||
|
@SpringBootTest(classes = DemoApplication.class) |
||||||
|
@BladeBootTest(appName = "blade-demo", profile = "test", enableLoader = true) |
||||||
|
public class LiteFlowTest { |
||||||
|
@Resource |
||||||
|
private FlowExecutor flowExecutor; |
||||||
|
|
||||||
|
@Test |
||||||
|
public void contextLoads() { |
||||||
|
// 构建上下文
|
||||||
|
BizContext bizContext = new BizContext(); |
||||||
|
bizContext.setId(1L); |
||||||
|
bizContext.setName("测试名称"); |
||||||
|
bizContext.setCategory(1); |
||||||
|
bizContext.setIsPublish(Boolean.TRUE); |
||||||
|
// 启动 demoChain 的规则引擎
|
||||||
|
LiteflowResponse resp = flowExecutor.execute2Resp("demoChain", null, bizContext); |
||||||
|
if (resp.isSuccess()) { |
||||||
|
BizContext contextBean = resp.getContextBean(BizContext.class); |
||||||
|
log.info(JsonUtil.toJson(contextBean)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue