¡Continúe creando, acelere el crecimiento! Este es el segundo día de mi participación en el "Nuggets Daily New Plan · June Update Challenge", haz clic para ver los detalles del evento
1. ¿Qué es RepositoryService?
RepositoryService proporciona operaciones para administrar y controlar implementaciones y definiciones de procesos. Gestionar información estática, etc.
1.0 Primero preparamos un archivo de proceso
<?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:flowable="http://flowable.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.flowable.org/processdef">
<process id="day01" name="测试流程图" isExecutable="true">
<startEvent id="startEvent1" flowable:formFieldValidation="true"></startEvent>
<userTask id="sid-24C112A4-C833-40C2-B642-FB7CD4E404C0" name="测试流程" flowable:assignee="${assignee1}" flowable:formFieldValidation="true">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<sequenceFlow id="sid-8DC6D33C-E325-4172-8C52-06420F3D5985" sourceRef="startEvent1" targetRef="sid-24C112A4-C833-40C2-B642-FB7CD4E404C0"></sequenceFlow>
<endEvent id="sid-04DE9E62-130A-492B-8CB2-DD2E852248E1"></endEvent>
<userTask id="sid-DBC538C3-81A7-41BA-A805-F5F145033062" name="审核" flowable:assignee="${assignee1}" flowable:formFieldValidation="true">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<sequenceFlow id="sid-2D0D3626-2006-4FA2-8AC5-EA23E469E19C" sourceRef="sid-24C112A4-C833-40C2-B642-FB7CD4E404C0" targetRef="sid-DBC538C3-81A7-41BA-A805-F5F145033062"></sequenceFlow>
<sequenceFlow id="sid-C4A78A1F-254E-49DF-AF78-B897FDF427D3" sourceRef="sid-DBC538C3-81A7-41BA-A805-F5F145033062" targetRef="sid-04DE9E62-130A-492B-8CB2-DD2E852248E1"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_day01">
<bpmndi:BPMNPlane bpmnElement="day01" id="BPMNPlane_day01">
<bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
<omgdc:Bounds height="30.0" width="30.0" x="100.0" y="163.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-24C112A4-C833-40C2-B642-FB7CD4E404C0" id="BPMNShape_sid-24C112A4-C833-40C2-B642-FB7CD4E404C0">
<omgdc:Bounds height="80.0" width="100.0" x="216.5" y="140.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-04DE9E62-130A-492B-8CB2-DD2E852248E1" id="BPMNShape_sid-04DE9E62-130A-492B-8CB2-DD2E852248E1">
<omgdc:Bounds height="28.0" width="28.0" x="540.0" y="166.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-DBC538C3-81A7-41BA-A805-F5F145033062" id="BPMNShape_sid-DBC538C3-81A7-41BA-A805-F5F145033062">
<omgdc:Bounds height="80.0" width="100.0" x="361.5" y="140.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sid-C4A78A1F-254E-49DF-AF78-B897FDF427D3" id="BPMNEdge_sid-C4A78A1F-254E-49DF-AF78-B897FDF427D3">
<omgdi:waypoint x="461.45000000000005" y="180.0"></omgdi:waypoint>
<omgdi:waypoint x="540.0" y="180.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-2D0D3626-2006-4FA2-8AC5-EA23E469E19C" id="BPMNEdge_sid-2D0D3626-2006-4FA2-8AC5-EA23E469E19C">
<omgdi:waypoint x="316.4499999999907" y="180.0"></omgdi:waypoint>
<omgdi:waypoint x="361.5" y="180.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-8DC6D33C-E325-4172-8C52-06420F3D5985" id="BPMNEdge_sid-8DC6D33C-E325-4172-8C52-06420F3D5985">
<omgdi:waypoint x="129.948660434253" y="178.1973431100433"></omgdi:waypoint>
<omgdi:waypoint x="216.49999999999937" y="179.33993399339934"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
复制代码
Este archivo se puede diseñar y descargar en Flowable UI. Tengo este tutorial en mi artículo anterior y puede consultarlo si lo necesita.
1.1 Implementar un proceso usando RepositoryService
@Test
public void DeployProcess(){
Deployment holiday = repositoryService.createDeployment()
.addClasspathResource("测试流程图.bpmn20.xml")
.name("测试流程部署")
.deploy();
}
复制代码
En el trabajo normal, el 测试流程图bpmn.xml
archivo se agrega en forma de flujo después de que se diseña el front-end. Lo pondremos directamente en el directorio de recursos para la demostración.
Resultado: una vez completada la ejecución, vaya a ACT_RE_DEPLOYMENT(部署信息表)
y ACT_RE_PROCDEF(流程信息定义表)
y para ver los datos en las ACT_GE_BYTEARRAY(流程的静态资源信息)
dos tablas.
ACT_RE_PROCDEF
Tabla de definición de procesos:
ACT_RE_DEPLOYMENT
Hoja de información de implementación:
ACT_RE_PROCDEF
Tabla de recursos estáticos:
1.2 Usar RepositoryService para consultar la información de implementación que acabamos de implementar
Podemos ver que hay muchos métodos, aquí demostraremos tres de uso común
@Test
public void DeploySelect(){
//批量查询
List<Deployment> list = repositoryService.createDeploymentQuery().list();
//批量分页查询
List<Deployment> listPage = repositoryService.createDeploymentQuery().listPage(0,10);
//精确查询只能返回一个 如果有多条记录会报错singleResult()
Deployment deployment = repositoryService.createDeploymentQuery().deploymentNameLike("测试流程部署").singleResult();
list.forEach(e->{
System.out.println(e.getName()+"list查询");
});
listPage.forEach(e->{
System.out.println(e.getName()+"listPage查询");
});
System.out.println(deployment.getName()+"精确查询");
}
复制代码
Por supuesto, hay muchos métodos a los que puede llamar createDeploymentQuery(), por lo que no los enumeraré uno por uno.
DeploymentQuery deploymentId(String var1);
DeploymentQuery deploymentIds(List<String> var1);
DeploymentQuery deploymentName(String var1);
DeploymentQuery deploymentNameLike(String var1);
DeploymentQuery deploymentCategory(String var1);
DeploymentQuery deploymentCategoryLike(String var1);
DeploymentQuery deploymentCategoryNotEquals(String var1);
DeploymentQuery deploymentKey(String var1);
DeploymentQuery deploymentKeyLike(String var1);
DeploymentQuery deploymentTenantId(String var1);
DeploymentQuery deploymentTenantIdLike(String var1);
DeploymentQuery deploymentWithoutTenantId();
DeploymentQuery deploymentEngineVersion(String var1);
DeploymentQuery deploymentDerivedFrom(String var1);
DeploymentQuery parentDeploymentId(String var1);
DeploymentQuery parentDeploymentIdLike(String var1);
DeploymentQuery parentDeploymentIds(List<String> var1);
DeploymentQuery processDefinitionKey(String var1);
DeploymentQuery processDefinitionKeyLike(String var1);
DeploymentQuery latest();
DeploymentQuery orderByDeploymentId();
DeploymentQuery orderByDeploymentName();
DeploymentQuery orderByDeploymentTime();
DeploymentQuery orderByTenantId();
复制代码
resultado:
1.3 Proceso de consulta
@Test
public void processSelect(){
List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().list();
List<ProcessDefinition> list1 = repositoryService.createNativeProcessDefinitionQuery().sql("select *from ACT_RE_PROCDEF").list();
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("day01").singleResult();
list.forEach(e->{
System.out.println(e.getName()+"list查询");
});
list1.forEach(e->{
System.out.println(e.getName()+"自己写 自定义sql 查询");
});
System.out.println(processDefinition.getName()+"精确查询");
}
复制代码
resultado:
1.4 Suspensión y activación de procesos de procesos
@Test
public void suspendActivateProcess(){
//使用流程定义的ID先查询到流程
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
.processDefinitionKey("day01").singleResult();
// isSuspended方法是在激活的时候返回true
boolean suspended = processDefinition.isSuspended();
if(suspended){
//挂起流程
repositoryService.activateProcessDefinitionById(processDefinition.getId());
System.out.println("激活流程...");
}else {
//激活流程
repositoryService.suspendProcessDefinitionById(processDefinition.getId());
System.out.println("挂起流程...");
}
复制代码
resultado:
1.5 Eliminación del proceso de implementación
@Test
public void deleteDeploy(){
Deployment deployment = repositoryService.createDeploymentQuery().deploymentNameLike("测试流程部署").singleResult();
// 删除指定流程部署,如果存在该流程部署的实例job或者历史任务,都会抛出异常
repositoryService.deleteDeployment(deployment.getId());
// 级联删除该流程部署所创建的所有任务信息和历史数据
// repositoryService.deleteDeployment(deployment.getId(),true);
}
复制代码
Resultado: los datos de la tabla se borran
1.6 Designar al iniciador del proceso
@Test
public void processStatrUser(){
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
.processDefinitionKey("day01").singleResult();
//并不会去验证 用户是否存在 。需要我们业务处理
repositoryService.addCandidateStarterUser(processDefinition.getId(),"张三");
}
复制代码
addCandidateStarterUser
En la implementación de este método, podemos ver que los parámetros entrantes son el ID del proceso y el ID del usuario o cuenta, aquí, el nombre se usa directamente para la demostración.
public void addCandidateStarterUser(String processDefinitionId, String userId) {
this.commandExecutor.execute(new AddIdentityLinkForProcessDefinitionCmd(processDefinitionId, userId, (String)null));
}
复制代码
Resultado: ACT_RU_IDENTITYLINK
el candidato de datos Zhang San se puede ver en la tabla
1.7 Borrar iniciador de proceso
@Test
public void processdeleteUser(){
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
.processDefinitionKey("day01").singleResult();
repositoryService.deleteCandidateStarterUser(processDefinition.getId(),"张三");
}
复制代码
resultado: