/** * If the payout-limit of current merchant is 'follow parent', TE should query its parent merchant * till find a parent merchant whose payout-limit isn't 'follow parent'. * * @return the PrizeGroup which will be applied at final. */ private PrizeGroup determinePrizeGroup(Context respCtx, Operator operator) throws ApplicationException { PrizeGroup prizeGroup = operator.getPrizeGroup(); if (prizeGroup == null) { throw new ApplicationException( SystemException.CODE_MERCHANT_UNALLOWED_PAY, "No any prize group definition found of Operator(" + operator + "), System will simply reject this payout request."); } if (PrizeGroup.ALLOWTYPE_USEPARENT == prizeGroup.getAllowType()) { // lookup prize group definition of operator's parent merchant Merchant leafMerchant = this.getMerchantDao().findById(Merchant.class, respCtx.getTransaction().getMerchantId()); if (leafMerchant == null) { throw new ApplicationException( SystemException.CODE_NO_MERCHANT, "can NOT find merhcant by id=" + respCtx.getTransaction().getMerchantId()); } prizeGroup = this.determinePrizeGroup(leafMerchant); } else { if (logger.isDebugEnabled()) { logger.debug( "Use the payout-limit setting(max=" + prizeGroup.getMaxPayoutAmount() + ",min=" + prizeGroup.getMinPayoutAmount() + ") of Operator(" + operator + ") to verify payout limit."); } } return prizeGroup; }
/** Found the valid prize group definition recursively. */ private PrizeGroup determinePrizeGroup(Merchant merchant) throws ApplicationException { if (Merchant.SUPER_MERCHANT_ID == merchant.getId()) { return null; } PrizeGroup prizeGroup = merchant.getPrizeGroup(); if (prizeGroup == null) { throw new ApplicationException( SystemException.CODE_MERCHANT_UNALLOWED_PAY, "No any prize group definition found of Merchant(" + merchant + "), System will simply reject this payout request."); } if (PrizeGroup.ALLOWTYPE_USEPARENT == prizeGroup.getAllowType()) { prizeGroup = this.determinePrizeGroup(merchant.getParentMerchant()); } else { if (logger.isDebugEnabled()) { logger.debug( "Use the payout-limit setting(max=" + prizeGroup.getMaxPayoutAmount() + ",min=" + prizeGroup.getMinPayoutAmount() + ") of merhcant(" + merchant + ") to verify payout limit."); } if (!prizeGroup.isPayoutAllowed()) { throw new ApplicationException( SystemException.CODE_MERCHANT_UNALLOWED_PAY, "Merchant(" + merchant + ") doesn't allow payout."); } } return prizeGroup; }
/** * When do payout/validation, system check the payout-limit of the merchant. A merchant maybe * follow its parent's payout-limit setting, system should handle this case. * * @param respCtx The context of current transaction. * @param actualPayout The actual amount of payout. * @param operator The operator who do payout. * @throws ApplicationException when encounter any business exception. */ private void verifyPayoutByLimit(Context respCtx, BigDecimal actualPayout, Operator operator) throws ApplicationException { PrizeGroup prizeGroup = this.determinePrizeGroup(respCtx, operator); if (PrizeGroup.ALLOWTYPE_UNLIMIT == prizeGroup.getAllowType()) { if (logger.isDebugEnabled()) { logger.debug("the prize group definition(" + prizeGroup.getId() + ") is no limited"); } return; } if (prizeGroup.getMaxPayoutAmount() != null && prizeGroup.getMaxPayoutAmount().compareTo(new BigDecimal("0")) >= 0) { if (actualPayout.compareTo(prizeGroup.getMaxPayoutAmount()) > 0) { throw new ApplicationException( SystemException.CODE_EXCEED_MAX_PAYOUT, "The prize actual amount(" + actualPayout + ") exceed the max " + "allowed payout amount(" + prizeGroup.getMaxPayoutAmount() + ")."); } } if (prizeGroup.getMinPayoutAmount() != null && prizeGroup.getMinPayoutAmount().compareTo(new BigDecimal("0")) >= 0) { if (actualPayout.compareTo(prizeGroup.getMinPayoutAmount()) < 0) { throw new ApplicationException( SystemException.CODE_EXCEED_MAX_PAYOUT, "The prize actual amount(" + actualPayout + ") is less than min " + "payout amount(" + prizeGroup.getMinPayoutAmount() + ")."); } } }