parent
a55b556f13
commit
3b4887a23e
3 changed files with 218 additions and 0 deletions
@ -0,0 +1,43 @@ |
|||||||
|
package org.springblade.plugin.workflow.test; |
||||||
|
|
||||||
|
import org.flowable.engine.RuntimeService; |
||||||
|
import org.flowable.engine.delegate.DelegateExecution; |
||||||
|
import org.flowable.engine.delegate.ExecutionListener; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* flowable 执行监听器示例 |
||||||
|
* 该监听器可以配置在节点和线 |
||||||
|
* @author ytl |
||||||
|
* @since 2022-12-28 11:13 |
||||||
|
*/ |
||||||
|
@Component |
||||||
|
public class Form1Listener implements ExecutionListener { |
||||||
|
@Autowired |
||||||
|
private RuntimeService runtimeService; |
||||||
|
|
||||||
|
@Override |
||||||
|
public void notify(DelegateExecution execution) { |
||||||
|
String event = execution.getEventName(); |
||||||
|
String processInstanceId = execution.getProcessInstanceId(); |
||||||
|
switch (event) { |
||||||
|
case "start" ://开始时触发
|
||||||
|
System.out.println("执行监听器示例start event------------------"); |
||||||
|
Map<String, Object> variables = execution.getVariables(); |
||||||
|
for(String s : variables.keySet()){ |
||||||
|
System.out.println("执行监听器获取到的表单参数:" + s + "-" + variables.get(s).toString()); |
||||||
|
} |
||||||
|
String currentActivityId = execution.getCurrentActivityId(); |
||||||
|
break; |
||||||
|
case "end" ://结束时触发
|
||||||
|
System.out.println("执行监听器示例end event-----------------"); |
||||||
|
break; |
||||||
|
case "take" ://主要用于监控流程线,当流程流转该线时触发
|
||||||
|
System.out.println("执行监听器示例take event-----------------"); |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,57 @@ |
|||||||
|
package org.springblade.plugin.workflow.test; |
||||||
|
|
||||||
|
import org.checkerframework.checker.units.qual.A; |
||||||
|
import org.flowable.engine.FormService; |
||||||
|
import org.flowable.engine.ProcessEngine; |
||||||
|
import org.flowable.engine.RuntimeService; |
||||||
|
import org.flowable.engine.TaskService; |
||||||
|
import org.flowable.engine.delegate.TaskListener; |
||||||
|
import org.flowable.engine.form.FormProperty; |
||||||
|
import org.flowable.engine.form.StartFormData; |
||||||
|
import org.flowable.engine.form.TaskFormData; |
||||||
|
import org.flowable.task.service.delegate.DelegateTask; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.beans.factory.annotation.Qualifier; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* 任务监听器示例 |
||||||
|
* 该监听器只能监听带有任务信息的节点,开始和结束节点由于没有任务因此无法监听 |
||||||
|
* @author ytl |
||||||
|
* @since 2022-12-28 11:36 |
||||||
|
*/ |
||||||
|
@Component |
||||||
|
public class TaskListenerTest implements TaskListener { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void notify(DelegateTask delegateTask) { |
||||||
|
String event = delegateTask.getEventName(); |
||||||
|
String taskId = delegateTask.getId(); |
||||||
|
String definitionId = delegateTask.getProcessDefinitionId(); |
||||||
|
|
||||||
|
switch (event) { |
||||||
|
case "create" :// 任务创建时触发,此时所有属性已被设置完毕
|
||||||
|
delegateTask.setAssignee("11111111111111"); |
||||||
|
Map<String, Object> variables = delegateTask.getVariables(); |
||||||
|
for(String s : variables.keySet()){ |
||||||
|
System.out.println("任务监听器示例获取的表单参数:" + s + "-" + variables.get(s).toString()); |
||||||
|
} |
||||||
|
System.out.println("任务监听器示例create event------"); |
||||||
|
break; |
||||||
|
case "assignment" :// 任务被委派给某人后触发,如通过变量的方式设置处理人时会触发,先于create事件触发
|
||||||
|
System.out.println("任务监听器示例assignment event------"); |
||||||
|
String assignee = delegateTask.getAssignee(); |
||||||
|
System.out.println("任务监听器获取当前负责人:" + assignee); |
||||||
|
break; |
||||||
|
case "complete" :// 在任务完成后,且被从运行时数据(runtime data)中删除前触发
|
||||||
|
System.out.println("任务监听器示例complete event------"); |
||||||
|
break; |
||||||
|
case "delete" :// 在任务将要被删除之前发生。
|
||||||
|
System.out.println("任务监听器示例delete event------"); |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,118 @@ |
|||||||
|
package org.springblade.plugin.workflow.test; |
||||||
|
|
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import org.flowable.engine.FormService; |
||||||
|
import org.flowable.engine.ProcessEngine; |
||||||
|
import org.flowable.engine.RuntimeService; |
||||||
|
import org.flowable.engine.TaskService; |
||||||
|
import org.flowable.engine.form.FormProperty; |
||||||
|
import org.flowable.engine.form.StartFormData; |
||||||
|
import org.flowable.engine.form.TaskFormData; |
||||||
|
import org.flowable.engine.runtime.ProcessInstance; |
||||||
|
import org.flowable.form.api.FormInfo; |
||||||
|
import org.flowable.task.api.Task; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ytl |
||||||
|
* @since 2022-12-28 10:26 |
||||||
|
*/ |
||||||
|
@RestController |
||||||
|
@AllArgsConstructor |
||||||
|
@RequestMapping("/flowTest") |
||||||
|
@Api(value = "", tags = "") |
||||||
|
public class TestController { |
||||||
|
@Autowired |
||||||
|
private RuntimeService runtimeService; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private TaskService taskService; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private FormService formService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 开启流程 |
||||||
|
*/ |
||||||
|
@GetMapping("/startProcess") |
||||||
|
public void startProcess(String processDefinitionId){ |
||||||
|
ProcessInstance processInstance = runtimeService |
||||||
|
.startProcessInstanceById(processDefinitionId) |
||||||
|
; |
||||||
|
System.out.println("processInstance--name==" + processInstance.getName()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 给节点分配负责人 |
||||||
|
*/ |
||||||
|
// @GetMapping("/setAssign")
|
||||||
|
// public void setAssign(){
|
||||||
|
// Map<String,Object> variable = new HashMap<>();
|
||||||
|
// variable.put("assignee","1531816365170929666");
|
||||||
|
// runtimeService
|
||||||
|
// }
|
||||||
|
/** |
||||||
|
* 测试查询某个流程到哪一步了 |
||||||
|
*/ |
||||||
|
@GetMapping("/testProcessStep") |
||||||
|
public void testProcessStep(){ |
||||||
|
List<String> activeActivityIds = runtimeService.getActiveActivityIds("3d4b3f06-865f-11ed-9d65-024236c41969"); |
||||||
|
for (String s : activeActivityIds){ |
||||||
|
System.out.println(s); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* FormService.getTaskFormData(String taskId) |
||||||
|
* 获取流程的form 表单中的数据(具体的数据) |
||||||
|
*/ |
||||||
|
@GetMapping("/getTaskFormData") |
||||||
|
public R getTaskFormData(String taskId){ |
||||||
|
TaskFormData taskFormData = formService.getTaskFormData(taskId); |
||||||
|
List<FormProperty> list = taskFormData.getFormProperties(); |
||||||
|
for (FormProperty p : list){ |
||||||
|
System.out.println(p.getName() + ":" + p.getValue() + ":" + p.getType()); |
||||||
|
} |
||||||
|
|
||||||
|
return R.data(""); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* getStartFormData |
||||||
|
* 获取流程的form定义的表单信息 |
||||||
|
*/ |
||||||
|
@GetMapping("/getStartFormData") |
||||||
|
public R getStartFormData(String processDefinitionId){ |
||||||
|
StartFormData startFormData = formService.getStartFormData(processDefinitionId); |
||||||
|
startFormData.getFormProperties().forEach(s->{ |
||||||
|
System.out.println(s.getName()); |
||||||
|
}); |
||||||
|
return R.data(""); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 给节点分配负责人 |
||||||
|
*/ |
||||||
|
@GetMapping("/doTask") |
||||||
|
public R doTask(String taskId){ |
||||||
|
Task task = taskService.createTaskQuery() |
||||||
|
// .taskAssignee("1530472079338819585")
|
||||||
|
// .processInstanceId("ee59a8ff-868c-11ed-ab1c-005056c00001")
|
||||||
|
.taskId(taskId) |
||||||
|
.singleResult(); |
||||||
|
Map<String, Object> processVariables = task.getProcessVariables(); |
||||||
|
Map<String, Object> caseVariables = task.getCaseVariables(); |
||||||
|
taskService.setVariable(taskId,"意见","同意把"); |
||||||
|
taskService.setAssignee(taskId,"1530823299437965313"); |
||||||
|
return R.success(""); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue