From 04b3b7665a472646126bbfc47e72c299d2a7ef51 Mon Sep 17 00:00:00 2001 From: eason Date: Thu, 2 Aug 2018 21:36:47 +0800 Subject: [PATCH 1/8] bd --- .../impls/BDPrizeCalculatorDefaultImpl.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/bdprize/support/impls/BDPrizeCalculatorDefaultImpl.java b/src/main/java/au/com/royalpay/payment/manage/bdprize/support/impls/BDPrizeCalculatorDefaultImpl.java index 7107827b1..603afd119 100644 --- a/src/main/java/au/com/royalpay/payment/manage/bdprize/support/impls/BDPrizeCalculatorDefaultImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/bdprize/support/impls/BDPrizeCalculatorDefaultImpl.java @@ -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 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> rates = rateConfigMap.get(level); - if (rates == null) { - rates = new HashMap<>(); - rateConfigMap.put(level, rates); + Map> levelRates = rateConfigMap.get(level); + if (levelRates == null) { + levelRates = new HashMap<>(); + rateConfigMap.put(level, levelRates); } - List rate = rates.get(kpiRange); + List 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> rates = rateConfigMap.get(bdLevel); - List rate = rates.get(kpiRange); + Map> levelRates = rateConfigMap.get(bdLevel); + List 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"); From 2627482fba6f2366bf7d54a55d31142f53d47b92 Mon Sep 17 00:00:00 2001 From: eason Date: Thu, 2 Aug 2018 22:29:58 +0800 Subject: [PATCH 2/8] fix --- .../support/impls/BDPrizeCalculatorDefaultImpl.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/bdprize/support/impls/BDPrizeCalculatorDefaultImpl.java b/src/main/java/au/com/royalpay/payment/manage/bdprize/support/impls/BDPrizeCalculatorDefaultImpl.java index 603afd119..1564f33be 100644 --- a/src/main/java/au/com/royalpay/payment/manage/bdprize/support/impls/BDPrizeCalculatorDefaultImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/bdprize/support/impls/BDPrizeCalculatorDefaultImpl.java @@ -89,15 +89,8 @@ public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator { log.put("total_amount", 0); log.put("total_prize", 0); log.put("total_donation", 0); - BigDecimal totalAmount = log.getBigDecimal("total_amount"); + BigDecimal totalAmount = bdTotalMap.get(bd.getString("bd_id")); List details = new ArrayList<>(); - for (Map.Entry 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 detail : resultItem.getValue().entrySet()) { JSONObject detailItem = detail.getValue(); int clientId = detailItem.getIntValue("client_id"); From 376687f25b4168c90bddb35f74b80a0d6a012b86 Mon Sep 17 00:00:00 2001 From: eason Date: Thu, 2 Aug 2018 22:58:28 +0800 Subject: [PATCH 3/8] fix bd prize --- .../bdprize/core/impls/BDPrizeServiceImpl.java | 2 +- .../manage/bdprize/support/BDPrizeCalculator.java | 2 +- .../impls/BDPrizeCalculatorDefaultImpl.java | 6 ++++-- .../manage/mappers/payment/TransactionMapper.java | 2 ++ .../manage/mappers/payment/TransactionMapper.xml | 15 +++++++++++++++ 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/bdprize/core/impls/BDPrizeServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/bdprize/core/impls/BDPrizeServiceImpl.java index c52dac881..8670ec2f6 100644 --- a/src/main/java/au/com/royalpay/payment/manage/bdprize/core/impls/BDPrizeServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/bdprize/core/impls/BDPrizeServiceImpl.java @@ -124,7 +124,7 @@ public class BDPrizeServiceImpl implements BDPrizeService { BDPrizeCalculator calculator = new BDPrizeCalculatorDefaultImpl(trades, now.getTime()).clientBDMapper(clientBDMapper) .clientsWithBDAwayDeterminor(new DefaultClientWithBDAwayDeterminor(clientsWithBDAway)).rateConfig(rateConfig); calculator.calculate(); - List report = calculator.getReport(); + List report = calculator.getReport(now.get(Calendar.YEAR),now.get(Calendar.MONTH) + 1); for (JSONObject log : report) { log.put("record_id", record.getString("record_id")); log.put("channel", channel); diff --git a/src/main/java/au/com/royalpay/payment/manage/bdprize/support/BDPrizeCalculator.java b/src/main/java/au/com/royalpay/payment/manage/bdprize/support/BDPrizeCalculator.java index 49e4365b6..049a5bedb 100644 --- a/src/main/java/au/com/royalpay/payment/manage/bdprize/support/BDPrizeCalculator.java +++ b/src/main/java/au/com/royalpay/payment/manage/bdprize/support/BDPrizeCalculator.java @@ -11,5 +11,5 @@ public interface BDPrizeCalculator { void calculate(); - List getReport(); + List getReport(int year,int month); } diff --git a/src/main/java/au/com/royalpay/payment/manage/bdprize/support/impls/BDPrizeCalculatorDefaultImpl.java b/src/main/java/au/com/royalpay/payment/manage/bdprize/support/impls/BDPrizeCalculatorDefaultImpl.java index 1564f33be..be9df684f 100644 --- a/src/main/java/au/com/royalpay/payment/manage/bdprize/support/impls/BDPrizeCalculatorDefaultImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/bdprize/support/impls/BDPrizeCalculatorDefaultImpl.java @@ -9,6 +9,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper; import com.alibaba.fastjson.JSONObject; import au.com.royalpay.payment.manage.bdprize.support.BDPrizeCalculator; @@ -30,6 +31,7 @@ public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator { private Map bdMap = new HashMap<>(); private Map>> rateConfigMap = new HashMap<>(); private Map bdTotalMap = new HashMap<>(); + private TransactionMapper transactionMapper; public BDPrizeCalculatorDefaultImpl(List tradeLogs, Date month) { this.tradeLogs = tradeLogs; @@ -76,7 +78,7 @@ public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator { } @Override - public List getReport() { + public List getReport(int year,int month1) { List report = new ArrayList<>(); for (Map.Entry> resultItem : results.entrySet()) { JSONObject log = new JSONObject(); @@ -89,7 +91,7 @@ public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator { log.put("total_amount", 0); log.put("total_prize", 0); log.put("total_donation", 0); - BigDecimal totalAmount = bdTotalMap.get(bd.getString("bd_id")); + BigDecimal totalAmount = transactionMapper.TotalAmountForBDPrize(year,month1,bd.getString("bd_id")); List details = new ArrayList<>(); for (Map.Entry detail : resultItem.getValue().entrySet()) { JSONObject detailItem = detail.getValue(); diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.java index be48b0efc..38eb75087 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.java @@ -93,6 +93,8 @@ public interface TransactionMapper { List listTransactionsForBDPrize(@Param("year") int year, @Param("month") int month, @Param("channel") String channel); + BigDecimal TotalAmountForBDPrize(@Param("year") int year, @Param("month") int month, @Param("bd_id") String bd_id); + BigDecimal TotalAmountForBDLeaderPrize(@Param("year") int year, @Param("month") int month, @Param("bd_group") String bd_group); BigDecimal TotalAmountForSydneyGMPrize(@Param("year") int year, @Param("month") int month); diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml index 3cb0cd8e4..6c6c00715 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml @@ -502,6 +502,21 @@ ORDER BY trade_date ASC, o.client_id ASC + +