|
@@ -1,16 +1,14 @@
|
|
package com.flow.listener;
|
|
package com.flow.listener;
|
|
|
|
|
|
-import com.flow.entity.FlowDefine;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
import com.flow.entity.Notify;
|
|
import com.flow.entity.Notify;
|
|
-import com.flow.entity.node.ApprovalNode;
|
|
|
|
-import com.flow.entity.node.TimerBoundary;
|
|
|
|
import com.flow.enums.ApprovalTimeoutEnum;
|
|
import com.flow.enums.ApprovalTimeoutEnum;
|
|
import com.flow.enums.NotifyEnum;
|
|
import com.flow.enums.NotifyEnum;
|
|
-import com.flow.enums.TimeUnitEnum;
|
|
|
|
-import com.flow.service.FlowDefineService;
|
|
|
|
|
|
+import com.flow.flowable.utils.ProcessElementUtil;
|
|
import com.flow.service.FlowTaskService;
|
|
import com.flow.service.FlowTaskService;
|
|
import com.flow.service.NotifyService;
|
|
import com.flow.service.NotifyService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.flowable.bpmn.model.BoundaryEvent;
|
|
import org.flowable.engine.TaskService;
|
|
import org.flowable.engine.TaskService;
|
|
import org.flowable.engine.delegate.DelegateExecution;
|
|
import org.flowable.engine.delegate.DelegateExecution;
|
|
import org.flowable.engine.delegate.ExecutionListener;
|
|
import org.flowable.engine.delegate.ExecutionListener;
|
|
@@ -20,7 +18,6 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
-import java.util.Objects;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* 审批超时处理
|
|
* 审批超时处理
|
|
@@ -28,8 +25,6 @@ import java.util.Objects;
|
|
@Slf4j
|
|
@Slf4j
|
|
@Component
|
|
@Component
|
|
public class ApprovalTimeoutListener implements ExecutionListener {
|
|
public class ApprovalTimeoutListener implements ExecutionListener {
|
|
- @Autowired
|
|
|
|
- private FlowDefineService flowDefineService;
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private FlowTaskService flowTaskService;
|
|
private FlowTaskService flowTaskService;
|
|
@Autowired
|
|
@Autowired
|
|
@@ -39,49 +34,36 @@ public class ApprovalTimeoutListener implements ExecutionListener {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void notify(DelegateExecution delegateExecution) {
|
|
public void notify(DelegateExecution delegateExecution) {
|
|
- String currentActivityId = delegateExecution.getCurrentActivityId();
|
|
|
|
- FlowDefine define = flowDefineService.getDefine(delegateExecution.getProcessDefinitionId());
|
|
|
|
- String nodeId = currentActivityId.replaceAll("_boundary", "");
|
|
|
|
- ApprovalNode approvalNode = define.getNode(nodeId, ApprovalNode.class);
|
|
|
|
- TimerBoundary timeout = approvalNode.getTimeout();
|
|
|
|
- Boolean enabled = timeout.getEnabled();
|
|
|
|
- if (Objects.nonNull(enabled) && enabled) {
|
|
|
|
- ApprovalTimeoutEnum timeoutAction = timeout.getAction();
|
|
|
|
- Integer duration = timeout.getDuration();
|
|
|
|
- TimeUnitEnum unit = timeout.getUnit();
|
|
|
|
- List<Task> taskList = taskService.createTaskQuery()
|
|
|
|
|
|
+ BoundaryEvent boundaryEvent = (BoundaryEvent) delegateExecution.getCurrentFlowElement();
|
|
|
|
+ String action = ProcessElementUtil.getExtensionElementValue(boundaryEvent, "action");
|
|
|
|
+ if (StringUtils.isNotBlank(action)) {
|
|
|
|
+ List<Task> tasks = taskService.createTaskQuery()
|
|
.processInstanceId(delegateExecution.getProcessInstanceId())
|
|
.processInstanceId(delegateExecution.getProcessInstanceId())
|
|
- .taskDefinitionKey(nodeId)
|
|
|
|
|
|
+ .taskDefinitionKey(boundaryEvent.getAttachedToRefId())
|
|
.list();
|
|
.list();
|
|
- switch (timeoutAction) {
|
|
|
|
- case AUTO_PASS:
|
|
|
|
- // 自动通过
|
|
|
|
- for (Task task : taskList) {
|
|
|
|
- flowTaskService.autoComplete(task.getId());
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
- case AUTO_REFUSE:
|
|
|
|
- // 自动拒绝
|
|
|
|
- for (Task task : taskList) {
|
|
|
|
- flowTaskService.autoRefuse(task.getId());
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
- case REMIND:
|
|
|
|
- // 提醒
|
|
|
|
- for (Task task : taskList) {
|
|
|
|
- Notify notify = new Notify();
|
|
|
|
- notify.setSender("admin");
|
|
|
|
- notify.setType(NotifyEnum.SYSTEM);
|
|
|
|
- notify.setReceivingTime(LocalDateTime.now());
|
|
|
|
- notify.setReceiver(task.getAssignee());
|
|
|
|
- notify.setUrl("/flow/todo");
|
|
|
|
- notify.setSubject("审批提醒");
|
|
|
|
- notify.setContent(String.format("您的审批任务【%s】已超%s%s未处理,请及时处理。", task.getName(), duration, unit.getDescription()));
|
|
|
|
- notifyService.notify(notify);
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- break;
|
|
|
|
|
|
+ if (action.equals(ApprovalTimeoutEnum.AUTO_PASS.getAction())) {
|
|
|
|
+ // 自动通过
|
|
|
|
+ for (Task task : tasks) {
|
|
|
|
+ flowTaskService.autoComplete(task.getId());
|
|
|
|
+ }
|
|
|
|
+ } else if (action.equals(ApprovalTimeoutEnum.AUTO_REFUSE.getAction())) {
|
|
|
|
+ // 自动拒绝
|
|
|
|
+ for (Task task : tasks) {
|
|
|
|
+ flowTaskService.autoRefuse(task.getId());
|
|
|
|
+ }
|
|
|
|
+ } else if (action.equals(ApprovalTimeoutEnum.REMIND.getAction())) {
|
|
|
|
+ // 提醒
|
|
|
|
+ for (Task task : tasks) {
|
|
|
|
+ Notify notify = new Notify();
|
|
|
|
+ notify.setSender("admin");
|
|
|
|
+ notify.setType(NotifyEnum.SYSTEM);
|
|
|
|
+ notify.setReceivingTime(LocalDateTime.now());
|
|
|
|
+ notify.setReceiver(task.getAssignee());
|
|
|
|
+ notify.setUrl("/flow/todo");
|
|
|
|
+ notify.setSubject("审批提醒");
|
|
|
|
+ notify.setContent(String.format("您的审批任务【%s】已超时,请及时处理。", task.getName()));
|
|
|
|
+ notifyService.notify(notify);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|