|
|
|
@ -2,9 +2,11 @@ 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.FinancialBDPrizeLogMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.log.ClearingLogMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.log.DailyReportMapper;
|
|
|
|
|
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;
|
|
|
|
@ -27,6 +29,7 @@ import javax.annotation.Resource;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
@ -38,6 +41,8 @@ public class DailyReportImp implements DailyReport {
|
|
|
|
|
@Resource
|
|
|
|
|
private ManagerMapper managerMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private ClientMapper clientMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private DailyReportMapper dailyReportMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private CashbackRecordsMapper cashbackRecordsMapper;
|
|
|
|
@ -47,6 +52,8 @@ public class DailyReportImp implements DailyReport {
|
|
|
|
|
private ClearingLogMapper clearingLogMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private MpWechatApiProvider mpWechatApiProvider;
|
|
|
|
|
@Resource
|
|
|
|
|
private FinancialBDPrizeLogMapper financialBDPrizeLogMapper;
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -71,6 +78,9 @@ public class DailyReportImp implements DailyReport {
|
|
|
|
|
JSONObject debitReport = getDebitReport(dt);
|
|
|
|
|
report.put("debit", JSON.toJSONString(debitReport));
|
|
|
|
|
|
|
|
|
|
JSONObject kpiReport = getKPI(dt);
|
|
|
|
|
report.put("kpi", JSON.toJSONString(kpiReport));
|
|
|
|
|
|
|
|
|
|
dailyReportMapper.save(report);
|
|
|
|
|
if (sendMsg) {
|
|
|
|
|
List<JSONObject> users = managerMapper.getDirectors();
|
|
|
|
@ -85,6 +95,65 @@ public class DailyReportImp implements DailyReport {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JSONObject getKPI(Date dt){
|
|
|
|
|
JSONObject report = new JSONObject();
|
|
|
|
|
List<JSONObject> kpiList =new ArrayList<>();
|
|
|
|
|
List<JSONObject> prizeAmountAndBdTypeList = 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> prizeAmountAndBdTypeListYesterDay = financialBDPrizeLogMapper.findBdPrizeAmountMonth(DateUtils.truncate(DateUtils.addDays(dt,-2), Calendar.DATE),DateUtils.truncate(DateUtils.addDays(dt,-1), Calendar.DATE),DateUtils.truncate(DateUtils.addDays(dt,-2), Calendar.MONTH));
|
|
|
|
|
List<JSONObject> clientsAmount = clientMapper.createClientsByGroup(DateUtils.truncate(DateUtils.addDays(dt,-1), Calendar.DATE),DateUtils.truncate(dt, Calendar.DATE));
|
|
|
|
|
//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")));
|
|
|
|
|
//昨日数据
|
|
|
|
|
kpi.put("total_amount",p.getBigDecimal("total_amount"));
|
|
|
|
|
//当月数据
|
|
|
|
|
kpi.put("month_amount",p.getBigDecimal("month_amount"));
|
|
|
|
|
kpi.put("kpi_amount",p.getBigDecimal("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("kpi_percent", p.getBigDecimal("month_amount").divide(p.getBigDecimal("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"))){
|
|
|
|
|
kpi.put("clients_history",clientAmount.getIntValue("clients_history"));
|
|
|
|
|
kpi.put("clients_yesterday",clientAmount.getIntValue("clients_yesterday"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
total_kpi_amount = total_kpi_amount.add(p.getBigDecimal("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);
|
|
|
|
|
return report;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String groupName(int bd_type){
|
|
|
|
|
switch (bd_type) {
|
|
|
|
|
case 1:
|
|
|
|
|
return "Sydney Team";
|
|
|
|
|
case 2:
|
|
|
|
|
return "KA Manager";
|
|
|
|
|
case 6:
|
|
|
|
|
return "Melbourne Team";
|
|
|
|
|
case 7:
|
|
|
|
|
return "KA Manager";
|
|
|
|
|
default:
|
|
|
|
|
return "Unknown Group";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JSONObject getDebitReport(Date dt) {
|
|
|
|
|
JSONObject report = new JSONObject();
|
|
|
|
|
BigDecimal redpack = actPartnerLMLogMapper.getRedpackAmount(dt);
|
|
|
|
@ -141,6 +210,7 @@ public class DailyReportImp implements DailyReport {
|
|
|
|
|
}
|
|
|
|
|
report.put("credit", JSON.parseObject(report.getString("credit")));
|
|
|
|
|
report.put("debit", JSON.parseObject(report.getString("debit")));
|
|
|
|
|
report.put("kpi", JSON.parseObject(report.getString("kpi")));
|
|
|
|
|
report.put("range", report.getDate("analysis_date"));
|
|
|
|
|
report.put("report_date", report.getDate("report_date"));
|
|
|
|
|
return report;
|
|
|
|
|