简单做图网站,佛山哪家公司建设网站,wordpress0day,台州英文网站建设文章目录 一、任务监听器事件类型配置方式(选)代码实现xml文件创建监听器class方式expression方式delegateExpression 测试流程部署流程启动流程完成任务 一、任务监听器 任务监听器可以在任务创建、任务分配、任务完成、任务删除发生时触发#xff0c;从而执行相应的逻辑。 事… 文章目录 一、任务监听器事件类型配置方式(选)代码实现xml文件创建监听器class方式expression方式delegateExpression 测试流程部署流程启动流程完成任务 一、任务监听器 任务监听器可以在任务创建、任务分配、任务完成、任务删除发生时触发从而执行相应的逻辑。 事件类型
create创建事件assignment指派事件complete完成事件delete删除事件
配置方式(选)
class直接配置class全名expressionspring bean容器对应名字与方法名delegateExpressionspring bean容器对应名字
代码实现 xml文件
?xml version1.0 encodingUTF-8?
definitions xmlnshttp://www.omg.org/spec/BPMN/20100524/MODEL xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlns:xsdhttp://www.w3.org/2001/XMLSchema xmlns:activitihttp://activiti.org/bpmn xmlns:bpmndihttp://www.omg.org/spec/BPMN/20100524/DI xmlns:omgdchttp://www.omg.org/spec/DD/20100524/DC xmlns:omgdihttp://www.omg.org/spec/DD/20100524/DI typeLanguagehttp://www.w3.org/2001/XMLSchema expressionLanguagehttp://www.w3.org/1999/XPath targetNamespacehttp://www.activiti.org/processdefprocess idtask-listener name任务监听器 isExecutabletruedocumentation测试任务监听器/documentationstartEvent idsid-30244641-2a1c-43e5-af5b-e77db43488bf name开始documentation开始了/documentation/startEventuserTask idsid-9e62413f-e04f-4c81-8d0c-e73f17e125ec name节点1 activiti:assignee${applyUserId} activiti:candidateUsers${candidateUsers}documentation任务节点1/documentationextensionElementsactiviti:taskListener eventcreate classcom.lmw.test.activiti.listener.task.MyTaskListener1/activiti:taskListener eventassignment expression${myTaskListener2.notify(task)}/activiti:taskListener eventcomplete delegateExpression${myTaskListener3}//extensionElements/userTasksequenceFlow idsid-1af5e647-b03c-4b12-807d-4171dfdf7ae9 sourceRefsid-30244641-2a1c-43e5-af5b-e77db43488bf targetRefsid-9e62413f-e04f-4c81-8d0c-e73f17e125ec name顺序流1documentation顺序流1了/documentation/sequenceFlowuserTask idsid-d903cb09-56c2-4cfe-bd05-5ba0699539d0 name节点2documentation任务节点2/documentation/userTasksequenceFlow idsid-300ac02e-dc56-4988-bdd4-fd94a5bb71f7 sourceRefsid-9e62413f-e04f-4c81-8d0c-e73f17e125ec targetRefsid-d903cb09-56c2-4cfe-bd05-5ba0699539d0 name顺序流2documentation顺序流2了/documentation/sequenceFlowendEvent idsid-ace3a923-023c-4226-875c-2a0a30cc1c50 name结束documentation结束了/documentation/endEventsequenceFlow idsid-dbf73610-a8b4-4149-828e-4f5bc252c80d sourceRefsid-d903cb09-56c2-4cfe-bd05-5ba0699539d0 targetRefsid-ace3a923-023c-4226-875c-2a0a30cc1c50 name顺序流3documentation顺序流3了/documentation/sequenceFlow/processbpmndi:BPMNDiagram idBPMNDiagram_execution-listenerbpmndi:BPMNPlane bpmnElementtask-listener idBPMNPlane_execution-listenerbpmndi:BPMNShape idshape-d4dd6424-1316-4c10-a8f9-f3c501cd4073 bpmnElementsid-30244641-2a1c-43e5-af5b-e77db43488bfomgdc:Bounds x-442.5 y-6.75 width30.0 height30.0//bpmndi:BPMNShapebpmndi:BPMNShape idshape-bcd8743b-6857-42d1-bc71-bd3bb6eed795 bpmnElementsid-9e62413f-e04f-4c81-8d0c-e73f17e125ecomgdc:Bounds x-388.0 y-31.75 width100.0 height80.0//bpmndi:BPMNShapebpmndi:BPMNEdge idedge-d562b253-050f-4617-bbad-2e16950c15e4 bpmnElementsid-1af5e647-b03c-4b12-807d-4171dfdf7ae9omgdi:waypoint x-412.5 y8.25/omgdi:waypoint x-388.0 y8.25//bpmndi:BPMNEdgebpmndi:BPMNShape idshape-cd7c00d6-f5f0-4afe-867c-6f576efc286d bpmnElementsid-d903cb09-56c2-4cfe-bd05-5ba0699539d0omgdc:Bounds x-259.0 y-31.75 width100.0 height80.0//bpmndi:BPMNShapebpmndi:BPMNEdge idedge-44a5c4d2-2ab7-48f1-adc7-c7a7a099800c bpmnElementsid-300ac02e-dc56-4988-bdd4-fd94a5bb71f7omgdi:waypoint x-288.0 y8.25/omgdi:waypoint x-259.0 y8.25//bpmndi:BPMNEdgebpmndi:BPMNShape idshape-05cc9b19-8019-471d-b31c-bb41c42e3529 bpmnElementsid-ace3a923-023c-4226-875c-2a0a30cc1c50omgdc:Bounds x-123.0 y-6.75 width30.0 height30.0//bpmndi:BPMNShapebpmndi:BPMNEdge idedge-923723d0-33e3-4a62-bed9-bb16d4c9b175 bpmnElementsid-dbf73610-a8b4-4149-828e-4f5bc252c80domgdi:waypoint x-159.0 y8.25/omgdi:waypoint x-123.0 y8.25//bpmndi:BPMNEdge/bpmndi:BPMNPlane/bpmndi:BPMNDiagram
/definitions创建监听器
class方式
public class MyTaskListener1 implements TaskListener {Overridepublic void notify(DelegateTask delegateTask) {System.out.println(MyTaskListener1);System.out.println(delegateTask.getProcessInstanceId() delegateTask.getProcessInstanceId());System.out.println(delegateTask.getTaskDefinitionKey() delegateTask.getTaskDefinitionKey());System.out.println(delegateTask.getEventName() delegateTask.getEventName());System.out.println(delegateTask.getName() delegateTask.getName());System.out.println(delegateTask.getAssignee() delegateTask.getAssignee());System.out.println(delegateTask.getVariables() delegateTask.getVariables());}
}expression方式
Component
public class MyTaskListener2 {public void notify(DelegateTask delegateTask) {System.out.println(MyTaskListener1);System.out.println(delegateTask.getProcessInstanceId() delegateTask.getProcessInstanceId());System.out.println(delegateTask.getTaskDefinitionKey() delegateTask.getTaskDefinitionKey());System.out.println(delegateTask.getEventName() delegateTask.getEventName());System.out.println(delegateTask.getName() delegateTask.getName());System.out.println(delegateTask.getAssignee() delegateTask.getAssignee());System.out.println(delegateTask.getVariables() delegateTask.getVariables());}
}delegateExpression
Component
public class MyTaskListener3 implements TaskListener {Overridepublic void notify(DelegateTask delegateTask) {System.out.println(MyTaskListener1);System.out.println(delegateTask.getProcessInstanceId() delegateTask.getProcessInstanceId());System.out.println(delegateTask.getTaskDefinitionKey() delegateTask.getTaskDefinitionKey());System.out.println(delegateTask.getEventName() delegateTask.getEventName());System.out.println(delegateTask.getName() delegateTask.getName());System.out.println(delegateTask.getAssignee() delegateTask.getAssignee());System.out.println(delegateTask.getVariables() delegateTask.getVariables());}
}测试流程
RunWith(SpringRunner.class)
SpringBootTest(webEnvironment SpringBootTest.WebEnvironment.RANDOM_PORT)
public class TestActivityTaskListener {Autowiredprivate RepositoryService repositoryService;Autowiredprivate RuntimeService runtimeService;Autowiredprivate TaskService taskService;private static final String PROCESS_INSTANCE_ID 5b10eb17-3b4d-11ee-982e-18c04dcd4aee;Testpublic void deployProcess() {Deployment deploy repositoryService.createDeployment().addClasspathResource(processes/task-listener.bpmn20.xml).deploy();System.out.println(deploy deploy);}Testpublic void startProcess() {MapString, Object variables new HashMap();variables.put(applyUserId, user123456);variables.put(candidateUsers, CollectionUtil.newArrayList(zhangsan, lisi, wangwu));String processDefinitionKey task-listener;String businessKey processDefinitionKey : 100001;ProcessInstance processInstance runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey, variables);System.out.println(processInstance processInstance);// 输出当前任务列表this.printTaskList(processInstance.getId());}Testpublic void completeTask() {// 查询任务Task task taskService.createTaskQuery().processInstanceId(PROCESS_INSTANCE_ID).singleResult();taskService.complete(task.getId());}private void printTaskList(String processInstanceId) {// 输出当前任务列表taskService.createTaskQuery().processInstanceId(processInstanceId).orderByTaskCreateTime().asc().list().forEach(k - {System.out.println(任务列表);System.out.println(任务ID k.getId());System.out.println(任务名称 k.getName());System.out.println(任务负责人 k.getAssignee());System.out.println(任务创建时间 k.getCreateTime());System.out.println(身份列表);// 输出用户身份关系列表taskService.getIdentityLinksForTask(k.getId()).forEach(link - {System.out.println(link.getType() link.getType());System.out.println(link.getUserId() link.getUserId());System.out.println(link.getGroupId() link.getGroupId());System.out.println(link.getTaskId() link.getTaskId());});});}}部署流程
运行 deployProcess
启动流程
运行 startProcess可以看到首先监听到任务节点1分配的事件然后再是创建任务事件因为有多个监听器顺序不一致。
完成任务
运行 completeTask首先完成的是节点1任务可以看到监听器监听到任务完成的事件。 文章转载自: http://www.morning.frfnb.cn.gov.cn.frfnb.cn http://www.morning.xkpjl.cn.gov.cn.xkpjl.cn http://www.morning.pynzj.cn.gov.cn.pynzj.cn http://www.morning.xmpbh.cn.gov.cn.xmpbh.cn http://www.morning.qwmpn.cn.gov.cn.qwmpn.cn http://www.morning.zmpsl.cn.gov.cn.zmpsl.cn http://www.morning.pxbrg.cn.gov.cn.pxbrg.cn http://www.morning.rgxf.cn.gov.cn.rgxf.cn http://www.morning.kjcll.cn.gov.cn.kjcll.cn http://www.morning.gxfzrb.com.gov.cn.gxfzrb.com http://www.morning.zbqsg.cn.gov.cn.zbqsg.cn http://www.morning.kwrzg.cn.gov.cn.kwrzg.cn http://www.morning.fgtls.cn.gov.cn.fgtls.cn http://www.morning.mjctt.cn.gov.cn.mjctt.cn http://www.morning.zfcfx.cn.gov.cn.zfcfx.cn http://www.morning.wkws.cn.gov.cn.wkws.cn http://www.morning.srgsb.cn.gov.cn.srgsb.cn http://www.morning.jgykx.cn.gov.cn.jgykx.cn http://www.morning.lpyjq.cn.gov.cn.lpyjq.cn http://www.morning.qxkjy.cn.gov.cn.qxkjy.cn http://www.morning.wgqtt.cn.gov.cn.wgqtt.cn http://www.morning.tkyxl.cn.gov.cn.tkyxl.cn http://www.morning.rwcw.cn.gov.cn.rwcw.cn http://www.morning.tqlhn.cn.gov.cn.tqlhn.cn http://www.morning.wdlyt.cn.gov.cn.wdlyt.cn http://www.morning.bhpjc.cn.gov.cn.bhpjc.cn http://www.morning.krswn.cn.gov.cn.krswn.cn http://www.morning.dytqf.cn.gov.cn.dytqf.cn http://www.morning.ktnt.cn.gov.cn.ktnt.cn http://www.morning.krxzl.cn.gov.cn.krxzl.cn http://www.morning.lrmts.cn.gov.cn.lrmts.cn http://www.morning.qtzwh.cn.gov.cn.qtzwh.cn http://www.morning.gwjsm.cn.gov.cn.gwjsm.cn http://www.morning.qhln.cn.gov.cn.qhln.cn http://www.morning.bktzr.cn.gov.cn.bktzr.cn http://www.morning.yrskc.cn.gov.cn.yrskc.cn http://www.morning.rbffj.cn.gov.cn.rbffj.cn http://www.morning.bzgpj.cn.gov.cn.bzgpj.cn http://www.morning.rjnx.cn.gov.cn.rjnx.cn http://www.morning.mnqz.cn.gov.cn.mnqz.cn http://www.morning.hfnbr.cn.gov.cn.hfnbr.cn http://www.morning.mbaiwan.com.gov.cn.mbaiwan.com http://www.morning.wtcd.cn.gov.cn.wtcd.cn http://www.morning.fhkr.cn.gov.cn.fhkr.cn http://www.morning.cwkcq.cn.gov.cn.cwkcq.cn http://www.morning.wpmqq.cn.gov.cn.wpmqq.cn http://www.morning.rwls.cn.gov.cn.rwls.cn http://www.morning.ljwyc.cn.gov.cn.ljwyc.cn http://www.morning.lfqnk.cn.gov.cn.lfqnk.cn http://www.morning.ptwrz.cn.gov.cn.ptwrz.cn http://www.morning.yfqhc.cn.gov.cn.yfqhc.cn http://www.morning.rnrfs.cn.gov.cn.rnrfs.cn http://www.morning.rlhh.cn.gov.cn.rlhh.cn http://www.morning.kqzt.cn.gov.cn.kqzt.cn http://www.morning.shyqcgw.cn.gov.cn.shyqcgw.cn http://www.morning.gfmpk.cn.gov.cn.gfmpk.cn http://www.morning.ntqgz.cn.gov.cn.ntqgz.cn http://www.morning.mkzdp.cn.gov.cn.mkzdp.cn http://www.morning.lfxcj.cn.gov.cn.lfxcj.cn http://www.morning.hdpcn.cn.gov.cn.hdpcn.cn http://www.morning.qzpw.cn.gov.cn.qzpw.cn http://www.morning.mfsjn.cn.gov.cn.mfsjn.cn http://www.morning.pkggl.cn.gov.cn.pkggl.cn http://www.morning.cxsdl.cn.gov.cn.cxsdl.cn http://www.morning.rmpfh.cn.gov.cn.rmpfh.cn http://www.morning.fgxws.cn.gov.cn.fgxws.cn http://www.morning.pyxtn.cn.gov.cn.pyxtn.cn http://www.morning.mbaiwan.com.gov.cn.mbaiwan.com http://www.morning.rnht.cn.gov.cn.rnht.cn http://www.morning.rxsgk.cn.gov.cn.rxsgk.cn http://www.morning.tkyxl.cn.gov.cn.tkyxl.cn http://www.morning.xqzrg.cn.gov.cn.xqzrg.cn http://www.morning.pzcjq.cn.gov.cn.pzcjq.cn http://www.morning.nbqwt.cn.gov.cn.nbqwt.cn http://www.morning.qqklk.cn.gov.cn.qqklk.cn http://www.morning.rknjx.cn.gov.cn.rknjx.cn http://www.morning.bpmnh.cn.gov.cn.bpmnh.cn http://www.morning.lfdzr.cn.gov.cn.lfdzr.cn http://www.morning.lhjmq.cn.gov.cn.lhjmq.cn http://www.morning.kryxk.cn.gov.cn.kryxk.cn