From 178532831df1d9ef74cef0c7a7ffc49604aad29e Mon Sep 17 00:00:00 2001 From: duLingLing Date: Wed, 27 Nov 2019 11:31:10 +0800 Subject: [PATCH] =?UTF-8?q?Upd:=E6=97=A5=E6=8A=A5=E8=A1=A8KPI=E4=BF=AE?= =?UTF-8?q?=E6=94=B9BD=E5=9B=A2=E9=98=9F=E6=95=B0=E9=87=8F=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=EF=BC=8C=E7=94=B1=E7=BB=9F=E8=AE=A1=E5=8E=9F=E9=A2=86?= =?UTF-8?q?=E9=98=9F=E5=95=86=E6=88=B7=E9=87=8F=EF=BC=8C=E6=9B=B4=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E7=BB=9F=E8=AE=A1=E5=9B=A2=E9=98=9F=E5=95=86=E6=88=B7?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../analysis/core/impls/DailyReportImp.java | 213 +++++++++--------- 1 file changed, 110 insertions(+), 103 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/DailyReportImp.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/DailyReportImp.java index 9400c7904..2c6952f4a 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/DailyReportImp.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/DailyReportImp.java @@ -3,6 +3,7 @@ package au.com.royalpay.payment.manage.analysis.core.impls; import au.com.royalpay.payment.manage.analysis.core.DailyReport; import au.com.royalpay.payment.manage.mappers.cashback.CashbackRecordsMapper; import au.com.royalpay.payment.manage.mappers.financial.FinancialBDCommissionConfigMapper; +import au.com.royalpay.payment.manage.mappers.financial.FinancialBDConfigMapper; import au.com.royalpay.payment.manage.mappers.financial.FinancialBDPrizeLogMapper; import au.com.royalpay.payment.manage.mappers.log.ClearingLogMapper; import au.com.royalpay.payment.manage.mappers.log.DailyReportMapper; @@ -10,7 +11,6 @@ import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper; import au.com.royalpay.payment.manage.mappers.redpack.ActPartnerLMLogMapper; import au.com.royalpay.payment.manage.mappers.system.ClientMapper; import au.com.royalpay.payment.manage.mappers.system.ManagerMapper; -import au.com.royalpay.payment.tools.permission.enums.ManagerRole; import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApi; import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApiProvider; import au.com.royalpay.payment.tools.connections.mpsupport.beans.TemplateMessage; @@ -18,6 +18,7 @@ import au.com.royalpay.payment.tools.env.PlatformEnvironment; import au.com.royalpay.payment.tools.exceptions.BadRequestException; import au.com.royalpay.payment.tools.exceptions.ForbiddenException; import au.com.royalpay.payment.tools.exceptions.NotFoundException; +import au.com.royalpay.payment.tools.permission.enums.ManagerRole; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import org.apache.commons.lang3.time.DateFormatUtils; @@ -31,7 +32,10 @@ import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import java.text.ParseException; -import java.util.*; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; /** * Created by yishuqian on 16/11/2017. @@ -59,16 +63,17 @@ public class DailyReportImp implements DailyReport { private Logger logger = LoggerFactory.getLogger(getClass()); @Resource private TransactionMapper transactionMapper; - + @Resource + private FinancialBDConfigMapper financialBDConfigMapper; @Override public void generateReport(String date, boolean sendMsg) { try { Date beginTime = DateUtils.parseDate(date, new String[]{"yyyy-MM-dd"}); - String reportId =DateFormatUtils.format(beginTime,"yyyy-MM-dd"); + String reportId = DateFormatUtils.format(beginTime, "yyyy-MM-dd"); Date yesterdayEndTime = DateUtils.addDays(beginTime, 1); String endDate = DateFormatUtils.format(yesterdayEndTime, "yyyy-MM-dd"); - Date endTime = DateUtils.parseDate(endDate, new String[]{"yyyy-MM-dd"}); + Date endTime = DateUtils.parseDate(endDate, new String[]{"yyyy-MM-dd"}); JSONObject report = dailyReportMapper.findOne(reportId); @@ -80,7 +85,7 @@ public class DailyReportImp implements DailyReport { report.put("analysis_date", beginTime); report.put("report_date", new Date()); - JSONObject creditReport = getCreditReport(beginTime,endTime); + JSONObject creditReport = getCreditReport(beginTime, endTime); report.put("credit", creditReport.toJSONString()); JSONObject debitReport = getDebitReport(beginTime); @@ -103,67 +108,69 @@ public class DailyReportImp implements DailyReport { } - private JSONObject getKPI(Date dt){ + private JSONObject getKPI(Date dt) { JSONObject report = new JSONObject(); - List kpiList =new ArrayList<>(); - List prizeAmountAndBdTypeList = financialBDPrizeLogMapper.findBdPrizeAmountMonth(DateUtils.truncate(dt, Calendar.DATE),DateUtils.truncate(DateUtils.addDays(dt,1), Calendar.DATE),DateUtils.truncate(dt, Calendar.MONTH)); - List prizeAmountAndBdTypeListYesterDay = financialBDPrizeLogMapper.findBdPrizeAmountMonth(DateUtils.truncate(DateUtils.addDays(dt,-1), Calendar.DATE),DateUtils.truncate(dt, Calendar.DATE),DateUtils.truncate(DateUtils.addDays(dt,-1), Calendar.MONTH)); - List clientsAmount = clientMapper.createClientsByGroup(DateUtils.truncate(dt, Calendar.DATE),DateUtils.truncate(DateUtils.addDays(dt,1), Calendar.DATE),DateUtils.truncate(dt, Calendar.MONTH)); + List kpiList = new ArrayList<>(); + List prizeAmountAndBdTypeList = financialBDPrizeLogMapper.findBdPrizeAmountMonth(DateUtils.truncate(dt, Calendar.DATE), DateUtils.truncate(DateUtils.addDays(dt, 1), Calendar.DATE), DateUtils.truncate(dt, Calendar.MONTH)); + List prizeAmountAndBdTypeListYesterDay = financialBDPrizeLogMapper.findBdPrizeAmountMonth(DateUtils.truncate(DateUtils.addDays(dt, -1), Calendar.DATE), DateUtils.truncate(dt, Calendar.DATE), DateUtils.truncate(DateUtils.addDays(dt, -1), Calendar.MONTH)); + List clientsAmount = clientMapper.createClientsByGroup(DateUtils.truncate(dt, Calendar.DATE), DateUtils.truncate(DateUtils.addDays(dt, 1), Calendar.DATE), DateUtils.truncate(dt, Calendar.MONTH)); //BD团队总KPI BigDecimal total_kpi_amount = BigDecimal.ZERO; //BD团队当月总销售额 BigDecimal total_month_amount = BigDecimal.ZERO; - for(JSONObject p :prizeAmountAndBdTypeList){ - JSONObject kpi = new JSONObject(); - kpi.put("bd_group",p.getString("bd_group")); - kpi.put("bd_name",p.getString("bd_name")); - kpi.put("group_name",groupName(p.getIntValue("bd_type"))); + for (JSONObject p : prizeAmountAndBdTypeList) { + JSONObject kpi = new JSONObject(); + kpi.put("bd_group", p.getString("bd_group")); + kpi.put("bd_name", p.getString("bd_name")); + kpi.put("group_name", groupName(p.getIntValue("bd_type"))); //昨日数据 - kpi.put("total_amount",p.getBigDecimal("total_amount")); + kpi.put("total_amount", p.getBigDecimal("total_amount")); //当月数据 - kpi.put("month_amount",p.getBigDecimal("month_amount")); - BigDecimal kpi_amount = financialBDCommissionConfigMapper.findCurrentCommissionMaxAmount(DateFormatUtils.format(DateUtils.truncate(dt,Calendar.MONTH),"yyyy-MM"), p.getIntValue("bd_type")); - kpi.put("kpi_amount",kpi_amount); - for(JSONObject prize : prizeAmountAndBdTypeListYesterDay){ - if(prize.getString("bd_group").equals(kpi.getString("bd_group"))){ + kpi.put("month_amount", p.getBigDecimal("month_amount")); + BigDecimal kpi_amount = financialBDCommissionConfigMapper.findCurrentCommissionMaxAmount(DateFormatUtils.format(DateUtils.truncate(dt, Calendar.MONTH), "yyyy-MM"), p.getIntValue("bd_type")); + kpi.put("kpi_amount", kpi_amount); + for (JSONObject prize : prizeAmountAndBdTypeListYesterDay) { + if (prize.getString("bd_group").equals(kpi.getString("bd_group"))) { BigDecimal compare = kpi.getBigDecimal("total_amount").subtract(prize.getBigDecimal("total_amount")); - kpi.put("compare",compare); - kpi.put("compare_value",Math.abs(compare.doubleValue())); + kpi.put("compare", compare); + kpi.put("compare_value", Math.abs(compare.doubleValue())); } } kpi.put("kpi_percent", p.getBigDecimal("month_amount").divide(kpi_amount, 4, BigDecimal.ROUND_HALF_DOWN).multiply(BigDecimal.valueOf(100)).toString().substring(0, 5) + "%"); for (JSONObject clientAmount : clientsAmount) { if (clientAmount.getString("bd_group").equals(kpi.getString("bd_group"))) { - // sys_clients中查询出此bd创建并属于此bd的商户,并且时间是昨天和本月 - JSONObject countByBd = clientMapper.findCountByBd(clientAmount.getString("bd_group"), DateUtils.truncate(DateUtils.addDays(dt, 1), Calendar.DATE), DateUtils.truncate(dt, Calendar.DATE), DateUtils.truncate(dt, Calendar.MONTH)); - if (countByBd.getInteger("month_count") == null){ - kpi.put("clients_month", 0); - }else { - kpi.put("clients_month", countByBd.getInteger("month_count")); - } - if (countByBd.getInteger("yesterday_count") == null){ - kpi.put("clients_yesterday", 0); - }else { - kpi.put("clients_yesterday", countByBd.getInteger("yesterday_count")); + //查询该领队下所有BD + List teamBDs = financialBDConfigMapper.listGroupBds(kpi.getString("bd_group")); + int bdMonthClientCount = 0; + int bdYesterdayClientCount = 0; + for (int i = 0; i < teamBDs.size(); i++) { + // sys_clients中查询出此bd创建并属于此bd的商户,并且时间是昨天和本月 + JSONObject countByBd = clientMapper.findCountByBd(teamBDs.get(i).getString("manager_id"), DateUtils.truncate(DateUtils.addDays(dt, 1), Calendar.DATE), DateUtils.truncate(dt, Calendar.DATE), DateUtils.truncate(dt, Calendar.MONTH)); + if (countByBd.getInteger("month_count") != null) { + bdMonthClientCount += countByBd.getInteger("month_count"); + } + if (countByBd.getInteger("yesterday_count") != null) { + bdYesterdayClientCount += countByBd.getInteger("yesterday_count"); + } } -// kpi.put("clients_month", clientAmount.getBigDecimal("clients_month")); -// kpi.put("clients_yesterday", clientAmount.getBigDecimal("clients_yesterday")); + kpi.put("clients_month", bdMonthClientCount); + kpi.put("clients_yesterday", bdYesterdayClientCount); } } total_kpi_amount = total_kpi_amount.add(kpi_amount); total_month_amount = total_month_amount.add(p.getBigDecimal("month_amount")); kpiList.add(kpi); } - report.put("kpiList",kpiList); - report.put("kpi_percent_total",total_month_amount.divide(total_kpi_amount,4,BigDecimal.ROUND_HALF_DOWN).multiply(BigDecimal.valueOf(100)).toString().substring(0,5)+"%"); - report.put("total_month_amount",total_month_amount); + report.put("kpiList", kpiList); + report.put("kpi_percent_total", total_month_amount.divide(total_kpi_amount, 4, BigDecimal.ROUND_HALF_DOWN).multiply(BigDecimal.valueOf(100)).toString().substring(0, 5) + "%"); + report.put("total_month_amount", total_month_amount); Calendar calendar = Calendar.getInstance(); calendar.setTime(dt); - report.put("time_percent",BigDecimal.valueOf(calendar.get(Calendar.DAY_OF_MONTH)).divide(BigDecimal.valueOf(calendar.getActualMaximum(Calendar.DAY_OF_MONTH)),4,BigDecimal.ROUND_HALF_DOWN).multiply(BigDecimal.valueOf(100)).toString().substring(0,5)+"%"); + report.put("time_percent", BigDecimal.valueOf(calendar.get(Calendar.DAY_OF_MONTH)).divide(BigDecimal.valueOf(calendar.getActualMaximum(Calendar.DAY_OF_MONTH)), 4, BigDecimal.ROUND_HALF_DOWN).multiply(BigDecimal.valueOf(100)).toString().substring(0, 5) + "%"); return report; } - private String groupName(int bd_type){ + private String groupName(int bd_type) { switch (bd_type) { case 1: return "Sydney Team"; @@ -181,21 +188,21 @@ public class DailyReportImp implements DailyReport { private JSONObject getDebitReport(Date dt) { JSONObject report = new JSONObject(); BigDecimal redpack = actPartnerLMLogMapper.getRedpackAmount(dt); - BigDecimal last_redpack = actPartnerLMLogMapper.getRedpackAmount(DateUtils.addDays(dt,-1)); + BigDecimal last_redpack = actPartnerLMLogMapper.getRedpackAmount(DateUtils.addDays(dt, -1)); JSONObject redpackObj = new JSONObject(); - redpackObj.put("value",redpack); + redpackObj.put("value", redpack); BigDecimal redpack_compare = redpack.subtract(last_redpack); - redpackObj.put("compare",redpack_compare); - redpackObj.put("compare_value",Math.abs(redpack_compare.doubleValue())); - report.put("redpack",redpackObj); + redpackObj.put("compare", redpack_compare); + redpackObj.put("compare_value", Math.abs(redpack_compare.doubleValue())); + report.put("redpack", redpackObj); BigDecimal cashback = cashbackRecordsMapper.getSettleDelayDebit(dt); - BigDecimal last_cashback = cashbackRecordsMapper.getSettleDelayDebit(DateUtils.addDays(dt,-1)); + BigDecimal last_cashback = cashbackRecordsMapper.getSettleDelayDebit(DateUtils.addDays(dt, -1)); JSONObject cashObj = new JSONObject(); - cashObj.put("value",cashback); + cashObj.put("value", cashback); BigDecimal cashback_compare = cashback.subtract(last_cashback); - cashObj.put("compare",cashback_compare); - cashObj.put("compare_value",Math.abs(cashback_compare.doubleValue())); - report.put("cashback",cashObj); + cashObj.put("compare", cashback_compare); + cashObj.put("compare_value", Math.abs(cashback_compare.doubleValue())); + report.put("cashback", cashObj); // BigDecimal total_debit=redpack.add(cashback); // BigDecimal last_debit=last_redpack.add(last_cashback); // report.put("total_debit",total_debit); @@ -205,9 +212,9 @@ public class DailyReportImp implements DailyReport { return report; } - private JSONObject getCreditReport(Date beginTime,Date endTime) { - JSONObject report = new JSONObject(); - List settles = transactionMapper.getSettleDataDailyReport(beginTime,endTime); + private JSONObject getCreditReport(Date beginTime, Date endTime) { + JSONObject report = new JSONObject(); + List settles = transactionMapper.getSettleDataDailyReport(beginTime, endTime); JSONObject yesterdayTotal = this.computerTotalAmount(settles); BigDecimal yesterday_settle_amount = yesterdayTotal.getBigDecimal("total_settle_amount"); BigDecimal yesterday_credit_amount = yesterdayTotal.getBigDecimal("total_credit_amount"); @@ -218,7 +225,7 @@ public class DailyReportImp implements DailyReport { BigDecimal yesterday_channel_surcharge = yesterdayTotal.getBigDecimal("total_channel_surcharge"); BigDecimal yesterday_tax_amount = yesterdayTotal.getBigDecimal("total_tax_amount"); - List last_settle = transactionMapper.getSettleDataDailyReport(DateUtils.addDays(beginTime,-1),DateUtils.addDays(endTime,-1)); + List last_settle = transactionMapper.getSettleDataDailyReport(DateUtils.addDays(beginTime, -1), DateUtils.addDays(endTime, -1)); JSONObject lastTotal = this.computerTotalAmount(last_settle); BigDecimal last_settle_amount = lastTotal.getBigDecimal("total_settle_amount"); BigDecimal last_total_credit = lastTotal.getBigDecimal("total_credit_amount"); @@ -238,44 +245,44 @@ public class DailyReportImp implements DailyReport { JSONObject percentage_yesterday_channel_surcharge = this.percentage(yesterday_channel_surcharge, last_channel_surcharge); JSONObject percentage_yesterday_tax_amount = this.percentage(yesterday_tax_amount, last_tax_amount); - report.put("channels",settles); - report.put("total_settle_amount",new JSONObject(){{ - put("amount",yesterday_settle_amount); - put("compare",percentage_yesterday_settle_amount); + report.put("channels", settles); + report.put("total_settle_amount", new JSONObject() {{ + put("amount", yesterday_settle_amount); + put("compare", percentage_yesterday_settle_amount); }}); - report.put("total_credit_amount",new JSONObject(){{ - put("amount",yesterday_credit_amount); - put("compare",percentage_yesterday_total_credit); + report.put("total_credit_amount", new JSONObject() {{ + put("amount", yesterday_credit_amount); + put("compare", percentage_yesterday_total_credit); }}); - report.put("total_debit_amount",new JSONObject(){{ - put("amount",yesterday_debit_amount); - put("compare",percentage_yesterday_debit_amount); + report.put("total_debit_amount", new JSONObject() {{ + put("amount", yesterday_debit_amount); + put("compare", percentage_yesterday_debit_amount); }}); - report.put("total_net_trading",new JSONObject(){{ - put("amount",yesterday_net_trading); - put("compare",percentage_yesterday_net_trading); + report.put("total_net_trading", new JSONObject() {{ + put("amount", yesterday_net_trading); + put("compare", percentage_yesterday_net_trading); }}); - report.put("total_total_surcharge",new JSONObject(){{ - put("amount",yesterday_total_surcharge); - put("compare",percentage_yesterday_total_surcharge); + report.put("total_total_surcharge", new JSONObject() {{ + put("amount", yesterday_total_surcharge); + put("compare", percentage_yesterday_total_surcharge); }}); - report.put("total_royal_surcharge",new JSONObject(){{ - put("amount",yesterday_royal_surcharge); - put("compare",percentage_yesterday_royal_surcharge); + report.put("total_royal_surcharge", new JSONObject() {{ + put("amount", yesterday_royal_surcharge); + put("compare", percentage_yesterday_royal_surcharge); }}); - report.put("total_channel_surcharge",new JSONObject(){{ - put("amount",yesterday_channel_surcharge); - put("compare",percentage_yesterday_channel_surcharge); + report.put("total_channel_surcharge", new JSONObject() {{ + put("amount", yesterday_channel_surcharge); + put("compare", percentage_yesterday_channel_surcharge); }}); - report.put("total_tax_amount",new JSONObject(){{ - put("amount",yesterday_tax_amount); - put("compare",percentage_yesterday_tax_amount); + report.put("total_tax_amount", new JSONObject() {{ + put("amount", yesterday_tax_amount); + put("compare", percentage_yesterday_tax_amount); }}); - return report; + return report; } - private JSONObject computerTotalAmount(List settles){ + private JSONObject computerTotalAmount(List settles) { BigDecimal total_settle_amount = new BigDecimal("0.00"); BigDecimal total_credit_amount = new BigDecimal("0.00"); BigDecimal total_debit_amount = new BigDecimal("0.00"); @@ -286,41 +293,41 @@ public class DailyReportImp implements DailyReport { BigDecimal total_tax_amount = new BigDecimal("0.00"); DecimalFormat df1 = new DecimalFormat("0.00"); - for (int i=0;i users, String reportId, String range) { ArrayList clean_users = new ArrayList<>(); String url = PlatformEnvironment.getEnv().concatUrl("/analysis/daily_reports/" + reportId); String time = DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm"); for (JSONObject user : users) { String openId = user.getString("wx_openid"); - if(openId!=null && clean_users.contains(openId)){ + if (openId != null && clean_users.contains(openId)) { continue; } if (openId != null) { @@ -403,7 +410,7 @@ public class DailyReportImp implements DailyReport { } } } - logger.info("DailyReportUsers"+clean_users.toString()); + logger.info("DailyReportUsers" + clean_users.toString()); } private TemplateMessage initMsg(String range, String url, String time, String openId, String templateId) {