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