1. 概要
在流程设计中,有一种服务任务,这种任务的特点是,他会执行节点上的任务,执行完成后,自动流转到下一环节。
这种节点我们可以自己定义需要执行任务。
在平台中默认实现了两种:
1.执行脚本
2.调用WEB请求。
2. 扩展步骤
在平台中,我们定义了服务任务接口,通过对接口的实现,我们可以定义后端的逻辑,另外,我们可以将配置信息保存到流程定义中。
2.1 服务接口定义
接口定义如下
package com.redxun.bpm.activiti.ext;import org.activiti.engine.delegate.DelegateExecution;/*** 服务任务接口*/public interface IServiceTask {ServiceType getType();void handle(DelegateExecution execution,String setting);}
2.1.1 调用脚本任务实现
下面的代码是调用脚本任务的实现。
@Componentpublic class ScriptTask implements IServiceTask {@ResourceGroovyEngine groovyEngine;@Overridepublic ServiceType getType() {return new ServiceType("脚本任务", "script");}@Overridepublic void handle(DelegateExecution execution, String setting) {JSONObject jsonObject = JSONObject.parseObject(setting);String script = jsonObject.getString("script");if (StringUtils.isEmpty(script)) {return;}Map<String, Object> contextData = ActivitiUtil.getContextData(execution);groovyEngine.executeScripts(script, contextData);}}
1.需要增加 @Component 注解。
2.实现执行脚本的逻辑。
2.2 前端实现
服务任务配置是在前端实现的。
components/bpmn/customModle/serviceTask.vue
通过接口实现,我们可以在下拉框选择我们的实现。

点击调用配置。
查看代码。serviceTask/js/ServiceTask
他会对每一种类型的任务,打开一个对话框进行配置,对话框会返回配置数据。
ServiceTaskApi.openServiceTask(self, function (action, data) {if (action != 'ok') return;self.nodeAttr.setting = data;})
文档更新时间: 2022-01-20 14:53 作者:zyg