yxk-20260506-自定义监听class:
SaveCurrentTaskAssigneeLocalListener保存当前节点办理人到子流程的局部变量中去
This commit is contained in:
+1
@@ -25,6 +25,7 @@ public class SaveCurrentTaskAssigneeLocalListener implements TaskListener {
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void notify(DelegateTask delegateTask) {
|
||||
if (delegateTask == null) return;
|
||||
|
||||
+16
-37
@@ -376,44 +376,7 @@ public class FlowNodeExpression {
|
||||
return usernames.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save current task assignee as execution local variable.
|
||||
* Example: ${flowNodeExpression.saveCurrentTaskAssigneeLocal(task, 'subApproveUser')}
|
||||
*
|
||||
* @param task current task
|
||||
* @param variableName local variable name
|
||||
*/
|
||||
public void saveCurrentTaskAssigneeLocal(DelegateTask task, String variableName) {
|
||||
if (task == null || StringUtils.isBlank(variableName)) {
|
||||
return;
|
||||
}
|
||||
String assignee = task.getAssignee();
|
||||
if (StringUtils.isBlank(assignee)) {
|
||||
log.warn("saveCurrentTaskAssigneeLocal skipped, taskId={}, taskDefinitionKey={}, assignee is blank",
|
||||
task.getId(), task.getTaskDefinitionKey());
|
||||
return;
|
||||
}
|
||||
if (StringUtils.isBlank(task.getExecutionId())) {
|
||||
log.warn("saveCurrentTaskAssigneeLocal skipped, taskId={}, taskDefinitionKey={}, executionId is blank",
|
||||
task.getId(), task.getTaskDefinitionKey());
|
||||
return;
|
||||
}
|
||||
Set<String> executionIds = new LinkedHashSet<>();
|
||||
executionIds.add(task.getExecutionId());
|
||||
|
||||
Execution execution = runtimeService.createExecutionQuery()
|
||||
.executionId(task.getExecutionId())
|
||||
.singleResult();
|
||||
if (execution != null && StringUtils.isNotBlank(execution.getParentId())) {
|
||||
executionIds.add(execution.getParentId());
|
||||
}
|
||||
|
||||
for (String executionId : executionIds) {
|
||||
runtimeService.setVariableLocal(executionId, variableName, assignee);
|
||||
}
|
||||
log.info("saveCurrentTaskAssigneeLocal success, taskId={}, taskDefinitionKey={}, variableName={}, assignee={}, executionIds={}",
|
||||
task.getId(), task.getTaskDefinitionKey(), variableName, assignee, executionIds);
|
||||
}
|
||||
|
||||
private List<String> splitUsernames(Object value) {
|
||||
if (value == null) {
|
||||
@@ -425,6 +388,22 @@ public class FlowNodeExpression {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private String getParentExecutionId(Execution execution, int parentLevel) {
|
||||
Execution current = execution;
|
||||
for (int i = 0; i < parentLevel; i++) {
|
||||
if (current == null) {
|
||||
return null;
|
||||
}
|
||||
if (StringUtils.isBlank(current.getParentId())) {
|
||||
return null;
|
||||
}
|
||||
current = runtimeService.createExecutionQuery()
|
||||
.executionId(current.getParentId())
|
||||
.singleResult();
|
||||
}
|
||||
return current == null ? null : current.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找上一级部门负责人
|
||||
* ${flowNodeExpression.getLevel1DepartLeaders(applyUserId)}
|
||||
|
||||
Reference in New Issue
Block a user