yxk-20260506-流程表达式:

1、getUsersListByDeptAndRole根据部门和角色id获取人员list
2、getSonProcessVariable根据子流程的变量名称,获取子流程的局部变量
This commit is contained in:
ye1023
2026-05-03 11:33:30 +08:00
parent 042c18baa2
commit 1737dffef2
@@ -5,6 +5,9 @@ import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.runtime.Execution;
import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.springframework.beans.factory.annotation.Autowired;
@@ -26,6 +29,8 @@ public class FlowNodeExpression {
// 自动注入 + 自动延迟加载(解决循环依赖)
private final @Lazy ISysBaseAPI sysbase;
private final RuntimeService runtimeService;
/**
* 查找当前部门负责人
@@ -87,6 +92,76 @@ public class FlowNodeExpression {
return ISysBaseAPI.getUsersListByJsonLocalAPI(jsonData,deptKeyName,roleId);
}
/**
* Get username list by department id and role id.
* Example: ${flowNodeExpression.getUsersListByDeptAndRole('deptIdValue', 'roleIdValue')}
*
* @param deptId department id
* @param roleId role id
* @return username list
*/
public List<String> getUsersListByDeptAndRole(String deptId, String roleId) {
if (StringUtils.isBlank(deptId) || StringUtils.isBlank(roleId)) {
return Collections.emptyList();
}
JSONObject json = new JSONObject();
json.put("deptId", deptId);
return ISysBaseAPI.getUsersListByJsonLocalAPI(json, "deptId", roleId);
}
/**
* Get subprocess variable.
* Example: ${flowNodeExpression.getSonProcessVariable(execution, 'subApproveUser')}
*
* @param execution current execution
* @param variableName subprocess variable name
* @return username list
*/
public List<String> getSonProcessVariable(DelegateExecution execution, String variableName) {
if (execution == null || StringUtils.isBlank(variableName)) {
return Collections.emptyList();
}
try {
if (execution.hasVariableLocal(variableName)) {
return splitUsernames(execution.getVariableLocal(variableName));
}
List<Execution> executions = runtimeService.createExecutionQuery()
.processInstanceId(execution.getProcessInstanceId())
.list();
for (Execution childExecution : executions) {
if (execution.getId().equals(childExecution.getId())) {
continue;
}
Object localVariable = runtimeService.getVariableLocal(childExecution.getId(), variableName);
if (localVariable != null) {
return splitUsernames(localVariable);
}
}
Object variable = execution.getVariable(variableName);
if (variable != null) {
return splitUsernames(variable);
}
} catch (Exception e) {
log.warn("getSonProcessVariable failed, executionId={}, variableName={}",
execution.getId(), variableName, e);
}
return Collections.emptyList();
}
private List<String> splitUsernames(Object value) {
if (value == null) {
return Collections.emptyList();
}
return Arrays.stream(String.valueOf(value).split(SymbolConstant.COMMA))
.map(String::trim)
.filter(StringUtils::isNotBlank)
.collect(Collectors.toList());
}
/**
* 查找上一级部门负责人
* ${flowNodeExpression.getLevel1DepartLeaders(applyUserId)}