mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-19 19:50:06 +08:00
增加 BpmUserTaskActivitiBehavior 自定义实现,为后续做自定义的任务分配机制做准备
This commit is contained in:
parent
9734eacf01
commit
645fd7624b
@ -1,26 +0,0 @@
|
|||||||
package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti;
|
|
||||||
|
|
||||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.task.listener.BpmTackActivitiEventListener;
|
|
||||||
import org.activiti.spring.SpringProcessEngineConfiguration;
|
|
||||||
import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BPM 模块的 Activiti 配置类
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class BpmActivitiConfiguration implements ProcessEngineConfigurationConfigurer {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private BpmTackActivitiEventListener taskActivitiEventListener;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void configure(SpringProcessEngineConfiguration configuration) {
|
|
||||||
// 注册监听器,例如说 BpmActivitiEventListener
|
|
||||||
configuration.setEventListeners(Collections.singletonList(taskActivitiEventListener));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,51 @@
|
|||||||
|
package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.config;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.behavior.BpmActivityBehaviorFactory;
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.listener.BpmTackActivitiEventListener;
|
||||||
|
import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import static org.activiti.spring.boot.ProcessEngineAutoConfiguration.BEHAVIOR_FACTORY_MAPPING_CONFIGURER;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BPM 模块的 Activiti 配置类
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class BpmActivitiConfiguration {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BPM 模块的 ProcessEngineConfigurationConfigurer 实现类,主要设置各种监听器
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public ProcessEngineConfigurationConfigurer bpmProcessEngineConfigurationConfigurer(
|
||||||
|
BpmTackActivitiEventListener taskActivitiEventListener) {
|
||||||
|
return configuration -> {
|
||||||
|
// 注册监听器,例如说 BpmActivitiEventListener
|
||||||
|
configuration.setEventListeners(Collections.singletonList(taskActivitiEventListener));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于设置自定义的 ActivityBehaviorFactory 实现的 ProcessEngineConfigurationConfigurer 实现类
|
||||||
|
*
|
||||||
|
* 目的:覆盖 {@link org.activiti.spring.boot.ProcessEngineAutoConfiguration} 的
|
||||||
|
* defaultActivityBehaviorFactoryMappingConfigurer 方法创建的 Bean
|
||||||
|
*/
|
||||||
|
@Bean(name = BEHAVIOR_FACTORY_MAPPING_CONFIGURER)
|
||||||
|
public ProcessEngineConfigurationConfigurer defaultActivityBehaviorFactoryMappingConfigurer(
|
||||||
|
BpmActivityBehaviorFactory bpmActivityBehaviorFactory) {
|
||||||
|
return configuration -> {
|
||||||
|
// 设置 ActivityBehaviorFactory 实现类,用于流程任务的审核人的自定义
|
||||||
|
configuration.setActivityBehaviorFactory(bpmActivityBehaviorFactory);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public BpmActivityBehaviorFactory bpmActivityBehaviorFactory() {
|
||||||
|
return new BpmActivityBehaviorFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.behavior;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.behavior.BpmUserTaskActivitiBehavior;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
import org.activiti.bpmn.model.UserTask;
|
||||||
|
import org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior;
|
||||||
|
import org.activiti.engine.impl.bpmn.parser.factory.DefaultActivityBehaviorFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义的 ActivityBehaviorFactory 实现类,目的如下:
|
||||||
|
* 1. 自定义 {@link #createUserTaskActivityBehavior(UserTask)}:实现自定义的流程任务的 assignee 负责人的分配
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public class BpmActivityBehaviorFactory extends DefaultActivityBehaviorFactory {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserTaskActivityBehavior createUserTaskActivityBehavior(UserTask userTask) {
|
||||||
|
return new BpmUserTaskActivitiBehavior(userTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO 芋艿:并行任务 ParallelMultiInstanceBehavior
|
||||||
|
|
||||||
|
// TODO 芋艿:并行任务 SequentialMultiInstanceBehavior
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.behavior;
|
||||||
|
|
||||||
|
import org.activiti.bpmn.model.UserTask;
|
||||||
|
import org.activiti.engine.delegate.DelegateExecution;
|
||||||
|
import org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior;
|
||||||
|
import org.activiti.engine.impl.el.ExpressionManager;
|
||||||
|
import org.activiti.engine.impl.persistence.entity.TaskEntity;
|
||||||
|
import org.activiti.engine.impl.persistence.entity.TaskEntityManager;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义的流程任务的 assignee 负责人的分配
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
public class BpmUserTaskActivitiBehavior extends UserTaskActivityBehavior {
|
||||||
|
|
||||||
|
public BpmUserTaskActivitiBehavior(UserTask userTask) {
|
||||||
|
super(userTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleAssignments(TaskEntityManager taskEntityManager,
|
||||||
|
String assignee, String owner, List<String> candidateUsers, List<String> candidateGroups,
|
||||||
|
TaskEntity task, ExpressionManager expressionManager, DelegateExecution execution) {
|
||||||
|
System.out.println("");
|
||||||
|
taskEntityManager.changeTaskAssignee(task, "1");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package cn.iocoder.yudao.adminserver.modules.bpm.service.task.listener;
|
package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.listener;
|
||||||
|
|
||||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.task.BpmProcessInstanceExtDO;
|
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.task.BpmProcessInstanceExtDO;
|
||||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmProcessInstanceService;
|
import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmProcessInstanceService;
|
@ -1,4 +1,4 @@
|
|||||||
package cn.iocoder.yudao.adminserver.modules.bpm.service.task.listener;
|
package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.listener;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmProcessDefinitionService;
|
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmProcessDefinitionService;
|
@ -1,10 +1,14 @@
|
|||||||
package cn.iocoder.yudao.adminserver.modules.bpm.service.task.listener;
|
package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.listener;
|
||||||
|
|
||||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.task.BpmTaskExtDO;
|
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.task.BpmTaskExtDO;
|
||||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmTaskService;
|
import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmTaskService;
|
||||||
|
import org.activiti.api.model.shared.event.RuntimeEvent;
|
||||||
|
import org.activiti.api.process.model.ProcessInstance;
|
||||||
|
import org.activiti.api.process.model.events.ProcessRuntimeEvent;
|
||||||
import org.activiti.api.task.model.Task;
|
import org.activiti.api.task.model.Task;
|
||||||
import org.activiti.api.task.model.events.TaskRuntimeEvent;
|
import org.activiti.api.task.model.events.TaskRuntimeEvent;
|
||||||
import org.activiti.api.task.runtime.events.listener.TaskEventListener;
|
import org.activiti.api.task.runtime.events.listener.TaskEventListener;
|
||||||
|
import org.activiti.api.task.runtime.events.listener.TaskRuntimeEventListener;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@ -16,15 +20,22 @@ import javax.annotation.Resource;
|
|||||||
* @author 芋道源码
|
* @author 芋道源码
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class BpmTaskEventListener<T extends TaskRuntimeEvent<? extends Task>>
|
public class BpmTaskEventListener<T extends RuntimeEvent<?, ?>>
|
||||||
implements TaskEventListener<T> {
|
implements TaskRuntimeEventListener<T> {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Lazy // 解决循环依赖
|
@Lazy // 解决循环依赖
|
||||||
private BpmTaskService taskService;
|
private BpmTaskService taskService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEvent(T event) {
|
@SuppressWarnings("unchecked")
|
||||||
|
public void onEvent(T rawEvent) {
|
||||||
|
// 由于 TaskRuntimeEventListener 无法保证只监听 TaskRuntimeEvent 事件,所以通过这样的方式
|
||||||
|
if (!(rawEvent instanceof TaskRuntimeEvent)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TaskRuntimeEvent<Task> event = (TaskRuntimeEvent<Task>) rawEvent;
|
||||||
|
|
||||||
// 创建时,插入拓展表
|
// 创建时,插入拓展表
|
||||||
if (event.getEventType() == TaskRuntimeEvent.TaskEvents.TASK_CREATED) {
|
if (event.getEventType() == TaskRuntimeEvent.TaskEvents.TASK_CREATED) {
|
||||||
taskService.createTaskExt(event.getEntity());
|
taskService.createTaskExt(event.getEntity());
|
@ -15,8 +15,11 @@ import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
|||||||
import cn.iocoder.yudao.framework.common.util.object.PageUtils;
|
import cn.iocoder.yudao.framework.common.util.object.PageUtils;
|
||||||
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
|
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.activiti.bpmn.converter.BpmnXMLConverter;
|
||||||
|
import org.activiti.bpmn.model.BpmnModel;
|
||||||
import org.activiti.engine.RepositoryService;
|
import org.activiti.engine.RepositoryService;
|
||||||
import org.activiti.engine.impl.persistence.entity.SuspensionState;
|
import org.activiti.engine.impl.persistence.entity.SuspensionState;
|
||||||
|
import org.activiti.engine.impl.util.io.StringStreamSource;
|
||||||
import org.activiti.engine.repository.Deployment;
|
import org.activiti.engine.repository.Deployment;
|
||||||
import org.activiti.engine.repository.Model;
|
import org.activiti.engine.repository.Model;
|
||||||
import org.activiti.engine.repository.ModelQuery;
|
import org.activiti.engine.repository.ModelQuery;
|
||||||
@ -27,6 +30,8 @@ import org.springframework.util.ObjectUtils;
|
|||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.xml.stream.XMLInputFactory;
|
||||||
|
import javax.xml.stream.XMLStreamReader;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -211,4 +216,11 @@ public class BpmModelServiceImpl implements BpmModelService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public static void main(String[] args) {
|
||||||
|
// // 创建转换对象
|
||||||
|
// BpmnXMLConverter converter = new BpmnXMLConverter();
|
||||||
|
// BpmnModel bpmnModel = converter.convertToBpmnModel(new StringStreamSource(""), true, true);
|
||||||
|
// bpmnModel.getProcesses()
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -87,8 +87,8 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
|
|||||||
runtimeService.setProcessInstanceName(instance.getId(), definition.getName());
|
runtimeService.setProcessInstanceName(instance.getId(), definition.getName());
|
||||||
|
|
||||||
// TODO 芋艿:临时使用, 保证分配
|
// TODO 芋艿:临时使用, 保证分配
|
||||||
List<Task> tasks = taskService.getTasksByProcessInstanceId(instance.getId());
|
// List<Task> tasks = taskService.getTasksByProcessInstanceId(instance.getId());
|
||||||
tasks.forEach(task -> taskService.updateTaskAssign(task.getId(), userId));
|
// tasks.forEach(task -> taskService.updateTaskAssign(task.getId(), userId));
|
||||||
|
|
||||||
// 添加初始的评论 TODO 芋艿:在思考下
|
// 添加初始的评论 TODO 芋艿:在思考下
|
||||||
// Task task = taskService.createTaskQuery().processInstanceId(instance.getId()).singleResult();
|
// Task task = taskService.createTaskQuery().processInstanceId(instance.getId()).singleResult();
|
||||||
|
Loading…
Reference in New Issue
Block a user