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

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

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

gitee源代码地址

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

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

1、上一节说到RedisReceiver ,这里有调用了NbcioRedisListener自定义业务监听,如下:

package com.ruoyi.common.redis.listener;import com.ruoyi.common.base.BaseMap;/***  自定义消息监听*  @author nbacheng*  @date 2023-09-20*/public interface NbcioRedisListener {void onMessage(BaseMap message);
}

2、实现这个代码如下:

package com.ruoyi.common.websocket;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;import com.ruoyi.common.base.BaseMap;
import com.ruoyi.common.constant.CommonSendStatus;
import com.ruoyi.common.redis.listener.NbcioRedisListener;import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;/*** 监听消息(采用redis发布订阅方式发送消息)*/
@Slf4j
@Component
public class SocketHandler implements NbcioRedisListener {@Autowiredprivate WebSocketServer webSocket;@Overridepublic void onMessage(BaseMap map) {log.info("【SocketHandler消息】Redis Listerer:" + map.toString());String userId = map.get("userId");String message = map.get("message");if (ObjectUtil.isNotEmpty(userId)) {webSocket.pushMessage(userId, message);//app端消息推送webSocket.pushMessage(userId+CommonSendStatus.APP_SESSION_SUFFIX, message);} else {webSocket.pushMessage(message);}}

       这里进行了websocket的服务器给用户推送,同时之前第一个节里公共类方法也同时往两个表增加数据,以便失败后后续可以进行发送,以确保能真正通知到用户。

3、接下来就是需要在用户提起流程发给审批人进行消息发送了

package com.ruoyi.flowable.listener;import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;import org.apache.commons.lang3.StringUtils;
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.api.delegate.event.FlowableEventType;
import org.flowable.engine.HistoryService;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.TaskService;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
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 javax.annotation.Resource;/*** 全局监听-工作流待办消息提醒** @author nbacheng*/
@Slf4j
@Component
@RequiredArgsConstructor
public class TaskCreateListener implements FlowableEventListener {private final TaskService taskService;@Resourceprivate CommonService commonService;@Resourceprotected RepositoryService repositoryService;@Resourceprotected HistoryService historyService;@Overridepublic void onEvent(FlowableEvent flowableEvent) {FlowableEventType type = flowableEvent.getType();if (type == FlowableEngineEventType.TASK_ASSIGNED) { if(flowableEvent instanceof org.flowable.engine.delegate.event.impl.FlowableEntityEventImpl ) {TaskEntity taskEntity = (TaskEntity) ((org.flowable.engine.delegate.event.impl.FlowableEntityEventImpl) flowableEvent).getEntity();String taskId = taskEntity.getId();String procInsId = taskEntity.getProcessInstanceId();HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(procInsId).singleResult();String businessKey =  historicProcessInstance.getBusinessKey();String deployId = historicProcessInstance.getDeploymentId();String startUserId = historicProcessInstance.getStartUserId();//获取任务接收人String receiver = taskEntity.getAssignee();if (StringUtils.isNotEmpty(receiver)) {//发送提醒消息String category = "";if(taskService.getVariables(taskId).get("category") != null) {category = taskService.getVariables(taskId).get("category").toString();}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=true" + ">点击这个进行处理</a>" ;}else {taskMessageUrl = "<a href=" + commonService.getBaseUrl() + "?procInsId=" + procInsId + "&deployId=" + deployId + "&taskId=" + taskId + "&businessKey" + "&category=" + category + "&finished=true" + ">点击这个进行处理</a>" ;}String msgContent = "流程待办通知" + taskMessageUrl;if(!StringUtils.equals(startUserId, receiver) || !StringUtils.equals((loginUser.getUserId()).toString(),receiver)) {//发起人或登录人自己不发送log.info("流程待办通知给:" + receiver);commonService.sendSysNotice(loginUser.getUserId().toString(), receiver, "流程待办通知", msgContent, Constants.MSG_CATEGORY_3);//setMsgCategory=3是待办}}}}	}@Overridepublic boolean isFailOnException() {return false;}@Overridepublic boolean isFireOnTransactionLifecycleEvent() {return false;}@Overridepublic String getOnTransaction() {return null;}
}

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

相关文章:

  • 用友第五届开发者大赛初赛晋级公示,复赛火热进行中!
  • SSL证书如何做到保障网站安全?
  • C# Onnx Yolov8 Detect Poker 扑克牌识别
  • 想要精通算法和SQL的成长之路 - 最长等差数列
  • 【简单的自动曝光】python实现-附ChatGPT解析
  • 网工内推 | 运维工程师,CCNP认证优先,周末双休,多次调薪机会
  • LeetCode 1337. The K Weakest Rows in a Matrix【数组,二分,堆,快速选择,排序】1224
  • 如何使用Spring提供的Retry
  • 【ONE·Linux || 进程间通信】
  • 207.Flink(二):架构及核心概念,flink从各种数据源读取数据,各种算子转化数据,将数据推送到各数据源
  • debian终端快捷键设置
  • 原生ajax
  • 面试题库(五):并发编程
  • Android FileProvider笔记
  • 华为云云耀云服务器L实例评测 |云服务器选购
  • 2023-09-22 LeetCode每日一题(将钱分给最多的儿童)
  • 功能测试的重要性
  • 《Linux高性能服务器编程》--高级I/O函数
  • 算法通关村 | 透彻理解动态规划
  • 数据结构(持续更新)
  • nginx部署vue后显示500 Internal Server Error解决方案
  • 微调大型语言模型(一):为什么要微调(Why finetune)?
  • 【GO】网络请求例子
  • 泡泡玛特海外布局动作不断,开启东南亚潮玩盛会
  • uniappAndroid平台签名证书(.keystore)生成
  • Gateway学习和源码解析
  • 移动机器人运动规划 --- 基于图搜索的Dijkstra算法
  • Mybatis SQL构建器
  • 怎么将几张图片做成pdf合在一起
  • 关于JPA +SpringBoot 遇到的一些问题及解决方法