需要在每个任务节点配置该监听 **监听类型: 任务监听 Event属性: create** ~~~ import com.alibaba.fastjson.JSONObject; import org.activiti.engine.TaskService; import org.activiti.engine.delegate.DelegateTask; import org.activiti.engine.delegate.TaskListener; import org.activiti.engine.task.IdentityLink; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.constant.CommonSendStatus; import org.jeecg.common.constant.WebsocketConst; import org.jeecg.common.util.SpringContextUtils; import org.jeecg.modules.message.websocket.WebSocket; import org.jeecg.modules.system.entity.SysAnnouncement; import org.jeecg.modules.system.entity.SysUser; import org.jeecg.modules.system.service.ISysAnnouncementService; import org.jeecg.modules.system.service.ISysUserService; import java.util.Date; import java.util.List; public class TaskCreateListener implements TaskListener { private static TaskService taskService; private static ISysAnnouncementService sysAnnouncementService; private static ISysUserService sysUserService; private static WebSocket webSocket; static { taskService = SpringContextUtils.getBean(TaskService.class); sysAnnouncementService = SpringContextUtils.getBean(ISysAnnouncementService.class); sysUserService = SpringContextUtils.getBean(ISysUserService.class); // 原WebSocket类 没有给@Component注解加value 这个jeecgWebSocket是后加的 webSocket = (WebSocket)SpringContextUtils.getBean("jeecgWebSocket"); } @Override public void notify(DelegateTask delegateTask) { String[] handlers = getNodeHandler(delegateTask); String title = "流程办理通知"; saveMessage(handlers, title); // 这里需要起线程 new Thread(new Runnable() { @Override public void run() { // 推送消息 JSONObject obj = new JSONObject(); obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_USER); obj.put(WebsocketConst.MSG_TXT, title); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } webSocket.sendMessage(handlers, obj.toJSONString()); } }).start(); } /** * 获取节点处理人/备选人 * @param delegateTask * @return */ private String[] getNodeHandler(DelegateTask delegateTask){ // 处理人 String handler = delegateTask.getAssignee(); if(handler==null){ List<IdentityLink> ls = taskService.getIdentityLinksForTask(delegateTask.getId()); String[] userIds = new String[ls.size()]; for(int i=0;i<ls.size();i++){ String username = ls.get(i).getUserId(); SysUser user = sysUserService.getUserByName(username); userIds[i] = user.getId(); } return userIds; }else{ String[] userIds = new String[1]; SysUser user = sysUserService.getUserByName(handler); userIds[0] = user.getId(); return userIds; } } /** * 保存消息 * @param userIds * @param title */ private void saveMessage(String[] userIds, String title){ SysAnnouncement msg = new SysAnnouncement(); msg.setTitile(title); msg.setMsgContent("您有新的任务需要处理!"); msg.setSender("系统"); msg.setPriority("M"); msg.setMsgCategory("1"); msg.setMsgType("USER"); msg.setUserIds(String.join(",",userIds)+","); msg.setDelFlag(CommonConstant.DEL_FLAG_0.toString()); msg.setSendStatus(CommonSendStatus.PUBLISHED_STATUS_1);//发布中 msg.setSendTime(new Date()); msg.setOpenType("url"); msg.setOpenPage("/bpm/task/MyTaskList"); sysAnnouncementService.saveAnnouncement(msg); } } ~~~ 演示效果: ![](https://img.kancloud.cn/f4/96/f49635e8b23ef7655162134e0b5e1fcf_1891x908.gif)