Example #1
0
 public void processUserRead(UserMessage entity, User user) {
   if (entity.getFirstReadTime() == null) {
     entity.setFirstReadTime(DateUtils.currentDate());
     entity.setLastReadTime(entity.getFirstReadTime());
     entity.setReadTotalCount(1);
   } else {
     entity.setLastReadTime(DateUtils.currentDate());
     entity.setReadTotalCount(entity.getReadTotalCount() + 1);
   }
   userMessageDao.save(entity);
 }
Example #2
0
  /**
   * 消息推送处理
   *
   * @param entity
   */
  public void pushMessage(UserMessage entity) {
    // 定向用户消息处理
    User targetUser = entity.getTargetUser();

    // 邮件推送处理
    if (entity.getEmailPush() && entity.getEmailPushTime() == null) {
      String email = targetUser.getEmail();
      if (StringUtils.isNotBlank(email)) {
        mailService.sendHtmlMail(entity.getTitle(), entity.getMessage(), true, email);
        entity.setEmailPushTime(DateUtils.currentDate());
      }
    }

    // 短信推送处理
    if (entity.getSmsPush() && entity.getSmsPushTime() == null) {
      if (smsService != null) {
        String mobileNum = targetUser.getMobile();
        if (StringUtils.isNotBlank(mobileNum)) {
          String errorMessage =
              smsService.sendSMS(entity.getNotification(), mobileNum, SmsMessageTypeEnum.Default);
          if (StringUtils.isBlank(errorMessage)) {
            entity.setSmsPushTime(DateUtils.currentDate());
          }
        }
      } else {
        logger.warn("SmsService implement NOT found.");
      }
    }

    // APP推送
    if (entity.getAppPush() && entity.getAppPushTime() == null) {
      if (messagePushService != null) {
        Boolean pushResult = messagePushService.sendPush(entity);
        if (pushResult == null || pushResult) {
          entity.setAppPushTime(DateUtils.currentDate());
        }
      } else {
        logger.warn("MessagePushService implement NOT found.");
      }
    }

    userMessageDao.save(entity);
  }