activiti 工作流 动态 设置 指定 节点任务人、责任人、组 的实现方式
首先給大家看一下我的流程圖:
流程文件leaveBill.bpmn
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="LeaveBill" name="LeaveBillProcess" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="提交申請(qǐng)" activiti:assignee="${inputUser}" activiti:formKey="workflowAction_audit.action"></userTask>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<userTask id="usertask2" name="經(jīng)紀(jì)人審批" activiti:formKey="workflowAction_audit.action">
<extensionElements>
<activiti:taskListener event="create" class="cn.itcast.ssh.utils.MangerTaskHandlerCandidateUsers"></activiti:taskListener>
</extensionElements>
</userTask>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="usertask2"></sequenceFlow>
<userTask id="usertask3" name="老總審批" activiti:assignee="王中軍" activiti:formKey="workflowAction_audit.action"></userTask>
<sequenceFlow id="flow3" sourceRef="usertask2" targetRef="usertask3"></sequenceFlow>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow4" sourceRef="usertask3" targetRef="endevent1"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_LeaveBill">
<bpmndi:BPMNPlane bpmnElement="LeaveBill" id="BPMNPlane_LeaveBill">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="290.0" y="60.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="255.0" y="140.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
<omgdc:Bounds height="55.0" width="105.0" x="255.0" y="230.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
<omgdc:Bounds height="55.0" width="105.0" x="255.0" y="310.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="290.0" y="400.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="307.0" y="95.0"></omgdi:waypoint>
<omgdi:waypoint x="307.0" y="140.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="307.0" y="195.0"></omgdi:waypoint>
<omgdi:waypoint x="307.0" y="230.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="307.0" y="285.0"></omgdi:waypoint>
<omgdi:waypoint x="307.0" y="310.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="307.0" y="365.0"></omgdi:waypoint>
<omgdi:waypoint x="307.0" y="400.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
---------好了進(jìn)入正題,我這個(gè)例子主要是兩個(gè)地方表現(xiàn)了兩種動(dòng)態(tài)指定任務(wù)人的例子;
一個(gè)就是提交申請(qǐng),usertask1節(jié)點(diǎn)的動(dòng)態(tài)設(shè)置辦理人
---<userTask id="usertask1" name="提交申請(qǐng)" activiti:assignee="${inputUser}" activiti:formKey="workflowAction_audit.action"></userTask>
--------?activiti:assignee="${inputUser}" 設(shè)置任務(wù)人,表達(dá)式使用類似于el表達(dá)式的寫法,使用activiti:assignee節(jié)點(diǎn),指定辦理人。這里需要?jiǎng)討B(tài)傳入?yún)?shù)來(lái)指定?
-----------我程序中,在提交申請(qǐng)啟動(dòng)運(yùn)行請(qǐng)假實(shí)例時(shí)的代碼片段
/**更新請(qǐng)假狀態(tài),啟動(dòng)流程實(shí)例,讓啟動(dòng)的流程實(shí)例關(guān)聯(lián)業(yè)務(wù)*/
@Override
public void saveStartProcess(WorkflowBean workflowBean) {
//1:獲取請(qǐng)假單ID,使用請(qǐng)假單ID,查詢請(qǐng)假單的對(duì)象LeaveBill
Long id = workflowBean.getId();
LeaveBill leaveBill = leaveBillDao.findLeaveBillById(id);
//2:更新請(qǐng)假單的請(qǐng)假狀態(tài)從0變成1(初始錄入-->審核中)
leaveBill.setState(1);
//3:使用當(dāng)前對(duì)象獲取到流程定義的key(對(duì)象的名稱就是流程定義的key)
String key = leaveBill.getClass().getSimpleName();
/**
* 4:從Session中獲取當(dāng)前任務(wù)的辦理人,使用流程變量設(shè)置下一個(gè)任務(wù)的辦理人
* inputUser是流程變量的名稱,
* 獲取的辦理人是流程變量的值
*/
Map<String, Object> variables = new HashMap<String,Object>();
variables.put("inputUser", SessionContext.get().getName());//表示惟一用戶,通過(guò)流程變量inputUser,指定當(dāng)前登錄讓人為節(jié)點(diǎn)辦理人
/**
* 5: (1)使用流程變量設(shè)置字符串(格式:LeaveBill.id的形式),通過(guò)設(shè)置,讓啟動(dòng)的流程(流程實(shí)例)關(guān)聯(lián)業(yè)務(wù)
(2)使用正在執(zhí)行對(duì)象表中的一個(gè)字段BUSINESS_KEY(Activiti提供的一個(gè)字段),讓啟動(dòng)的流程(流程實(shí)例)關(guān)聯(lián)業(yè)務(wù)
*/
//格式:LeaveBill.id的形式(使用流程變量)
String objId = key+"."+id;
variables.put("objId", objId);
//6:使用流程定義的key,啟動(dòng)流程實(shí)例,同時(shí)設(shè)置流程變量,同時(shí)向正在執(zhí)行的執(zhí)行對(duì)象表中的字段BUSINESS_KEY添加業(yè)務(wù)
//數(shù)據(jù), 同時(shí)讓流程關(guān)聯(lián)業(yè)務(wù)
runtimeService.startProcessInstanceByKey(key,objId,variables);
}
二、動(dòng)態(tài)指定多人處理節(jié)點(diǎn)任務(wù) 使用了自己實(shí)現(xiàn)監(jiān)聽(tīng)的方式。我想讓在經(jīng)紀(jì)人審核這個(gè)節(jié)點(diǎn)上,不止指定一個(gè)人來(lái)處理,這個(gè)節(jié)點(diǎn)的處理人有可能會(huì)變。
?
?
---bpmn文件節(jié)點(diǎn)明細(xì)
<userTask id="usertask2" name="經(jīng)紀(jì)人審批" activiti:formKey="workflowAction_audit.action">
<extensionElements>
<activiti:taskListener event="create" class="cn.itcast.ssh.utils.MangerTaskHandlerCandidateUsers"></activiti:taskListener>
</extensionElements>
</userTask>
-----下面是我的實(shí)現(xiàn)類
}
------------以上就是動(dòng)態(tài)設(shè)置多用戶任務(wù)人的例子,這里我是手寫的demo,實(shí)際項(xiàng)目中我們可以在notify(DelegateTask delegateTask)中,通過(guò)查詢固定數(shù)據(jù)表或者緩存來(lái),實(shí)現(xiàn)靈活的任務(wù)人設(shè)置。這是我的個(gè)人拙見(jiàn)啊。
再啰嗦一下,如果是設(shè)置用戶組的話,這里應(yīng)該是delegateTask.addCandidateGroup("某組");
設(shè)置流程變量值:delegateTask.setVariable("inputName", "小明");//inputName流程變量名
轉(zhuǎn)載于:https://www.cnblogs.com/bootdo/p/10687791.html
總結(jié)
以上是生活随笔為你收集整理的activiti 工作流 动态 设置 指定 节点任务人、责任人、组 的实现方式的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: React 和 Vue的特点
- 下一篇: 在 Go 语言中,如何正确的使用并发