当前位置: 首页 > 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 {

    @Autowired
    private WebSocketServer webSocket;

    @Override
    public 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;
    
    @Resource
    private CommonService commonService;
    
    @Resource
	protected RepositoryService repositoryService;
	
	@Resource
    protected HistoryService historyService;
	   

    @Override
    public 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是待办
    	        	}
    	        }
    		}
    	}	
    }

    @Override
    public boolean isFailOnException() {
        return false;
    }

    @Override
    public boolean isFireOnTransactionLifecycleEvent() {
        return false;
    }

    @Override
    public String getOnTransaction() {
        return null;
    }
}

相关文章:

  • LeetCode 面试题 05.01. 插入
  • 利用优化算法提高爬虫任务调度效率
  • swift 约束布局
  • Arduino与Proteus仿真-WiFi TCP客户端数据通信
  • Unity减少发布打包文件的体积——获取精灵图片的信息限制它的大小
  • CSDN每日一练 |『狄杰斯特拉』『选择客栈』『零钱兑换』2023-09-22
  • 2.策略模式
  • 基于matlab求两个数最大公约数函数gcd
  • 一款非常容易上手的报表工具,简单操作实现BI炫酷界面数据展示,驱动支持众多不同类型的数据库,可视化神器,免开源了
  • 地球系统模式(CESM)技术应用
  • uni-app混合开发 navigateTo、reLaunch、redirectTo、switchTab区别
  • 游戏创业小知识:游戏运营的步骤和流程
  • java---jar详解
  • Windows如何删除“$WINDOWS.~BT“文件夹,解决权限不足无法删除
  • uniapp实时获取当前位置
  • 计算物理专题----随机游走实战
  • elk日志某个时间节点突然搜索不到了
  • Cesium 空间量算——生成点位坐标
  • 2023常用的原型设计软件推荐
  • 【无标题】
  • 智飞生物一季度营收下滑79%,连续三个季度亏损,称业绩波动与行业整体趋势一致
  • 人民日报评“我愿意跟他挨着”:城市要善待奋斗者,惩治作恶者
  • 海南医科大学继续开展部门正职竞聘上岗,致力营造“谁有本事谁来”
  • “棉花糖爸爸”陈生梨:女儿将落户到贵州纳雍
  • 第13届京都国际摄影节,14位艺术家展现东西方视角:人性
  • 占比超1/3,江苏何以连续多年霸榜“千亿县”?