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


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

    gitee源代码地址

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

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

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

    1. package com.ruoyi.common.redis.listener;
    2. import com.ruoyi.common.base.BaseMap;
    3. /**
    4. * 自定义消息监听
    5. * @author nbacheng
    6. * @date 2023-09-20
    7. */
    8. public interface NbcioRedisListener {
    9. void onMessage(BaseMap message);
    10. }

    2、实现这个代码如下:

    1. package com.ruoyi.common.websocket;
    2. import org.springframework.beans.factory.annotation.Autowired;
    3. import org.springframework.stereotype.Component;
    4. import com.ruoyi.common.base.BaseMap;
    5. import com.ruoyi.common.constant.CommonSendStatus;
    6. import com.ruoyi.common.redis.listener.NbcioRedisListener;
    7. import cn.hutool.core.util.ObjectUtil;
    8. import lombok.extern.slf4j.Slf4j;
    9. /**
    10. * 监听消息(采用redis发布订阅方式发送消息)
    11. */
    12. @Slf4j
    13. @Component
    14. public class SocketHandler implements NbcioRedisListener {
    15. @Autowired
    16. private WebSocketServer webSocket;
    17. @Override
    18. public void onMessage(BaseMap map) {
    19. log.info("【SocketHandler消息】Redis Listerer:" + map.toString());
    20. String userId = map.get("userId");
    21. String message = map.get("message");
    22. if (ObjectUtil.isNotEmpty(userId)) {
    23. webSocket.pushMessage(userId, message);
    24. //app端消息推送
    25. webSocket.pushMessage(userId+CommonSendStatus.APP_SESSION_SUFFIX, message);
    26. } else {
    27. webSocket.pushMessage(message);
    28. }
    29. }

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

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

    1. package com.ruoyi.flowable.listener;
    2. import lombok.RequiredArgsConstructor;
    3. import lombok.extern.slf4j.Slf4j;
    4. import org.apache.commons.lang3.StringUtils;
    5. import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
    6. import org.flowable.common.engine.api.delegate.event.FlowableEvent;
    7. import org.flowable.common.engine.api.delegate.event.FlowableEventListener;
    8. import org.flowable.common.engine.api.delegate.event.FlowableEventType;
    9. import org.flowable.engine.HistoryService;
    10. import org.flowable.engine.RepositoryService;
    11. import org.flowable.engine.TaskService;
    12. import org.flowable.engine.history.HistoricProcessInstance;
    13. import org.flowable.task.service.impl.persistence.entity.TaskEntity;
    14. import org.springframework.stereotype.Component;
    15. import com.ruoyi.common.core.service.CommonService;
    16. import com.ruoyi.common.constant.Constants;
    17. import com.ruoyi.common.core.domain.model.LoginUser;
    18. import javax.annotation.Resource;
    19. /**
    20. * 全局监听-工作流待办消息提醒
    21. *
    22. * @author nbacheng
    23. */
    24. @Slf4j
    25. @Component
    26. @RequiredArgsConstructor
    27. public class TaskCreateListener implements FlowableEventListener {
    28. private final TaskService taskService;
    29. @Resource
    30. private CommonService commonService;
    31. @Resource
    32. protected RepositoryService repositoryService;
    33. @Resource
    34. protected HistoryService historyService;
    35. @Override
    36. public void onEvent(FlowableEvent flowableEvent) {
    37. FlowableEventType type = flowableEvent.getType();
    38. if (type == FlowableEngineEventType.TASK_ASSIGNED) {
    39. if(flowableEvent instanceof org.flowable.engine.delegate.event.impl.FlowableEntityEventImpl ) {
    40. TaskEntity taskEntity = (TaskEntity) ((org.flowable.engine.delegate.event.impl.FlowableEntityEventImpl) flowableEvent).getEntity();
    41. String taskId = taskEntity.getId();
    42. String procInsId = taskEntity.getProcessInstanceId();
    43. HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
    44. .processInstanceId(procInsId)
    45. .singleResult();
    46. String businessKey = historicProcessInstance.getBusinessKey();
    47. String deployId = historicProcessInstance.getDeploymentId();
    48. String startUserId = historicProcessInstance.getStartUserId();
    49. //获取任务接收人
    50. String receiver = taskEntity.getAssignee();
    51. if (StringUtils.isNotEmpty(receiver)) {
    52. //发送提醒消息
    53. String category = "";
    54. if(taskService.getVariables(taskId).get("category") != null) {
    55. category = taskService.getVariables(taskId).get("category").toString();
    56. }
    57. LoginUser loginUser = commonService.getLoginUser();
    58. String taskMessageUrl;
    59. if(StringUtils.isNotBlank(businessKey)) {
    60. }
    61. else {
    62. }
    63. String msgContent = "流程待办通知" + taskMessageUrl;
    64. if(!StringUtils.equals(startUserId, receiver) || !StringUtils.equals((loginUser.getUserId()).toString(),receiver)) {//发起人或登录人自己不发送
    65. log.info("流程待办通知给:" + receiver);
    66. commonService.sendSysNotice(loginUser.getUserId().toString(), receiver, "流程待办通知", msgContent, Constants.MSG_CATEGORY_3);//setMsgCategory=3是待办
    67. }
    68. }
    69. }
    70. }
    71. }
    72. @Override
    73. public boolean isFailOnException() {
    74. return false;
    75. }
    76. @Override
    77. public boolean isFireOnTransactionLifecycleEvent() {
    78. return false;
    79. }
    80. @Override
    81. public String getOnTransaction() {
    82. return null;
    83. }
    84. }

  • 相关阅读:
    Vcenter6.5扩容存储后无法创建虚机处理方法
    代码随想录算法训练营第七天|二叉树(截止到层序遍历)
    IDEA中配置完Maven后 重启就恢复默认设置
    泛微e-office json_common.php SQL注入漏洞
    Springboot 对于数据库字段加密方案(此方案是对字符串处理的方案)
    链家网房源价格信息的爬虫分析工具
    notepad++怎么运行以及配置
    DLR 的扩展库 Dynamitey
    CRUD和文件上传下载
    【VMware vSAN】全新vSAN 8 ESA快速存储架构配置文件服务并创建文件共享。
  • 原文地址:https://blog.csdn.net/qq_40032778/article/details/133189428