flowable画图教程_flowable笔记 - 简单的通用流程

本文提供了一个Flowable实现的简单通用审批流程示例,包括流程图的构造,审批节点设置,条件表达式,以及审批方法的定义。讲解了如何使用Java类处理流程中的审批逻辑,如判断审批人是否存在,获取审批人信息,审批状态检查等。
摘要由CSDN通过智能技术生成

...

${auditMethod.existAuditor(execution)}

]]>

<sequenceFlow id="auditorNotExistFlow" sourceRef="auditorExist" targetRef="agreeDelegate" />

<!-- 第三步:审批人审批 -->

<userTask id="approveTask" name="等待审批"

flowable:candidateGroups="${auditMethod.getCandidateGroups(execution)}"

flowable:candidateUsers="${auditMethod.getCandidateUsers(execution)}"/>

<sequenceFlow sourceRef="approveTask" targetRef="decision"/>

<!-- 唯一网关:一个审批一个审批人 -->

<exclusiveGateway id="decision" default="rejectFlow"/>

<sequenceFlow sourceRef="decision" targetRef="assignToAuditor">

<conditionExpression xsi:type="tFormalExpression">

<![CDATA[

${auditMethod.isApproved(execution)}

]]>

</conditionExpression>

</sequenceFlow>

<sequenceFlow id="rejectFlow" sourceRef="decision" targetRef="rejectDelegate" />

<!-- 第四步:同意后存储数据,发送通知 -->

<serviceTask id="agreeDelegate" name="数据存储"

flowable:class="me.xwbz.flowable.delegate.StandardRequestAgreeDelegate"/>

<sequenceFlow sourceRef="agreeDelegate" targetRef="approveEnd"/>

<serviceTask id="rejectDelegate" name="回复拒绝消息"

flowable:class="me.xwbz.flowable.delegate.BaseRejectDelegate"/>

<sequenceFlow sourceRef="rejectDelegate" targetRef="rejectEnd"/>

<!-- 第五步:结束 -->

<endEvent id="approveEnd" name="已同意"/>

<endEvent id="rejectEnd" name="已驳回"/>

</process>

...

常量部分

这次没有另外存储数据,所以变量都是直接存储到flowable自带的变量表里

强烈建议大家另外存储,自带的查询起来非常麻烦!

审批人列表:AUDITOR_LIST_KEY = "AUDITOR_LIST";

当前审批人:AUDITOR_KEY = "AUDITOR";

当前审批人下标:AUDITOR_IDX_KEY = "AUDITOR_IDX";

是否已审批:APPROVED_KEY = "AUDIT_APPROVED";

申请类型:AUDIT_TYPE_KEY = "AUDIT_TYPE";

申请状态:AUDIT_STATUS_KEY = "AUDIT_STATUS";

其他参数:AUDIT_PARAMS_KEY = "AUDIT_PARAMS";

申请状态

public enum AuditStatus {

/** 待审批 */

WAIT_AUDIT,

/** 已同意申请 */

AGREE_AUDIT,

/** 已拒绝申请 */

REJECT_AUDIT,

/** 已取消 */

CANCEL

}

申请人类型

public enum CandidateType{

/** 候选人 */

USER,

/** 候选组 */

GROUP

}

审批使用的方法定义

一个普通的Java类

package me.xwbz.flowable.method;

import com.alibaba.fastjson.JSONObject;

import org.flowable.engine.delegate.DelegateExecution;

/**审批相关的方法

用于flowable流程使用

*/

public class AuditMethod{

/**

是否存在审批者

<conditionExpression xsi:type="tFormalExpression">

<![CDATA[

${auditMethod.existAuditor(execution)}

]]>

*/

public boolean existAuditor(DelegateExecution execution){

return execution.hasVariable(AUDITOR_KEY);

}

/**

获取当前审批者

/

public JSONObject getCurrentAuditor(DelegateExecution execution){

return JSONObject.parseObject((String)execution.getVariable(AUDITOR_KEY));

}

/*

获取当前候选组

*/

public String getCandidateGroups(DelegateExecution execution){

JSONObject candidate = getCurrentAuditor(execution);

if(candidate.getIntValue("type") == CandidateType.GROUP.ordinal()) {

return candidate.getString("id");

}

return null;

}

public String getCandidateUsers(DelegateExecution execution){

JSONObject candidate = getCurrentAuditor(execution);

if(candidate.getIntValue("type") == CandidateType.USER.ordinal()) {

return candidate.getString("id");

}

return null;

}

/**

获取当前审批者id

*/

public String getCurrentAuditorId(DelegateExecution execution){

JSONObject auditor = getCurrentAuditor(execution);

return JSONObject.toJavaObject(auditor, User.class).getId();

}

/**是否同意申请

*/

public boolean isApproved(DelegateExecution execution){

Boolean approved = execution.getVariable(APPROVED_KEY, Boolean.class);

return approved != null && approved;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值