|
@@ -1,6 +1,7 @@
|
|
package cn.iocoder.yudao.module.bpm.service.task.listener;
|
|
package cn.iocoder.yudao.module.bpm.service.task.listener;
|
|
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
import cn.hutool.core.lang.Assert;
|
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
|
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
|
|
@@ -9,13 +10,14 @@ import cn.iocoder.yudao.module.bpm.enums.definition.BpmChildProcessStartUserEmpt
|
|
import cn.iocoder.yudao.module.bpm.enums.definition.BpmChildProcessStartUserTypeEnum;
|
|
import cn.iocoder.yudao.module.bpm.enums.definition.BpmChildProcessStartUserTypeEnum;
|
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
|
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
|
|
import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService;
|
|
import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService;
|
|
|
|
+import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService;
|
|
import jakarta.annotation.Resource;
|
|
import jakarta.annotation.Resource;
|
|
import lombok.Setter;
|
|
import lombok.Setter;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.flowable.engine.delegate.DelegateExecution;
|
|
import org.flowable.engine.delegate.DelegateExecution;
|
|
import org.flowable.engine.delegate.ExecutionListener;
|
|
import org.flowable.engine.delegate.ExecutionListener;
|
|
import org.flowable.engine.impl.el.FixedValue;
|
|
import org.flowable.engine.impl.el.FixedValue;
|
|
-import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
|
|
|
|
|
|
+import org.flowable.engine.runtime.ProcessInstance;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -37,30 +39,32 @@ public class BpmCallActivityListener implements ExecutionListener {
|
|
@Resource
|
|
@Resource
|
|
private BpmProcessDefinitionService processDefinitionService;
|
|
private BpmProcessDefinitionService processDefinitionService;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private BpmProcessInstanceService processInstanceService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void notify(DelegateExecution execution) {
|
|
public void notify(DelegateExecution execution) {
|
|
String expressionText = listenerConfig.getExpressionText();
|
|
String expressionText = listenerConfig.getExpressionText();
|
|
Assert.notNull(expressionText, "监听器扩展字段({})不能为空", expressionText);
|
|
Assert.notNull(expressionText, "监听器扩展字段({})不能为空", expressionText);
|
|
BpmSimpleModelNodeVO.ChildProcessSetting.StartUserSetting startUserSetting = JsonUtils.parseObject(
|
|
BpmSimpleModelNodeVO.ChildProcessSetting.StartUserSetting startUserSetting = JsonUtils.parseObject(
|
|
expressionText, BpmSimpleModelNodeVO.ChildProcessSetting.StartUserSetting.class);
|
|
expressionText, BpmSimpleModelNodeVO.ChildProcessSetting.StartUserSetting.class);
|
|
|
|
+ ProcessInstance processInstance = processInstanceService.getProcessInstance(execution.getRootProcessInstanceId());
|
|
|
|
|
|
// 1. 当发起人来源为主流程发起人时,并兜底 startUserSetting 为空时
|
|
// 1. 当发起人来源为主流程发起人时,并兜底 startUserSetting 为空时
|
|
if (startUserSetting == null
|
|
if (startUserSetting == null
|
|
|| startUserSetting.getType().equals(BpmChildProcessStartUserTypeEnum.MAIN_PROCESS_START_USER.getType())) {
|
|
|| startUserSetting.getType().equals(BpmChildProcessStartUserTypeEnum.MAIN_PROCESS_START_USER.getType())) {
|
|
- ExecutionEntity parent = (ExecutionEntity) execution.getParent();
|
|
|
|
- FlowableUtils.setAuthenticatedUserId(Long.parseLong(parent.getStartUserId()));
|
|
|
|
|
|
+ FlowableUtils.setAuthenticatedUserId(Long.parseLong(processInstance.getStartUserId()));
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
// 2. 当发起人来源为表单时
|
|
// 2. 当发起人来源为表单时
|
|
if (startUserSetting.getType().equals(BpmChildProcessStartUserTypeEnum.FROM_FORM.getType())) {
|
|
if (startUserSetting.getType().equals(BpmChildProcessStartUserTypeEnum.FROM_FORM.getType())) {
|
|
- ExecutionEntity parent = (ExecutionEntity) execution.getParent();
|
|
|
|
- String formFieldValue = parent.getVariable(startUserSetting.getFormField(), String.class);
|
|
|
|
|
|
+ String formFieldValue = MapUtil.getStr(processInstance.getProcessVariables(), startUserSetting.getFormField());
|
|
// 2.1 当表单值为空时
|
|
// 2.1 当表单值为空时
|
|
if (StrUtil.isEmpty(formFieldValue)) {
|
|
if (StrUtil.isEmpty(formFieldValue)) {
|
|
// 2.1.1 来自主流程发起人
|
|
// 2.1.1 来自主流程发起人
|
|
if (startUserSetting.getEmptyType().equals(BpmChildProcessStartUserEmptyTypeEnum.MAIN_PROCESS_START_USER.getType())) {
|
|
if (startUserSetting.getEmptyType().equals(BpmChildProcessStartUserEmptyTypeEnum.MAIN_PROCESS_START_USER.getType())) {
|
|
- FlowableUtils.setAuthenticatedUserId(Long.parseLong(parent.getStartUserId()));
|
|
|
|
|
|
+ FlowableUtils.setAuthenticatedUserId(Long.parseLong(processInstance.getStartUserId()));
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
// 2.1.2 来自子流程管理员
|
|
// 2.1.2 来自子流程管理员
|
|
@@ -72,7 +76,7 @@ public class BpmCallActivityListener implements ExecutionListener {
|
|
}
|
|
}
|
|
// 2.1.3 来自主流程管理员
|
|
// 2.1.3 来自主流程管理员
|
|
if (startUserSetting.getEmptyType().equals(BpmChildProcessStartUserEmptyTypeEnum.MAIN_PROCESS_ADMIN.getType())) {
|
|
if (startUserSetting.getEmptyType().equals(BpmChildProcessStartUserEmptyTypeEnum.MAIN_PROCESS_ADMIN.getType())) {
|
|
- BpmProcessDefinitionInfoDO processDefinition = processDefinitionService.getProcessDefinitionInfo(parent.getProcessDefinitionId());
|
|
|
|
|
|
+ BpmProcessDefinitionInfoDO processDefinition = processDefinitionService.getProcessDefinitionInfo(processInstance.getProcessDefinitionId());
|
|
List<Long> managerUserIds = processDefinition.getManagerUserIds();
|
|
List<Long> managerUserIds = processDefinition.getManagerUserIds();
|
|
FlowableUtils.setAuthenticatedUserId(managerUserIds.get(0));
|
|
FlowableUtils.setAuthenticatedUserId(managerUserIds.get(0));
|
|
return;
|
|
return;
|
|
@@ -84,7 +88,7 @@ public class BpmCallActivityListener implements ExecutionListener {
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.error("[notify][监听器:{},子流程监听器设置流程的发起人字符串转 Long 失败,字符串:{}]",
|
|
log.error("[notify][监听器:{},子流程监听器设置流程的发起人字符串转 Long 失败,字符串:{}]",
|
|
DELEGATE_EXPRESSION, formFieldValue);
|
|
DELEGATE_EXPRESSION, formFieldValue);
|
|
- FlowableUtils.setAuthenticatedUserId(Long.parseLong(parent.getStartUserId()));
|
|
|
|
|
|
+ FlowableUtils.setAuthenticatedUserId(Long.parseLong(processInstance.getStartUserId()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|