flowable集成

This commit is contained in:
459816669@qq.com 2020-12-07 21:04:17 +08:00
parent c13f146814
commit 293d34b6a0
6 changed files with 124 additions and 46 deletions

View File

@ -270,16 +270,12 @@ public class SysOaLeaveController extends BaseController
Integer checkStatus = finishTaskDTO.getCheckStatus(); Integer checkStatus = finishTaskDTO.getCheckStatus();
if(checkStatus==0){ if(checkStatus==0){
completeTaskDTO.setIsPass(true); completeTaskDTO.setIsPass(true);
sysOaLeave.setProcessStatus(ProcessStatus.PASS.ordinal());
}else { }else {
completeTaskDTO.setIsPass(false); completeTaskDTO.setIsPass(false);
sysOaLeave.setProcessStatus(ProcessStatus.REJECT.ordinal());
} }
completeTaskDTO.setComment(finishTaskDTO.getSuggestion()); completeTaskDTO.setComment(finishTaskDTO.getSuggestion());
flowableService.completeTask(completeTaskDTO); flowableService.completeTask(completeTaskDTO);
sysOaLeave.setUpdateBy(sysUser.getUserName()); return AjaxResult.success();
int i = sysOaLeaveService.updateSysOaLeaveByLeaveNo(sysOaLeave);
return toAjax(i);
} }
/** /**
@ -291,7 +287,6 @@ public class SysOaLeaveController extends BaseController
public AjaxResult reStartTask(LeaveFinishTaskDTO sysOaLeave) public AjaxResult reStartTask(LeaveFinishTaskDTO sysOaLeave)
{ {
SysUser sysUser = ShiroUtils.getSysUser(); SysUser sysUser = ShiroUtils.getSysUser();
sysOaLeave.setApplyPerson(sysUser.getUserName()); sysOaLeave.setApplyPerson(sysUser.getUserName());
int i = sysOaLeaveService.updateSysOaLeave(sysOaLeave); int i = sysOaLeaveService.updateSysOaLeave(sysOaLeave);
SysOaLeave newSysOaLeave = sysOaLeaveService.selectSysOaLeaveById(sysOaLeave.getId()); SysOaLeave newSysOaLeave = sysOaLeaveService.selectSysOaLeaveById(sysOaLeave.getId());

View File

@ -1,5 +1,8 @@
package com.snow.flowable.config; package com.snow.flowable.config;
import com.google.common.collect.Lists;
import com.snow.flowable.listener.AbstractEventListener;
import org.flowable.common.engine.api.delegate.event.FlowableEventListener;
import org.flowable.common.engine.impl.EngineDeployer; import org.flowable.common.engine.impl.EngineDeployer;
import org.flowable.engine.impl.rules.RulesDeployer; import org.flowable.engine.impl.rules.RulesDeployer;
import org.flowable.spring.SpringProcessEngineConfiguration; import org.flowable.spring.SpringProcessEngineConfiguration;
@ -11,6 +14,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
/** /**
* @author qimingjin * @author qimingjin
@ -36,6 +40,10 @@ public class FlowableConfig{
add(new RulesDeployer()); add(new RulesDeployer());
} }
}); });
//注入全局监听器
List<FlowableEventListener> flowableEventListenerList=Lists.newArrayList();
flowableEventListenerList.add(new AbstractEventListener());
configuration.setEventListeners(flowableEventListenerList);
//设置流程图显示乱码 //设置流程图显示乱码
configuration.setActivityFontName("宋体"); configuration.setActivityFontName("宋体");
configuration.setLabelFontName("宋体"); configuration.setLabelFontName("宋体");

View File

@ -1,32 +0,0 @@
package com.snow.flowable.listener;
import org.flowable.common.engine.api.delegate.event.FlowableEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEventListener;
/**
* @author qimingjin
* @Title:
* @Description: 全局事件监听
* @date 2020/12/7 18:13
*/
public class AbstartctEventListener implements FlowableEventListener {
@Override
public void onEvent(FlowableEvent flowableEvent) {
}
@Override
public boolean isFailOnException() {
return false;
}
@Override
public boolean isFireOnTransactionLifecycleEvent() {
return false;
}
@Override
public String getOnTransaction() {
return null;
}
}

View File

@ -0,0 +1,94 @@
package com.snow.flowable.listener;
import com.alibaba.fastjson.JSON;
import com.snow.flowable.common.constants.FlowConstants;
import com.snow.flowable.common.enums.FlowDefEnum;
import com.snow.flowable.service.impl.FlowableServiceImpl;
import lombok.extern.slf4j.Slf4j;
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.history.HistoricProcessInstance;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* @author qimingjin
* @Title:
* @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)) {
return;
}
FlowableEntityEventImpl entityEvent = (FlowableEntityEventImpl) 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());
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();
processVariables.get(FlowConstants.IS_PASS);
log.info("processVariables{}",JSON.toJSONString(processVariables));
}
}
if(type.name().equals("TASK_ASSIGNED")){
//todo
log.info("任务已分配,这个时候可以发送短信,邮件通知");
}
if(type.name().equals("TASK_COMPLETED")){
//todo
log.info("任务已完成,这个时候可以处理一些业务逻辑");
}
}
@Override
public boolean isFailOnException() {
return false;
}
@Override
public boolean isFireOnTransactionLifecycleEvent() {
return false;
}
@Override
public String getOnTransaction() {
return null;
}
}

View File

@ -1,6 +1,8 @@
package com.snow.flowable.listener.leave; package com.snow.flowable.listener.leave;
import com.alibaba.fastjson.JSON;
import com.snow.common.enums.ProcessStatus; import com.snow.common.enums.ProcessStatus;
import com.snow.flowable.common.constants.FlowConstants;
import com.snow.flowable.domain.leave.SysOaLeaveForm; import com.snow.flowable.domain.leave.SysOaLeaveForm;
import com.snow.flowable.listener.AbstractExecutionListener; import com.snow.flowable.listener.AbstractExecutionListener;
import com.snow.system.domain.SysOaLeave; import com.snow.system.domain.SysOaLeave;
@ -24,10 +26,17 @@ public class LeaveEndListener extends AbstractExecutionListener<SysOaLeaveForm>
@Override @Override
protected void process() { protected void process() {
SysOaLeaveForm appForms = getAppForms(); SysOaLeaveForm appForms = getAppForms();
String businessKey= getBusinessKey(); log.info("获取到的表单数据:{}",JSON.toJSONString(appForms));
SysOaLeave sysOaLeave=new SysOaLeave(); Boolean isPass = getVariable(FlowConstants.IS_PASS);
sysOaLeave.setProcessStatus(ProcessStatus.PASS.ordinal()); if(isPass){
sysOaLeave.setLeaveNo(businessKey); String businessKey= getBusinessKey();
sysOaLeaveService.updateSysOaLeaveByLeaveNo(sysOaLeave); SysOaLeave sysOaLeave=new SysOaLeave();
sysOaLeave.setProcessStatus(ProcessStatus.PASS.ordinal());
sysOaLeave.setLeaveNo(businessKey);
sysOaLeaveService.updateSysOaLeaveByLeaveNo(sysOaLeave);
}else {
log.info("上个节点的审批结果:{}",isPass);
}
} }
} }

View File

@ -5,12 +5,13 @@ import com.snow.flowable.listener.AbstractTaskListener;
import com.snow.system.domain.SysOaLeave; import com.snow.system.domain.SysOaLeave;
import com.snow.system.service.ISysOaLeaveService; import com.snow.system.service.ISysOaLeaveService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.TaskListener; import org.flowable.task.service.TaskService;
import org.flowable.task.service.delegate.DelegateTask; import org.flowable.task.service.impl.TaskServiceImpl;
import org.flowable.task.service.impl.persistence.entity.TaskEntityImpl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Map; import javax.annotation.Resource;
/** /**
* @program: snow * @program: snow
@ -25,6 +26,7 @@ public class LeaveStartTaskListener extends AbstractTaskListener {
@Autowired @Autowired
private ISysOaLeaveService sysOaLeaveService; private ISysOaLeaveService sysOaLeaveService;
@Override @Override
protected void processTask() { protected void processTask() {
SysOaLeave sysOaLeave=new SysOaLeave(); SysOaLeave sysOaLeave=new SysOaLeave();
@ -35,6 +37,8 @@ public class LeaveStartTaskListener extends AbstractTaskListener {
sysOaLeave.setProcessStatus(ProcessStatus.CANCEL.ordinal()); sysOaLeave.setProcessStatus(ProcessStatus.CANCEL.ordinal());
}else { }else {
sysOaLeave.setProcessStatus(ProcessStatus.CHECKING.ordinal()); sysOaLeave.setProcessStatus(ProcessStatus.CHECKING.ordinal());
String id = getDelegateTask().getId();
log.info("获取到的taskID:{}",id);
} }
sysOaLeaveService.updateSysOaLeaveByLeaveNo(sysOaLeave); sysOaLeaveService.updateSysOaLeaveByLeaveNo(sysOaLeave);
} }