示例#1
0
 @Override
 @Transactional(readOnly = true)
 public Page<MessageSend> findMessageSends(MessageSendPageParam param) {
   int total = messageSendDao.selectCount(param);
   List<MessageSend> datas = messageSendDao.selectPage(param);
   return new Page<MessageSend>(param, total, datas);
 }
示例#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();
 }
示例#3
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);
  }
示例#4
0
  private MessageSend loadMessageSend(Integer id) throws LogicException {
    MessageSend send = messageSendDao.selectById(id);
    if (send == null) {
      throw new LogicException("error.message.notFound");
    }

    return send;
  }
示例#5
0
 @Override
 public void afterPropertiesSet() throws Exception {
   MessageSendPageParam param = new MessageSendPageParam();
   param.setCurrentPage(1);
   param.setPageSize(maxCount);
   param.setType(MessageType.GLOBAL);
   List<MessageSend> globalMessages = messageSendDao.selectPage(param);
   globalMessageCache.put(GLOBAL_MESSAGE, globalMessages);
 }
示例#6
0
  @Override
  @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
  public void deleteMessageSends(Set<Integer> sends) throws LogicException {
    for (Integer id : sends) {
      MessageSend send = loadMessageSend(id);
      super.doAuthencation(UserContext.getUser(), send.getSender());

      messageSendDao.deleteById(id);

      if (MessageType.GLOBAL.equals(send.getType())) {
        deleteMessageSend(send);
      }
    }
  }
示例#7
0
  @Override
  @Transactional(readOnly = true)
  public Page<MessageReceive> findMessageReceives(MessageReceivePageParam param) {

    if (param.getSend() != null) {
      MessageSend send = messageSendDao.selectById(param.getSend().getId());
      if (send == null) {
        return new Page<MessageReceive>(param, 0, new ArrayList<MessageReceive>());
      }

      super.doAuthencation(UserContext.getUser(), send.getSender());
    }

    int total = messageReceiveDao.selectCount(param);
    List<MessageReceive> datas = messageReceiveDao.selectPage(param);
    return new Page<MessageReceive>(param, total, datas);
  }
示例#8
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);
   }
 }