Esempio n. 1
0
  @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);
  }
Esempio n. 2
0
 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();
 }
Esempio n. 3
0
 @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);
   }
 }