一个流程实例
一个流程案例
从实际应用中开发学习
什么是流程?
工作流是对工作流程及其各操作步骤之间业务规则的抽象、概括描述。举几个例子说明一下什么是流程,
请假,无论是还在工作的同学们还是已经工作的工友们肯定对于请假这个流程不会陌生。那么请假的话 肯定就会有请假人(申请人).
同样的也会有负责同意或者驳回我们请假的人(老师或者是领导),如果这个请假再复杂一点的话,可能老师同意之后还需要主任或者是更高级的
领导进行请假的审批。这些我们统称为(审批人)。
流程的定义
在实际的生活中,请假流程的审批顺序一般是依据校规或者企业规章制度来制定的。在系统程序中,我们也要制定这样的规则。在程序中,我们使用一种专门的描述语言来表达这种规则,这个过程我们称之为流程定义。
流程的部署- repository:仓库
如果一个流程只是处于规则制定阶段的话,这个规则是不能够对其相关的使用者进行约束的。所以我们需要进行一个流程的部署操作。在activiti框架中,我们使用repositoryService进行流程的部署。
一个简单的流程例子。
下面我们通过一个简单的例子来操作流程的制定和部署。
@RunWith(SpringRunner.class)
@SpringBootTest(classes = DemoApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ActivitiJunitTest {
private static final Logger log = LoggerFactory.getLogger(ActivitiJunitTest.class);
@Autowired
RepositoryService repositoryService;
@Autowired
RuntimeService runtimeService;
@Autowired
TaskService taskService;
@Autowired
HistoryService historyService;
/***
* 1.流程部署
* @author lxd
* @date2023-09-06 10:00
* @param[]
* @return void
*/
@Test
public void testDeployment() {
Deployment deployment = repositoryService.createDeployment()
.name("测试流程文件部署")
.addClasspathResource("leavess.bpmn")
// .addClasspathResource("processes/leave.jpg")
.deploy();
System.out.println("部署的流程id ="+ deployment.getId());
System.out.println("部署的流程id ="+ deployment.getName());
log.info("部署的流程id = {}", deployment.getId());
log.info("部署的流程名称 = {}", deployment.getName());
}
@Test
public void start(){
Map<String,Object> map=new HashMap<>();
List<String> groupList=new ArrayList<>();
groupList.add("hr");
groupList.add("ceshi");
map.put("hr",groupList);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("v3",map);
log.info("启动流程实例成功 = {}", processInstance);
log.info("流程实例id = {}", processInstance.getId());
log.info("流程定义id = {}", processInstance.getProcessDefinitionId());
}
@Test
public void testGetTaskByAssignee() {
List<Task> tasks = taskService.createTaskQuery()
.taskCandidateGroup("hr")
.list();
for (Task task : tasks) {
System.out.println(task.getName());
}
}
}
流程的xml文件
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef">
<process id="v3" name="v2" isExecutable="true">
<startEvent id="sid-06D994D1-2C0E-417E-8351-B472490F386A"></startEvent>
<userTask id="sid-5CEB1E7A-0860-46A1-8D9D-B2C5E9086DB6" name="发起申请啊" activiti:candidateGroups="hr"></userTask>
<sequenceFlow id="sid-8B085EB8-E1B5-4CD8-BB92-5CEAB980BE16" sourceRef="sid-06D994D1-2C0E-417E-8351-B472490F386A" targetRef="sid-5CEB1E7A-0860-46A1-8D9D-B2C5E9086DB6"></sequenceFlow>
<endEvent id="sid-BE42DCB2-13EE-44BB-ADC0-1B2994BA2199"></endEvent>
<sequenceFlow id="sid-3EA5C2F3-0191-4700-99A3-447398272A79" sourceRef="sid-5CEB1E7A-0860-46A1-8D9D-B2C5E9086DB6" targetRef="sid-BE42DCB2-13EE-44BB-ADC0-1B2994BA2199"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_v3">
<bpmndi:BPMNPlane bpmnElement="v3" id="BPMNPlane_v3">
<bpmndi:BPMNShape bpmnElement="sid-06D994D1-2C0E-417E-8351-B472490F386A" id="BPMNShape_sid-06D994D1-2C0E-417E-8351-B472490F386A">
<omgdc:Bounds height="30.0" width="30.0" x="95.0" y="30.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-5CEB1E7A-0860-46A1-8D9D-B2C5E9086DB6" id="BPMNShape_sid-5CEB1E7A-0860-46A1-8D9D-B2C5E9086DB6">
<omgdc:Bounds height="80.0" width="100.0" x="60.0" y="120.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-BE42DCB2-13EE-44BB-ADC0-1B2994BA2199" id="BPMNShape_sid-BE42DCB2-13EE-44BB-ADC0-1B2994BA2199">
<omgdc:Bounds height="28.0" width="28.0" x="96.0" y="420.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sid-3EA5C2F3-0191-4700-99A3-447398272A79" id="BPMNEdge_sid-3EA5C2F3-0191-4700-99A3-447398272A79">
<omgdi:waypoint x="110.0" y="200.0"></omgdi:waypoint>
<omgdi:waypoint x="110.0" y="420.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-8B085EB8-E1B5-4CD8-BB92-5CEAB980BE16" id="BPMNEdge_sid-8B085EB8-E1B5-4CD8-BB92-5CEAB980BE16">
<omgdi:waypoint x="110.0" y="60.0"></omgdi:waypoint>
<omgdi:waypoint x="110.0" y="120.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
节点说明
definitions
bpmndi
omgdi