/* * 创建事件 业务部分写在pullEvent()方法中,这个方法会被定时调用。 */ @Override protected Event pullEvent() { Event event = Event.createDataEvent("/notify/message"); int count = SessionManager.getInstance().getSessionCount(); if (count >= 1) { Session[] sessions = SessionManager.getInstance().getSessions(); String userId = sessions[0].getEvent().getField("user_id"); WebApplicationContext context = SpringContextHolder.getContext(); NotifyMessageService notifyService = (NotifyMessageService) context.getBean("notifyService"); NotifyMessage entity = new NotifyMessage(); entity.setIs_query(false); entity.setIs_read(false); entity.setReceiver_id(Integer.parseInt(userId)); Map<Integer, List<NotifyMessage>> map = notifyService.modifyAndQueryMapList(entity); try { String data = buildText(map); event.setField("data", data); } catch (Exception ex) { LogHelper.getLogger().error("构建事务通知信息时出错", ex); } // 在线用户 event.setField("userCount", OnlineUser.getInstance().gainUserCount()); } return event; }
/** * @Description 获取列表数据 * * @param model * @author davidwan */ @RequestMapping("/homelist") public @ResponseBody Map<Integer, List<NotifyMessage>> homeList( Boolean is_init, HttpServletRequest request) { NotifyMessage entity = new NotifyMessage(); entity.setIs_read(false); entity.setIs_query(!is_init); entity.setReceiver_id(getCurrentUserId()); Map<Integer, List<NotifyMessage>> map = notifyMessageService.modifyAndQueryMapList(entity); return map; }