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..99217ffa0 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 @@ -28,6 +28,8 @@ import com.github.miemiedev.mybatis.paginator.domain.PageBounds; import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateUtils; import org.joda.time.DateTime; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -79,6 +81,7 @@ public class BDPrizeServiceImpl implements BDPrizeService { private static BigDecimal percent = new BigDecimal(100); private static String[] channels = new String[]{"Wechat", "Alipay", "Bestpay", "jd", "AlipayOnline","hf"}; + private static Logger logger = LoggerFactory.getLogger(BDPrizeServiceImpl.class); @Override public void generateRecord(String month) { @@ -121,14 +124,16 @@ public class BDPrizeServiceImpl implements BDPrizeService { List trades = transactionMapper.listTransactionsForBDPrize(now.get(Calendar.YEAR), now.get(Calendar.MONTH) + 1, channel); List clientsWithBDAway = clientBDMapper.clientsWithBDAway(); List rateConfig = getRateConfig(); - BDPrizeCalculator calculator = new BDPrizeCalculatorDefaultImpl(trades, now.getTime()).clientBDMapper(clientBDMapper) + BDPrizeCalculator calculator = new BDPrizeCalculatorDefaultImpl(trades, now.getTime()).clientBDMapper(clientBDMapper).transactionMapper(transactionMapper) .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); + logger.info("======calculator.report=========="+channel+"===="+report.toString()); for (JSONObject log : report) { log.put("record_id", record.getString("record_id")); log.put("channel", channel); log.remove("prize_log_id"); + logger.info("=========financialBDPrizeLogMapper.save======="+log.toString()); financialBDPrizeLogMapper.save(log); List details = (List) log.get("details"); for (JSONObject detail : details) { 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 7107827b1..d2e234522 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,16 +9,20 @@ 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; 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; @@ -27,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; @@ -38,6 +43,11 @@ public class BDPrizeCalculatorDefaultImpl implements BDPrizeCalculator { return this; } + public BDPrizeCalculatorDefaultImpl transactionMapper(TransactionMapper transactionMapper) { + this.transactionMapper = transactionMapper; + return this; + } + public BDPrizeCalculatorDefaultImpl clientsWithBDAwayDeterminor(DefaultClientWithBDAwayDeterminor clientWithBDAwayDeterminor) { this.clientsWithBDAwayDeterminor = clientWithBDAwayDeterminor; return this; @@ -47,15 +57,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); } @@ -73,7 +83,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(); @@ -86,15 +96,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 = transactionMapper.TotalAmountForBDPrize(year,month1,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"); @@ -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"); 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 c6911c549..4b4b0063e 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,23 +502,32 @@ ORDER BY trade_date ASC, o.client_id ASC + +