flowable集成
This commit is contained in:
parent
c13f146814
commit
293d34b6a0
|
@ -270,16 +270,12 @@ public class SysOaLeaveController extends BaseController
|
|||
Integer checkStatus = finishTaskDTO.getCheckStatus();
|
||||
if(checkStatus==0){
|
||||
completeTaskDTO.setIsPass(true);
|
||||
sysOaLeave.setProcessStatus(ProcessStatus.PASS.ordinal());
|
||||
}else {
|
||||
completeTaskDTO.setIsPass(false);
|
||||
sysOaLeave.setProcessStatus(ProcessStatus.REJECT.ordinal());
|
||||
}
|
||||
completeTaskDTO.setComment(finishTaskDTO.getSuggestion());
|
||||
flowableService.completeTask(completeTaskDTO);
|
||||
sysOaLeave.setUpdateBy(sysUser.getUserName());
|
||||
int i = sysOaLeaveService.updateSysOaLeaveByLeaveNo(sysOaLeave);
|
||||
return toAjax(i);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -291,7 +287,6 @@ public class SysOaLeaveController extends BaseController
|
|||
public AjaxResult reStartTask(LeaveFinishTaskDTO sysOaLeave)
|
||||
{
|
||||
SysUser sysUser = ShiroUtils.getSysUser();
|
||||
|
||||
sysOaLeave.setApplyPerson(sysUser.getUserName());
|
||||
int i = sysOaLeaveService.updateSysOaLeave(sysOaLeave);
|
||||
SysOaLeave newSysOaLeave = sysOaLeaveService.selectSysOaLeaveById(sysOaLeave.getId());
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
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.engine.impl.rules.RulesDeployer;
|
||||
import org.flowable.spring.SpringProcessEngineConfiguration;
|
||||
|
@ -11,6 +14,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
|||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author qimingjin
|
||||
|
@ -36,6 +40,10 @@ public class FlowableConfig{
|
|||
add(new RulesDeployer());
|
||||
}
|
||||
});
|
||||
//注入全局监听器
|
||||
List<FlowableEventListener> flowableEventListenerList=Lists.newArrayList();
|
||||
flowableEventListenerList.add(new AbstractEventListener());
|
||||
configuration.setEventListeners(flowableEventListenerList);
|
||||
//设置流程图显示乱码
|
||||
configuration.setActivityFontName("宋体");
|
||||
configuration.setLabelFontName("宋体");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package com.snow.flowable.listener.leave;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.snow.common.enums.ProcessStatus;
|
||||
import com.snow.flowable.common.constants.FlowConstants;
|
||||
import com.snow.flowable.domain.leave.SysOaLeaveForm;
|
||||
import com.snow.flowable.listener.AbstractExecutionListener;
|
||||
import com.snow.system.domain.SysOaLeave;
|
||||
|
@ -24,10 +26,17 @@ public class LeaveEndListener extends AbstractExecutionListener<SysOaLeaveForm>
|
|||
@Override
|
||||
protected void process() {
|
||||
SysOaLeaveForm appForms = getAppForms();
|
||||
String businessKey= getBusinessKey();
|
||||
SysOaLeave sysOaLeave=new SysOaLeave();
|
||||
sysOaLeave.setProcessStatus(ProcessStatus.PASS.ordinal());
|
||||
sysOaLeave.setLeaveNo(businessKey);
|
||||
sysOaLeaveService.updateSysOaLeaveByLeaveNo(sysOaLeave);
|
||||
log.info("获取到的表单数据:{}",JSON.toJSONString(appForms));
|
||||
Boolean isPass = getVariable(FlowConstants.IS_PASS);
|
||||
if(isPass){
|
||||
String businessKey= getBusinessKey();
|
||||
SysOaLeave sysOaLeave=new SysOaLeave();
|
||||
sysOaLeave.setProcessStatus(ProcessStatus.PASS.ordinal());
|
||||
sysOaLeave.setLeaveNo(businessKey);
|
||||
sysOaLeaveService.updateSysOaLeaveByLeaveNo(sysOaLeave);
|
||||
}else {
|
||||
log.info("上个节点的审批结果:{}",isPass);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,12 +5,13 @@ import com.snow.flowable.listener.AbstractTaskListener;
|
|||
import com.snow.system.domain.SysOaLeave;
|
||||
import com.snow.system.service.ISysOaLeaveService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.flowable.engine.delegate.TaskListener;
|
||||
import org.flowable.task.service.delegate.DelegateTask;
|
||||
import org.flowable.task.service.TaskService;
|
||||
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.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @program: snow
|
||||
|
@ -25,6 +26,7 @@ public class LeaveStartTaskListener extends AbstractTaskListener {
|
|||
@Autowired
|
||||
private ISysOaLeaveService sysOaLeaveService;
|
||||
|
||||
|
||||
@Override
|
||||
protected void processTask() {
|
||||
SysOaLeave sysOaLeave=new SysOaLeave();
|
||||
|
@ -35,6 +37,8 @@ public class LeaveStartTaskListener extends AbstractTaskListener {
|
|||
sysOaLeave.setProcessStatus(ProcessStatus.CANCEL.ordinal());
|
||||
}else {
|
||||
sysOaLeave.setProcessStatus(ProcessStatus.CHECKING.ordinal());
|
||||
String id = getDelegateTask().getId();
|
||||
log.info("获取到的taskID:{}",id);
|
||||
}
|
||||
sysOaLeaveService.updateSysOaLeaveByLeaveNo(sysOaLeave);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue