示例#1
0
 public void checkInSim(String msisdn) {
   SimInfo simInfo = simInfos.get(msisdn);
   if (simInfo != null) {
     simInfo.setSimStatus(AppConstants.YES_FLAG);
     simInfos.put(msisdn, simInfo);
   }
 }
示例#2
0
  private void load() {
    simInfos.clear();
    simIds.clear();
    try {
      SimInfoDao infoDao = new SimInfoDao();
      List<SimInfo> list = infoDao.selectAll();

      for (SimInfo simInfo : list) {
        simIds.add(simInfo.getMsisdn());
        simInfo.setSimStatus(AppConstants.YES_FLAG);
        simInfos.put(simInfo.getMsisdn(), simInfo);
      }
    } catch (Exception e) {
      log.error("Fail to init sim manager", e);
    }
  }
示例#3
0
  public SimInfo checkOutSimPort(long amount, String msisdn) {
    SimInfo result = null;
    SimInfo temp = null;
    SimInfo simInfo = null;
    SimInfoDao infoDao = new SimInfoDao();
    try {
      for (String simId : simIds) {
        temp = simInfos.get(simId);

        if (temp == null) continue;

        if (!AppConstants.YES_FLAG.equalsIgnoreCase(temp.getSimStatus())) continue;

        simInfo = new SimInfo();
        simInfo.setMsisdn(temp.getMsisdn());
        //			validate in database. status and amount
        try {
          if (!infoDao.selectByMsisdn(simInfo)) continue;
        } catch (DaoException e) {
          log.error("Fail to get simInfo from database", e);
          try {
            Thread.sleep(2000L);
          } catch (InterruptedException e1) {
          }
          continue;
        }

        if (!AppConstants.YES_FLAG.equalsIgnoreCase(simInfo.getSimStatus())) continue;

        if (simInfo.getCurrentAmount() - simInfo.getLockAmount() - amount < 0) continue;
        //				check for available transferTxn
        SimTransaction simTransaction = new SimTransaction();
        simTransaction.setSimId(simInfo.getMsisdn());
        simTransaction.setTxnType(AppConstants.ANYPAY_SETTINGS.TRANSFER_TXN);
        SimTransactionDao simTransactionDao = new SimTransactionDao();
        List<SimTransaction> xferTxns =
            simTransactionDao.selectPendingStatusBySimIdTxnType(simTransaction);
        if (xferTxns != null) {
          for (SimTransaction xferTxn : xferTxns) {
            transfer(xferTxn);
          }
        }

        if (result == null) result = simInfo;
        else {
          if (result.getCurrentAmount() - result.getLockAmount()
              < simInfo.getCurrentAmount() - simInfo.getLockAmount()) result = simInfo;
        }
      }
    } catch (Exception e) {
      log.error("Error while checkout simInfo", e);
    }
    if (result != null) {
      result.setSimStatus(AppConstants.NO_FLAG);
      simInfos.put(result.getMsisdn(), result);
    }
    return result;
  }