示例#1
0
  public void execute() {
    // 短信
    try {
      List<User> users = userManager.getNotifiedSmsUser();
      for (User user : users) {
        String mobile = user.getMobile();
        if (!StringUtils.isNumeric(mobile)) continue;

        // 待办
        /*                List<FlowNode> todoList = flowNodeManager.getAllPendingNodes(user);
        for (FlowNode todo : todoList) {
            messageManager.buildSms(mobile,todo.getFlow().getTitle());
            todo.setNotified("true");
            flowNodeManager.save(todo);
        }*/
        // 系统消息
        List<Message> allUnSms = messageManager.getAllUnSms(user);
        for (Message msg : allUnSms) {
          if (msg.getNotified().equals("3")) messageManager.buildSms(mobile, msg.getContent());
          else messageManager.buildSms(mobile, msg.getTitle());
          msg.setNotified(MsgConstants.NOTIFIED);
          messageManager.save(msg);
        }
      }
    } catch (Exception e) {
      logger.debug(e.getMessage());
    }

    // 邮件
    try {
      List<User> users = userManager.getNotifiedUsers();
      messages = new ArrayList<MimeMessage>();
      from = userManager.getAdmin().getEmail();

      for (User user : users) {
        List<FlowNode> todoList = flowNodeManager.getAllPendingNodes(user);
        String to = user.getEmail();
        if (StringUtils.isBlank(to)) continue;
        for (FlowNode todo : todoList) {
          buildEmail(to, todo);
          todo.setNotified("true");
          flowNodeManager.save(todo);
        }
      }
      mailSender.send(messages.toArray(new MimeMessage[messages.size()]));
    } catch (MailException e) {
      logger.debug(e.getMessage());
    }
  }
示例#2
0
  /**
   * 根据待办信息构建邮件
   *
   * @param to
   * @param todo
   */
  private void buildEmail(String to, FlowNode todo) {
    try {
      MimeMessage message = mailSender.createMimeMessage();
      MimeMessageHelper helper = new MimeMessageHelper(message, "UTF-8");
      helper.setTo(to);
      helper.setFrom(from);
      helper.setSubject(todo.getFlow().getTitle());
      String content =
          "<a href='http://zjoa.meibu.net/zjimis/flow/node/view.do?model.id="
              + todo.getId()
              + "'>查看详情</a>";
      helper.setText(content, true);
      helper.setSentDate(new Date());
      messages.add(message);

    } catch (Exception e) {
      logger.debug(e.getMessage());
    }
  }