public static MerchantEntry getMerchant(long agentId, long cpId) throws Exception {
    Connection connection = null;
    MerchantEntry merchant = null;
    PreparedStatement stmtMerchant = null;

    ResultSet rsMerchant = null;

    try {
      String sql =
          "Select * From MerchantAgent A, MerchantEntry B Where A.merchantId = ? and A.agentId = ? and"
              + " A.merchantId = B.merchantId";
      connection = Database.getConnection();
      stmtMerchant = connection.prepareStatement(sql);
      stmtMerchant.setLong(1, cpId);
      stmtMerchant.setLong(2, agentId);

      rsMerchant = stmtMerchant.executeQuery();

      if (rsMerchant.next()) {
        merchant = new MerchantEntry();
        merchant.setMerchantId(rsMerchant.getLong("merchantId"));
        merchant.setAgentId(rsMerchant.getLong("agentId"));
        merchant.setCode(rsMerchant.getString("code"));
        merchant.setServiceAddress(rsMerchant.getString("serviceAddress"));
        merchant.setScreenName(rsMerchant.getString("screenName"));
        merchant.setPassword(rsMerchant.getString("password_"));
        merchant.setStartIP(rsMerchant.getString("startIP"));
        merchant.setEndIP(rsMerchant.getString("endIP"));
        merchant.setMaxTps(rsMerchant.getInt("maxTPS"));
        merchant.setMaxConnection(rsMerchant.getInt("maxsession"));
        merchant.setPermisstion(rsMerchant.getString("permission"));
        merchant.setSubscriptionRetry(rsMerchant.getInt("subretry"));
      }
    } catch (Exception e) {
      e.printStackTrace();
      throw e;
    } finally {
      Database.closeObject(stmtMerchant);
      Database.closeObject(connection);
      Database.closeObject(rsMerchant);
    }

    return merchant;
  }
Beispiel #2
0
  public boolean getBalanceQuery(
      CommandInstance instance, ProvisioningCommand provisioningCommand, CommandMessage request)
      throws Exception {
    Connection connection = Database.getConnection();

    PreparedStatement stmtUsage = null;
    ResultSet rsUsage = null;

    PreparedStatement stmtBalance = null;
    ResultSet rsBalance = null;
    try {
      request.setCause("success");

      double balanceAmount = 0.0D;

      String SQL =
          "Select * From SubscriberBalance Where sourceAddress = ? and balanceType = 'LOYALTY' ";

      stmtBalance = connection.prepareStatement(SQL);
      stmtBalance.setString(1, request.getIsdn());

      rsBalance = stmtBalance.executeQuery();

      if (rsBalance.next()) {
        balanceAmount = rsBalance.getDouble("balanceAmount");
      } else {
        throw new AppException(NOT_REGISTERED);
      }

      SQL =
          "Select * From SubscriberRank Where cycleDate = ? and sourceAddress = ? and balanceType = 'LOYALTY'";

      stmtUsage = connection.prepareStatement(SQL);

      stmtUsage.setDate(1, new java.sql.Date(request.getCycleDate().getTime()));
      stmtUsage.setString(2, request.getIsdn());

      rsUsage = stmtUsage.executeQuery();

      String response = "";

      double totalAmount = 0.0D;

      RankEntry rankRule = null;

      String rankStartDate = "";
      String rankExpirationDate = "";

      if (rsUsage.next()) {
        request.setCause("success");

        if (rsUsage.getDate("expirationDate") == null) {
          request.setCause("not-exist");
        } else {
          rankRule = RankFactory.getCache().getRank(rsUsage.getLong("rankId"));
        }

        totalAmount = rsUsage.getDouble("totalAmount");

        SimpleDateFormat formatDate = new SimpleDateFormat("dd/MM/yyyy");
        if (rsUsage.getDate("startDate") != null) {
          rankStartDate = formatDate.format(rsUsage.getDate("startDate"));
        }
        if (rsUsage.getDate("expirationDate") != null) {
          rankExpirationDate = formatDate.format(rsUsage.getDate("expirationDate"));
        }
      } else {
        request.setCause(NOT_REGISTERED);
      }

      // response = ProductFactory.getCache().getProductMessage(request, "vni");

      if (rankRule != null) {
        response =
            response.replaceAll(
                "<totalAmount>", String.valueOf(new Double(totalAmount).longValue()));
        response =
            response.replaceAll(
                "<balanceAmount>", String.valueOf(new Double(balanceAmount).longValue()));
        response = response.replaceAll("<fromDate>", rankStartDate);
        response = response.replaceAll("<toDate>", rankExpirationDate);
        response = response.replaceAll("<rank>", rankRule.getTitle());
      }

      // instance.getDispatcher().sendSMS(request, request.getServiceAddress(), request.getIsdn(),
      // response);

      request.setStatus(0);
    } catch (AppException e) {
      request.setCause(e.getMessage());
    } catch (Exception e) {
      throw e;
    } finally {
      Database.closeObject(rsUsage);
      Database.closeObject(stmtUsage);
      Database.closeObject(rsBalance);
      Database.closeObject(stmtBalance);

      Database.closeObject(connection);
    }
    return true;
  }
  @Override
  public void checkPromotion(
      OrderRoutingInstance instance, ProductRoute orderRoute, CommandMessage order)
      throws Exception {
    if (order.getActionType().equals(Constants.ACTION_REGISTER)) {
      String strSQL_Select =
          "select statis_list_id, status "
              + " from max_sms_promotion_eligible "
              + " where 1 = 1 "
              + "       and isdn = ? "
              + "       and status = ? ";

      String strISDN = order.getIsdn();

      Connection connection = null;
      PreparedStatement stmt = null;
      ResultSet rs = null;
      try {
        connection = Database.getConnection();
        stmt = connection.prepareStatement(strSQL_Select);
        stmt.setString(1, strISDN);
        stmt.setInt(2, Constants.STATUS_INACTIVE);
        rs = stmt.executeQuery();
        if (!rs.next()) {
          throw new AppException(Constants.ERROR_INVALID_PROMOTION);
        } else {
          int iStatus = rs.getInt(2);
          if (iStatus == Constants.STATUS_ACTIVE || iStatus == Constants.STATUS_CANCEL) {
            throw new AppException(Constants.ERROR_REGISTERED);
          }
          String primaryKey = rs.getString(1);
          order.setResponseValue("primaryKey", primaryKey);
        }
      } finally {
        Database.closeObject(stmt);
        Database.closeObject(rs);
        Database.closeObject(connection);
      }
    } else if (order.getActionType().equals(Constants.ACTION_UNREGISTER)) {
      String strSQL_Select =
          "select to_char(expirationdate,'dd/mm/yyyy hh24:mi:ss')"
              + "             from subscriberproduct "
              + "             where 1 = 1 "
              + "                   and sysdate < expirationdate "
              + "                   and productid = ? and isdn = ?";

      Connection connection = null;
      PreparedStatement stmt = null;
      ResultSet rs = null;
      try {
        connection = Database.getConnection();
        stmt = connection.prepareStatement(strSQL_Select);
        stmt.setLong(1, order.getProductId());
        stmt.setString(2, order.getIsdn());
        rs = stmt.executeQuery();
        if (!rs.next()) {
          throw new AppException(Constants.ERROR_INVALID_PROMOTION);
        }
      } finally {
        Database.closeObject(stmt);
        Database.closeObject(rs);
        Database.closeObject(connection);
      }
    }
  }