コード例 #1
0
  @Override
  public CashOutByOperatorPassDto cashoutOperatorByPass(
      Context respCtx, Context responseCtx, CashOutByOperatorPassDto cashoutDto)
      throws ApplicationException {
    // tried times add 1
    this.cashoutPassDao.increaseTriedTimes(cashoutDto.getBarcode());

    // lookup the 'CASHOUT_PASS' according to field 'BARCODE' & 'password'
    CashoutPass cashoutpass = this.cashoutPassDao.findByBarcode(cashoutDto.getBarcode());
    if (cashoutpass == null || cashoutpass.getId() == null || "".equals(cashoutpass.getId())) {
      // throw new ApplicationException(SystemException.CODE_CASHOUTPASS_NO_EXIST_BARCODE,
      // "[CashoutByPassword](barcode="
      // + cashoutDto.getBarcode() + ") not exist the barcode].");
      responseCtx.setResponseCode(SystemException.CODE_CASHOUTPASS_NO_EXIST_BARCODE);
      logger.error("======================================");
      logger.error(
          "[CashoutByPassword](barcode=" + cashoutDto.getBarcode() + ") not exist the barcode].");
      logger.error("======================================");
      return null;
    }

    // check whether or not used
    if (cashoutpass.getCashoutTeTransactionId() != null
        && !"".equals(cashoutpass.getCashoutTeTransactionId())) {
      // throw new ApplicationException(SystemException.CODE_CASHOUTPASS_ALREADY_USED,
      // "[CashoutByPassword](barcode="
      // + cashoutDto.getBarcode() + ") is already used].");
      responseCtx.setResponseCode(SystemException.CODE_CASHOUTPASS_ALREADY_USED);
      logger.error("======================================");
      logger.error(
          "[CashoutByPassword](barcode=" + cashoutDto.getBarcode() + ") is already used].");
      logger.error("======================================");
      return null;
    }

    // check expired time
    if (new Date().compareTo(cashoutpass.getExpireTime()) > 0) {
      // throw new ApplicationException(SystemException.CODE_CASHOUTPASS_EXPIRETIME,
      // "[CashoutByPassword] The cashout password is expiry !");
      responseCtx.setResponseCode(SystemException.CODE_CASHOUTPASS_EXPIRETIME);
      logger.error("======================================");
      logger.error("[CashoutByPassword] The cashout password is expiry !");
      logger.error("======================================");
      return null;
    }

    // check max tried times
    SysConfiguration sysConf = this.getSysConfigurationDao().getSysConfiguration();
    int maxiumtimes = sysConf.getMaxiumTimesOfCashoutPass();
    if ((cashoutpass.getTriedTimes()) > maxiumtimes) {
      // throw new ApplicationException(SystemException.CODE_CASHOUTPASS_EXCEED_MAXTIMES,
      // "[CashoutByPassword] The cashout by password is exceed max tried times !");
      responseCtx.setResponseCode(SystemException.CODE_CASHOUTPASS_EXCEED_MAXTIMES);
      logger.error("======================================");
      logger.error("[CashoutByPassword] The cashout by password is exceed max tried times !");
      logger.error("======================================");
      return null;
    }

    // check password whether or not correct
    if (!cashoutpass.getCashoutPassword().equals(cashoutDto.getPassword())) {
      // throw new ApplicationException(SystemException.CODE_CASHOUTPASS_INCORRECT,
      // "[CashoutByPassword](barcode="
      // + cashoutDto.getBarcode() + ") password is incorrect].");
      responseCtx.setResponseCode(SystemException.CODE_CASHOUTPASS_INCORRECT);
      logger.error("======================================");
      logger.error(
          "[CashoutByPassword](barcode=" + cashoutDto.getBarcode() + ") password is incorrect].");
      logger.error("======================================");
      return null;
    }

    // main logic for cash out
    cashoutLogic(
        respCtx,
        cashoutpass,
        cashoutpass.getOperatorId(),
        cashoutpass.getCashoutAmount(),
        TransactionType.CASH_OUT_OPERATOR_PASS.getRequestType());

    // ==========================

    // assemble response bean
    CashOutByOperatorPassDto respCashoutPassDto = new CashOutByOperatorPassDto();
    respCashoutPassDto.setAmount(cashoutpass.getCashoutAmount());
    respCashoutPassDto.setOperatorId(cashoutpass.getOperatorId());

    return respCashoutPassDto;
  }