Exemplo n.º 1
0
  /**
   * 获取用户设置
   *
   * @param userno
   * @param smstype
   * @return
   */
  @Transactional
  public UserSettingDTO getUserSMSTiming(String userno, BigDecimal smstype) {
    if (StringUtils.isBlank(userno)) {
      throw new IllegalArgumentException("the argument userno is required");
    }
    if (smstype == null) {
      throw new IllegalArgumentException("the argument smstype is required");
    }
    SendType[] sendTypes = SendType.values();
    List<SendChannel> sendChannels = new ArrayList<SendChannel>();
    UserSMSTiming userSMSTiming = UserSMSTiming.findByUsernoAndSmstypeFromCache(userno, smstype);
    // 缓存和数据库中都没有
    if (userSMSTiming == null) {
      userSMSTiming = UserSMSTiming.createUserSMSTiming(userno, smstype, 1);
      for (SendType sendType : sendTypes) {
        Integer needToSend = 0;
        // 默认开启短信
        if (sendType.getValue() == SendType.MESSAGE.getValue()) {
          needToSend = 1;
        }
        SendChannel sendchannel =
            SendChannel.createOrMergeSendChannel(
                userSMSTiming.getId(), needToSend, sendType.getValue());
        sendChannels.add(sendchannel);
      }
    } else {
      // 内存中有用户设置缓存 开始查询发送渠道
      for (SendType sendType : sendTypes) {
        SendChannel sendchannel =
            SendChannel.findByUserSMStimingIdAndSendtypeFromCache(
                userSMSTiming.getId(), sendType.getValue());
        // 缓存和数据库中都没有
        if (sendchannel == null) {
          Integer needToSend = 0;
          if (sendType.getValue() == SendType.MESSAGE.getValue()) {
            needToSend = 1;
          }
          sendchannel =
              SendChannel.createSendChannel(userSMSTiming.getId(), needToSend, sendType.getValue());
        }
        sendChannels.add(sendchannel);
      }
    }
    if (sendChannels.size() == 0) {}

    return new UserSettingDTO(userSMSTiming, sendChannels);
  }
Exemplo n.º 2
0
 /**
  * 查询用户发送设置
  *
  * @param userno
  * @param type
  * @return
  */
 public Set<ISendObserver> findSendSetting(String userno, BigDecimal type) {
   Set<ISendObserver> sendables = new HashSet<ISendObserver>();
   UserSMSTiming userSMSTiming = UserSMSTiming.findByUsernoAndSmstypeFromCache(userno, type);
   if (userSMSTiming == null) {
     sendables.add(sendSMS);
     // 增加站内信发送方式
     sendables.add(sendLetterObserver);
     return sendables;
   } else {
     if (userSMSTiming.getNeedToSend() != null && userSMSTiming.getNeedToSend() == 0) {
       return sendables;
     }
     SendType[] sendTypes = SendType.values();
     for (SendType sendType : sendTypes) {
       SendChannel sendChannel =
           SendChannel.findByUserSMStimingIdAndSendtypeFromCache(
               userSMSTiming.getId(), sendType.getValue());
       if (sendChannel == null) {
         Integer needToSend = 0;
         if (sendType.getValue() == SendType.MESSAGE.getValue()) {
           needToSend = 1;
         }
         sendChannel =
             SendChannel.createSendChannel(userSMSTiming.getId(), needToSend, sendType.getValue());
       }
       if (sendChannel.getNeedToSend().intValue() == 1) {
         if (sendChannel.getSendtype().equals(SendType.MESSAGE.getValue())) {
           sendables.add(sendSMS);
         }
         if (sendChannel.getSendtype().equals(SendType.EMAIL.getValue())) {
           sendables.add(sendEmail);
         }
         if (sendChannel.getSendtype().equals(SendType.IPHONE.getValue())) {
           sendables.add(sendIOSMsg);
         }
       }
     }
     // 增加站内信发送方式
     sendables.add(sendLetterObserver);
   }
   return sendables;
 }