diff --git a/jeecg-boot-platform/jeecg-boot-module-bpm-flowable/src/main/java/org/jeecg/modules/extbpm/process/common/expression/FlowNodeExpression.java b/jeecg-boot-platform/jeecg-boot-module-bpm-flowable/src/main/java/org/jeecg/modules/extbpm/process/common/expression/FlowNodeExpression.java index 7eeb5ee..f9e7874 100644 --- a/jeecg-boot-platform/jeecg-boot-module-bpm-flowable/src/main/java/org/jeecg/modules/extbpm/process/common/expression/FlowNodeExpression.java +++ b/jeecg-boot-platform/jeecg-boot-module-bpm-flowable/src/main/java/org/jeecg/modules/extbpm/process/common/expression/FlowNodeExpression.java @@ -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 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 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 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 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)}