Activiti_使用
Activiti_使用
流程设计器:https://gitee.com/KonBAI-Q/ruoyi-flowable-plus
https://gitee.com/MiyueSC/bpmn-process-designer
任务的执行者或候选执行者
assignee: 指定任务的具体执行者,通常是一个用户或者用户组。candidateUsers: 指定任务的候选执行者,可以是一个或多个用户。candidateGroups: 指定任务的候选执行者组,通常用于对任务进行分组授权。
Activiti提供了两种基于子流程的实现:
- 。一种是内嵌子流程:子流程元素
<subProcess>内嵌在主流程元素<process>之内,只能在该流程中使用该子流程外部是无法访问到的这种子流程一般作为局部通用逻辑处理,或者因为特定业务需要,使得比较复杂的单个主流程设计清晰直观。 - 另一种是调用子流程:首先实现一个流程,在另一个流程中可以调用该流程,通常可以定义一些通用的流程作为这种调用子流程,供其他多个流程定义复用。这种子流程使用
<calLActivity>元素来进行调用,间接地嵌入到主流程中,用起来比较方便。
https://blog.csdn.net/Nought_Love/article/details/100081893
activiti多实例子流程
https://zhuanlan.zhihu.com/p/532828957?utm_id=0https://zhuanlan.zhihu.com/p/88177072?utm_id=0https://zhuanlan.zhihu.com/p/532828957?utm_id=0
https://codeleading.com/article/66634185298/

1. 子流程
- 独立的子流程
- 嵌入的子流程
在 Activiti 中,多实例任务(Multi-instance Task)允许您为一个任务定义一个集合,并为每个集合中的元素执行相同的任务。其中,集合可以是一个列表、数组或集。
在您的场景中,groupList 是作为多实例任务的输入集合,并指定了元素变量 yjzzr。根据您的描述,groupList 的数据格式可以是一个字符串,多个元素通过某种分隔符进行分隔。
以下是一些常见的数据格式示例:
- 使用逗号分隔的字符串:
String groupList = "user1,user2,user3";
- 使用空格分隔的字符串:
String groupList = "user1 user2 user3";
- 使用数组:
String[] groupList = {"user1", "user2", "user3"};
- 使用列表:
List<String> groupList = Arrays.asList("user1", "user2", "user3");
1.监听器的使用

activiti监听器有两种,一种是TaskListeners,一种是ExecutionListeners。
2. 查找上一个已经完成的 节点
/**
* 查找上一个已完成的user taskId
* @param delegateTask
*/
private HistoricActivityInstance getPreNode(DelegateTask delegateTask) {
List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery()
.activityType("userTask")
.processInstanceId(delegateTask.getProcessInstanceId())
.finished()
.orderByHistoricActivityInstanceEndTime()
.desc()
.list();
if(historicActivityInstances!=null && historicActivityInstances.size()>0){
return historicActivityInstances.get(0);
}
return null;
}
获取连线
Process process = ProcessDefinitionUtil.getProcess(delegateTask.getProcessDefinitionId());
//获取当前节点信息
FlowNode flowNode = (FlowNode) process.getFlowElement(delegateTask.getTaskDefinitionKey());//"task.getTaskDefinitionKey()"
//获取当前节点输入连线
List<SequenceFlow> ingoingFlows = flowNode.getIncomingFlows();
//遍历输出连线
for (SequenceFlow ingoingFlow : ingoingFlows) {
//获取输出节点元素
FlowElement sourceFlowElement = ingoingFlow.getSourceFlowElement();
//排除非用户任务接点
if(sourceFlowElement instanceof UserTask){
//获取节点
System.out.println(sourceFlowElement);
}
}
拿到当前节点的连线
FlowElement currentFlowElement = bpmnModel.getFlowElement(taskDefinitionKey);
List<SequenceFlow> outgoingFlows = ((FlowNode) currentFlowElement).getOutgoingFlows(); // 进线
List<SequenceFlow> incomingFlows = ((FlowNode) currentFlowElement).getIncomingFlows();// 出线
修改当前节点代办组任务的值
代办组任务:由 act_ru_identitylink 字段 GROUP_ID_ 确定,如果对其修改,就能自定义审批人
addCandidateGroups 增加组任务审批组
private void updateCandidateGroup(DelegateTask delegateTask) {
if(businessDept==null){
return;
}
Object jsonObj = businessDept.getValue(delegateTask); // 从变量中获取数值
if (jsonObj!=null) {
String business_dept = jsonObj.toString();
// 获取任务服务
String taskId = delegateTask.getId();
// 查询指定任务的所有身份关系并修改 GROUP_ID_ 属性
Set<IdentityLink> candidates = delegateTask.getCandidates();
for (IdentityLink item : candidates) {
if (item instanceof IdentityLinkEntity) {
IdentityLinkEntity itemBean = (IdentityLinkEntity) item;
if (itemBean.isGroup()) { // 候选组
String groupId = itemBean.getGroupId();
taskService.deleteCandidateGroup(taskId, groupId);
taskService.addCandidateGroup(delegateTask.getId(),groupId+":"+ business_dept);
}
}
}
}
}
Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); // 不需要权限
待办查询
org.activiti.engine.impl.persistence.entity.TaskEntityImpl.selectTaskCountByQueryCriteria
activiti-engine-7.1.0.M6.jar!\org\activiti\db\mapping\entity\Task.xml
SELECT
count( DISTINCT RES.ID_ )
FROM
ACT_RU_TASK RES
LEFT JOIN ACT_RU_IDENTITYLINK I ON I.TASK_ID_ = RES.ID_
INNER JOIN ACT_RE_PROCDEF D ON RES.PROC_DEF_ID_ = D.ID_
WHERE
RES.NAME_ LIKE '%添加%'
AND RES.DESCRIPTION_ LIKE '%补偿协议审批单%'
AND D.KEY_ IN ( 'oc_year_plan_flow', 'oc_month_capital_plan_flow', 'oc_sub_plan_flow', 'oc_bargaining_flow', 'oc_bcxyspd_flow', 'oc_compensation_agreement_flow', 'oc_high_risk_tree_clearance_approval_flow', 'oc_implementation_register_flow' )
AND (
RES.ASSIGNEE_ = '18'
OR (
RES.ASSIGNEE_ IS NULL
AND I.TYPE_ = 'candidate'
AND (
I.USER_ID_ = '18'
OR I.GROUP_ID_ IN ( 'POST:qzzz', 'POST:qzzz:248', 'POST:yjzzr', 'POST:yjzzr:248', 'ROLE:136', 'ROLE:136:248', 'ROLE:144', 'ROLE:144:248', 'ROLE:148', 'ROLE:148:248' )
)))