private HkPaymentResponse createPayment(
      String gatewayOrderId,
      String gatewayReferenceId,
      String rrn,
      String respMsg,
      String txnType,
      String amount,
      String authIdCode) {
    HkPaymentResponse hkPaymentResponse =
        new HkPaymentResponse(
            gatewayOrderId,
            gatewayReferenceId,
            respMsg,
            EnumGateway.EBS.asGateway(),
            null,
            null,
            rrn,
            authIdCode,
            NumberUtils.toDouble(amount));

    if (txnType.equalsIgnoreCase(EnumPaymentTransactionType.SALE.getName())) {
      hkPaymentResponse.setGatewayOrderId(gatewayOrderId);
      hkPaymentResponse.setTransactionType(EnumPaymentTransactionType.SALE.getName());
    } else if (txnType.equalsIgnoreCase(EnumPaymentTransactionType.REFUND.getName())) {
      hkPaymentResponse.setTransactionType(EnumPaymentTransactionType.REFUND.getName());
    }
    return hkPaymentResponse;
  }
예제 #2
0
 public static double toDouble(final Object o, final int casas) {
   if (o == null) {
     return 0d;
   } else if (o instanceof BigDecimal) {
     return ((BigDecimal) o).setScale(casas, RoundingMode.HALF_UP).doubleValue();
   } else {
     return NumberUtils.toDouble(String.valueOf(o), casas);
   }
 }
예제 #3
0
 public static double toDouble(final Object o) {
   if (o == null) {
     return 0d;
   } else if (o instanceof BigDecimal) {
     return ((BigDecimal) o).doubleValue();
   } else {
     return NumberUtils.toDouble(String.valueOf(o));
   }
 }
  private HkPaymentResponse verifyAndCreateHkResponsePayment(
      Element element, String gatewayOrderId, String transactionType) {
    HkPaymentResponse hkPaymentResponse = null;
    if (element != null) {
      hkPaymentResponse =
          createPayment(
              gatewayOrderId,
              null,
              null,
              null,
              transactionType,
              null,
              null); // EnumPaymentTransactionType.SALE.getName()

      String paymentId =
          element.getAttributeValue(GatewayResponseKeys.EbsConstants.TXN_PAYMENT_ID.getKey());
      String transactionId =
          element.getAttributeValue(GatewayResponseKeys.EbsConstants.TXN_TRANSACTION_ID.getKey());
      String amount = element.getAttributeValue(GatewayResponseKeys.EbsConstants.AMOUNT.getKey());
      String status =
          element.getAttributeValue(GatewayResponseKeys.EbsConstants.TXN_STATUS.getKey());
      String isFlagged =
          element.getAttributeValue(GatewayResponseKeys.EbsConstants.IS_FLAGGED.getKey());
      String errorCode = element.getAttributeValue(EbsPaymentGatewayWrapper.TXN_ERROR_CODE);
      String errorMessage = element.getAttributeValue(EbsPaymentGatewayWrapper.TXN_ERROR_MSG);
      String ebsTransactionType =
          element.getAttributeValue(EbsPaymentGatewayWrapper.TXN_TRANSACTION_TYPE);
      // String gatewayOrderId =
      // element.getAttributeValue(EbsPaymentGatewayWrapper.TXN_REFERENCE_NO);

      if (paymentId != null) {

        hkPaymentResponse.setGatewayReferenceId(paymentId);
        hkPaymentResponse.setRrn(transactionId);
        hkPaymentResponse.setAmount(NumberUtils.toDouble(amount));
        hkPaymentResponse.setResponseMsg(status);
        updateResponseStatus(
            hkPaymentResponse, transactionType, isFlagged, status, ebsTransactionType);

      } else {
        hkPaymentResponse.setHKPaymentStatus(EnumHKPaymentStatus.FAILURE);
        hkPaymentResponse.setErrorLog(errorMessage);
      }
    }

    return hkPaymentResponse;
  }
예제 #5
0
 @Override
 Double parse(String s) {
   return StringUtils.isBlank(s) ? null : NumberUtils.toDouble(s);
 }
예제 #6
0
 public static double toDouble(final Integer number) {
   return NumberUtils.toDouble(String.valueOf(number));
 }
  public WarningActionsConfig(ConfigurationSection config) {
    isEnabled = config.getBoolean("enabled", false);
    actions = new HashMap<>();

    if (!isEnabled) return;

    ConfigurationSection actionsConf = config.getConfigurationSection("actions");

    if (actionsConf == null) return;

    for (String amount : actionsConf.getKeys(false)) {
      if (!StringUtils.isNumeric(amount)) {
        plugin.getLogger().warning("Invalid warning action, " + amount + " is not numeric");
        continue;
      }

      // New check
      List<Map<?, ?>> mapList = actionsConf.getMapList(amount);
      if (mapList != null && mapList.size() != 0) {
        List<ActionCommand> actionCommands = new ArrayList<>(mapList.size());

        for (Map<?, ?> map : mapList) {
          if (map.get("cmd") == null) {
            plugin.getLogger().severe("Missing cmd from warningActions " + amount);
            continue;
          }

          long delay = 0;

          if (map.get("delay") != null) {
            try {
              delay = Long.valueOf((Integer) map.get("delay"));
            } catch (NumberFormatException e) {
              plugin.getLogger().severe("Invalid delay for " + map.get("cmd"));
              continue;
            }

            delay = delay * 20L; // Convert from seconds to ticks
          }

          actionCommands.add(new ActionCommand((String) map.get("cmd"), delay));
        }

        this.actions.put(NumberUtils.toDouble(amount), actionCommands);
      } else {
        List<String> actions = actionsConf.getStringList(amount);
        if (actions.size() == 0) continue;

        plugin
            .getLogger()
            .warning(
                "warningActions amount "
                    + amount
                    + " is using a deprecated list, please use new cmd and delay syntax");
        List<ActionCommand> actionCommands = new ArrayList<>(actions.size());

        for (String action : actions) {
          actionCommands.add(new ActionCommand(action, 0));
        }

        this.actions.put(NumberUtils.toDouble(amount), actionCommands);
      }
    }
  }
예제 #8
0
  // load Block locations of given world
  public void loadWorldData(String uuid, World world) {

    File file = new File(p.getDataFolder(), "data.yml");
    if (file.exists()) {

      FileConfiguration data = YamlConfiguration.loadConfiguration(file);

      // loading BCauldron
      if (data.contains("BCauldron." + uuid)) {
        ConfigurationSection section = data.getConfigurationSection("BCauldron." + uuid);
        for (String cauldron : section.getKeys(false)) {
          // block is splitted into x/y/z
          String block = section.getString(cauldron + ".block");
          if (block != null) {
            String[] splitted = block.split("/");
            if (splitted.length == 3) {

              Block worldBlock =
                  world.getBlockAt(
                      parseInt(splitted[0]), parseInt(splitted[1]), parseInt(splitted[2]));
              BIngredients ingredients =
                  loadIngredients(section.getConfigurationSection(cauldron + ".ingredients"));
              int state = section.getInt(cauldron + ".state", 1);

              new BCauldron(worldBlock, ingredients, state);
            } else {
              errorLog(
                  "Incomplete Block-Data in data.yml: "
                      + section.getCurrentPath()
                      + "."
                      + cauldron);
            }
          } else {
            errorLog(
                "Missing Block-Data in data.yml: " + section.getCurrentPath() + "." + cauldron);
          }
        }
      }

      // loading Barrel
      if (data.contains("Barrel." + uuid)) {
        ConfigurationSection section = data.getConfigurationSection("Barrel." + uuid);
        for (String barrel : section.getKeys(false)) {
          // block spigot is splitted into x/y/z
          String spigot = section.getString(barrel + ".spigot");
          if (spigot != null) {
            String[] splitted = spigot.split("/");
            if (splitted.length == 3) {

              // load itemStacks from invSection
              ConfigurationSection invSection = section.getConfigurationSection(barrel + ".inv");
              Block block =
                  world.getBlockAt(
                      parseInt(splitted[0]), parseInt(splitted[1]), parseInt(splitted[2]));
              float time = (float) section.getDouble(barrel + ".time", 0.0);
              byte sign = (byte) section.getInt(barrel + ".sign", 0);
              String[] st = section.getString(barrel + ".st", "").split(",");
              String[] wo = section.getString(barrel + ".wo", "").split(",");

              if (invSection != null) {
                new Barrel(block, sign, st, wo, invSection.getValues(true), time);
              } else {
                // Barrel has no inventory
                new Barrel(block, sign, st, wo, null, time);
              }

            } else {
              errorLog(
                  "Incomplete Block-Data in data.yml: " + section.getCurrentPath() + "." + barrel);
            }
          } else {
            errorLog("Missing Block-Data in data.yml: " + section.getCurrentPath() + "." + barrel);
          }
        }
      }

      // loading Wakeup
      if (data.contains("Wakeup." + uuid)) {
        ConfigurationSection section = data.getConfigurationSection("Wakeup." + uuid);
        for (String wakeup : section.getKeys(false)) {
          // loc of wakeup is splitted into x/y/z/pitch/yaw
          String loc = section.getString(wakeup);
          if (loc != null) {
            String[] splitted = loc.split("/");
            if (splitted.length == 5) {

              double x = NumberUtils.toDouble(splitted[0]);
              double y = NumberUtils.toDouble(splitted[1]);
              double z = NumberUtils.toDouble(splitted[2]);
              float pitch = NumberUtils.toFloat(splitted[3]);
              float yaw = NumberUtils.toFloat(splitted[4]);
              Location location = new Location(world, x, y, z, yaw, pitch);

              Wakeup.wakeups.add(new Wakeup(location));

            } else {
              errorLog(
                  "Incomplete Location-Data in data.yml: "
                      + section.getCurrentPath()
                      + "."
                      + wakeup);
            }
          }
        }
      }
    }
  }
예제 #9
0
  @Override
  public void runJob() {
    addLog("开始更新基线", LOG_TYPE_SUCCESS);
    Calendar cl = Calendar.getInstance();
    long times = cl.getTimeInMillis();
    TaskInfoDto taskInfo = (TaskInfoDto) this.params.get(TASKINFO_KEY);

    String[] strs = taskInfo.getConfigDesc().split(";");

    // splunk服务器连接信息
    String[] serCfg = strs[0].split(",");
    if (serCfg.length != 4) {
      addLog("连接服务器参数不对:" + strs[0], LOG_TYPE_ERROR);
      return;
    }

    // 基本查询条件
    String baseStr = strs[2];

    String baseStr2 = strs.length < 14 ? "" : strs[13];

    // 统计值字段名
    String cntCol = strs[3];

    // 时间字段名
    String timeCol = strs[4];

    try {
      // 连接参数
      ServiceArgs loginArgs = new ServiceArgs();
      loginArgs.setUsername(serCfg[2]);
      loginArgs.setPassword(serCfg[3]);
      loginArgs.setHost(serCfg[0]);
      loginArgs.setPort(NumberUtils.toInt(serCfg[1]));

      // 连接
      Service service = Service.connect(loginArgs);

      // 延迟
      int delayMi = NumberUtils.toInt(strs[5], 0);

      String searchStr = createNSearchStr(baseStr, cntCol, timeCol, delayMi, baseStr2);

      this.addLog("查询:" + searchStr, LOG_TYPE_SUCCESS);

      // 查询
      Job nJob = service.search(searchStr); // 最近1分钟

      ResultsReader results;
      Event et;
      Iterator<Event> ie;
      InputStream is;
      ////////////////////////////////////////////////////////// 最近1分钟
      while (!nJob.isDone()) {
        Thread.sleep(1000);
      }
      is = nJob.getResults(new Args("output_mode", "json"));

      results = createResultsReader(ResultsReaderJson.class, is);

      List<String> nNumVal1 = new ArrayList<String>();
      List<String> nNumVal2 = new ArrayList<String>();
      List<String> nNumVal3 = new ArrayList<String>();
      List<Date> nDate = new ArrayList<Date>();

      if (nJob.getResultCount() > 0) {
        ie = results.iterator();

        while (ie.hasNext()) {
          if (strs.length > 12 && "1".equals(strs[12])) {

            et = ie.next();
            nNumVal1.add(et.get("my_cnt1"));
            nNumVal2.add(et.get("my_cnt2"));
            nDate.add(convertDate(et.get("my_time")));

          } else if (strs.length > 12 && "2".equals(strs[12])) {
            while (ie.hasNext()) {
              et = ie.next();
              nNumVal1.add(et.get("my_cnt1"));
              nNumVal2.add(et.get("my_cnt2"));
              nNumVal3.add(et.get("my_cnt3"));
              nDate.add(convertDate(et.get("my_time")));
            }
          } else {

            et = ie.next();
            nNumVal1.add(et.get("my_cnt1"));
            nDate.add(convertDate(et.get("my_time")));
          }
        }
      }
      is.close();
      nJob.cancel();

      ////////////////////////////////////////////////////////// 最近1分钟 end
      String curTime;
      BizMiDto dto;
      BizMiDao bdao = new BizMiDao();
      double rr;
      if (!nNumVal1.isEmpty()) {
        for (int i = 0; i < nNumVal1.size(); i++) {
          cl.set(Calendar.SECOND, 0);
          if (nDate.get(i) != null) {
            cl.setTime(nDate.get(i));
            curTime = DateUtil.datetimeFormat.format(nDate.get(i));
          } else {
            cl.add(Calendar.MINUTE, -delayMi);
            curTime = DateUtil.datetimeFormat.format(cl.getTime());
          }

          try {
            dto = bdao.findByTimeAndMi(strs[7], strs[8], curTime, strs[6]);
            if (dto == null) {
              this.addLog(
                  "更新出错,找不到更新点:" + strs[7] + "::" + strs[8] + "::" + curTime + "::" + strs[6],
                  LOG_TYPE_ERROR);
              this.addLog("更新出错,找不到更新点", LOG_TYPE_ERROR);
            }
            dto.setVal(ckVal(nNumVal1.get(i)));
            bdao.updateByTimeAndMi(dto);
          } catch (Exception e) {
            addLog("更新入口VAL:" + formatExpection(e), LOG_TYPE_ERROR);
          }

          if (!nNumVal2.isEmpty()) {
            try {
              dto = bdao.findByTimeAndMi(strs[7], strs[9], curTime, strs[6]);
              if (dto == null) {
                this.addLog(
                    "更新出错,找不到更新点:" + strs[7] + "::" + strs[9] + "::" + curTime + "::" + strs[6],
                    LOG_TYPE_ERROR);
              }
              dto.setVal(ckVal(nNumVal2.get(i)));
              bdao.updateByTimeAndMi(dto);
            } catch (Exception e) {
              addLog("更新出口VAL:" + formatExpection(e), LOG_TYPE_ERROR);
            }

            try {
              dto = bdao.findByTimeAndMi(strs[7], strs[10], curTime, strs[6]);
              if (dto == null) {
                this.addLog(
                    "更新出错,找不到更新点:" + strs[7] + "::" + strs[10] + "::" + curTime + "::" + strs[6],
                    LOG_TYPE_ERROR);
              }
              rr =
                  NumberUtils.toDouble(nNumVal2.get(i), 0)
                      / NumberUtils.toDouble(nNumVal1.get(i), 0);
              if (rr == Double.NaN) {
                dto.setVal(String.valueOf(0));
              } else {
                dto.setVal(String.valueOf(rr));
              }
              bdao.updateByTimeAndMi(dto);
            } catch (Exception e) {
              addLog("更新响应率:" + formatExpection(e), LOG_TYPE_ERROR);
            }
          }

          if (!nNumVal3.isEmpty()) {
            dto = bdao.findByTimeAndMi(strs[7], strs[11], curTime, strs[6]);
            dto.setVal(ckVal(nNumVal3.get(i)));
            bdao.updateByTimeAndMi(dto);
            try {
              bdao.saveByTable(dto, strs[6]);
            } catch (Exception e) {
              addLog("更新响应时间:" + formatExpection(e), LOG_TYPE_ERROR);
            }
          }
        }
      }

      addLog("任务耗时:" + (Calendar.getInstance().getTimeInMillis() - times) + "毫秒", LOG_TYPE_SUCCESS);

    } catch (Exception e) {
      e.printStackTrace();
      addLog(formatExpection(e), LOG_TYPE_ERROR);
    }
  }