eason 6 years ago
parent c8657980cf
commit 04b3b7665a

@ -14,11 +14,14 @@ import com.alibaba.fastjson.JSONObject;
import au.com.royalpay.payment.manage.bdprize.support.BDPrizeCalculator;
import au.com.royalpay.payment.manage.mappers.system.ClientBDMapper;
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Created by yixian on 2017-02-08.
*/
public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator {
private static Logger logger = LoggerFactory.getLogger(BDPrizeCalculator.class);
private final List<JSONObject> tradeLogs;
private final Date month;
private ClientBDMapper clientBDMapper;
@ -47,15 +50,15 @@ public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator {
for (JSONObject rateCfgItem : rateConfig) {
int level = rateCfgItem.getIntValue("bd_level");
int kpiRange = rateCfgItem.getIntValue("kpi_range");
Map<Integer, List<JSONObject>> rates = rateConfigMap.get(level);
if (rates == null) {
rates = new HashMap<>();
rateConfigMap.put(level, rates);
Map<Integer, List<JSONObject>> levelRates = rateConfigMap.get(level);
if (levelRates == null) {
levelRates = new HashMap<>();
rateConfigMap.put(level, levelRates);
}
List<JSONObject> rate = rates.get(kpiRange);
List<JSONObject> rate = levelRates.get(kpiRange);
if (rate == null) {
rate = new ArrayList<>();
rates.put(kpiRange, rate);
levelRates.put(kpiRange, rate);
}
rate.add(rateCfgItem);
}
@ -102,6 +105,7 @@ public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator {
BigDecimal totalTransaction = detailItem.getBigDecimal("total_transaction");
BigDecimal coefficient = detailItem.getBigDecimal("coefficient");
int prizeLevel = getKpiPrizeLevel(totalAmount,log.getBigDecimal("kpi_amount"));
logger.debug("-------->bd kpi level:"+bd.getString("bd_name")+"---level:"+prizeLevel+",kpi:"+log.getBigDecimal("kpi_amount")+",trans:"+totalAmount+",client_id:"+clientId);
BigDecimal bdRate = getNewRate(bdLevel, prizeLevel, detailItem.getIntValue("client_source"), detailItem.getBigDecimal("rate_value"));
BigDecimal prizeValue = totalTransaction.multiply(coefficient).multiply(bdRate).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_DOWN);
BigDecimal donation = BigDecimal.ZERO;
@ -222,8 +226,8 @@ public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator {
private BigDecimal getNewRate(int bdLevel, int kpiRange, int clientSource, BigDecimal clientRate) {
BigDecimal prizeRate = BigDecimal.ZERO;
Map<Integer, List<JSONObject>> rates = rateConfigMap.get(bdLevel);
List<JSONObject> rate = rates.get(kpiRange);
Map<Integer, List<JSONObject>> levelRates = rateConfigMap.get(bdLevel);
List<JSONObject> rate = levelRates.get(kpiRange);
for (JSONObject rateCfg : rate) {
if (rateCfg.getBigDecimal("rate_from").compareTo(clientRate) <= 0 && rateCfg.getBigDecimal("rate_to").compareTo(clientRate) >= 0) {
prizeRate= rateCfg.getBigDecimal("prize_rate");

Loading…
Cancel
Save