当前位置: 首页 > news >正文

基于若依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;@Overridepublic 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;@Resourceprivate CommonService commonService;@Autowiredprotected HistoryService historyService;@Resourceprotected RepositoryService repositoryService;@Overrideprotected 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);}@Overrideprotected void taskCompleted(FlowableEngineEntityEvent event) {System.out.println("进入taskCompleted监听器……");super.taskCompleted(event);}@Overridepublic void onEvent(FlowableEvent flowableEvent) {System.out.println("进入taskCompleted监听器--onEvent……");super.onEvent(flowableEvent);}
}

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

http://www.lryc.cn/news/174436.html

相关文章:

  • RestTemplate:简化HTTP请求的强大工具
  • 【数据结构】什么是数据结构?
  • c++源码编译过程(翻译阶段)的若干细节概要
  • Go内置函数make和new的区别?
  • 动手学深度学习(pytorch版)第二章-2.3线性代数Note-linear-algebra
  • Docker CMD指令如何覆写
  • 动手吧,vue单独使用的复选框
  • 升级iOS17后可以降级吗?iOS17退回iOS16方法教程分享
  • 基于STM32和LORA组网的养老院智能控制系统设计(第十八届研电赛)
  • 关于Qt适配不同分辨率和缩放率时可能遇到的问题和解决方案
  • 第1篇 目标检测概述 —(1)目标检测基础知识
  • Discuz论坛网站标题栏Powered by Discuz!版权信息如何去除或是修改?
  • springboot整合aop,实现日志操作
  • openjdk和oracle jdk的区别
  • 深度学习-Python调用ONNX模型
  • [2023.09.24]: 今天差点又交白卷
  • css,环形
  • php食堂点餐系统hsg5815ABA2程序-计算机毕业设计源码+数据库+lw文档+系统+部署
  • Vite打包时使用plugin解决浏览器兼容问题
  • java Excel 自用开发模板
  • 34.CSS魔线图标的悬停效果
  • Django — 会话
  • SpringBoot集成easypoi实现execl导出
  • 第9章 【MySQL】InnoDB的表空间
  • 工作、生活常用免费api接口大全
  • 寻找单身狗
  • 【pytest】 allure 生成报告
  • 动态链接库搜索顺序
  • 【CAN、LIN通信的区分】
  • Redis环境配置