基于若依ruoyi-nbcio增加flowable流程待办消息的提醒,并提供右上角的红字数字提醒(四)

简介: 基于若依ruoyi-nbcio增加flowable流程待办消息的提醒,并提供右上角的红字数字提醒(四)

更多ruoyi-nbcio功能请看演示系统

gitee源代码地址

前后端代码: https://gitee.com/nbacheng/ruoyi-nbcio

演示地址:RuoYi-Nbcio后台管理系统

 

上一节说到待办系统的监听器TaskCreateListener,需要在flowable全局监听配置里加入配置

 1、GlobalEventListenerConfig.java文件如下:

package com.ruoyi.flowable.config;
import com.ruoyi.flowable.listener.GlobalEventListener;
import com.ruoyi.flowable.listener.ProcessCompleteListener;
import com.ruoyi.flowable.listener.TaskCreateListener;
import lombok.AllArgsConstructor;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.api.delegate.event.FlowableEventDispatcher;
import org.flowable.engine.RuntimeService;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;
/**
 * flowable全局监听配置
 *
 * @author ssc
 */
@Configuration
@AllArgsConstructor
public class GlobalEventListenerConfig implements ApplicationListener<ContextRefreshedEvent> {
  private final GlobalEventListener globalEventListener;
  private final RuntimeService runtimeService;
  private final SpringProcessEngineConfiguration configuration;
    private final TaskCreateListener taskCreateListener;
    private final ProcessCompleteListener processCompleteListener;
  @Override
  public void onApplicationEvent(ContextRefreshedEvent event) {
    FlowableEventDispatcher dispatcher = configuration.getEventDispatcher();
        // 任务创建全局监听-待办消息发送
        dispatcher.addEventListener(taskCreateListener, FlowableEngineEventType.TASK_CREATED, FlowableEngineEventType.TASK_ASSIGNED);
        //任务创建全局监听-完成消息发送
        dispatcher.addEventListener(processCompleteListener, FlowableEngineEventType.PROCESS_COMPLETED);
    // 流程正常结束
    runtimeService.addEventListener(globalEventListener, FlowableEngineEventType.PROCESS_COMPLETED);
  }
}

2、还增加了一个流程结束的通知监听如下:

package com.ruoyi.flowable.listener;
import java.util.List;
import javax.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEvent;
import org.flowable.engine.HistoryService;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.TaskService;
import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl;
import org.flowable.task.api.Task;
import org.flowable.variable.api.persistence.entity.VariableInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.common.core.service.CommonService;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.model.LoginUser;
import lombok.RequiredArgsConstructor;
/**
 * 全局监听-工作流完成消息提醒
 *
 * @author nbacheng
 */
//必须要用 AbstractFlowableEngineEventListener 用FlowableEventListener这个会出现问题,应该是已经完成了
@Component
@RequiredArgsConstructor
public class ProcessCompleteListener extends AbstractFlowableEngineEventListener {
  private final TaskService taskService;
  
    @Resource
    private CommonService commonService;
    
    @Autowired
    protected HistoryService historyService;
    
    @Resource
  protected RepositoryService repositoryService;
    @Override
    protected void processCompleted(FlowableEngineEntityEvent event) {
        System.out.println("进入流程结束监听器……");
        String procInsId = event.getProcessInstanceId();
        HistoricProcessInstance hi = historyService.createHistoricProcessInstanceQuery()
                .processInstanceId(procInsId)
                .singleResult();
        
        List<Task> listtask = taskService.createTaskQuery().processInstanceId(procInsId).active().list();
        String taskId = "";
        if(listtask !=null) {
          taskId = listtask.get(0).getId();
        }
        String startUserId = hi.getStartUserId();
    String businessKey =  hi.getBusinessKey();
    String deployId = hi.getDeploymentId();
    String category =  "";
        
        if (StringUtils.isNotEmpty(startUserId)) {
            // TODO:  发送提醒消息
          if(((ExecutionEntityImpl)event.getEntity()).getVariableInstances().get("category") !=null) {
            category = ((VariableInstance)((ExecutionEntityImpl)event.getEntity()).getVariableInstances().get("category")).getTextValue();
          }
          
          LoginUser loginUser = commonService.getLoginUser();
          String taskMessageUrl;
          if(StringUtils.isNotBlank(businessKey)) {
          taskMessageUrl = "<a href=" + commonService.getBaseUrl() + "?procInsId=" + procInsId + "&deployId=" 
                          + deployId + "&taskId=" + taskId + "&businessKey=" + businessKey + "&category=" + category
                          + "&finished=false" + ">点击这个进行查看</a>" ;
        }
        else {
          taskMessageUrl = "<a href=" + commonService.getBaseUrl() + "?procInsId=" + procInsId + "&deployId=" 
                      + deployId + "&taskId=" + taskId + "&businessKey" + "&category=" + category + "&finished=false" + ">点击这个进行查看</a>" ;
        }
          String msgContent = "流程任务结束通知" + taskMessageUrl; 
          commonService.sendSysNotice(loginUser.getUsername(), startUserId, "流程任务结束通知", msgContent, Constants.MSG_CATEGORY_1);//setMsgCategory=1是通知
        }
        super.processCompleted(event);
    }
    @Override
    protected void taskCompleted(FlowableEngineEntityEvent event) {
        System.out.println("进入taskCompleted监听器……");
        super.taskCompleted(event);
    }
    @Override
    public void onEvent(FlowableEvent flowableEvent) {
        System.out.println("进入taskCompleted监听器--onEvent……");
        super.onEvent(flowableEvent);
    }
}

当然这两个监听还需要根据实际进行个性化定制与修改。


相关文章
|
5天前
ruoyi-nbcio项目增加右上角的消息提醒
ruoyi-nbcio项目增加右上角的消息提醒
15 0
|
5天前
基于若依ruoyi-nbcio增加flowable流程待办消息的提醒,并提供右上角的红字数字提醒(三)
基于若依ruoyi-nbcio增加flowable流程待办消息的提醒,并提供右上角的红字数字提醒(三)
23 0
|
5天前
|
NoSQL Redis
基于若依ruoyi-nbcio增加flowable流程待办消息的提醒,并提供右上角的红字数字提醒(二)
基于若依ruoyi-nbcio增加flowable流程待办消息的提醒,并提供右上角的红字数字提醒(二)
18 0
|
5天前
|
前端开发
基于若依ruoyi-nbcio增加flowable流程待办消息的提醒,并提供右上角的红字数字提醒(六)
基于若依ruoyi-nbcio增加flowable流程待办消息的提醒,并提供右上角的红字数字提醒(六)
27 0
|
5天前
|
SQL 前端开发
基于若依ruoyi-nbcio增加flowable流程待办消息的提醒,并提供右上角的红字数字提醒(八)
基于若依ruoyi-nbcio增加flowable流程待办消息的提醒,并提供右上角的红字数字提醒(八)
37 0
|
5天前
|
SQL 前端开发
基于若依ruoyi-nbcio增加flowable流程待办消息的提醒,并提供右上角的红字数字提醒(五)
基于若依ruoyi-nbcio增加flowable流程待办消息的提醒,并提供右上角的红字数字提醒(五)
23 0
|
5天前
|
前端开发
基于若依ruoyi-nbcio增加flowable流程待办消息的提醒,并提供右上角的红字数字提醒(七)
基于若依ruoyi-nbcio增加flowable流程待办消息的提醒,并提供右上角的红字数字提醒(七)
18 0
|
5天前
|
前端开发 数据库
ruoyi-nbcio增加flowable流程待办消息的提醒,并提供右上角的红字数字提醒(一)
ruoyi-nbcio增加flowable流程待办消息的提醒,并提供右上角的红字数字提醒(一)
15 0
|
5天前
|
前端开发
基于jeecgboot的flowable流程支持退回到发起人节点表单修改功能
基于jeecgboot的flowable流程支持退回到发起人节点表单修改功能
31 0
|
5天前
基于若依ruoyi-nbcio支持flowable流程角色,同时修改流转用户为username,流程启动做大调整(一)
基于若依ruoyi-nbcio支持flowable流程角色,同时修改流转用户为username,流程启动做大调整(一)
21 1