Upd:【财务报表】修改查询数据表,修改页面数据展示结构

master
duLingLing 5 years ago
parent d81de4673f
commit 1fb4f23f9f

@ -6,6 +6,7 @@ import au.com.royalpay.payment.manage.mappers.financial.FinancialBDCommissionCon
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.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;
@ -27,11 +28,10 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.*;
/**
* Created by yishuqian on 16/11/2017.
@ -57,13 +57,19 @@ public class DailyReportImp implements DailyReport {
@Resource
private FinancialBDCommissionConfigMapper financialBDCommissionConfigMapper;
private Logger logger = LoggerFactory.getLogger(getClass());
@Resource
private TransactionMapper transactionMapper;
@Override
public void generateReport(String date, boolean sendMsg) {
try {
Date dt = DateUtils.parseDate(date, new String[]{"yyyy-MM-dd"});
String reportId =DateFormatUtils.format(dt,"yyyy-MM-dd");
Date beginTime = DateUtils.parseDate(date, new String[]{"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"});
JSONObject report = dailyReportMapper.findOne(reportId);
if (report != null) {
@ -71,16 +77,16 @@ public class DailyReportImp implements DailyReport {
}
report = new JSONObject();
report.put("report_id", reportId);
report.put("analysis_date", dt);
report.put("analysis_date", beginTime);
report.put("report_date", new Date());
JSONObject creditReport = getCreditReport(dt);
JSONObject creditReport = getCreditReport(beginTime,endTime);
report.put("credit", creditReport.toJSONString());
JSONObject debitReport = getDebitReport(dt);
JSONObject debitReport = getDebitReport(beginTime);
report.put("debit", JSON.toJSONString(debitReport));
JSONObject kpiReport = getKPI(dt);
JSONObject kpiReport = getKPI(beginTime);
report.put("kpi", JSON.toJSONString(kpiReport));
dailyReportMapper.save(report);
@ -199,23 +205,152 @@ public class DailyReportImp implements DailyReport {
return report;
}
private JSONObject getCreditReport(Date dt) {
private JSONObject getCreditReport(Date beginTime,Date endTime) {
JSONObject report = new JSONObject();
JSONObject settle = clearingLogMapper.getSettleDataDailyReport(dt);
BigDecimal total_credit = settle.getBigDecimal("royalpay_charge");
BigDecimal settle_amount = settle.getBigDecimal("net_amount");
JSONObject last_settle = clearingLogMapper.getSettleDataDailyReport(DateUtils.addDays(dt,-1));
BigDecimal last_credit = last_settle.getBigDecimal("royalpay_charge");
report.put("settle_amount",settle_amount);
report.put("total_credit",total_credit);
BigDecimal credit_compare = total_credit.subtract(last_credit);
report.put("compare",credit_compare);
report.put("compare_value",Math.abs(credit_compare.doubleValue()));
List<JSONObject> channels = clearingLogMapper.getSettlementChannelsDailyReport(dt);
report.put("channels",channels);
List<JSONObject> settles = transactionMapper.getSettleDataDailyReport(beginTime,endTime);
JSONObject yesterdayTotal = this.computerTotalAmount(settles);
BigDecimal yesterday_credit_amount = yesterdayTotal.getBigDecimal("total_credit_amount");
BigDecimal yesterday_debit_amount = yesterdayTotal.getBigDecimal("total_debit_amount");
BigDecimal yesterday_net_trading = yesterdayTotal.getBigDecimal("total_net_trading");
BigDecimal yesterday_total_surcharge = yesterdayTotal.getBigDecimal("total_total_surcharge");
BigDecimal yesterday_royal_surcharge = yesterdayTotal.getBigDecimal("total_royal_surcharge");
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));
JSONObject lastTotal = this.computerTotalAmount(last_settle);
BigDecimal last_total_credit = lastTotal.getBigDecimal("total_credit_amount");
BigDecimal last_debit_amount = lastTotal.getBigDecimal("total_debit_amount");
BigDecimal last_net_trading = lastTotal.getBigDecimal("total_net_trading");
BigDecimal last_total_surcharge = lastTotal.getBigDecimal("total_total_surcharge");
BigDecimal last_royal_surcharge = lastTotal.getBigDecimal("total_royal_surcharge");
BigDecimal last_channel_surcharge = lastTotal.getBigDecimal("total_channel_surcharge");
BigDecimal last_tax_amount = lastTotal.getBigDecimal("total_tax_amount");
JSONObject percentage_yesterday_total_credit = this.percentage(yesterday_credit_amount, last_total_credit);
JSONObject percentage_yesterday_debit_amount = this.percentage(yesterday_debit_amount, last_debit_amount);
JSONObject percentage_yesterday_net_trading = this.percentage(yesterday_net_trading, last_net_trading);
JSONObject percentage_yesterday_total_surcharge = this.percentage(yesterday_total_surcharge, last_total_surcharge);
JSONObject percentage_yesterday_royal_surcharge = this.percentage(yesterday_royal_surcharge, last_royal_surcharge);
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_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_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_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_tax_amount",new JSONObject(){{
put("amount",yesterday_tax_amount);
put("compare",percentage_yesterday_tax_amount);
}});
return report;
}
private JSONObject computerTotalAmount(List<JSONObject> settles){
BigDecimal total_credit_amount = new BigDecimal("0.00");
BigDecimal total_debit_amount = new BigDecimal("0.00");
BigDecimal total_net_trading = new BigDecimal("0.00");
BigDecimal total_total_surcharge = new BigDecimal("0.00");
BigDecimal total_royal_surcharge = new BigDecimal("0.00");
BigDecimal total_channel_surcharge = new BigDecimal("0.00");
BigDecimal total_tax_amount = new BigDecimal("0.00");
DecimalFormat df1 = new DecimalFormat("0.00");
for (int i=0;i<settles.size();i++){
JSONObject jsonObject = settles.get(i);
BigDecimal credit_amount = jsonObject.getBigDecimal("credit_amount");
total_credit_amount = total_credit_amount.add(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));
BigDecimal net_trading = jsonObject.getBigDecimal("net_trading");
total_net_trading = total_net_trading.add(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));
BigDecimal royal_surcharge = jsonObject.getBigDecimal("royal_surcharge");
total_royal_surcharge = total_royal_surcharge.add(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));
BigDecimal tax_amount = jsonObject.getBigDecimal("tax_amount");
total_tax_amount = total_tax_amount.add(tax_amount);
jsonObject.put("tax_amount",df1.format(tax_amount));
}
String finalTotal_credit_amount = df1.format(total_credit_amount);
String finalTotal_debit_amount = df1.format(total_debit_amount);
String finalTotal_net_trading = df1.format(total_net_trading);
String finalTotal_total_surcharge = df1.format(total_total_surcharge);
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_credit_amount", finalTotal_credit_amount);
put("total_debit_amount", finalTotal_debit_amount);
put("total_net_trading", finalTotal_net_trading);
put("total_total_surcharge", finalTotal_total_surcharge);
put("total_royal_surcharge", finalTotal_royal_surcharge);
put("total_channel_surcharge", finalTotal_channel_surcharge);
put("total_tax_amount", finalTotal_tax_amount);
}};
}
private JSONObject percentage(BigDecimal num1, BigDecimal num2) {
boolean positive =true;
double n1 = num1.doubleValue();
double n2 = num2.doubleValue();
if(Double.compare(n2, 0) == 0)
throw new RuntimeException("输入有误");
double ratio = n1 / n2;
if(ratio<1){
positive = false;
}
NumberFormat format = NumberFormat.getPercentInstance();
format.setMaximumFractionDigits(2);
String result=format.format(ratio<1?1-ratio:ratio-1);
boolean finalPositive = positive;
return new JSONObject(){{
put("compare",result);
put("positive", finalPositive);
}};
}
@Override
public JSONObject getReport(String reportId, String openid) {
JSONObject manager = managerMapper.findByWxOpenId(openid);

@ -159,4 +159,13 @@ public interface TransactionMapper {
List<JSONObject> getLastDaytransAmount(JSONObject params);
List<Integer> useAlipayOnlineClients();
/**
*
* @param beginTime
* @param endTime
* @return
*/
List<JSONObject> getSettleDataDailyReport(@Param("beginTime") Date beginTime,@Param("endTime")Date endTime);
}

@ -1216,4 +1216,23 @@
WHERE order_channel='AlipayOnline'
and create_time>='2019-01-01 00:00:00'
</select>
<select id="getSettleDataDailyReport" resultType="com.alibaba.fastjson.JSONObject">
SELECT
channel,
SUM(IF(transaction_type = 'Credit', clearing_amount, 0)) AS credit_amount,
SUM(IF(transaction_type = 'Credit', 0, -clearing_amount)) AS debit_amount,
SUM(IF(transaction_type = 'Credit', clearing_amount, -clearing_amount)) AS net_trading,
SUM(IF(transaction_type = 'Credit', total_surcharge, -total_surcharge)) AS total_surcharge,
SUM(IF(transaction_type = 'Credit', royal_surcharge, -royal_surcharge)) AS royal_surcharge,
SUM(IF(transaction_type = 'Credit', channel_surcharge, -channel_surcharge)) AS channel_surcharge,
SUM(IF(transaction_type = 'Credit', tax_amount, -tax_amount)) AS tax_amount,
cashback_send_flag,
surcharge_cashback
FROM pmt_transactions
WHERE create_time >= #{beginTime}
AND create_time &lt; #{endTime}
AND channel != 'Settlement'
GROUP BY channel
</select>
</mapper>

@ -36,63 +36,97 @@
<div class="weui-tab__panel">
<div class="tabcontent">
<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">清算金额(A$)</div>
<div class="weui-cell__ft weui-flex__item"
th:text="${report.credit.settle_amount}"></div>
<div style="display:inline">
<div class="weui-panel__hd">Total <span style="float: right">较昨日数据</span></div>
</div>
<div class="weui-panel__ft">
<div class="weui-cell">
<div class="weui-cell__bd weui-cell_primary">总入账</div>
<div class="weui-cell__ft" th:text="${report.credit.total_credit_amount.amount}"></div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<div class="weui-cell__ft">
<span style="color: green" th:if="${report.credit.total_credit_amount.compare.positive}" th:text="'↑'+${report.credit.total_credit_amount.compare.compare}"></span>
<span style="color: red" th:if="${!report.credit.total_credit_amount.compare.positive}" th:text="'↓'+${report.credit.total_credit_amount.compare.compare}"></span>
</div>
</div>
</div>
<div class="weui-panel__ft">
<div class="weui-cell">
<div class="weui-cell__bd weui-cell_primary">总出账</div>
<div class="weui-cell__ft" th:text="${report.credit.total_debit_amount.amount}"></div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<div class="weui-cell__ft">
<span style="color: green" th:if="${report.credit.total_debit_amount.compare.positive}" th:text="'↑'+${report.credit.total_debit_amount.compare.compare}"></span>
<span style="color: red" th:if="${!report.credit.total_debit_amount.compare.positive}" th:text="'↓'+${report.credit.total_debit_amount.compare.compare}"></span>
</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">RoyalPay手续费(A$)</div>
</div>
<div class="weui-cell weui-flex"
th:each=" charge : ${report.credit.channels}">
<div class="weui-cell__hd weui-flex__item"
th:text="${charge.channel}"></div>
<div class="weui-cell__ft weui-flex__item"
th:text="${charge.charge}"></div>
</div>
<div class="weui-panel__ft">
<div class="weui-cell">
<div class="weui-cell__bd weui-cell_primary">净交易</div>
<div class="weui-cell__ft" th:text="${report.credit.total_net_trading.amount}"></div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<div class="weui-cell__ft">
<span style="color: green" th:if="${report.credit.total_net_trading.compare.positive}" th:text="'↑'+${report.credit.total_net_trading.compare.compare}"></span>
<span style="color: red" th:if="${!report.credit.total_net_trading.compare.positive}" th:text="'↓'+${report.credit.total_net_trading.compare.compare}"></span>
</div>
</div>
</div>
<div class="weui-panel__ft">
<div class="weui-cell">
<div class="weui-cell__bd weui-cell_primary">总手续费</div>
<div class="weui-cell__ft" th:text="${report.credit.total_total_surcharge.amount}"></div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<div class="weui-cell__ft">
<span style="color: green" th:if="${report.credit.total_total_surcharge.compare.positive}" th:text="'↑'+${report.credit.total_total_surcharge.compare.compare}"></span>
<span style="color: red" th:if="${!report.credit.total_total_surcharge.compare.positive}" th:text="'↓'+${report.credit.total_total_surcharge.compare.compare}"></span>
</div>
</div>
</div>
<div class="weui-panel">
<div class="weui-panel__hd">Total</div>
<div class="weui-panel__ft">
<div class="weui-cell">
<div class="weui-cell__bd weui-cell_primary">总收入</div>
<div class="weui-cell__ft" th:text="${report.credit.total_credit}"></div>
<div class="weui-cell__bd weui-cell_primary">平台手续费</div>
<div class="weui-cell__ft" th:text="${report.credit.total_royal_surcharge.amount}"></div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<div class="weui-cell__ft">
<span style="color: green" th:if="${report.credit.total_royal_surcharge.compare.positive}" th:text="'↑'+${report.credit.total_royal_surcharge.compare.compare}"></span>
<span style="color: red" th:if="${!report.credit.total_royal_surcharge.compare.positive}" th:text="'↓'+${report.credit.total_royal_surcharge.compare.compare}"></span>
</div>
</div>
</div>
<div class="weui-panel__ft">
<div class="weui-cell">
<div class="weui-cell__bd weui-cell_primary">较昨天比较</div>
<div class="weui-cell__bd weui-cell_primary">渠道成本手续费</div>
<div class="weui-cell__ft" th:text="${report.credit.total_channel_surcharge.amount}"></div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<div class="weui-cell__ft">
<span style="color: green" th:if="${report.credit.compare>0}"
th:text="'↑'+${report.credit.compare_value}"></span>
<span style="color: red" th:if="${report.credit.compare<0}"
th:text="'↓'+${report.credit.compare_value}"></span>
<span th:if="${report.credit.compare==0}"
th:text="${report.credit.compare_value}"></span>
<span style="color: green" th:if="${report.credit.total_channel_surcharge.compare.positive}" th:text="'↑'+${report.credit.total_channel_surcharge.compare.compare}"></span>
<span style="color: red" th:if="${!report.credit.total_channel_surcharge.compare.positive}" th:text="'↓'+${report.credit.total_channel_surcharge.compare.compare}"></span>
</div>
</div>
</div>
<div class="weui-panel__ft">
<div class="weui-cell">
<div class="weui-cell__bd weui-cell_primary"></div>
<div class="weui-cell__ft" th:text="${report.credit.total_tax_amount.amount}"></div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<div class="weui-cell__ft">
<span style="color: green" th:if="${report.credit.total_tax_amount.compare.positive}" th:text="'↑'+${report.credit.total_tax_amount.compare.compare}"></span>
<span style="color: red" th:if="${!report.credit.total_tax_amount.compare.positive}" th:text="'↓'+${report.credit.total_tax_amount.compare.compare}"></span>
</div>
</div>
</div>
<div class="weui-panel">
<div class="weui-panel__hd">
Channel
<select style="float: right" id="channelSelect" onChange="switchChannel(value)">
<option value="">请选择渠道</option>
<option th:each="channel:${report.credit.channels}" th:value="${channel}" th:utext="${channel.channel}"></option>
</select>
</div>
<div id="showChannelData"></div>
</div>
</div>
</div>
<!--<div class="tabcontent" style="display: none;">-->
<!--<div class="weui-panel">-->
@ -206,10 +240,70 @@
</div>
</div>
</div>
</div>
</div>
</body>
<script type="text/javascript" th:inline="javascript">
function switchChannel(channel){
var tmp = document.getElementById("showChannelData");
if(channel!='' && channel !=null && typeof channel != 'undefined'){
var convertJsonChannel = JSON.parse(channel)
tmp.innerHTML= " <div class='tabcontent'>\n" +
" <div class='weui-panel__ft'>\n" +
" <div class='weui-panel__ft'>\n" +
" <div class='weui-cell'>\n" +
" <div class='weui-cell__bd weui-cell_primary'>总入账</div>\n" +
" <div class='weui-cell__ft'>"+convertJsonChannel.credit_amount+"</div>\n" +
" </div>\n" +
" </div>\n" +
" <div class='weui-panel__ft'>\n" +
" <div class='weui-cell'>\n" +
" <div class='weui-cell__bd weui-cell_primary'>总出账</div>\n" +
" <div class='weui-cell__ft'>"+convertJsonChannel.debit_amount+"</div>\n" +
" </div>\n" +
" </div>\n" +
" <div class='weui-panel__ft'>\n" +
" <div class='weui-cell'>\n" +
" <div class='weui-cell__bd weui-cell_primary'>净交易</div>\n" +
" <div class='weui-cell__ft'>"+convertJsonChannel.net_trading+"</div>\n" +
" </div>\n" +
" </div>\n" +
" <div class='weui-panel__ft'>\n" +
" <div class='weui-cell'>\n" +
" <div class='weui-cell__bd weui-cell_primary'>总手续费</div>\n" +
" <div class='weui-cell__ft'>"+convertJsonChannel.total_surcharge+"</div>\n" +
" </div>\n" +
" </div>\n" +
" <div class='weui-panel__ft'>\n" +
" <div class='weui-cell'>\n" +
" <div class='weui-cell__bd weui-cell_primary'>总手续费</div>\n" +
" <div class='weui-cell__ft'>"+convertJsonChannel.total_surcharge+"</div>\n" +
" </div>\n" +
" </div>\n" +
" <div class='weui-panel__ft'>\n" +
" <div class='weui-cell'>\n" +
" <div class='weui-cell__bd weui-cell_primary'>平台总手续费</div>\n" +
" <div class='weui-cell__ft'>"+convertJsonChannel.royal_surcharge+"</div>\n" +
" </div>\n" +
" </div>\n" +
" <div class='weui-panel__ft'>\n" +
" <div class='weui-cell'>\n" +
" <div class='weui-cell__bd weui-cell_primary'>渠道成本总手续费</div>\n" +
" <div class='weui-cell__ft'>"+convertJsonChannel.channel_surcharge+"</div>\n" +
" </div>\n" +
" </div>\n" +
" <div class='weui-panel__ft'>\n" +
" <div class='weui-cell'>\n" +
" <div class='weui-cell__bd weui-cell_primary'>总税费</div>\n" +
" <div class='weui-cell__ft'>"+convertJsonChannel.tax_amount+"</div>\n" +
" </div>\n" +
" </div>\n" +
" </div>\n" +
" </div>";
}else{
tmp.innerHTML =''
}
}
</script>
</html>

Loading…
Cancel
Save