...
${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;
}
}