flowable集成
This commit is contained in:
parent
293d34b6a0
commit
4568783e2e
|
@ -1,5 +1,6 @@
|
|||
package com.snow;
|
||||
|
||||
import com.snow.flowable.common.SpringContextUtil;
|
||||
import org.flowable.ui.common.rest.idm.remote.RemoteAccountResource;
|
||||
import org.flowable.ui.modeler.properties.FlowableModelerAppProperties;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
@ -8,6 +9,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|||
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
|
@ -37,7 +39,9 @@ public class SnowApplication
|
|||
public static void main(String[] args)
|
||||
{
|
||||
// System.setProperty("spring.devtools.restart.enabled", "false");
|
||||
SpringApplication.run(SnowApplication.class, args);
|
||||
//SpringApplication.run(SnowApplication.class, args);
|
||||
ApplicationContext context=SpringApplication.run(SnowApplication.class, args);
|
||||
SpringContextUtil.setApplicationContext(context);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package com.snow.flowable.common;
|
||||
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
/**
|
||||
* @program: snow
|
||||
* @description
|
||||
* @author: 没用的阿吉
|
||||
* @create: 2020-12-07 21:56
|
||||
**/
|
||||
public class SpringContextUtil {
|
||||
|
||||
|
||||
private static ApplicationContext applicationContext;
|
||||
|
||||
//获取上下文
|
||||
public static ApplicationContext getApplicationContext() {
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
//设置上下文
|
||||
public static void setApplicationContext(ApplicationContext applicationContext) {
|
||||
SpringContextUtil.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
//通过名字获取上下文中的bean
|
||||
public static Object getBean(String name){
|
||||
return applicationContext.getBean(name);
|
||||
}
|
||||
|
||||
//通过类型获取上下文中的bean
|
||||
public static Object getBean(Class<?> requiredType){
|
||||
return applicationContext.getBean(requiredType);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,21 +1,29 @@
|
|||
package com.snow.flowable.listener;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.snow.flowable.common.SpringContextUtil;
|
||||
import com.snow.flowable.common.constants.FlowConstants;
|
||||
import com.snow.flowable.common.enums.FlowDefEnum;
|
||||
import com.snow.flowable.service.FlowableService;
|
||||
|
||||
import com.snow.flowable.service.impl.FlowableServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.flowable.bpmn.model.Task;
|
||||
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
|
||||
import org.flowable.common.engine.api.delegate.event.FlowableEvent;
|
||||
import org.flowable.common.engine.api.delegate.event.FlowableEventListener;
|
||||
import org.flowable.common.engine.impl.event.FlowableEngineEventImpl;
|
||||
import org.flowable.common.engine.impl.event.FlowableEntityEventImpl;
|
||||
|
||||
import org.flowable.engine.RepositoryService;
|
||||
import org.flowable.engine.delegate.event.impl.FlowableEntityEventImpl;
|
||||
import org.flowable.engine.history.HistoricProcessInstance;
|
||||
|
||||
import org.flowable.engine.repository.ProcessDefinition;
|
||||
import org.flowable.engine.runtime.ProcessInstance;
|
||||
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.flowable.task.service.impl.persistence.entity.TaskEntityImpl;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -25,55 +33,59 @@ import java.util.Map;
|
|||
* @Description: 全局事件监听
|
||||
* @date 2020/12/7 18:13
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AbstractEventListener implements FlowableEventListener {
|
||||
@Autowired
|
||||
private FlowableServiceImpl flowableService;
|
||||
@Autowired
|
||||
private RepositoryService repositoryService;
|
||||
|
||||
|
||||
@Override
|
||||
public void onEvent(FlowableEvent flowableEvent) {
|
||||
if (!(flowableEvent instanceof FlowableEntityEventImpl)) {
|
||||
RepositoryService repositoryService = (RepositoryService)SpringContextUtil.getBean(RepositoryService.class);
|
||||
|
||||
FlowableServiceImpl flowableService = (FlowableServiceImpl)SpringContextUtil.getBean(FlowableServiceImpl.class);
|
||||
|
||||
if (!(flowableEvent instanceof FlowableEngineEventImpl)) {
|
||||
return;
|
||||
}
|
||||
FlowableEntityEventImpl entityEvent = (FlowableEntityEventImpl) flowableEvent;
|
||||
FlowableEngineEventImpl entityEvent = (FlowableEngineEventImpl) flowableEvent;
|
||||
log.info("监听到的事件类型:{}",entityEvent.getType());
|
||||
Object entity = entityEvent.getEntity();
|
||||
|
||||
//是否是任务实体类
|
||||
if (!(entity instanceof TaskEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
TaskEntity taskEntity = (TaskEntity) entity;
|
||||
|
||||
|
||||
FlowableEngineEventType type = entityEvent.getType();
|
||||
log.info("监听到的事件类型:{}",type.name());
|
||||
// log.info("监听到的事件类型:{}",type.name());
|
||||
String processInstanceId = entityEvent.getProcessInstanceId();
|
||||
if(type.name().equals("TASK_CREATED")){
|
||||
Object variableLocal = taskEntity.getVariableLocal(FlowConstants.IS_PASS);
|
||||
ProcessDefinition processDefinition = repositoryService.getProcessDefinition(processInstanceId);
|
||||
if(processDefinition.getName().equals(FlowDefEnum.SNOW_OA_LEAVE.getCode())){
|
||||
HistoricProcessInstance historicProcessInstance = flowableService.getHistoricProcessInstanceById(processInstanceId);
|
||||
Map<String, Object> processVariables = historicProcessInstance.getProcessVariables();
|
||||
if(type.name().equals("TASK_COMPLETED")){
|
||||
//todo
|
||||
log.info("任务已完成,这个时候可以处理一些业务逻辑");
|
||||
ProcessDefinition processDefinition = repositoryService.getProcessDefinition(entityEvent.getProcessDefinitionId());
|
||||
if(processDefinition.getKey().equals(FlowDefEnum.SNOW_OA_LEAVE.getCode())){
|
||||
ProcessInstance processInstance= flowableService.getProcessInstanceById(processInstanceId);
|
||||
Map<String, Object> processVariables = processInstance.getProcessVariables();
|
||||
processVariables.get(FlowConstants.IS_PASS);
|
||||
log.info("processVariables:{}",JSON.toJSONString(processVariables));
|
||||
|
||||
}
|
||||
FlowableEntityEventImpl flowableEntityEvent = (FlowableEntityEventImpl) flowableEvent;
|
||||
log.info("flowableEntityEvent:{}",JSON.toJSONString(flowableEntityEvent));
|
||||
TaskEntity entity = (TaskEntity)flowableEntityEvent.getEntity();
|
||||
Object variable = entity.getVariable(FlowConstants.IS_PASS);
|
||||
log.info("entity:{}",JSON.toJSONString(entity));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
if(type.name().equals("TASK_ASSIGNED")){
|
||||
FlowableEntityEventImpl flowableEntityEvent = (FlowableEntityEventImpl) flowableEvent;
|
||||
log.info("TASK_ASSIGNED-flowableEntityEvent:{}",JSON.toJSONString(flowableEntityEvent));
|
||||
//todo
|
||||
log.info("任务已分配,这个时候可以发送短信,邮件通知");
|
||||
}
|
||||
|
||||
if(type.name().equals("TASK_COMPLETED")){
|
||||
if(type.name().equals("TASK_CREATED")){
|
||||
//todo
|
||||
log.info("任务已完成,这个时候可以处理一些业务逻辑");
|
||||
log.info("任务创建,这个时候可以处理一些业务逻辑");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue