|
@@ -15,11 +15,11 @@ import com.flow.flowable.utils.ProcessElementUtil;
|
|
|
import com.flow.model.FormInfo;
|
|
|
import com.flow.service.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.flowable.bpmn.model.FlowElement;
|
|
|
-import org.flowable.bpmn.model.UserTask;
|
|
|
+import org.flowable.bpmn.model.*;
|
|
|
import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
|
|
|
import org.flowable.common.engine.api.delegate.event.FlowableEngineEvent;
|
|
|
import org.flowable.engine.ManagementService;
|
|
|
+import org.flowable.engine.RepositoryService;
|
|
|
import org.flowable.engine.RuntimeService;
|
|
|
import org.flowable.engine.TaskService;
|
|
|
import org.flowable.engine.delegate.DelegateExecution;
|
|
@@ -28,6 +28,7 @@ import org.flowable.engine.delegate.event.FlowableCancelledEvent;
|
|
|
import org.flowable.engine.delegate.event.FlowableProcessStartedEvent;
|
|
|
import org.flowable.engine.delegate.event.impl.FlowableProcessCancelledEventImpl;
|
|
|
import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl;
|
|
|
+import org.flowable.engine.repository.ProcessDefinition;
|
|
|
import org.flowable.engine.runtime.ProcessInstance;
|
|
|
import org.flowable.task.service.impl.persistence.entity.TaskEntityImpl;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -36,6 +37,7 @@ import org.springframework.transaction.support.TransactionSynchronization;
|
|
|
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.Collection;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
@@ -60,6 +62,8 @@ public class GlobalActivityEventListener extends AbstractFlowableEngineEventList
|
|
|
|
|
|
@Autowired
|
|
|
private UserService userService;
|
|
|
+ @Autowired
|
|
|
+ private RepositoryService repositoryService;
|
|
|
|
|
|
// 任务创建监听器
|
|
|
@Override
|
|
@@ -146,7 +150,44 @@ public class GlobalActivityEventListener extends AbstractFlowableEngineEventList
|
|
|
|
|
|
// 审批节点
|
|
|
notify.setContent(fromName + "-" + entity.getName());
|
|
|
- notify.setSender(userByUserId.getUsername());
|
|
|
+
|
|
|
+ // 获取流程定义-判断是否为第一个和最后一个节点
|
|
|
+ ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
|
|
|
+ .processDefinitionId(execution.getProcessDefinitionId())
|
|
|
+ .singleResult();
|
|
|
+
|
|
|
+ // 获取流程定义中的所有流元素-判断是否为第一个和最后一个节点
|
|
|
+ BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
|
|
|
+ Collection<FlowElement> flowElements = bpmnModel.getMainProcess().getFlowElements();
|
|
|
+
|
|
|
+ // 获取第一个节点(开始事件)和最后一个节点(结束事件)的 ID-判断是否为第一个和最后一个节点
|
|
|
+ String startActivityId = null;
|
|
|
+ String endActivityId = null;
|
|
|
+ for (FlowElement flowElement : flowElements) {
|
|
|
+ if (flowElement instanceof StartEvent) {
|
|
|
+ startActivityId = flowElement.getId();
|
|
|
+ } else if (flowElement instanceof EndEvent) {
|
|
|
+ endActivityId = flowElement.getId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断是否是第一个节点或最后一个节点
|
|
|
+ boolean isFirstNode = currentFlowElement.getId().equals(startActivityId);
|
|
|
+ boolean isLastNode = currentFlowElement.getId().equals(endActivityId);
|
|
|
+
|
|
|
+
|
|
|
+ // // 判断是否是第一个节点或最后一个节点
|
|
|
+ // boolean isFirstNode = ProcessElementUtil.isFirstNode(currentFlowElement);
|
|
|
+ // boolean isLastNode = ProcessElementUtil.isLastNode(currentFlowElement);
|
|
|
+ //
|
|
|
+ if (isFirstNode || isLastNode) {
|
|
|
+ // 第一个节点或最后一个节点,消息发送人为当前登录用户
|
|
|
+ notify.setSender(SecurityContextUtil.getUserId());
|
|
|
+ } else {
|
|
|
+ // 其余节点,消息发送人为发起人
|
|
|
+ notify.setSender(userByUserId.getUsername());
|
|
|
+ }
|
|
|
+
|
|
|
notify.setType(NotifyEnum.TODO);
|
|
|
// 接收者 entity.getAssignee() 下一节点的审批人
|
|
|
notify.setReceiver(entity.getAssignee());
|