add - 新增 Activity 事件的新实现,利用配置级的执行监听来实现
This commit is contained in:
parent
ec9986a6c9
commit
05ec1b6c4d
@ -0,0 +1,48 @@
|
||||
package cn.axzo.workflow.common.model.request.bpmn.task;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 业务节点设置审批人
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2023/12/21 13:57
|
||||
*/
|
||||
@ApiModel("业务节点设置审批人")
|
||||
@Data
|
||||
public class BpmnActivitySetAssigneeDTO {
|
||||
/**
|
||||
* PROCESS_ACTIVITY_WAIT_ASSIGNEE 事件中的触发 ID
|
||||
*/
|
||||
@ApiModelProperty(value = "等待业务推送审批的事件中的触发 ID", notes = "参考 PROCESS_ACTIVITY_WAIT_ASSIGNEE 事件")
|
||||
@NotBlank(message = "节点的触发 ID 不能为空")
|
||||
private String triggerId;
|
||||
|
||||
/**
|
||||
* 指定的活动节点 ID
|
||||
*/
|
||||
@ApiModelProperty(value = "指定的活动节点 ID", notes = "流程定义中节点的 ID")
|
||||
private String activityId;
|
||||
|
||||
/**
|
||||
* 实例 ID
|
||||
*/
|
||||
@ApiModelProperty(value = "实例 ID")
|
||||
private String processInstanceId;
|
||||
|
||||
/**
|
||||
* 需要设置的审批人, 业务侧自行去重
|
||||
*/
|
||||
@ApiModelProperty(value = "审批人集合信息", notes = "业务传参时,需要注意去重")
|
||||
@Valid
|
||||
@NotEmpty(message = "审批人不能为空")
|
||||
private List<BpmnTaskDelegateAssigner> assigners;
|
||||
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
package cn.axzo.workflow.core.engine.event;
|
||||
|
||||
import org.flowable.common.engine.api.delegate.event.FlowableEventType;
|
||||
import org.flowable.engine.delegate.DelegateExecution;
|
||||
import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 业务节点通知业务传递审批人的事件
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2023/12/21 11:36
|
||||
*/
|
||||
public class BizSpecifyAssigneeEventImpl implements BizSpecifyAssigneeEvent {
|
||||
|
||||
private final BizSpecifyAssigneeEventType type;
|
||||
private final String activityId;
|
||||
private final String activityName;
|
||||
private final String processInstanceId;
|
||||
private final String processDefinitionId;
|
||||
private final String executionId;
|
||||
private final Map<String, Object> variables;
|
||||
|
||||
public BizSpecifyAssigneeEventImpl(BizSpecifyAssigneeEventType bizSpecifyAssigneeEventType,
|
||||
DelegateExecution execution) {
|
||||
this.type = bizSpecifyAssigneeEventType;
|
||||
this.activityId = execution.getCurrentActivityId();
|
||||
this.activityName = ((ExecutionEntityImpl) execution).getCurrentActivityName();
|
||||
this.processInstanceId = execution.getProcessInstanceId();
|
||||
this.processDefinitionId = execution.getProcessDefinitionId();
|
||||
this.executionId = execution.getId();
|
||||
this.variables = execution.getVariables();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlowableEventType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getActivityId() {
|
||||
return activityId;
|
||||
}
|
||||
|
||||
public String getActivityName() {
|
||||
return activityName;
|
||||
}
|
||||
|
||||
public String getProcessInstanceId() {
|
||||
return processInstanceId;
|
||||
}
|
||||
|
||||
public String getProcessDefinitionId() {
|
||||
return processDefinitionId;
|
||||
}
|
||||
|
||||
public String getExecutionId() {
|
||||
return executionId;
|
||||
}
|
||||
|
||||
public Map<String, Object> getVariables() {
|
||||
return variables;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
package cn.axzo.workflow.core.engine.listener;
|
||||
|
||||
import cn.axzo.framework.jackson.utility.JSON;
|
||||
import cn.axzo.workflow.core.engine.event.BizSpecifyAssigneeEvent;
|
||||
import cn.axzo.workflow.core.engine.event.BizSpecifyAssigneeEventType;
|
||||
import cn.axzo.workflow.core.listener.BpmnActivityEventListener;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.flowable.common.engine.api.delegate.event.AbstractFlowableEventListener;
|
||||
import org.flowable.common.engine.api.delegate.event.FlowableEvent;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.axzo.workflow.core.engine.event.BizSpecifyAssigneeEventType.ADD_ASSIGNEE;
|
||||
import static cn.axzo.workflow.core.engine.event.BizSpecifyAssigneeEventType.REMOVE_ASSIGNEE;
|
||||
import static cn.axzo.workflow.core.engine.event.BizSpecifyAssigneeEventType.UPDATE_ASSIGNEE;
|
||||
|
||||
/**
|
||||
* Activity 节点的扩展事件, 用于处理业务节点通知业务添加审批人
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2023/12/21 11:25
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class EngineActivityExtEventListener extends AbstractFlowableEventListener {
|
||||
|
||||
@Resource
|
||||
ObjectProvider<List<BpmnActivityEventListener>> activityListeners;
|
||||
|
||||
public static final Set<BizSpecifyAssigneeEventType> BIZ_SPECIFY_ASSIGNEE_EVENTS =
|
||||
ImmutableSet.<BizSpecifyAssigneeEventType>builder()
|
||||
.add(ADD_ASSIGNEE)
|
||||
.add(UPDATE_ASSIGNEE)
|
||||
.add(REMOVE_ASSIGNEE)
|
||||
.build();
|
||||
|
||||
@Override
|
||||
public void onEvent(FlowableEvent flowableEvent) {
|
||||
if (flowableEvent instanceof BizSpecifyAssigneeEvent) {
|
||||
BizSpecifyAssigneeEvent event = (BizSpecifyAssigneeEvent) flowableEvent;
|
||||
BizSpecifyAssigneeEventType type = (BizSpecifyAssigneeEventType) event.getType();
|
||||
if (BIZ_SPECIFY_ASSIGNEE_EVENTS.contains(type)) {
|
||||
switch (type) {
|
||||
case ADD_ASSIGNEE:
|
||||
getOrderedListeners().forEach(i -> i.onWaitAssignee(event));
|
||||
break;
|
||||
case UPDATE_ASSIGNEE:
|
||||
break;
|
||||
case REMOVE_ASSIGNEE:
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<BpmnActivityEventListener> getOrderedListeners() {
|
||||
List<BpmnActivityEventListener> orderListeners = new ArrayList<>();
|
||||
activityListeners.ifAvailable(orderListeners::addAll);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Order Lists: {}", JSON.toJSONString(orderListeners));
|
||||
}
|
||||
return orderListeners;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFailOnException() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package cn.axzo.workflow.core.engine.listener;
|
||||
|
||||
import cn.axzo.framework.jackson.utility.JSON;
|
||||
import cn.axzo.workflow.core.listener.BpmnActivityEventListener;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.flowable.engine.delegate.DelegateExecution;
|
||||
import org.flowable.engine.delegate.ExecutionListener;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 活动节点开始事件监听器
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2023/12/21 16:55
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class EngineActivityTakeEventListener implements ExecutionListener {
|
||||
|
||||
@Resource
|
||||
ObjectProvider<List<BpmnActivityEventListener>> activityListeners;
|
||||
|
||||
@Override
|
||||
public void notify(DelegateExecution execution) {
|
||||
log.info("EngineActivityTakeEventListener Event: {}", execution.getEventName());
|
||||
getOrderedListeners().forEach(i -> i.onTake(execution));
|
||||
}
|
||||
|
||||
private List<BpmnActivityEventListener> getOrderedListeners() {
|
||||
List<BpmnActivityEventListener> orderListeners = new ArrayList<>();
|
||||
activityListeners.ifAvailable(orderListeners::addAll);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Order Lists: {}", JSON.toJSONString(orderListeners));
|
||||
}
|
||||
return orderListeners;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user