/* * 创建事件 业务部分写在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 id * @return JsonResult */ @RequestMapping("/read") public @ResponseBody JsonResult read(Integer id) { NotifyMessage entity = new NotifyMessage(); entity.setId(id); entity.setIs_read(true); return notifyMessageService.modify(entity); }
/** * @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; }
/** * @Description 获取列表数据 * * @param request * @param model * @author davidwan */ private void getList(HttpServletRequest request, Model model) { int pageIndex = WebUtil.getInt(request, "page_index", 0); int pageSize = WebUtil.getInt(request, "page_size", ConfigValue.PAGE_SIZE); String name = WebUtil.getString(request, "name", ""); NotifyMessage entity = new NotifyMessage(); if (StringUtils.isNotBlank(name)) { // entity.setName(name); } PageInfo<NotifyMessage> pageInfo = notifyMessageService.queryPageList(entity, pageIndex, pageSize); model.addAttribute("list", pageInfo.getData()); model.addAttribute("pageInfo", pageInfo); }
/** * @Description 进入详情页面 * * @param id * @param model * @return String * @author davidwan */ @RequestMapping("/view") public String view(Integer id, Model model) { NotifyMessage entity = notifyMessageService.findById(id); model.addAttribute("model", entity); return getPathView(); }
/** * @Title: batchDelete @Description: Ajax批量删除 * * @param ids * @return JsonResult */ @RequestMapping(value = "/batchdelete", method = RequestMethod.POST) public @ResponseBody JsonResult batchDelete(String ids) { return notifyMessageService.removeByIds(ids); }
/** * @Title: delete @Description: Ajax删除 * * @param id * @return JsonResult */ @RequestMapping(value = "/delete", method = RequestMethod.POST) @ResponseBody public JsonResult delete(Integer id) { return notifyMessageService.removeById(id); }
/** * @Title: update @Description: Ajax保存修改信息 * * @param entity * @return JsonResult */ @RequestMapping(value = "/update", method = RequestMethod.POST) public @ResponseBody JsonResult update(NotifyMessage entity) { return notifyMessageService.modify(entity); }
/** * @Description 标记当前用户所有未读提醒为已读 * * @param entity * @return JsonResult */ @RequestMapping("/readall") public @ResponseBody JsonResult readAll(NotifyMessage entity) { entity.getMap().put("receiver_id", getCurrentUserId()); entity.setIs_read(true); return notifyMessageService.modify(entity); }