场景3:行政审批
1、链配置示例
- 请假审批
# demo.chain.yml
id: "d1"
title: "请假审批"
nodes:
- { id: "s", type: "start", title: "发起人", meta: {role: "employee", form: "form-1"}, link: "n1"}
- { id: "n1", type: "execute", title: "主管批", meta: {role: "tl"}, link: "g1"}
- { id: "g1", type: "exclusive", link:[
{nextId: "e"},
{nextId: "n2", title: "3天以上", condition: "day>=3"}]}
- { id: "n2", type: "execute", title: "部门经理批", meta: {role: "dm"}, link: "g2"}
- { id: "g2", type: "exclusive", link:[
{nextId: "e"},
{nextId: "n3", title: "7天以上", condition: "day>=7"}]}
- { id: "n3", type: "execute", title: "副总批", meta: {role: "vp"}, link: "g2"}
- { id: "e", type: "end"}
# tl: team leader; dm: department manager; vp: vice-president
描述:员工发起请假;团队主管审批;如果超过3天的,部分经理再批;如果超过7天的,副总再批。
- 合同审批(条件会签)
# demo.chain.yml
id: "d1"
title: "合同审批(条件会签)"
nodes:
- { id: "s", type: "start", title: "发起人", meta: {role: "biz"}, link: "n1"}
- { id: "n1", type: "execute", title: "主管批", meta: {role: "tl"}, link: "g1"}
- { id: "g1-s", type: "inclusive", title: "会签" , link:[
{nextId: "n2", title: "10万以上", condition: "amount>=100000"}
{nextId: "n3", title: "50万以上", condition: "amount>=500000"}
{nextId: "n4", title: "90万以上", condition: "amount>=900000"}]}
- { id: "n2", type: "execute", title: "本部门经理批", meta: {role: "dm"}, link: "g1-e"}
- { id: "n3", type: "execute", title: "生产部经理批", meta: {role: "dm"}, link: "g1-e"}
- { id: "n4", type: "execute", title: "财务部经理批", meta: {role: "dm"}, link: "g1-e"}
- { id: "g1-e", type: "inclusive", link: "e"}
- { id: "e", type: "end"}
# tl: team leader; dm: department manager; vp: vice-president
描述:商务人员发起合同审批;超过10万的本部分经理要会签通过;超过50万要求生产部门会签通过;超过90万要求财务会签通过。
- 合同审批(无条件会签)
# demo.chain.yml
id: "d1"
title: "合同审批(无条件会签)"
nodes:
- { id: "s", type: "start", title: "发起人", meta: {role: "biz"}, link: "n1"}
- { id: "n1", type: "execute", title: "主管批", meta: {role: "tl"}, link: "g1"}
- { id: "g1-s", type: "parallel", title: "会签" , link:[
{nextId: "n2"}
{nextId: "n3"}
{nextId: "n4"}]}
- { id: "n2", type: "execute", title: "本部门经理批", meta: {role: "dm"}, link: "g1-e"}
- { id: "n3", type: "execute", title: "生产部经理批", meta: {role: "dm"}, link: "g1-e"}
- { id: "n4", type: "execute", title: "财务部经理批", meta: {role: "dm"}, link: "g1-e"}
- { id: "g1-e", type: "parallel", meta: {cc: "vp"}, link: "e"}
- { id: "e", type: "end", task: "."}
# tl: team leader; dm: department manager; vp: vice-president; cc: Carbon Copy
描述:商务人员发起合同审批,本部门经理、生产部经理、财务部经理,都要会签通过。
- 决议投票
# demo.chain.yml
id: "d1"
title: "决议投票"
nodes:
- { id: "s", type: "start", title: "发起人", meta: {role: "biz"}, link: "n1"}
- { id: "n1", type: "execute", title: "主管复核", meta: {role: "tl"}, link: "g1"}
- { id: "g1-s", type: "parallel", title: "投票", meta: {timeout: "7d", default: "false"}, link:[
{nextId: "n2"}
{nextId: "n3"}
{nextId: "n4"}]}
- { id: "n2", type: "execute", title: "本部门经投票", meta: {role: "dm"}, link: "g1-e"}
- { id: "n3", type: "execute", title: "生产部经投票", meta: {role: "dm"}, link: "g1-e"}
- { id: "n4", type: "execute", title: "财务部经投票", meta: {role: "dm"}, link: "g1-e"}
- { id: "g1-e", type: "parallel", link: "n5"}
- { id: "n5", type: "execute", title: "结果通知", meta: {cc: "vp"}, link: "e"}
- { id: "e", type: "end"}
# tl: team leader; dm: department manager; vp: vice-president; cc: Carbon Copy
描述:商务人员发起项目方案投票;主管复核资料正确性;然后开始投票(如果7天内没票,算“否”);投票结束后,通知各方。
2、驱动定制参考
- 定制驱动(是否替代掉默认的?按需选择)
@Component
public class ApproveChainDriver extends SimpleChainDriver implements ChainDriver {
@Override
public void handleTask(ChainContext context, Task task) throws Throwable {
if (isChain(task.description())) {
//如果跨链调用
tryAsChainTask(context, task, task.description());
return;
}
String instance_id = context.get("instance_id");
String user_id = context.get("user_id");
String role_id = context.get("role_id");
String chain_id = task.node().chain().id();
String task_id = task.node().id();
//把状态批量加载到上下文参考(或者通过数据库查找状态)
TaskState taskState = null;//查询任务装态
if (taskState == null) {
//中断(流,不会再往下驱动),等用户操作出状态
context.interrupt();
//查询数据库,是否有提醒记录。如果没有,发布通知
//...
//如果当前用户匹配这个节点任务
if(role_id.equals(task.node().meta().get("role_id"))){
//则把这个节点,作为结果(用于展示界面)
context.result = task.node();
}
}
}
}
- 定制驱动应用
public class ApproveChainDriverDemo {
@Inject
private FlowEngine flowEngine;
public void demo() throws Throwable {
//可以在链配置时指定,也可以在运行时指定
ChainContext context = new ChainContext();
context.put("instance_id", "i1");
context.put("user_id", "u1");
context.put("role_id", "r1");
flowEngine.eval("c12", context);
//运行后,获取当前展示的节点
Node node = (Node) context.result;
//根据转点,展示界面
}
}