Ejemplo n.º 1
0
 @Override
 public void execute() {
   if (!this.isEnable()) {
     this.log.info(("no process for this job | enable-" + this.isEnable()));
     return;
   }
   try {
     ProviderAmountDao providerAmountDao = new ProviderAmountDao();
     List listCurProviderAmounts = providerAmountDao.selectAll();
     if (listCurProviderAmounts != null) {
       for (int i = 0; i < listCurProviderAmounts.size(); ++i) {
         ProviderAmount providerAmount = (ProviderAmount) listCurProviderAmounts.get(i);
         String providerId = providerAmount.getProviderId();
         ProviderAccountDao accountDao = new ProviderAccountDao();
         long totalAmount =
             accountDao.selectTotalAmountByProviderId(providerAmount.getProviderId());
         long currentAmount = totalAmount - providerAmount.getTotalUsed();
         if (currentAmount < providerAmount.getNotifAmount()) {
           if (providerAmount.getNotifSent().booleanValue()) continue;
           ContextBase context = new ContextBase();
           context.put("provider_id", providerId);
           context.putLong("current_amount", currentAmount);
           context.putLong("notif_amount", providerAmount.getNotifAmount().longValue());
           if (AppConstants.NOTIFICATION_SETTINGS.sendNotification(
               NotificationSettings.TEMPLATE_TYPE.PROVIDER_AMOUNT_ALERT, new Object[] {context})) {
             providerAmount = new ProviderAmount();
             providerAmount.setProviderId(providerId);
             providerAmount.setNotifSent(Boolean.valueOf(true));
             providerAmountDao.update(providerAmount);
             continue;
           }
           this.log.error("======================================================");
           this.log.error("========= Fail to send PROVIDER_AMOUNT_ALERT =========");
           this.log.error("======================================================");
           continue;
         }
         if (!providerAmount.getNotifSent().booleanValue()) continue;
         providerAmount = new ProviderAmount();
         providerAmount.setProviderId(providerId);
         providerAmount.setNotifSent(Boolean.valueOf(false));
         providerAmountDao.update(providerAmount);
       }
     }
   } catch (Exception e) {
     this.log.error(e);
   }
 }
Ejemplo n.º 2
0
  public void transfer(SimTransaction txn) {
    try {
      SimTransaction simTransaction = new SimTransaction();
      simTransaction.setTxnId(txn.getTxnId());
      simTransaction.setTxnStatus(AppConstants.TXN_STATUS_DELIVERING);

      SimTransactionDao simTransactionDao = new SimTransactionDao();
      if (simTransactionDao.update(simTransaction)) {
        ContextBase ctxRequest = new ContextBase();
        ctxRequest.put(Attributes.ATTR_TXN_TYPE, txn.getTxnType());
        ctxRequest.put(Attributes.ATTR_COM_ID, txn.getSimId());
        ctxRequest.put(Attributes.ATTR_MSISDN, txn.getMsisdn());
        ctxRequest.putLong(Attributes.ATTR_AMOUNT, txn.getAmount());
        ContextBase response = SimConnectionFactory.getInstance().process(ctxRequest);
        log.info("Transfer money:" + response);
      } else log.info("Fail to change txn status of transfer txn :" + txn);
    } catch (Exception e) {
      log.error("Fail to transfer money", e);
    }
  }