diff --git a/snow-admin/src/main/java/com/snow/web/controller/system/SysOaLeaveController.java b/snow-admin/src/main/java/com/snow/web/controller/system/SysOaLeaveController.java index c51aaf0..1544191 100644 --- a/snow-admin/src/main/java/com/snow/web/controller/system/SysOaLeaveController.java +++ b/snow-admin/src/main/java/com/snow/web/controller/system/SysOaLeaveController.java @@ -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()); diff --git a/snow-flowable/src/main/java/com/snow/flowable/config/FlowableConfig.java b/snow-flowable/src/main/java/com/snow/flowable/config/FlowableConfig.java index a489a64..95d338e 100644 --- a/snow-flowable/src/main/java/com/snow/flowable/config/FlowableConfig.java +++ b/snow-flowable/src/main/java/com/snow/flowable/config/FlowableConfig.java @@ -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 flowableEventListenerList=Lists.newArrayList(); + flowableEventListenerList.add(new AbstractEventListener()); + configuration.setEventListeners(flowableEventListenerList); //设置流程图显示乱码 configuration.setActivityFontName("宋体"); configuration.setLabelFontName("宋体"); diff --git a/snow-flowable/src/main/java/com/snow/flowable/listener/AbstartctEventListener.java b/snow-flowable/src/main/java/com/snow/flowable/listener/AbstartctEventListener.java deleted file mode 100644 index 551c0f2..0000000 --- a/snow-flowable/src/main/java/com/snow/flowable/listener/AbstartctEventListener.java +++ /dev/null @@ -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; - } -} diff --git a/snow-flowable/src/main/java/com/snow/flowable/listener/AbstractEventListener.java b/snow-flowable/src/main/java/com/snow/flowable/listener/AbstractEventListener.java new file mode 100644 index 0000000..94a1536 --- /dev/null +++ b/snow-flowable/src/main/java/com/snow/flowable/listener/AbstractEventListener.java @@ -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 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; + } +} diff --git a/snow-flowable/src/main/java/com/snow/flowable/listener/leave/LeaveEndListener.java b/snow-flowable/src/main/java/com/snow/flowable/listener/leave/LeaveEndListener.java index 928a5d1..3cf6f5a 100644 --- a/snow-flowable/src/main/java/com/snow/flowable/listener/leave/LeaveEndListener.java +++ b/snow-flowable/src/main/java/com/snow/flowable/listener/leave/LeaveEndListener.java @@ -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 @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); + } + } } diff --git a/snow-flowable/src/main/java/com/snow/flowable/listener/leave/LeaveStartTaskListener.java b/snow-flowable/src/main/java/com/snow/flowable/listener/leave/LeaveStartTaskListener.java index dbee505..261a50e 100644 --- a/snow-flowable/src/main/java/com/snow/flowable/listener/leave/LeaveStartTaskListener.java +++ b/snow-flowable/src/main/java/com/snow/flowable/listener/leave/LeaveStartTaskListener.java @@ -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); }