Merge remote-tracking branch 'origin/develop'

master
james.zhao 6 years ago
commit 98ed0042ab

@ -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;

@ -91,13 +91,14 @@ public interface FinancialBDPrizeLogMapper {
List<JSONObject> 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<JSONObject> 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<JSONObject> findBdPrizeAmountMonth(@Param("start_date") Date start_date, @Param("end_date") Date end_date,@Param("month_start_date") Date month_start_date);
}

@ -118,4 +118,6 @@ public interface ClientMapper {
@Select("select client_id from sys_clients where parent_client_id=#{parent_client_id}")
List<Integer> childClientId(@Param("parent_client_id") int parent_client_id);
List<JSONObject> createClientsByGroup(@Param("start_date") Date start_date,@Param("end_date") Date end_date);
}

@ -377,11 +377,10 @@
<select id="countNewCustomers" resultType="java.lang.Integer">
<![CDATA[
SELECT COUNT(DISTINCT customer_id) FROM (SELECT o.customer_id FROM pmt_transactions t
INNER JOIN pmt_orders o ON o.order_id = t.order_id
SELECT COUNT(DISTINCT customer_id) FROM pmt_orders o
]]>
<![CDATA[
WHERE o.create_time >= #{begin} AND o.create_time < #{end}
WHERE o.create_time >= #{begin} AND o.create_time < #{end} AND o.status>4
]]>
<if test="client_ids!=null">
AND o.client_id IN
@ -392,30 +391,31 @@
<if test="client_ids==null and client_id != null">
and o.client_id=#{client_id}
</if>
<if test="org_id!=null and org_ids==null">and t.org_id=#{org_id}</if>
<if test="org_ids!=null">and t.org_id in
<if test="org_id!=null and org_ids==null">and o.org_id=#{org_id}</if>
<if test="org_ids!=null">and o.org_id in
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach>
</if>
<if test="channel !=null">and o.channel = #{channel}</if>
<![CDATA[
GROUP BY o.customer_id) p
where p.customer_id NOT IN (SELECT o.customer_id FROM pmt_transactions t INNER JOIN pmt_orders o ON o.order_id = t.order_id
]]>
<![CDATA[
WHERE o.create_time < #{begin}
]]>
<if test="client_ids!=null">
AND o.client_id IN
<foreach collection="client_ids" open="(" close=")" separator="," item="client_id">
#{client_id}
</foreach>
</if>
<if test="client_ids==null and client_id != null">
and o.client_id=#{client_id}
</if>
<![CDATA[
AND EXISTS (
<![CDATA[
select customer_id from pmt_orders oo where oo.customer_id=o.customer_id
and oo.create_time < #{begin} AND oo.status>4
]]>
<if test="client_ids!=null">
AND oo.client_id IN
<foreach collection="client_ids" open="(" close=")" separator="," item="client_id">
#{client_id}
</foreach>
</if>
<if test="client_ids==null and client_id != null">
and oo.client_id=#{client_id}
</if>
<if test="org_id!=null and org_ids==null">and oo.org_id=#{org_id}</if>
<if test="org_ids!=null">and oo.org_id in
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach>
</if>
<if test="channel !=null">and oo.channel = #{channel}</if>
)
]]>
</select>
<select id="countOldCustomers" resultType="java.lang.Integer">
<![CDATA[

@ -543,4 +543,52 @@
<bind name="manager_id_pattern" value="'%'+manager_id+'%'"/>
bd_user LIKE #{manager_id_pattern} AND is_valid=1;
</select>
</mapper>
<select id="createClientsByGroup" resultType="com.alibaba.fastjson.JSONObject">
SELECT
t1.*,
ifnull( t2.clients_yesterday, 0 ) clients_yesterday
FROM
(
SELECT
fbc.bd_name,
fbc.bd_group,
fbc.bd_type,
count( * ) clients_history
FROM
sys_clients sc
INNER JOIN sys_client_bd d ON sc.client_id = d.client_id
INNER JOIN financial_bd_config c ON d.bd_id = c.manager_id
INNER JOIN financial_bd_config fbc ON fbc.manager_id = c.bd_group
WHERE
sc.org_id = 1
AND sc.create_time &lt; #{start_date}
AND d.is_valid = 1
AND c.bd_group IS NOT NULL
AND d.start_date &lt;= now( ) AND d.is_valid = 1 AND ( d.end_date IS NULL OR d.end_date &gt; now( )
)
GROUP BY
fbc.bd_type
) t1
LEFT JOIN (
SELECT
count( * ) clients_yesterday,
fbc.bd_group
FROM
sys_clients sc
INNER JOIN sys_client_bd d ON sc.client_id = d.client_id
INNER JOIN financial_bd_config c ON d.bd_id = c.manager_id
INNER JOIN financial_bd_config fbc ON fbc.manager_id = c.bd_group
WHERE
sc.org_id = 1
AND sc.create_time &gt;= #{start_date}
AND sc.create_time &lt; #{end_date}
AND d.is_valid = 1
AND d.start_date &lt;= now( ) AND d.is_valid = 1 AND ( d.end_date IS NULL OR d.end_date &gt; now( )
)
GROUP BY
fbc.bd_type
) t2 ON t1.bd_group = t2.bd_group
WHERE
t1.bd_type IN ( 1, 2, 6, 7 )
</select>
</mapper>

@ -10,5 +10,6 @@
<plugin interceptor="com.github.miemiedev.mybatis.paginator.OffsetLimitInterceptor">
<property name="dialectClass" value="com.github.miemiedev.mybatis.paginator.dialect.MySQLDialect"/>
</plugin>
<plugin interceptor="cn.yixblog.support.mybatis.plugins.AdvancedPaginationInterceptor"/>
</plugins>
</configuration>

@ -148,7 +148,7 @@
<div style="display: flex;justify-content: center;">
<img style="width: 7.5rem;height: 7.5rem"
<img style="width: 10rem;height: 7.5rem"
src="https://mpay.royalpay.com.au/static/images/logo_light.png">
</div>

@ -31,6 +31,7 @@
<div class="weui-navbar">
<a class="weui-navbar__item weui-bar__item_on">收入</a>
<a class="weui-navbar__item">支出</a>
<a class="weui-navbar__item">KPI</a>
</div>
<div class="weui-tab__panel">
<div class="tabcontent">
@ -132,9 +133,77 @@
</div>
</div>
</div>
<div class="tabcontent" style="display: none;">
<div class="weui-panel">
<div class="weui-panel__hd">KPI进度</div>
<div class="weui-panel__bd">
<div class="weui-media-box weui-media-box_small-appmsg">
<div class="weui-cells">
<div class="weui-cell weui-flex">
<div class="weui-cell__hd weui-flex__item">总KPI完成度</div>
<div class="weui-cell__ft weui-flex__item"
th:text="${report.kpi.kpi_percent_total}"></div>
</div>
<div class="weui-cell weui-flex"
th:each=" kpi : ${report.kpi.kpiList}">
<div class="weui-cell__hd weui-flex__item"
th:text="${kpi.group_name}"></div>
<div class="weui-cell__ft weui-flex__item"
th:text="${kpi.kpi_percent}"></div>
</div>
</div>
</div>
</div>
</div>
<div class="weui-panel">
<div class="weui-panel__hd">昨日销售额(增长量)</div>
<div class="weui-panel__bd">
<div class="weui-media-box weui-media-box_small-appmsg">
<div class="weui-cells">
<!--<div class="weui-cell weui-flex">-->
<!--<div class="weui-cell__hd weui-flex__item">当月总销售额</div>-->
<!--<div class="weui-cell__ft weui-flex__item" th:text="${report.kpi.total_month_amount}"></div>-->
<!--</div>-->
<div class="weui-cell weui-flex"
th:each=" kpi : ${report.kpi.kpiList}">
<div class="weui-cell__hd weui-flex__item"
th:text="${kpi.group_name}"></div>
<div style="color: green" class="weui-cell__ft weui-flex__item" th:if="${kpi.compare>0}"
th:text="${kpi.total_amount}+'('+'↑'+${kpi.compare_value}+')'">
</div>
<div style="color: red" class="weui-cell__ft weui-flex__item" th:if="${kpi.compare<0}"
th:text="${kpi.total_amount}+'('+'↓'+${kpi.compare_value}+')'"></div>
<div class="weui-cell__ft weui-flex__item" th:if="${kpi.compare==0}"
th:text="${kpi.total_amount}+'('+${kpi.compare_value}+')'"></div>
</div>
</div>
</div>
</div>
</div>
<div class="weui-panel">
<div class="weui-panel__hd">昨日开户数(历史开户数)</div>
<div class="weui-panel__ft">
<div class="weui-media-box weui-media-box_small-appmsg">
<div class="weui-cells">
<div class="weui-cell weui-flex"
th:each=" kpi : ${report.kpi.kpiList}">
<div class="weui-cell__hd weui-flex__item"
th:text="${kpi.group_name}"></div>
<div class="weui-cell__ft weui-flex__item"
th:text="${kpi.clients_yesterday}+'('+${kpi.clients_history}+')'"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
</html>

Loading…
Cancel
Save