1. 内置表单
流程图
测试
package com.sw.camundademo;
import org.camunda.bpm.engine.FormService;
import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.TaskService;
import org.camunda.bpm.engine.form.FormField;
import org.camunda.bpm.engine.form.StartFormData;
import org.camunda.bpm.engine.repository.Deployment;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Author Suaxi
* @Date 2024/8/20 21:02
* @Description
*/
@SpringBootTest
public class FlowFormsTest {
@Autowired
private RepositoryService repositoryService;
@Autowired
private RuntimeService runtimeService;
@Autowired
private TaskService taskService;
@Autowired
private FormService formService;
@Test
public void deploy() {
Deployment deploy = repositoryService.createDeployment()
.name("动态表单-内置表单")
.addClasspathResource("flow/40.动态表单-内置表单.bpmn")
.deploy();
System.out.println(deploy.getId());
}
@Test
public void getDeploymentData() {
String processId = "Process_0fc8vlb:1:791e3a95-5ef4-11ef-9b8d-10ffe00abd05";
StartFormData startFormData = formService.getStartFormData(processId);
System.out.println("FormKey: " + startFormData.getFormKey());
List<FormField> formFieldList = startFormData.getFormFields();
if (formFieldList != null && formFieldList.size() > 0) {
for (FormField formField : formFieldList) {
System.out.println(formField.getId() + " - " + formField.getLabel() + ": " + formField.getValue().getValue());
}
}
}
@Test
public void startFlow() {
String processId = "Process_0fc8vlb:1:791e3a95-5ef4-11ef-9b8d-10ffe00abd05";
Map<String, Object> map = new HashMap<>();
map.put("reason", "有事要请假!");
map.put("days", 3);
runtimeService.startProcessInstanceById(processId, map);
}
@Test
public void startFormFlow() {
String processId = "Process_0fc8vlb:1:791e3a95-5ef4-11ef-9b8d-10ffe00abd05";
Map<String, Object> map = new HashMap<>();
map.put("reason", "我要请假!");
map.put("days", 5);
formService.submitStartForm(processId, map);
}
@Test
public void getTaskFormData() {
String processId = "Process_0fc8vlb:1:791e3a95-5ef4-11ef-9b8d-10ffe00abd05";
String taskId = "5fe00ff2-5ef6-11ef-859a-10ffe00abd05";
StartFormData startFormData = formService.getStartFormData(processId);
List<FormField> formFieldList = startFormData.getFormFields();
if (formFieldList != null && formFieldList.size() > 0) {
for (FormField formField : formFieldList) {
String id = formField.getId();
System.out.println(id + ": " + taskService.getVariable(taskId, id));
}
}
}
}
2. Camunda表单
流程图
测试步骤同理内置表单
3. 外置表单
流程图
测试步骤同理内置表单
启动流程后,可在组长审批节点打开外置表单
评论 (0)