jsp网站建设毕业设计,p2p理财网站开发要求,贵安新区微信网站建设,成都网站推广找四川冠辰前言
在前面我们介绍了Springboot简单使用了foleable以及flowableUI的安装和使用#xff0c;在之前我们分配任务的处理人的时候都是通过Assignee去指定固定的人的。这在实际业务中是不合适的#xff0c;我们希望在流程中动态的去解析每个节点的处理人#xff0c;当前flowab…前言
在前面我们介绍了Springboot简单使用了foleable以及flowableUI的安装和使用在之前我们分配任务的处理人的时候都是通过Assignee去指定固定的人的。这在实际业务中是不合适的我们希望在流程中动态的去解析每个节点的处理人当前flowable也支持这样去做。
一、 UEL表达式
Flowable使用UEL进行表达式解析。UEL代表Unified Expression Language是EE6规范的一部分.Flowable支持两种UEL表达式 UEL-value 和UEL-method
UEL-value值表达式 Value expression: 解析为一个值。默认情况下所有流程变量都可以使用。
${userCode}
${isEndWorkFlag true isSnedEmailFlag true}
# 这里userCode可以是任意值员工号编码isEndWorkFlag和isSnedEmailFlag可以是boolean类型的值UEL-method将method方法注入到activiti的processEngineConfiguration的bean中。
${userService.findManagerUserCodeByEmpCode(empCode)}# 这里userService就是我们spring当中的bean,这里先说明一下值表达式后续整合spring的时候在补充这块。我们知道了UEL表达式之后我们简单测试一下使用
二、使用FlowableUI绘制流程 绘制一个简单的流程在分配人那里使用UEL表达式去指定节点处理人绘制完成之后点击下载将流程下载下来放置项目的resources下这里有想尝试的可以直接使用如下MyHoliday.bpmn20.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:flowablehttp://flowable.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.flowable.org/processdef exporterFlowable Open Source Modeler exporterVersion6.7.2process idMyHoliday nameMyHoliday isExecutabletruestartEvent idstartEvent1 name开始 flowable:formFieldValidationtrue/startEventuserTask idsid-320C4AED-D9F4-4C53-B2B6-D4ACCBA155F5 name直线审批 flowable:assignee${firstAssigne} flowable:formFieldValidationtrueextensionElementsmodeler:initiator-can-complete xmlns:modelerhttp://flowable.org/modeler![CDATA[false]]/modeler:initiator-can-complete/extensionElements/userTasksequenceFlow idsid-422764E6-61F4-454A-BF08-9CF973E1E67D sourceRefstartEvent1 targetRefsid-320C4AED-D9F4-4C53-B2B6-D4ACCBA155F5/sequenceFlowuserTask idsid-873E297E-9E6B-4F4E-AF6A-2E085F1806B1 name部门审批 flowable:assignee${deptAssigne} flowable:formFieldValidationtrueextensionElementsmodeler:initiator-can-complete xmlns:modelerhttp://flowable.org/modeler![CDATA[false]]/modeler:initiator-can-complete/extensionElements/userTasksequenceFlow idsid-A0869337-10D3-43BC-90C1-036C9719308E sourceRefsid-320C4AED-D9F4-4C53-B2B6-D4ACCBA155F5 targetRefsid-873E297E-9E6B-4F4E-AF6A-2E085F1806B1/sequenceFlowendEvent idsid-CAB64925-F653-4167-8E12-ED956B723D2E name结束/endEventsequenceFlow idsid-91D96B3A-3408-4504-A23D-8F0C2AFE19A7 sourceRefsid-873E297E-9E6B-4F4E-AF6A-2E085F1806B1 targetRefsid-CAB64925-F653-4167-8E12-ED956B723D2E/sequenceFlow/processbpmndi:BPMNDiagram idBPMNDiagram_MyHolidaybpmndi:BPMNPlane bpmnElementMyHoliday idBPMNPlane_MyHolidaybpmndi:BPMNShape bpmnElementstartEvent1 idBPMNShape_startEvent1omgdc:Bounds height30.0 width30.0 x89.99999731779107 y149.99999552965178/omgdc:Bounds/bpmndi:BPMNShapebpmndi:BPMNShape bpmnElementsid-320C4AED-D9F4-4C53-B2B6-D4ACCBA155F5 idBPMNShape_sid-320C4AED-D9F4-4C53-B2B6-D4ACCBA155F5omgdc:Bounds height80.0 width100.00000000000003 x164.99999731779107 y124.99999552965178/omgdc:Bounds/bpmndi:BPMNShapebpmndi:BPMNShape bpmnElementsid-873E297E-9E6B-4F4E-AF6A-2E085F1806B1 idBPMNShape_sid-873E297E-9E6B-4F4E-AF6A-2E085F1806B1omgdc:Bounds height80.00000000000001 width100.0 x299.99999105930357 y119.99999642372141/omgdc:Bounds/bpmndi:BPMNShapebpmndi:BPMNShape bpmnElementsid-CAB64925-F653-4167-8E12-ED956B723D2E idBPMNShape_sid-CAB64925-F653-4167-8E12-ED956B723D2Eomgdc:Bounds height28.0 width28.0 x464.9999861419205 y145.9999920725826/omgdc:Bounds/bpmndi:BPMNShapebpmndi:BPMNEdge bpmnElementsid-91D96B3A-3408-4504-A23D-8F0C2AFE19A7 idBPMNEdge_sid-91D96B3A-3408-4504-A23D-8F0C2AFE19A7 flowable:sourceDockerX50.0 flowable:sourceDockerY40.00000000000001 flowable:targetDockerX14.0 flowable:targetDockerY14.0omgdi:waypoint x399.94999034668683 y159.99999473723344/omgdi:waypointomgdi:waypoint x464.99998600932435 y159.99999254311274/omgdi:waypoint/bpmndi:BPMNEdgebpmndi:BPMNEdge bpmnElementsid-A0869337-10D3-43BC-90C1-036C9719308E idBPMNEdge_sid-A0869337-10D3-43BC-90C1-036C9719308E flowable:sourceDockerX50.000000000000014 flowable:sourceDockerY40.0 flowable:targetDockerX50.0 flowable:targetDockerY40.00000000000001omgdi:waypoint x264.9499973177909 y163.1481439230865/omgdi:waypointomgdi:waypoint x299.9999910593035 y161.8499961786801/omgdi:waypoint/bpmndi:BPMNEdgebpmndi:BPMNEdge bpmnElementsid-422764E6-61F4-454A-BF08-9CF973E1E67D idBPMNEdge_sid-422764E6-61F4-454A-BF08-9CF973E1E67D flowable:sourceDockerX15.0 flowable:sourceDockerY15.0 flowable:targetDockerX50.000000000000014 flowable:targetDockerY40.0omgdi:waypoint x119.94999580774865 y164.99999552965178/omgdi:waypointomgdi:waypoint x164.9999973177828 y164.99999552965178/omgdi:waypoint/bpmndi:BPMNEdge/bpmndi:BPMNPlane/bpmndi:BPMNDiagram
/definitions三、部署流程 Testpublic void testDeploy() {//1.获取ProcessEngine 对象ProcessEngine processEngine ProcessEngines.getDefaultProcessEngine();//2.获取RepositoryServiceRepositoryService repositoryService processEngine.getRepositoryService();//3.完成流程部署操作Deployment deploy repositoryService.createDeployment().addClasspathResource(MyHoliday.bpmn20.xml) //关联要部署的流程名称.name(请假流程).deploy(); //部署流程System.out.println(id: deploy.getId());System.out.println(name: deploy.getName());System.out.println(key: deploy.getKey());}注意ProcessEngines.getDefaultProcessEngine();该获取方式会去加载resources下的 flowable.cfg.xml文件该文件为数据库的一些配置以及启动配置信息 beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdbean idprocessEngineConfigurationclassorg.flowable.engine.impl.cfg.StandaloneProcessEngineConfigurationproperty namejdbcUrl valuejdbc:mysql://xxxxxx/flowable?allowMultiQueriestrueamp;useUnicodetrueamp;characterEncodingUTF-8amp;useSSLfalseamp;serverTimezoneUTCamp;nullCatalogMeansCurrenttrue /property namejdbcDriver valuecom.mysql.cj.jdbc.Driver /property namejdbcUsername valuexxx /property namejdbcPassword valuexxx /--是否自动创建表--property namedatabaseSchemaUpdate valuetrue /!---是否启用异步任务--property nameasyncExecutorActivate valuefalse //bean
/beans不想使用该方法的也可以使用之前文章中的示例去进行创建ProcessEngine对象如下 Testpublic void testProcessEngine() {// 获取 ProcessEngineConfiguration 对象ProcessEngineConfiguration configuration new StandaloneProcessEngineConfiguration();//配置相关的数据库连接信息configuration.setJdbcDriver(com.mysql.cj.jdbc.Driver);configuration.setJdbcUsername(xxxx);configuration.setJdbcPassword(xxxx);configuration.setJdbcUrl(jdbc:mysql://xxxxx/flowable?useUnicodetruecharacterEncodingUTF-8serverTimezoneAsia/Shanghai);//如果数据库中的表结构不存在就新建configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);//构建流程引擎对象ProcessEngine processEngine configuration.buildProcessEngine();System.out.println(processEngine processEngine);}启动完成之后 查询表ACT_RE_PROCDEF流程定义信息上篇文章有介绍到flowable表的作用和注释有兴趣的可以去看看。 这里
ID_字段表示流程定义ID可以理解成后续扩展版本控制的时候这个表示不同的版本号DEPLOYMENT_ID_表示此次部署的ID
查询表 ACT_GE_BYTEARRAY 表的资源信息可以看到我们绘制的xml文件一些信息
四、启动流程 Testpublic void startTest() {ProcessEngine defaultProcessEngine ProcessEngines.getDefaultProcessEngine();RuntimeService runtimeService defaultProcessEngine.getRuntimeService();MapString, Object variables new HashMap();//部门处理人指定为张三处理firstAssigne为上述绘制指派人所填写的变量variables.put(firstAssigne, 张三);variables.put(deptAssigne, 李四);//MyHoliday:1:22504就是上面介绍到的 流程定义IDProcessInstance processInstance runtimeService.startProcessInstanceById(MyHoliday:1:22504, variables);System.out.println(processInstance.getProcessInstanceId() processInstance.getProcessInstanceId());}启动完成之后 查询表 ACT_RU_VARIABLE查询我们决策变量。 查询表ACT_RU_TASK可以看到我们当前流程的任务处理到哪了
五、审批操作 Testpublic void complete() {ProcessEngine defaultProcessEngine ProcessEngines.getDefaultProcessEngine();TaskService taskService defaultProcessEngine.getTaskService();taskService.setAssignee(25007, 张三);taskService.complete(25007);}完成审批后可以看到act_ru_task表的节点达到部门审批了。 继续审批 Testpublic void complete01() {ProcessEngine defaultProcessEngine ProcessEngines.getDefaultProcessEngine();TaskService taskService defaultProcessEngine.getTaskService();Task task taskService.createTaskQuery()//流程实例ID很多地方可以拿ACT_RU_EXECUTION表中PROC_INST_ID_或者ACT_RU_TASK中的PROC_INST_ID_等等.processInstanceId(25001).taskAssignee(李四).singleResult();taskService.complete(task.getId());}六、结束
经过上述操作该流程已经完成了审批了。我们可以查询ACT_HI_ACTINST看到历史流程实例信息
本篇内容简单的介绍了一下从绘制流程到审批介绍的简单过程如果有不正确或者不足的地方还恳请各位小伙伴给出一些建议。