display multi banks

master
yixian 8 years ago
parent 6c5680f78e
commit 20addb778a

@ -24,6 +24,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.util.Date;
import java.util.List;
@ -259,7 +260,7 @@ public class AreaMerchantTradeAnalysisImpl implements AreaMerchantTradeAnalysis{
}
}
if(thisAmount.getBigDecimal("total").compareTo(BigDecimal.ZERO)>0 && thisAmount.getBigDecimal("old_total").compareTo(BigDecimal.ZERO)>0) {
lastTotal = (thisAmount.getBigDecimal("total").subtract(thisAmount.getBigDecimal("old_total"))).divide(thisAmount.getBigDecimal("old_total"), 4, BigDecimal.ROUND_HALF_UP);
lastTotal = (thisAmount.getBigDecimal("total").subtract(thisAmount.getBigDecimal("old_total"))).divide(thisAmount.getBigDecimal("old_total"), 4, RoundingMode.HALF_UP);
}
}else {
if(thisAmount.getBigDecimal("total").compareTo(BigDecimal.ZERO) == 0){
@ -274,7 +275,7 @@ public class AreaMerchantTradeAnalysisImpl implements AreaMerchantTradeAnalysis{
}
}
if(thisAmount.getBigDecimal("alipay_total").compareTo(BigDecimal.ZERO)>0 && thisAmount.getBigDecimal("old_alipay_total").compareTo(BigDecimal.ZERO)>0){
alipayTotal = (thisAmount.getBigDecimal("alipay_total").subtract(thisAmount.getBigDecimal("old_alipay_total"))).divide(thisAmount.getBigDecimal("old_alipay_total"),4,BigDecimal.ROUND_HALF_UP);
alipayTotal = (thisAmount.getBigDecimal("alipay_total").subtract(thisAmount.getBigDecimal("old_alipay_total"))).divide(thisAmount.getBigDecimal("old_alipay_total"),4,RoundingMode.HALF_UP);
}
}else {
if(thisAmount.getBigDecimal("alipay_total").compareTo(BigDecimal.ZERO) == 0){
@ -290,7 +291,7 @@ public class AreaMerchantTradeAnalysisImpl implements AreaMerchantTradeAnalysis{
}
}
if(thisAmount.getBigDecimal("wechat_toatl").compareTo(BigDecimal.ZERO)>0 && thisAmount.getBigDecimal("old_wechat_toatl").compareTo(BigDecimal.ZERO)>0){
wechatToatl = (thisAmount.getBigDecimal("wechat_toatl").subtract(thisAmount.getBigDecimal("old_wechat_toatl"))).divide(thisAmount.getBigDecimal("old_wechat_toatl"),4,BigDecimal.ROUND_HALF_UP);
wechatToatl = (thisAmount.getBigDecimal("wechat_toatl").subtract(thisAmount.getBigDecimal("old_wechat_toatl"))).divide(thisAmount.getBigDecimal("old_wechat_toatl"),4,RoundingMode.HALF_UP);
}
}else {
if(thisAmount.getBigDecimal("wechat_toatl").compareTo(BigDecimal.ZERO) == 0){

@ -303,9 +303,9 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT
res.put("today",today);
res.put("yes",yes);
res.put("not_settled", new BigDecimal(transactionAnalysisMapper.analysisNotSettled(params)));
res.put("trade_amount_rise",yes.getBigDecimal("trade_amount").compareTo(BigDecimal.ZERO)>0 ? (today.getBigDecimal("trade_amount").subtract(yes.getBigDecimal("trade_amount"))).divide(yes.getBigDecimal("trade_amount"), 4, BigDecimal.ROUND_HALF_UP):BigDecimal.ZERO);
res.put("trade_count_rise", yes.getIntValue("trade_count") > 0 ? (today.getBigDecimal("trade_count").subtract(yes.getBigDecimal("trade_count"))).divide(yes.getBigDecimal("trade_count"), 4, BigDecimal.ROUND_HALF_UP) : 0);
res.put("customers_rise", yes.getIntValue("customers") > 0 ? (today.getBigDecimal("customers").subtract(yes.getBigDecimal("customers"))).divide(yes.getBigDecimal("customers"), 4, BigDecimal.ROUND_HALF_UP) : 0);
res.put("trade_amount_rise",yes.getBigDecimal("trade_amount").compareTo(BigDecimal.ZERO)>0 ? (today.getBigDecimal("trade_amount").subtract(yes.getBigDecimal("trade_amount"))).divide(yes.getBigDecimal("trade_amount"), 4, RoundingMode.HALF_UP):BigDecimal.ZERO);
res.put("trade_count_rise", yes.getIntValue("trade_count") > 0 ? (today.getBigDecimal("trade_count").subtract(yes.getBigDecimal("trade_count"))).divide(yes.getBigDecimal("trade_count"), 4, RoundingMode.HALF_UP) : 0);
res.put("customers_rise", yes.getIntValue("customers") > 0 ? (today.getBigDecimal("customers").subtract(yes.getBigDecimal("customers"))).divide(yes.getBigDecimal("customers"), 4, RoundingMode.HALF_UP) : 0);
params.remove("begin");
params.remove("end");
List<JSONObject> logs = transactionMapper.listSettlementLogTotal(params);

@ -5,6 +5,7 @@ import au.com.royalpay.payment.tools.CommonConsts;
import com.alibaba.fastjson.JSONObject;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
@ -49,25 +50,25 @@ public class AgentCommissionAnalysis {
Date tradeDate = dayAnalysis.getDate("trade_date");
BigDecimal grossAmount = dayAnalysis.getBigDecimal("total");
BigDecimal dayRate = dayAnalysis.getBigDecimal(channel+"_rate_value");
BigDecimal agentCharge = grossAmount.multiply(dayRate.divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP));
BigDecimal agentCharge = grossAmount.multiply(dayRate.divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP));
BigDecimal orgCharge = BigDecimal.ZERO;
BigDecimal orgNetCharge = BigDecimal.ZERO;
switch (channel){
case "alipay":
orgCharge = grossAmount.multiply(org.getBigDecimal("alipay_rate_value").divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP));
orgNetCharge = orgCharge.subtract(grossAmount.multiply(parentOrg.getBigDecimal("alipay_rate_value").divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP)));
orgCharge = grossAmount.multiply(org.getBigDecimal("alipay_rate_value").divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP));
orgNetCharge = orgCharge.subtract(grossAmount.multiply(parentOrg.getBigDecimal("alipay_rate_value").divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP)));
break;
case "wechat":
orgCharge = grossAmount.multiply(org.getBigDecimal("wechat_rate_value").divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP));
orgNetCharge = orgCharge.subtract(grossAmount.multiply(parentOrg.getBigDecimal("wechat_rate_value").divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP)));
orgCharge = grossAmount.multiply(org.getBigDecimal("wechat_rate_value").divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP));
orgNetCharge = orgCharge.subtract(grossAmount.multiply(parentOrg.getBigDecimal("wechat_rate_value").divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP)));
break;
case "jd":
orgCharge = grossAmount.multiply(org.getBigDecimal("jd_rate_value").divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP));
orgNetCharge = orgCharge.subtract(grossAmount.multiply(parentOrg.getBigDecimal("jd_rate_value").divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP)));
orgCharge = grossAmount.multiply(org.getBigDecimal("jd_rate_value").divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP));
orgNetCharge = orgCharge.subtract(grossAmount.multiply(parentOrg.getBigDecimal("jd_rate_value").divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP)));
break;
case "alipayonline":
orgCharge = grossAmount.multiply(org.getBigDecimal("alipayonline_rate_value").divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP));
orgNetCharge = orgCharge.subtract(grossAmount.multiply(parentOrg.getBigDecimal("alipayonline_rate_value").divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP)));
orgCharge = grossAmount.multiply(org.getBigDecimal("alipayonline_rate_value").divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP));
orgNetCharge = orgCharge.subtract(grossAmount.multiply(parentOrg.getBigDecimal("alipayonline_rate_value").divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP)));
break;
default:
break;

@ -67,9 +67,9 @@ public class CityPartnerCommissionAnalysis {
Date tradeDate = dayAnalysis.getDate("trade_date");
BigDecimal total = dayAnalysis.getBigDecimal("total");
BigDecimal dayRate = dayAnalysis.getBigDecimal(channel + "_rate_value");
BigDecimal dayCharge = total.multiply(dayRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
BigDecimal dayCharge = total.multiply(dayRate).divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP);
BigDecimal royalpayCharge = total.multiply(rate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
BigDecimal royalpayCharge = total.multiply(rate).divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP);
BigDecimal thirdPartyPaymentCharge = getThirdPartyCharge(channel, total);
BigDecimal netCharge = royalpayCharge.subtract(thirdPartyPaymentCharge);
@ -161,13 +161,13 @@ public class CityPartnerCommissionAnalysis {
Date tradeDate = dayAnalysis.getDate("trade_date");
BigDecimal total = dayAnalysis.getBigDecimal("total");
BigDecimal dayRate = dayAnalysis.getBigDecimal(channel + "_rate_value");
BigDecimal dayCharge = total.multiply(dayRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
BigDecimal dayCharge = total.multiply(dayRate).divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP);
BigDecimal royalpayCharge = total.multiply(rate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
BigDecimal royalpayCharge = total.multiply(rate).divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP);
BigDecimal thirdPartyPaymentCharge = getThirdPartyCharge(channel, total);
BigDecimal netCharge = royalpayCharge.subtract(thirdPartyPaymentCharge);
BigDecimal orgCharge = netCharge.multiply(orgRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
BigDecimal orgCharge = netCharge.multiply(orgRate).divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP);
totalGrossAmount = totalGrossAmount.add(total);
totalChargeSum = totalChargeSum.add(dayCharge);
totalRoyalPayCharge = totalRoyalPayCharge.add(royalpayCharge);
@ -216,16 +216,16 @@ public class CityPartnerCommissionAnalysis {
BigDecimal thirdPartyPaymentCharge = BigDecimal.ZERO;
switch (channel) {
case "alipay":
thirdPartyPaymentCharge = total.multiply(alipayChargeRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
thirdPartyPaymentCharge = total.multiply(alipayChargeRate).divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP);
break;
case "wechat":
thirdPartyPaymentCharge = total.multiply(wechatChargeRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
thirdPartyPaymentCharge = total.multiply(wechatChargeRate).divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP);
break;
case "jd":
thirdPartyPaymentCharge = total.multiply(jdChargeRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
thirdPartyPaymentCharge = total.multiply(jdChargeRate).divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP);
break;
case "alipayonline":
thirdPartyPaymentCharge = total.multiply(alipayonlineChargeRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
thirdPartyPaymentCharge = total.multiply(alipayonlineChargeRate).divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP);
break;
default:
break;

@ -34,7 +34,7 @@ public class ReferrerCommissionAnalysis {
}
BigDecimal total = dayAnalysis.getBigDecimal("total");
BigDecimal orgCharge = total.multiply(referrerRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
BigDecimal orgCharge = total.multiply(referrerRate).divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP);
Date tradeDate = dayAnalysis.getDate("trade_date");
totalGrossAmount = totalGrossAmount.add(total);

@ -113,7 +113,7 @@ public class XPlanFundConfigServiceImpl implements XPlanFundConfigService {
}
public static BigDecimal calculateInterest(BigDecimal interestRate, BigDecimal amount) {
return amount.multiply(interestRate.divide(CommonConsts.HUNDRED, 4, BigDecimal.ROUND_DOWN)).divide(BigDecimal.valueOf(365), 2, BigDecimal.ROUND_HALF_UP);
return amount.multiply(interestRate.divide(CommonConsts.HUNDRED, 4, BigDecimal.ROUND_DOWN)).divide(BigDecimal.valueOf(365), 2, RoundingMode.HALF_UP);
}
private JSONObject getClient(String clientMoniker) {

@ -1,5 +1,6 @@
package au.com.royalpay.payment.manage.management.clearing.core;
import au.com.royalpay.payment.manage.support.abafile.ABAFile;
import au.com.royalpay.payment.manage.tradelog.beans.ClearingLogQuery;
import com.alibaba.fastjson.JSONObject;
import org.springframework.transaction.annotation.Transactional;
@ -44,7 +45,7 @@ public interface CleanService {
List<JSONObject> getXlsx(Date date) throws IOException;
List<JSONObject> getAba(Date dt) throws IOException;
List<ABAFile> getAba(Date dt, String bank) throws IOException;
void settlementAba(Date date, HttpServletResponse response) throws IOException;

@ -4,11 +4,7 @@ import au.com.royalpay.payment.core.PaymentApi;
import au.com.royalpay.payment.core.exceptions.InvalidShortIdException;
import au.com.royalpay.payment.core.tasksupport.SettlementSupport;
import au.com.royalpay.payment.manage.management.clearing.core.CleanService;
import au.com.royalpay.payment.manage.mappers.log.ClearingDetailAnalysisMapper;
import au.com.royalpay.payment.manage.mappers.log.ClearingDetailMapper;
import au.com.royalpay.payment.manage.mappers.log.ClearingLogMapper;
import au.com.royalpay.payment.manage.mappers.log.LogSettleMailMapper;
import au.com.royalpay.payment.manage.mappers.log.ValidationLogMapper;
import au.com.royalpay.payment.manage.mappers.log.*;
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper;
import au.com.royalpay.payment.manage.mappers.system.CalendarMapper;
import au.com.royalpay.payment.manage.mappers.system.ClientRateMapper;
@ -20,6 +16,7 @@ import au.com.royalpay.payment.manage.notice.core.MailService;
import au.com.royalpay.payment.manage.signin.beans.TodoNotice;
import au.com.royalpay.payment.manage.signin.core.ManagerTodoNoticeProvider;
import au.com.royalpay.payment.manage.support.abafile.ABAFile;
import au.com.royalpay.payment.manage.support.abafile.ABATemplate;
import au.com.royalpay.payment.manage.tradelog.beans.ClearingLogQuery;
import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApi;
import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApiProvider;
@ -34,14 +31,12 @@ import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
import au.com.royalpay.payment.tools.tasksupport.TaskFinishNotifyEvent;
import au.com.royalpay.payment.tools.utils.PageListUtils;
import au.com.royalpay.payment.tools.utils.TimeZoneUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
@ -50,12 +45,7 @@ import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.joda.time.DateTime;
import org.joda.time.Days;
@ -72,13 +62,9 @@ import org.springframework.util.CollectionUtils;
import org.thymeleaf.context.Context;
import org.thymeleaf.spring4.SpringTemplateEngine;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URISyntaxException;
@ -90,9 +76,6 @@ import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import static au.com.royalpay.payment.manage.permission.utils.OrgCheckUtils.checkOrgPermission;
/**
@ -145,7 +128,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
@Value("${app.redis.settle.check-code.prefix}")
private String reidsCheckCodeKey;
private final String[] open_ids = { "o32MzuEeb5ZT_DJQYbzZf6VCu1HQ", "o32MzuIsa3OBOkvC9pL90h9pgHPg", "o32MzuCpqGQJTlvTK7VQ7m_LVXiQ" };
private final String[] open_ids = {"o32MzuEeb5ZT_DJQYbzZf6VCu1HQ", "o32MzuIsa3OBOkvC9pL90h9pgHPg", "o32MzuCpqGQJTlvTK7VQ7m_LVXiQ"};
private ApplicationEventPublisher publisher;
// private final String[] open_ids = { "o32MzuO4s8c7iFOVxnxejkbhMoEc" };
@ -226,8 +209,22 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
addBigDecimal(total, log, "wechat_charge");
addBigDecimal(total, log, "royalpay_charge");
addBigDecimal(total, log, "net_amount");
details.addAll(clearingDetailMapper.listReportsOfSettlement(log.getIntValue("clearing_id")));
List<JSONObject> logDetails = clearingDetailMapper.listReportsOfSettlement(log.getIntValue("clearing_id"));
details.addAll(logDetails);
List<String> banks = logDetails.stream().map(detail -> detail.getString("settle_bank")).distinct().collect(Collectors.toList());
List<JSONObject> bankStatistics = banks.stream().map(bank -> {
JSONObject data = new JSONObject();
data.put("bank", bank);
data.put("total_settle", logDetails.stream()
.filter(detail -> bank.equals(detail.getString("settle_bank")))
.map(detail -> detail.getBigDecimal("net_amount"))
.reduce(BigDecimal::add)
);
return data;
}).collect(Collectors.toList());
log.put("bank_statistics", bankStatistics);
}
total.put("logs", logs);
total.put("details", details);
List<JSONObject> channels = clearingDetailAnalysisMapper.analysisChannelReportDaily(settleDate);
total.put("channel_analysis", channels);
@ -260,7 +257,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
}
@Override
public Map<String,JSONObject> getDayAndChannelOfAnalysisMap(int detailId,String channel,JSONObject manager) {
public Map<String, JSONObject> getDayAndChannelOfAnalysisMap(int detailId, String channel, JSONObject manager) {
JSONObject cleanLog = clearingDetailMapper.findByDetailId(detailId);
if (cleanLog == null) {
throw new NotFoundException();
@ -269,7 +266,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
Assert.notNull(client, "Client ID invalid");
checkOrgPermission(manager, client);
return getDayAnalysisMap(String.valueOf(detailId),channel,client);
return getDayAnalysisMap(String.valueOf(detailId), channel, client);
}
@Override
@ -378,34 +375,17 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
}
@Override
public List<JSONObject> getAba(Date dt) throws IOException {
public List<ABAFile> getAba(Date dt, String bank) {
List<JSONObject> logs = clearingLogMapper.findByDate(dt);
if (logs.isEmpty()) {
throw new NotFoundException();
}
List<JSONObject> result = new ArrayList<>();
int index = 1;
if (logs.size() > 1) {
// todo email edit
for (JSONObject log : logs) {
JSONObject file = new JSONObject();
List<JSONObject> details = clearingDetailMapper.listReportsOfSettlement(log.getIntValue("clearing_id"));
String filename = "Merchant_Settlement_Info_" + DateFormatUtils.format(dt, "yyyyMMdd") + "_" + index + ".aba";
file.put("name", filename);
file.put("byteArr", generateSettleAbaFile(dt, details, index++));
result.add(file);
}
} else {
for (JSONObject log : logs) {
List<JSONObject> details = clearingDetailMapper.listReportsOfSettlement(log.getIntValue("clearing_id"));
String filename = "Merchant_Settlement_Info_" + DateFormatUtils.format(dt, "yyyyMMdd") + ".aba";
JSONObject file = new JSONObject();
file.put("name", filename);
file.put("byteArr", generateSettleAbaFile(dt, details, index++));
result.add(file);
}
List<ABAFile> files = new ArrayList<>();
for (JSONObject log : logs) {
List<JSONObject> details = clearingDetailMapper.listReportsOfSettlement(log.getIntValue("clearing_id"));
files.addAll(generateSettleAbaFiles(dt, details, log.getDate("operate_time")));
}
return result;
return files.stream().filter(file -> bank.equals(file.bank())).collect(Collectors.toList());
}
private byte[] generateSettleXlsxFile(Date dt, List<JSONObject> settlements) throws IOException {
@ -434,34 +414,56 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
if (logs.isEmpty()) {
throw new NotFoundException();
}
String zipName = "Merchant_Settlement_Info_" + DateFormatUtils.format(dt, "yyyyMMdd") + RandomStringUtils.random(8, false, true) + "_aba.zip";
resp.setContentType("application/octet-stream;");
resp.addHeader("Content-Disposition", "attachment; filename=" + zipName);
OutputStream ous = resp.getOutputStream();
ZipOutputStream zos = new ZipOutputStream(ous);
int index = 1;
List<ABAFile> files = new ArrayList<>();
for (JSONObject log : logs) {
String dateString = DateFormatUtils.format(log.getDate("operate_time"), "yyyyMMddHHmmss");
String filename = "Merchant_Settlement_Info_" + dateString + RandomStringUtils.random(8, false, true) + ".aba";
zos.putNextEntry(new ZipEntry(filename));
List<JSONObject> details = clearingDetailMapper.listReportsOfSettlement(log.getIntValue("clearing_id"));
byte[] file = generateSettleAbaFile(dt, details, index++);
IOUtils.write(file, zos);
files.addAll(generateSettleAbaFiles(dt, details, log.getDate("operate_time")));
}
zos.flush();
IOUtils.closeQuietly(zos);
OutputStream ous = resp.getOutputStream();
if (files.size() == 1) {
ABAFile file = files.get(0);
resp.setContentType("application/octet-stream;");
resp.addHeader("Content-Disposition", "attachment; filename=" + file.filename());
ous.write(file.output(1));
ous.flush();
IOUtils.closeQuietly(ous);
} else {
String zipName = "Merchant_Settlement_Info_" + DateFormatUtils.format(dt, "yyyyMMdd") + RandomStringUtils.random(8, false, true) + "_aba.zip";
resp.setContentType("application/octet-stream;");
resp.addHeader("Content-Disposition", "attachment; filename=" + zipName);
ZipOutputStream zos = new ZipOutputStream(ous);
Map<String, Integer> bankCounts = new HashMap<>();
for (ABAFile file : files) {
String filename = file.filename();
zos.putNextEntry(new ZipEntry(filename));
int serializeNo = bankCounts.get(file.bank()) == null ? 1 : bankCounts.get(file.bank()) + 1;
bankCounts.put(file.bank(), serializeNo);
IOUtils.write(file.output(serializeNo), zos);
}
zos.flush();
IOUtils.closeQuietly(zos);
}
}
private List<ABAFile> generateSettleAbaFiles(Date dt, List<JSONObject> settlements, Date operateTime) {
List<String> banks = settlements.stream().map(detail -> detail.getString("settle_bank")).distinct().collect(Collectors.toList());
return banks.stream().map(bank -> generateSettleAbaFile(bank, dt, settlements)).peek(file -> file.setOperateTime(operateTime)).collect(Collectors.toList());
}
private byte[] generateSettleAbaFile(Date dt, List<JSONObject> settlements, int index) {
ABAFile aba = new ABAFile(dt, index);
private ABAFile generateSettleAbaFile(String bank, Date dt, List<JSONObject> settlements) {
ABAFile aba = ABATemplate.getConfig().initFile(bank, dt);
for (JSONObject settle : settlements) {
if (!bank.equals(settle.getString("settle_bank"))) {
continue;
}
if (settle.getBigDecimal("clearing_amount").compareTo(BigDecimal.ZERO) == 0) {
continue;
}
aba.addSettleMerchant(settle.getString("bsb_no"), settle.getString("account_no"), settle.getString("account_name"),
settle.getBigDecimal("clearing_amount"));
}
return aba.output();
return aba;
}
private byte[] generateSettleCSVFile(Date settleDate, List<JSONObject> details) throws IOException {
@ -474,12 +476,12 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
if (detail.getDoubleValue("clearing_amount") == 0) {
continue;
}
String grossAmount = detail.getBigDecimal("gross_amount").setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + " @ "
+ detail.getBigDecimal("rate").setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "%";
String totalCharge = detail.getBigDecimal("total_charge").setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString();
String clearingAmount = detail.getBigDecimal("clearing_amount").setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString();
String[] values = { detail.getString("client_moniker"), "AUD", grossAmount, totalCharge, clearingAmount, detail.getString("bsb_no"),
detail.getString("account_no"), detail.getString("account_name"), settlementDate };
String grossAmount = detail.getBigDecimal("gross_amount").setScale(2, RoundingMode.HALF_UP).toPlainString() + " @ "
+ detail.getBigDecimal("rate").setScale(2, RoundingMode.HALF_UP).toPlainString() + "%";
String totalCharge = detail.getBigDecimal("total_charge").setScale(2, RoundingMode.HALF_UP).toPlainString();
String clearingAmount = detail.getBigDecimal("clearing_amount").setScale(2, RoundingMode.HALF_UP).toPlainString();
String[] values = {detail.getString("client_moniker"), "AUD", grossAmount, totalCharge, clearingAmount, detail.getString("bsb_no"),
detail.getString("account_no"), detail.getString("account_name"), settlementDate};
csv.printRecord((Object[]) values);
}
csv.flush();
@ -500,9 +502,9 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
BigDecimal.ROUND_HALF_DOWN);
BigDecimal clearingAmount = transaction.getBigDecimal("clearing_amount").multiply(BigDecimal.valueOf(multiply)).setScale(2,
BigDecimal.ROUND_HALF_DOWN);
String[] values = { transaction.getString("system_transaction_id"), transaction.getString("order_id"), transaction.getString("client_id"),
String[] values = {transaction.getString("system_transaction_id"), transaction.getString("order_id"), transaction.getString("client_id"),
transaction.getString("device_id"), transaction.getString("transaction_currency"), transactionAmount.toPlainString(),
transaction.getString("clearing_currency"), clearingAmount.toPlainString(), transaction.getString("channel"), transactionTime, "0" };
transaction.getString("clearing_currency"), clearingAmount.toPlainString(), transaction.getString("channel"), transactionTime, "0"};
csv.printRecord((Object[]) values);
}
csv.flush();
@ -650,7 +652,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
String timezone_client = client.getString("timezone");
if (timezone_client != null) {
transactions.parallelStream().forEach(p -> {
TimeZoneUtils.switchTimeZone(p, timezone_client, "transaction_time");
TimeZoneUtils.switchTimeZone(p, timezone_client, "transaction_time");
});
}
clearClient.put("report", transactions);
@ -665,7 +667,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
}
@Override
public Map<String,JSONObject> channelAndDayOfAnalysis(int client_id, String clearingDetailId,String channel,JSONObject partner) {
public Map<String, JSONObject> channelAndDayOfAnalysis(int client_id, String clearingDetailId, String channel, JSONObject partner) {
JSONObject client = clientManager.getClientInfo(client_id);
Assert.notNull(client, "Client not exists");
int parent_client_id = client.getIntValue("parent_client_id");
@ -673,15 +675,15 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
if (client_id != partner.getIntValue("client_id") && parent_client_id != partner.getIntValue("client_id")) {
throw new ForbiddenException("No Permission");
}
return getDayAnalysisMap(clearingDetailId,channel,client);
return getDayAnalysisMap(clearingDetailId, channel, client);
}
private Map<String,JSONObject> getDayAnalysisMap(String clearingDetailId,String channel,JSONObject client){
private Map<String, JSONObject> getDayAnalysisMap(String clearingDetailId, String channel, JSONObject client) {
List<JSONObject> transactions = transactionMapper.listTransactionsOfClearingOrder(Integer.parseInt(clearingDetailId),
new PageBounds(Order.formString("order_id.asc")));
String timezone_client = client.getString("timezone");
if(!channel.equals("null")){
transactions = transactions.stream().filter(t->t.getString("channel").equals(channel)).collect(Collectors.toList());
if (!channel.equals("null")) {
transactions = transactions.stream().filter(t -> t.getString("channel").equals(channel)).collect(Collectors.toList());
}
List<String> dateKeysList = new ArrayList<>();
dateKeysList.add("transaction_time");
@ -689,35 +691,36 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
transactions.parallelStream().forEach(p -> {
TimeZoneUtils.switchTimeZone(p, timezone_client, "transaction_time");
});
TimeZoneUtils.switchTimeZoneToString(transactions,timezone_client,TimeZoneUtils.PATTERN_DATE,dateKeysList);
TimeZoneUtils.switchTimeZoneToString(transactions, timezone_client, TimeZoneUtils.PATTERN_DATE, dateKeysList);
}
Map<String,List<JSONObject>> dayTransactionsMap = transactions.stream().collect(Collectors.groupingBy(x -> x.getString("transaction_time").substring(0,10)));
Map<String,JSONObject> dayAnalysisMap = new TreeMap<>();
for (Map.Entry<String, List<JSONObject>> entry : dayTransactionsMap.entrySet()){
Map<String, List<JSONObject>> dayTransactionsMap = transactions.stream().collect(Collectors.groupingBy(x -> x.getString("transaction_time").substring(0, 10)));
Map<String, JSONObject> dayAnalysisMap = new TreeMap<>();
for (Map.Entry<String, List<JSONObject>> entry : dayTransactionsMap.entrySet()) {
JSONObject analysis = new JSONObject();
List<JSONObject> transactionsOfDay = entry.getValue();
BigDecimal total_credit = transactionsOfDay.stream().filter(t->t.getString("transaction_type").equals("Credit")).filter(t->t.containsKey("clearing_amount")).map(t-> t.getBigDecimal("clearing_amount")).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal total_debit = transactionsOfDay.stream().filter(t->t.getString("transaction_type").equals("Debit")).filter(t->t.containsKey("clearing_amount")).map(t-> t.getBigDecimal("clearing_amount")).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal total_charge_credit = transactionsOfDay.stream().filter(t->t.getString("transaction_type").equals("Credit")).filter(t->t.containsKey("total_surcharge")).map(t-> t.getBigDecimal("total_surcharge")).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal total_charge_debit = transactionsOfDay.stream().filter(t->t.getString("transaction_type").equals("Debit")).filter(t->t.containsKey("total_surcharge")).map(t-> t.getBigDecimal("total_surcharge")).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal net_amount_credit = transactionsOfDay.stream().filter(t->t.getString("transaction_type").equals("Credit")).filter(t->t.containsKey("settle_amount")).map(t-> t.getBigDecimal("settle_amount")).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal net_amount_debit = transactionsOfDay.stream().filter(t->t.getString("transaction_type").equals("Debit")).filter(t->t.containsKey("settle_amount")).map(t-> t.getBigDecimal("settle_amount")).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal tax_amount_credit = transactionsOfDay.stream().filter(t->t.getString("transaction_type").equals("Credit")).filter(t->t.containsKey("tax_amount")).map(t-> t.getBigDecimal("tax_amount")).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal tax_amount_debit = transactionsOfDay.stream().filter(t->t.getString("transaction_type").equals("Debit")).filter(t->t.containsKey("tax_amount")).map(t-> t.getBigDecimal("tax_amount")).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal total_credit = transactionsOfDay.stream().filter(t -> t.getString("transaction_type").equals("Credit")).filter(t -> t.containsKey("clearing_amount")).map(t -> t.getBigDecimal("clearing_amount")).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal total_debit = transactionsOfDay.stream().filter(t -> t.getString("transaction_type").equals("Debit")).filter(t -> t.containsKey("clearing_amount")).map(t -> t.getBigDecimal("clearing_amount")).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal total_charge_credit = transactionsOfDay.stream().filter(t -> t.getString("transaction_type").equals("Credit")).filter(t -> t.containsKey("total_surcharge")).map(t -> t.getBigDecimal("total_surcharge")).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal total_charge_debit = transactionsOfDay.stream().filter(t -> t.getString("transaction_type").equals("Debit")).filter(t -> t.containsKey("total_surcharge")).map(t -> t.getBigDecimal("total_surcharge")).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal net_amount_credit = transactionsOfDay.stream().filter(t -> t.getString("transaction_type").equals("Credit")).filter(t -> t.containsKey("settle_amount")).map(t -> t.getBigDecimal("settle_amount")).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal net_amount_debit = transactionsOfDay.stream().filter(t -> t.getString("transaction_type").equals("Debit")).filter(t -> t.containsKey("settle_amount")).map(t -> t.getBigDecimal("settle_amount")).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal tax_amount_credit = transactionsOfDay.stream().filter(t -> t.getString("transaction_type").equals("Credit")).filter(t -> t.containsKey("tax_amount")).map(t -> t.getBigDecimal("tax_amount")).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal tax_amount_debit = transactionsOfDay.stream().filter(t -> t.getString("transaction_type").equals("Debit")).filter(t -> t.containsKey("tax_amount")).map(t -> t.getBigDecimal("tax_amount")).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal tax_amount = tax_amount_credit.subtract(tax_amount_debit);
analysis.put("total_credit",total_credit.setScale(2,BigDecimal.ROUND_HALF_UP));
analysis.put("total_debit",total_debit.setScale(2,BigDecimal.ROUND_HALF_UP));
analysis.put("net_amount",net_amount_credit.subtract(net_amount_debit).setScale(2,BigDecimal.ROUND_HALF_UP));
analysis.put("tax_amount",tax_amount.setScale(2,BigDecimal.ROUND_HALF_UP));
analysis.put("total_charge",total_charge_credit.subtract(total_charge_debit).add(tax_amount).setScale(2,BigDecimal.ROUND_HALF_UP));
analysis.put("gross_amount",total_credit.subtract(total_debit).setScale(2,BigDecimal.ROUND_HALF_UP));
dayAnalysisMap.put(entry.getKey(),analysis);
analysis.put("total_credit", total_credit.setScale(2, RoundingMode.HALF_UP));
analysis.put("total_debit", total_debit.setScale(2, RoundingMode.HALF_UP));
analysis.put("net_amount", net_amount_credit.subtract(net_amount_debit).setScale(2, RoundingMode.HALF_UP));
analysis.put("tax_amount", tax_amount.setScale(2, RoundingMode.HALF_UP));
analysis.put("total_charge", total_charge_credit.subtract(total_charge_debit).add(tax_amount).setScale(2, RoundingMode.HALF_UP));
analysis.put("gross_amount", total_credit.subtract(total_debit).setScale(2, RoundingMode.HALF_UP));
dayAnalysisMap.put(entry.getKey(), analysis);
}
return dayAnalysisMap;
}
@Override
public void exportListClearingTransactions(int client_id, String clearingDetailId, JSONObject partner, HttpServletResponse resp) {
OutputStream ous = null;
@ -738,9 +741,9 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
Sheet sheet = wb.createSheet("Merchant_Settlement_Info_" + DateFormatUtils.format(reportDate, "yyyyMMdd"));
int rowNum = 0;
Row row = sheet.createRow(rowNum);
String[] title = { "order Id", "Client Order Id", "Transaction Time", "Channel", "Gateway", "Exchange Rate", "Transaction Type", "Currency",
"Input Amount", "Total Amount", "Clearing Amount", "Sruchange Rate", "Settle Amount", "Remark" };
String[] analysis = { "Total Credit", "Total Debit", "Gross Amount", "Total Charge", "Net Amount" };
String[] title = {"order Id", "Client Order Id", "Transaction Time", "Channel", "Gateway", "Exchange Rate", "Transaction Type", "Currency",
"Input Amount", "Total Amount", "Clearing Amount", "Sruchange Rate", "Settle Amount", "Remark"};
String[] analysis = {"Total Credit", "Total Debit", "Gross Amount", "Total Charge", "Net Amount"};
for (int i = 0; i < title.length; i++) {
row.createCell(i, Cell.CELL_TYPE_STRING).setCellValue(title[i]);
}
@ -755,7 +758,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue(settle.getString("order_id"));
row.createCell(1, Cell.CELL_TYPE_STRING).setCellValue(settle.getString("client_order_id"));
Calendar calendar = (Calendar) settle.get("transaction_time");
row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(DateFormatUtils.format(calendar, "yyyy-MM-dd HH:mm:ss",calendar.getTimeZone()));
row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(DateFormatUtils.format(calendar, "yyyy-MM-dd HH:mm:ss", calendar.getTimeZone()));
row.createCell(3, Cell.CELL_TYPE_STRING).setCellValue(settle.getString("channel"));
if (settle.getInteger("gateway") != null) {
row.createCell(4, Cell.CELL_TYPE_STRING).setCellValue(TradeType.fromGatewayNumber(settle.getIntValue("gateway")).getTradeType());
@ -937,15 +940,23 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
attachList.add(attach1);
JSONObject attach2 = new JSONObject();
List<JSONObject> abaFileList = getAba(date);
List<ABAFile> abaFileList = getAba(date, "CBA");
String fileName2 = "Merchant_Settlement_Info_aba_" + DateFormatUtils.format(date, "yyyyMMdd");
if (abaFileList.size() > 1) {
fileName2 += ".zip";
attach2.put("content", Base64.encodeBase64String(getZipByteArr(abaFileList)));
List<JSONObject> entities = new ArrayList<>();
int index = 0;
for (ABAFile file : abaFileList) {
JSONObject entity = new JSONObject();
entity.put("name", file.filename());
entity.put("byteArr", file.output(index++));
entities.add(entity);
}
attach2.put("content", Base64.encodeBase64String(getZipByteArr(entities)));
} else {
fileName2 += ".aba";
attach2.put("content", Base64.encodeBase64String((byte[]) abaFileList.get(0).get("byteArr")));
attach2.put("content", Base64.encodeBase64String(abaFileList.get(0).output(1)));
}
attach2.put("name", fileName2);
attachList.add(attach2);

@ -258,7 +258,7 @@ public class SettleDelayConfigurerImpl implements SettleDelayConfigurer {
}
totalSurcharge = totalSurcharge.add(surcharge);
}
BigDecimal cashbackAmount = CurrencyAmountUtils.scale(totalSurcharge.multiply(attend.getBigDecimal("surcharge_discount")).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP), PlatformEnvironment.getEnv().getForeignCurrency());
BigDecimal cashbackAmount = CurrencyAmountUtils.scale(totalSurcharge.multiply(attend.getBigDecimal("surcharge_discount")).divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP), PlatformEnvironment.getEnv().getForeignCurrency());
String remark = "Surcharge cashback for " + saturday.toString("dd/MMM/yyyy", Locale.ENGLISH) + " ~ " + sunday.toString("dd/MMM/yyyy", Locale.ENGLISH);
if (cashbackAmount.compareTo(BigDecimal.ZERO) > 0) {
cashbackService.saveSurchargeDiscountCashback(clientId, clientMoniker, transactionOrderId, cashbackAmount, date, remark);

@ -119,7 +119,7 @@ public class ActRedPackServiceImpl implements ActRedPackService {
if ("CNY".equals(currency)) {
JSONObject income = transactionService.findIncomeByOrderId(orderId);
BigDecimal exchange = income.getBigDecimal("exchange_rate");
currencyAmount = exchange.multiply(currencyAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
currencyAmount = exchange.multiply(currencyAmount).setScale(2, RoundingMode.HALF_UP);
}
if (ruleOrderTotal != null) {
if (!(currencyAmount.compareTo(ruleOrderTotal) >= 0)) {

@ -0,0 +1,111 @@
package au.com.royalpay.payment.manage.support.abafile;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* Create by yixian at 2018-06-25 17:39
*/
@ConfigurationProperties("settle.abafile")
public class ABAConfig {
private Map<String, ABABase> bank = new HashMap<>();
private String defaultBank;
public ABAFile initFile(String bank, Date settleDate) {
ABABase base = this.bank.get(bank);
if (base == null) {
throw new BadRequestException("Invalid bank:" + bank);
}
return base.initFile(settleDate);
}
public String getDefaultBank() {
return defaultBank;
}
public ABAConfig setDefaultBank(String defaultBank) {
this.defaultBank = defaultBank;
return this;
}
public Map<String, ABABase> getBank() {
return bank;
}
public ABAConfig setBank(Map<String, ABABase> bank) {
this.bank = bank;
return this;
}
public static class ABABase {
private boolean manualSending = false;
private String bank;
private String apca;
private String bsb;
private String accountNo;
private String accountName;
public ABAFile initFile(Date settleDate) {
return new ABAFile(this, settleDate);
}
public boolean isManualSending() {
return manualSending;
}
public ABABase setManualSending(boolean manualSending) {
this.manualSending = manualSending;
return this;
}
public String getBank() {
return bank;
}
public ABABase setBank(String bank) {
this.bank = bank;
return this;
}
public String getApca() {
return apca;
}
public ABABase setApca(String apca) {
this.apca = apca;
return this;
}
public String getBsb() {
return bsb;
}
public ABABase setBsb(String bsb) {
this.bsb = bsb;
return this;
}
public String getAccountNo() {
return accountNo;
}
public ABABase setAccountNo(String accountNo) {
this.accountNo = accountNo;
return this;
}
public String getAccountName() {
return accountName;
}
public ABABase setAccountName(String accountName) {
this.accountName = accountName;
return this;
}
}
}

@ -15,21 +15,17 @@ import java.util.List;
public class ABAFile {
private final String baseLine = StringUtils.repeat(" ", 120);
private int sequenceNo = 1;
private String bank = "CBA";
private String company = "Tunnel Show Pty Ltd";
private String selfBSB = "063109";
private String selfAccountNo = "11655861";
private String apca = "301500";
private final ABAConfig.ABABase base;
private final Date settleDate;
private List<SettleMerchantInfo> settlements;
private BigDecimal totalSettleAmount;
private Date operateTime;
public ABAFile(Date settleDate, int index) {
public ABAFile(ABAConfig.ABABase base, Date settleDate) {
this.base = base;
this.settleDate = settleDate;
settlements = new ArrayList<>();
totalSettleAmount = BigDecimal.ZERO;
sequenceNo = index;
}
public void addSettleMerchant(String bsbNo, String accountNo, String accountName, BigDecimal settleAmount) {
@ -37,11 +33,19 @@ public class ABAFile {
totalSettleAmount = totalSettleAmount.add(settleAmount);
}
public byte[] output() {
public boolean manualSending() {
return base.isManualSending();
}
public String bank() {
return base.getBank();
}
public byte[] output(int serializeNo) {
StringWriter out = new StringWriter();
PrintWriter writer = new PrintWriter(out);
writer.print(generateTopLine() + "\r\n");
writer.print(generateTopLine(serializeNo) + "\r\n");
for (SettleMerchantInfo info : settlements) {
String line = info.settleLine();
writer.print(line + "\r\n");
@ -66,27 +70,27 @@ public class ABAFile {
private String generateBalanceLine() {
StringBuilder lineBuilder = new StringBuilder(baseLine);
lineBuilder.replace(0, 1, "1");
lineBuilder.replace(1, 8, bsbNo(selfBSB));
lineBuilder.replace(8, 17, StringUtils.leftPad(selfAccountNo, 9));
lineBuilder.replace(1, 8, bsbNo(base.getBsb()));
lineBuilder.replace(8, 17, StringUtils.leftPad(base.getAccountNo(), 9));
lineBuilder.replace(18, 20, "13");
lineBuilder.replace(20, 30, amountString(totalSettleAmount, 10));
lineBuilder.replace(30, 62, StringUtils.rightPad(StringUtils.substring(company, 0, 32), 32));
lineBuilder.replace(30, 62, StringUtils.rightPad(StringUtils.substring(base.getAccountName(), 0, 32), 32));
lineBuilder.replace(62, 80, StringUtils.rightPad(DateFormatUtils.format(settleDate, "yyyyMMdd"), 18));
lineBuilder.replace(80, 87, bsbNo(selfBSB));
lineBuilder.replace(87, 96, StringUtils.leftPad(selfAccountNo, 9));
lineBuilder.replace(96, 112, StringUtils.left(StringUtils.rightPad(company, 16), 16));
lineBuilder.replace(80, 87, bsbNo(base.getBsb()));
lineBuilder.replace(87, 96, StringUtils.leftPad(base.getAccountNo(), 9));
lineBuilder.replace(96, 112, StringUtils.left(StringUtils.rightPad(base.getAccountName(), 16), 16));
lineBuilder.replace(112, 120, StringUtils.leftPad("0", 8, "0"));
return lineBuilder.toString();
}
private String generateTopLine() {
private String generateTopLine(int serializeNo) {
StringBuilder topLineBuilder = new StringBuilder(baseLine);
topLineBuilder.replace(0, 1, "0");
topLineBuilder.replace(18, 20, StringUtils.leftPad("1", 2, "0"));
Assert.isTrue(bank.length() == 3, "Invalid Bank Code:" + bank);
topLineBuilder.replace(20, 23, bank);
topLineBuilder.replace(30, 56, StringUtils.rightPad(company, 26));
topLineBuilder.replace(56, 62, StringUtils.leftPad(apca, 6, "0"));
Assert.isTrue(base.getBank().length() == 3, "Invalid Bank Code:" + base.getBank());
topLineBuilder.replace(20, 23, base.getBank());
topLineBuilder.replace(30, 56, StringUtils.rightPad(base.getAccountName(), 26));
topLineBuilder.replace(56, 62, StringUtils.leftPad(base.getApca(), 6, "0"));
topLineBuilder.replace(62, 74, StringUtils.rightPad(DateFormatUtils.format(settleDate, "yyyyMMdd"), 12));
topLineBuilder.replace(74, 80, DateFormatUtils.format(settleDate, "ddMMyy"));
return topLineBuilder.toString();
@ -102,6 +106,22 @@ public class ABAFile {
return StringUtils.leftPad("" + amount, size, "0");
}
public void setOperateTime(Date operateTime) {
this.operateTime = operateTime;
}
public String getOperateTimeString() {
return operateTime == null ? "" : DateFormatUtils.format(operateTime, "yyyyMMddHHmmss");
}
public Date getOperateTime() {
return operateTime;
}
public String filename() {
return "Merchant_Settlement_Info_" + bank() + "_" + getOperateTimeString() + ".aba";
}
private class SettleMerchantInfo {
private final String bsbNo;
private final String accountNo;
@ -124,9 +144,9 @@ public class ABAFile {
lineBuilder.replace(20, 30, getSettleAmount());
lineBuilder.replace(30, 62, getAccountName());
lineBuilder.replace(62, 80, StringUtils.rightPad("RoyalPay" + DateFormatUtils.format(settleDate, "yyyyMMdd"), 18));
lineBuilder.replace(80, 87, bsbNo(selfBSB));
lineBuilder.replace(87, 96, StringUtils.leftPad(selfAccountNo, 9));
lineBuilder.replace(96, 112, StringUtils.left(StringUtils.rightPad(company, 16), 16));
lineBuilder.replace(80, 87, bsbNo(base.getBsb()));
lineBuilder.replace(87, 96, StringUtils.leftPad(base.getAccountNo(), 9));
lineBuilder.replace(96, 112, StringUtils.left(StringUtils.rightPad(base.getAccountName(), 16), 16));
lineBuilder.replace(112, 120, StringUtils.leftPad("0", 8, "0"));
return lineBuilder.toString();
}

@ -0,0 +1,27 @@
package au.com.royalpay.payment.manage.support.abafile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
/**
* Create by yixian at 2018-06-25 17:16
*/
@Component
@EnableConfigurationProperties(ABAConfig.class)
public class ABATemplate {
private static ABATemplate tpl;
@Autowired
private ABAConfig config;
@PostConstruct
public void init() {
tpl = this;
}
public static ABAConfig getConfig() {
return tpl.config;
}
}

@ -111,3 +111,20 @@ mail.mailgun.default.merchantlist=merchants@mail.royalpay.com.au
##############
royalpay.sms.appid=1400094878
royalpay.sms.appkey=43390d81e20c5191c278fbf4cd275be2
#清算银行配置
settle.abafile.default-bank=CBA
settle.abafile.bank.CBA.bank=CBA
settle.abafile.bank.CBA.apca=301500
settle.abafile.bank.CBA.bsb=063109
settle.abafile.bank.CBA.account-no=11655861
settle.abafile.bank.CBA.account-name=Tunnel Show Pty Ltd
settle.abafile.bank.ANZ.manual-sending=true
settle.abafile.bank.ANZ.bank=ANZ
settle.abafile.bank.ANZ.apca=514624
settle.abafile.bank.ANZ.bsb=013006
settle.abafile.bank.ANZ.account-no=837022519
settle.abafile.bank.ANZ.account-name=Tunnel Show Pty Ltd
Loading…
Cancel
Save