@Override @Transactional(rollbackFor = Exception.class, propagation = Propagation.NESTED) public void sendTip(TipMessage message) { if (message.getSender().equals(message.getReceiver())) { return; } MessageDetail detail = new MessageDetail(message.getTitle(), message.getContent()); messageDetailDao.insert(detail); MessageSend toSend = new MessageSend(); toSend.setDetail(detail); toSend.setSendDate(new Date()); toSend.setSender(message.getSender()); toSend.setType(MessageType.SYSTEM); messageSendDao.insert(toSend); MessageReceive toReceive = new MessageReceive(); toReceive.setMessage(toSend); toReceive.setReceiver(message.getReceiver()); toReceive.setStatus(MessageStatus.COMMON); messageReceiveDao.insert(toReceive); addCount(message.getReceiver(), 1); }
private int handleGlobalMessage(User user) { List<MessageSend> messages = null; List<MessageSend> all = (List<MessageSend>) globalMessageCache.get(GLOBAL_MESSAGE); Map<String, Object> map = (Map<String, Object>) messageCache.get(user.getId()); if (map == null) { map = new HashMap<String, Object>(); } if (!map.containsKey(GLOBAL_MESSAGE)) { messages = messageSendDao.selectUnSendMessageByTypeAndUser(MessageType.GLOBAL, user, maxCount); } else { List<MessageSend> received = (List<MessageSend>) map.get(GLOBAL_MESSAGE); if (!Validators.isEmptyOrNull(received)) { messages = getUnrecieve(received, all); } else { messages = all; } } if (!messages.isEmpty()) { List<MessageReceive> receives = new ArrayList<MessageReceive>(messages.size()); for (MessageSend send : messages) { MessageReceive receive = new MessageReceive(); receive.setMessage(send); receive.setIsRead(false); receive.setReceiver(user); receive.setStatus(MessageStatus.COMMON); receives.add(receive); } messageReceiveDao.inserts(receives); } map.put(GLOBAL_MESSAGE, new ArrayList<MessageSend>(all)); messageCache.put(user.getId(), map); return messages.size(); }
@Override @Transactional(readOnly = true) public MessageReceive getMessageReceive(Integer id) throws LogicException { MessageReceive receive = loadMessageReceive(id); super.doAuthencation(UserContext.getUser(), receive.getReceiver()); cleanMessageDetail(receive.getMessage().getDetail()); return receive; }
@Override @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) public void updateMessageRecieveStatus(Set<Integer> receives, MessageStatus status) throws LogicException { for (Integer id : receives) { MessageReceive receive = loadMessageReceive(id); super.doAuthencation(UserContext.getUser(), receive.getReceiver()); if (!receive.getStatus().equals(status)) { receive.setStatus(status); messageReceiveDao.update(receive); } } }
@Override @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) public void deleteMessageReceives(Set<Integer> receives) throws LogicException { for (Integer id : receives) { MessageReceive receive = loadMessageReceive(id); super.doAuthencation(UserContext.getUser(), receive.getReceiver()); messageReceiveDao.deleteById(id); if (!receive.getIsRead()) { addCount(receive.getReceiver(), -1); } } }
@Override @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) public void insertMessage(MessageSendDetail message) throws LogicException { messageDetailDao.insert(message.getDetail()); messageSendDao.insert(message); for (String username : message.getReceivers()) { User user = userServer.getUserByNameOrEmail(username); MessageReceive receive = new MessageReceive(); receive.setMessage(message); receive.setIsRead(false); receive.setReceiver(user); receive.setMessage(message); receive.setStatus(MessageStatus.COMMON); messageReceiveDao.insert(receive); addCount(user, 1); } }
@Override @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) public void updateIsRead(Set<Integer> receives, boolean isRead) throws LogicException { for (Integer id : receives) { MessageReceive receive = loadMessageReceive(id); super.doAuthencation(UserContext.getUser(), receive.getReceiver()); boolean _isRead = receive.getIsRead(); if (!Boolean.valueOf(receive.getIsRead()).equals(isRead)) { receive.setIsRead(isRead); messageReceiveDao.update(receive); } if (!_isRead && isRead) { addCount(receive.getReceiver(), -1); } if (_isRead && !isRead) { addCount(receive.getReceiver(), 1); } } }