工作流Flowable实战 (六)自定义身份


一、重写Flowable接口

系统中肯定有自己的一套用户,而flowable默认用户和用户组无法和自己系统中的用户统一,所以重写floeable用户和用户组接口,让flowable直接查自己的用户数据。
EditorUsersResource,EditorGroupsResource
在这里插入图片描述

二、自定义审核人

1、前端增加选项

flowable默认有分配给流程发起人,想自定义一个分配给流程发起人上级领导,如何实现。
在这里插入图片描述
在这里插入图片描述

修改flowable-modeler源码,此时页面中会多出一个选项。
在这里插入图片描述

1、后端监听

后端监听器监听任务的创建事件,动态赋值任务的审核人。

@Configuration
public class FlowableGlobListenerConfig implements ApplicationListener<ContextRefreshedEvent> {
	@Autowired
	private SpringProcessEngineConfiguration configuration;

	@Autowired
	private GlobalTaskCreatedListener globalTaskCreatedListener;

	@Override
	public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
		FlowableEventDispatcher dispatcher = configuration.getEventDispatcher();
		dispatcher.addEventListener(globalTaskCreatedListener, FlowableEngineEventType.TASK_CREATED);
	}
}
@Component
@Slf4j
public class GlobalTaskCreatedListener implements FlowableEventListener {
	@Autowired
	private TaskService taskService;
	@Autowired
	private RuntimeService runtimeService;
	@Autowired
	private RepositoryService repositoryService;

	@Override
	public void onEvent(FlowableEvent event) {
		FlowableEntityEventImpl entityEvent = (FlowableEntityEventImpl) event;
		TaskEntity taskEntity = (TaskEntity) entityEvent.getEntity();
		String processInstanceId = taskEntity.getProcessInstanceId();
		BpmnModel bpmnModel = repositoryService.getBpmnModel(taskEntity.getProcessDefinitionId());
		List<Process> processes = bpmnModel.getProcesses();

		processes.forEach(process -> process.findFlowElementsOfType(UserTask.class).forEach(userTask -> {
			if (StringUtil.equals(userTask.getId(), taskEntity.getTaskDefinitionKey()) && StringUtil.isNotBlank(userTask.getAssignee())) {
				ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
				if (StringUtil.equals(userTask.getAssignee().toLowerCase(), FlowAssigneeEnum.INITIATOR.getKey())) {
					taskService.setAssignee(taskEntity.getId(), processInstance.getStartUserId());
				} else if (StringUtil.equals(userTask.getAssignee().toLowerCase(), FlowAssigneeEnum.SUPERIOR.getKey())) {
					String startUserId = processInstance.getStartUserId();
					User startUser = UserCache.getUser(Long.parseLong(startUserId));
					startUser.getDeptId();
					// TODO 自行实现获取上级领导用户id
				}
			}
		}));
	}
}
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
Flowable是一个轻量级的工作流引擎,它具有可配置、可扩展和可重用的特性。它可以用于处理业务流程、审批流程、工作流等场景。 下面是一个Flowable工作流实战: 1. 创建流程定义文件 首先需要创建一个流程定义文件,它通常是一个XML文件,描述了流程中的各个节点、任务、流程变量等信息。可以使用Flowable Designer或者手动创建文件。例如,以下是一个简单的流程定义文件: ``` <?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:flowable="http://flowable.org/bpmn" targetNamespace="http://activiti.org/bpmn20" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd http://flowable.org/bpmn http://flowable.org/xsd/bpmn/flowable-bpmn-2.0.xsd" id="simpleProcess"> <process id="myProcess" name="My process" isExecutable="true"> <startEvent id="startEvent" /> <sequenceFlow id="flow1" sourceRef="startEvent" targetRef="task1" /> <userTask id="task1" name="Task 1" flowable:assignee="${assignee}" /> <sequenceFlow id="flow2" sourceRef="task1" targetRef="endEvent" /> <endEvent id="endEvent" /> </process> </definitions> ``` 2. 部署流程定义文件 部署流程定义文件可以使用Flowable的API或者管理控制台。例如,以下是使用Flowable的API进行部署的示例代码: ``` ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); RepositoryService repositoryService = processEngine.getRepositoryService(); Deployment deployment = repositoryService.createDeployment() .addClasspathResource("simpleProcess.bpmn20.xml") .deploy(); ``` 3. 启动流程实例 启动流程实例可以使用Flowable的API或者通过调用REST API。例如,以下是使用Flowable的API进行流程实例启动的示例代码: ``` ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); RuntimeService runtimeService = processEngine.getRuntimeService(); Map<String, Object> variables = new HashMap<>(); variables.put("assignee", "user1"); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess", variables); ``` 4. 处理任务 处理任务可以使用Flowable的API或者通过调用REST API。例如,以下是使用Flowable的API进行任务处理的示例代码: ``` ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); TaskService taskService = processEngine.getTaskService(); Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult(); taskService.complete(task.getId()); ``` 5. 监控流程实例 可以使用Flowable的API或者Flowable的管理控制台进行流程实例监控。例如,以下是使用Flowable的API进行流程实例监控的示例代码: ``` ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); HistoryService historyService = processEngine.getHistoryService(); List<HistoricProcessInstance> processInstances = historyService.createHistoricProcessInstanceQuery().list(); ``` 以上是一个简单的Flowable工作流实战示例,可根据实际需求进行调整和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值