Upd:日报表KPI修改BD团队数量统计,由统计原领队商户量,更改为统计团队商户量

master
duLingLing 5 years ago
parent a50dbd66a9
commit 178532831d

@ -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<JSONObject> kpiList =new ArrayList<>();
List<JSONObject> prizeAmountAndBdTypeList = financialBDPrizeLogMapper.findBdPrizeAmountMonth(DateUtils.truncate(dt, Calendar.DATE),DateUtils.truncate(DateUtils.addDays(dt,1), Calendar.DATE),DateUtils.truncate(dt, Calendar.MONTH));
List<JSONObject> 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<JSONObject> clientsAmount = clientMapper.createClientsByGroup(DateUtils.truncate(dt, Calendar.DATE),DateUtils.truncate(DateUtils.addDays(dt,1), Calendar.DATE),DateUtils.truncate(dt, Calendar.MONTH));
List<JSONObject> kpiList = new ArrayList<>();
List<JSONObject> prizeAmountAndBdTypeList = financialBDPrizeLogMapper.findBdPrizeAmountMonth(DateUtils.truncate(dt, Calendar.DATE), DateUtils.truncate(DateUtils.addDays(dt, 1), Calendar.DATE), DateUtils.truncate(dt, Calendar.MONTH));
List<JSONObject> 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<JSONObject> 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<JSONObject> 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<JSONObject> settles = transactionMapper.getSettleDataDailyReport(beginTime,endTime);
private JSONObject getCreditReport(Date beginTime, Date endTime) {
JSONObject report = new JSONObject();
List<JSONObject> 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<JSONObject> last_settle = transactionMapper.getSettleDataDailyReport(DateUtils.addDays(beginTime,-1),DateUtils.addDays(endTime,-1));
List<JSONObject> 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<JSONObject> settles){
private JSONObject computerTotalAmount(List<JSONObject> 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<settles.size();i++){
for (int i = 0; i < settles.size(); i++) {
JSONObject jsonObject = settles.get(i);
BigDecimal settle_amount = jsonObject.getBigDecimal("settle_amount");
total_settle_amount = total_settle_amount.add(settle_amount);
jsonObject.put("settle_amount",df1.format(settle_amount));
jsonObject.put("settle_amount", df1.format(settle_amount));
BigDecimal credit_amount = jsonObject.getBigDecimal("credit_amount");
total_credit_amount = total_credit_amount.add(credit_amount);
jsonObject.put("credit_amount",df1.format(credit_amount));
jsonObject.put("credit_amount", df1.format(credit_amount));
BigDecimal debit_amount = jsonObject.getBigDecimal("debit_amount");
total_debit_amount = total_debit_amount.add(debit_amount);
jsonObject.put("debit_amount",df1.format(debit_amount));
jsonObject.put("debit_amount", df1.format(debit_amount));
BigDecimal net_trading = jsonObject.getBigDecimal("net_trading");
total_net_trading = total_net_trading.add(net_trading);
jsonObject.put("net_trading",df1.format(net_trading));
jsonObject.put("net_trading", df1.format(net_trading));
BigDecimal total_surcharge = jsonObject.getBigDecimal("total_surcharge");
total_total_surcharge = total_total_surcharge.add(total_surcharge);
jsonObject.put("total_surcharge",df1.format(total_surcharge));
jsonObject.put("total_surcharge", df1.format(total_surcharge));
BigDecimal royal_surcharge = jsonObject.getBigDecimal("royal_surcharge");
total_royal_surcharge = total_royal_surcharge.add(royal_surcharge);
jsonObject.put("royal_surcharge",df1.format(royal_surcharge));
jsonObject.put("royal_surcharge", df1.format(royal_surcharge));
BigDecimal channel_surcharge = jsonObject.getBigDecimal("channel_surcharge");
total_channel_surcharge = total_channel_surcharge.add(channel_surcharge);
jsonObject.put("channel_surcharge",df1.format(channel_surcharge));
jsonObject.put("channel_surcharge", df1.format(channel_surcharge));
BigDecimal tax_amount = jsonObject.getBigDecimal("tax_amount");
total_tax_amount = total_tax_amount.add(tax_amount);
jsonObject.put("tax_amount",df1.format(tax_amount));
jsonObject.put("tax_amount", df1.format(tax_amount));
}
String finalTotal_settle_amount = df1.format(total_settle_amount);
String finalTotal_credit_amount = df1.format(total_credit_amount);
@ -330,8 +337,8 @@ public class DailyReportImp implements DailyReport {
String finalTotal_royal_surcharge = df1.format(total_royal_surcharge);
String finalTotal_channel_surcharge = df1.format(total_channel_surcharge);
String finalTotal_tax_amount = df1.format(total_tax_amount);
return new JSONObject(){{
put("total_settle_amount",finalTotal_settle_amount);
return new JSONObject() {{
put("total_settle_amount", finalTotal_settle_amount);
put("total_credit_amount", finalTotal_credit_amount);
put("total_debit_amount", finalTotal_debit_amount);
put("total_net_trading", finalTotal_net_trading);
@ -343,28 +350,27 @@ public class DailyReportImp implements DailyReport {
}
private JSONObject percentage(BigDecimal num1, BigDecimal num2) {
boolean positive =true;
boolean positive = true;
double n1 = num1.doubleValue();
double n2 = num2.doubleValue();
if(Double.compare(n2, 0) == 0)
if (Double.compare(n2, 0) == 0)
throw new RuntimeException("输入有误");
double ratio = n1 / n2;
if(ratio<1){
if (ratio < 1) {
positive = false;
}
NumberFormat format = NumberFormat.getPercentInstance();
format.setMaximumFractionDigits(2);
String result=format.format(ratio<1?1-ratio:ratio-1);
String result = format.format(ratio < 1 ? 1 - ratio : ratio - 1);
boolean finalPositive = positive;
return new JSONObject(){{
put("compare",result);
return new JSONObject() {{
put("compare", result);
put("positive", finalPositive);
}};
}
@Override
public JSONObject getReport(String reportId, String openid) {
JSONObject manager = managerMapper.findByWxOpenId(openid);
@ -382,13 +388,14 @@ public class DailyReportImp implements DailyReport {
report.put("report_date", report.getDate("report_date"));
return report;
}
private void publishMessages(List<JSONObject> users, String reportId, String range) {
ArrayList<String> 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) {

Loading…
Cancel
Save