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 d48b72cbc..cfd767040 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 @@ -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 users = managerMapper.getDirectors(); @@ -85,6 +95,65 @@ public class DailyReportImp implements DailyReport { } + private JSONObject getKPI(Date dt){ + JSONObject report = new JSONObject(); + List kpiList =new ArrayList<>(); + List 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 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 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; diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeLogMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeLogMapper.java index cb9f467ca..317c66c07 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeLogMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeLogMapper.java @@ -91,13 +91,14 @@ public interface FinancialBDPrizeLogMapper { List findBdPrizeAmountAndBdType(@Param("record_id") String recordId); @Select("SELECT\n" + - "\tc.*,\n" + - "\tsum( ( o.total ) * d.proportion ) AS total_amount\n" + + "\tfbc.*,\n" + + "\tsum( ( o.total ) * d.proportion ) AS total_amount \n" + "FROM\n" + "\tstatistics_customer_order o\n" + "\tINNER JOIN sys_clients sc ON sc.client_id = o.client_id\n" + "\tINNER JOIN sys_client_bd d ON o.client_id = d.client_id\n" + - "\tINNER JOIN financial_bd_config c ON d.bd_id = c.manager_id \n" + + "\tINNER JOIN financial_bd_config c ON d.bd_id = c.manager_id\n" + + "\tINNER JOIN financial_bd_config fbc ON fbc.manager_id = c.bd_group \n" + "WHERE\n" + "\tsc.org_id = 1 \n" + "\tAND o.date >= #{start_date} \n" + @@ -106,6 +107,52 @@ public interface FinancialBDPrizeLogMapper { "\t) \n" + "\tAND c.bd_group IS NOT NULL \n" + "GROUP BY\n" + - "\tc.bd_group") + "\tfbc.bd_type") List findBdPrizeAmountRealTime(@Param("start_date") Date start_date, @Param("end_date") Date end_date); + + @Select("SELECT\n" + + "\tt1.*,\n" + + "\tt2.total_amount AS month_amount \n" + + "FROM\n" + + "\t(\n" + + "SELECT\n" + + "\tfbc.*,\n" + + "\tsum( ( o.total ) * d.proportion ) AS total_amount \n" + + "FROM\n" + + "\tstatistics_customer_order o\n" + + "\tINNER JOIN sys_clients sc ON sc.client_id = o.client_id\n" + + "\tINNER JOIN sys_client_bd d ON o.client_id = d.client_id\n" + + "\tINNER JOIN financial_bd_config c ON d.bd_id = c.manager_id\n" + + "\tINNER JOIN financial_bd_config fbc ON fbc.manager_id = c.bd_group \n" + + "WHERE\n" + + "\tsc.org_id = 1 \n" + + "\tAND o.date >= #{start_date} \n" + + "\tAND o.date < #{end_date} \n" + + "\tAND d.start_date <= o.date AND d.is_valid = 1 AND ( d.end_date IS NULL OR d.end_date > o.date \n" + + "\t) \n" + + "\tAND c.bd_group IS NOT NULL \n" + + "GROUP BY\n" + + "\tfbc.bd_type \n" + + "\t) t1\n" + + "\tLEFT JOIN (\n" + + "SELECT\n" + + "\tfbc.*,\n" + + "\tsum( ( o.total ) * d.proportion ) AS total_amount \n" + + "FROM\n" + + "\tstatistics_customer_order o\n" + + "\tINNER JOIN sys_clients sc ON sc.client_id = o.client_id\n" + + "\tINNER JOIN sys_client_bd d ON o.client_id = d.client_id\n" + + "\tINNER JOIN financial_bd_config c ON d.bd_id = c.manager_id\n" + + "\tINNER JOIN financial_bd_config fbc ON fbc.manager_id = c.bd_group \n" + + "WHERE\n" + + "\tsc.org_id = 1 \n" + + "\tAND o.date >= #{month_start_date} \n" + + "\tAND o.date < #{end_date} \n" + + "\tAND d.start_date <= o.date AND d.is_valid = 1 AND ( d.end_date IS NULL OR d.end_date > o.date \n" + + "\t) \n" + + "\tAND c.bd_group IS NOT NULL \n" + + "GROUP BY\n" + + "\tfbc.bd_type \n" + + "\t) t2 ON t1.bd_group = t2.bd_group") + List findBdPrizeAmountMonth(@Param("start_date") Date start_date, @Param("end_date") Date end_date,@Param("month_start_date") Date month_start_date); } diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClientMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClientMapper.java index 58330bc84..50c765812 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClientMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClientMapper.java @@ -118,4 +118,6 @@ public interface ClientMapper { @Select("select client_id from sys_clients where parent_client_id=#{parent_client_id}") List childClientId(@Param("parent_client_id") int parent_client_id); + + List createClientsByGroup(@Param("start_date") Date start_date,@Param("end_date") Date end_date); } diff --git a/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/TransactionAnalysisMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/TransactionAnalysisMapper.xml index a4c461eeb..32ef0c8cf 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/TransactionAnalysisMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/TransactionAnalysisMapper.xml @@ -377,11 +377,10 @@ - \ No newline at end of file + + diff --git a/src/main/resources/mybatis-config.xml b/src/main/resources/mybatis-config.xml index 5849c55f3..9304ed6a6 100644 --- a/src/main/resources/mybatis-config.xml +++ b/src/main/resources/mybatis-config.xml @@ -10,5 +10,6 @@ + \ No newline at end of file diff --git a/src/main/resources/templates/mail/new_client_notice.html b/src/main/resources/templates/mail/new_client_notice.html index 3e2aaa514..988938f1e 100644 --- a/src/main/resources/templates/mail/new_client_notice.html +++ b/src/main/resources/templates/mail/new_client_notice.html @@ -148,7 +148,7 @@
-
diff --git a/src/main/resources/templates/reports/daily_report.html b/src/main/resources/templates/reports/daily_report.html index bc05c2037..713c403be 100644 --- a/src/main/resources/templates/reports/daily_report.html +++ b/src/main/resources/templates/reports/daily_report.html @@ -31,6 +31,7 @@
@@ -132,9 +133,77 @@
+ + + - \ No newline at end of file +