|
|
@ -9,16 +9,20 @@ import java.util.LinkedHashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.manage.bdprize.support.BDPrizeCalculator;
|
|
|
|
import au.com.royalpay.payment.manage.bdprize.support.BDPrizeCalculator;
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ClientBDMapper;
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ClientBDMapper;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Created by yixian on 2017-02-08.
|
|
|
|
* Created by yixian on 2017-02-08.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator {
|
|
|
|
public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator {
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(BDPrizeCalculator.class);
|
|
|
|
private final List<JSONObject> tradeLogs;
|
|
|
|
private final List<JSONObject> tradeLogs;
|
|
|
|
private final Date month;
|
|
|
|
private final Date month;
|
|
|
|
private ClientBDMapper clientBDMapper;
|
|
|
|
private ClientBDMapper clientBDMapper;
|
|
|
@ -27,6 +31,7 @@ public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator {
|
|
|
|
private Map<String, JSONObject> bdMap = new HashMap<>();
|
|
|
|
private Map<String, JSONObject> bdMap = new HashMap<>();
|
|
|
|
private Map<Integer, Map<Integer, List<JSONObject>>> rateConfigMap = new HashMap<>();
|
|
|
|
private Map<Integer, Map<Integer, List<JSONObject>>> rateConfigMap = new HashMap<>();
|
|
|
|
private Map<String, BigDecimal> bdTotalMap = new HashMap<>();
|
|
|
|
private Map<String, BigDecimal> bdTotalMap = new HashMap<>();
|
|
|
|
|
|
|
|
private TransactionMapper transactionMapper;
|
|
|
|
|
|
|
|
|
|
|
|
public BDPrizeCalculatorDefaultImpl(List<JSONObject> tradeLogs, Date month) {
|
|
|
|
public BDPrizeCalculatorDefaultImpl(List<JSONObject> tradeLogs, Date month) {
|
|
|
|
this.tradeLogs = tradeLogs;
|
|
|
|
this.tradeLogs = tradeLogs;
|
|
|
@ -38,6 +43,11 @@ public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator {
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public BDPrizeCalculatorDefaultImpl transactionMapper(TransactionMapper transactionMapper) {
|
|
|
|
|
|
|
|
this.transactionMapper = transactionMapper;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public BDPrizeCalculatorDefaultImpl clientsWithBDAwayDeterminor(DefaultClientWithBDAwayDeterminor clientWithBDAwayDeterminor) {
|
|
|
|
public BDPrizeCalculatorDefaultImpl clientsWithBDAwayDeterminor(DefaultClientWithBDAwayDeterminor clientWithBDAwayDeterminor) {
|
|
|
|
this.clientsWithBDAwayDeterminor = clientWithBDAwayDeterminor;
|
|
|
|
this.clientsWithBDAwayDeterminor = clientWithBDAwayDeterminor;
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
@ -47,15 +57,15 @@ public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator {
|
|
|
|
for (JSONObject rateCfgItem : rateConfig) {
|
|
|
|
for (JSONObject rateCfgItem : rateConfig) {
|
|
|
|
int level = rateCfgItem.getIntValue("bd_level");
|
|
|
|
int level = rateCfgItem.getIntValue("bd_level");
|
|
|
|
int kpiRange = rateCfgItem.getIntValue("kpi_range");
|
|
|
|
int kpiRange = rateCfgItem.getIntValue("kpi_range");
|
|
|
|
Map<Integer, List<JSONObject>> rates = rateConfigMap.get(level);
|
|
|
|
Map<Integer, List<JSONObject>> levelRates = rateConfigMap.get(level);
|
|
|
|
if (rates == null) {
|
|
|
|
if (levelRates == null) {
|
|
|
|
rates = new HashMap<>();
|
|
|
|
levelRates = new HashMap<>();
|
|
|
|
rateConfigMap.put(level, rates);
|
|
|
|
rateConfigMap.put(level, levelRates);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<JSONObject> rate = rates.get(kpiRange);
|
|
|
|
List<JSONObject> rate = levelRates.get(kpiRange);
|
|
|
|
if (rate == null) {
|
|
|
|
if (rate == null) {
|
|
|
|
rate = new ArrayList<>();
|
|
|
|
rate = new ArrayList<>();
|
|
|
|
rates.put(kpiRange, rate);
|
|
|
|
levelRates.put(kpiRange, rate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rate.add(rateCfgItem);
|
|
|
|
rate.add(rateCfgItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -73,7 +83,7 @@ public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<JSONObject> getReport() {
|
|
|
|
public List<JSONObject> getReport(int year,int month1) {
|
|
|
|
List<JSONObject> report = new ArrayList<>();
|
|
|
|
List<JSONObject> report = new ArrayList<>();
|
|
|
|
for (Map.Entry<String, Map<String, JSONObject>> resultItem : results.entrySet()) {
|
|
|
|
for (Map.Entry<String, Map<String, JSONObject>> resultItem : results.entrySet()) {
|
|
|
|
JSONObject log = new JSONObject();
|
|
|
|
JSONObject log = new JSONObject();
|
|
|
@ -86,15 +96,8 @@ public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator {
|
|
|
|
log.put("total_amount", 0);
|
|
|
|
log.put("total_amount", 0);
|
|
|
|
log.put("total_prize", 0);
|
|
|
|
log.put("total_prize", 0);
|
|
|
|
log.put("total_donation", 0);
|
|
|
|
log.put("total_donation", 0);
|
|
|
|
BigDecimal totalAmount = log.getBigDecimal("total_amount");
|
|
|
|
BigDecimal totalAmount = transactionMapper.TotalAmountForBDPrize(year,month1,bd.getString("bd_id"));
|
|
|
|
List<JSONObject> details = new ArrayList<>();
|
|
|
|
List<JSONObject> details = new ArrayList<>();
|
|
|
|
for (Map.Entry<String, JSONObject> detail : resultItem.getValue().entrySet()) {
|
|
|
|
|
|
|
|
JSONObject detailItem = detail.getValue();
|
|
|
|
|
|
|
|
BigDecimal totalTransaction = detailItem.getBigDecimal("total_transaction");
|
|
|
|
|
|
|
|
BigDecimal coefficient = detailItem.getBigDecimal("coefficient");
|
|
|
|
|
|
|
|
BigDecimal realTransaction = totalTransaction.multiply(coefficient).setScale(2,BigDecimal.ROUND_DOWN);
|
|
|
|
|
|
|
|
totalAmount = totalAmount.add(realTransaction);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Map.Entry<String, JSONObject> detail : resultItem.getValue().entrySet()) {
|
|
|
|
for (Map.Entry<String, JSONObject> detail : resultItem.getValue().entrySet()) {
|
|
|
|
JSONObject detailItem = detail.getValue();
|
|
|
|
JSONObject detailItem = detail.getValue();
|
|
|
|
int clientId = detailItem.getIntValue("client_id");
|
|
|
|
int clientId = detailItem.getIntValue("client_id");
|
|
|
@ -102,6 +105,7 @@ public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator {
|
|
|
|
BigDecimal totalTransaction = detailItem.getBigDecimal("total_transaction");
|
|
|
|
BigDecimal totalTransaction = detailItem.getBigDecimal("total_transaction");
|
|
|
|
BigDecimal coefficient = detailItem.getBigDecimal("coefficient");
|
|
|
|
BigDecimal coefficient = detailItem.getBigDecimal("coefficient");
|
|
|
|
int prizeLevel = getKpiPrizeLevel(totalAmount,log.getBigDecimal("kpi_amount"));
|
|
|
|
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 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 prizeValue = totalTransaction.multiply(coefficient).multiply(bdRate).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_DOWN);
|
|
|
|
BigDecimal donation = BigDecimal.ZERO;
|
|
|
|
BigDecimal donation = BigDecimal.ZERO;
|
|
|
@ -222,8 +226,8 @@ public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator {
|
|
|
|
|
|
|
|
|
|
|
|
private BigDecimal getNewRate(int bdLevel, int kpiRange, int clientSource, BigDecimal clientRate) {
|
|
|
|
private BigDecimal getNewRate(int bdLevel, int kpiRange, int clientSource, BigDecimal clientRate) {
|
|
|
|
BigDecimal prizeRate = BigDecimal.ZERO;
|
|
|
|
BigDecimal prizeRate = BigDecimal.ZERO;
|
|
|
|
Map<Integer, List<JSONObject>> rates = rateConfigMap.get(bdLevel);
|
|
|
|
Map<Integer, List<JSONObject>> levelRates = rateConfigMap.get(bdLevel);
|
|
|
|
List<JSONObject> rate = rates.get(kpiRange);
|
|
|
|
List<JSONObject> rate = levelRates.get(kpiRange);
|
|
|
|
for (JSONObject rateCfg : rate) {
|
|
|
|
for (JSONObject rateCfg : rate) {
|
|
|
|
if (rateCfg.getBigDecimal("rate_from").compareTo(clientRate) <= 0 && rateCfg.getBigDecimal("rate_to").compareTo(clientRate) >= 0) {
|
|
|
|
if (rateCfg.getBigDecimal("rate_from").compareTo(clientRate) <= 0 && rateCfg.getBigDecimal("rate_to").compareTo(clientRate) >= 0) {
|
|
|
|
prizeRate= rateCfg.getBigDecimal("prize_rate");
|
|
|
|
prizeRate= rateCfg.getBigDecimal("prize_rate");
|
|
|
|