|
|
@ -3,6 +3,7 @@ package au.com.royalpay.payment.manage.management.clearing.core.impl;
|
|
|
|
import au.com.royalpay.payment.core.PaymentApi;
|
|
|
|
import au.com.royalpay.payment.core.PaymentApi;
|
|
|
|
import au.com.royalpay.payment.core.exceptions.InvalidShortIdException;
|
|
|
|
import au.com.royalpay.payment.core.exceptions.InvalidShortIdException;
|
|
|
|
import au.com.royalpay.payment.core.tasksupport.SettlementSupport;
|
|
|
|
import au.com.royalpay.payment.core.tasksupport.SettlementSupport;
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.core.utils.ExtParamsUtils;
|
|
|
|
import au.com.royalpay.payment.manage.management.clearing.core.CleanService;
|
|
|
|
import au.com.royalpay.payment.manage.management.clearing.core.CleanService;
|
|
|
|
import au.com.royalpay.payment.manage.mappers.log.*;
|
|
|
|
import au.com.royalpay.payment.manage.mappers.log.*;
|
|
|
|
import au.com.royalpay.payment.manage.mappers.payment.TaskManualSettleMapper;
|
|
|
|
import au.com.royalpay.payment.manage.mappers.payment.TaskManualSettleMapper;
|
|
|
@ -32,6 +33,7 @@ import au.com.royalpay.payment.tools.exceptions.ForbiddenException;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.NotFoundException;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.NotFoundException;
|
|
|
|
import au.com.royalpay.payment.tools.locale.LocaleSupport;
|
|
|
|
import au.com.royalpay.payment.tools.locale.LocaleSupport;
|
|
|
|
import au.com.royalpay.payment.tools.lock.Locker;
|
|
|
|
import au.com.royalpay.payment.tools.lock.Locker;
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.tools.merchants.beans.BalanceGroup;
|
|
|
|
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
|
|
|
|
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
|
|
|
|
import au.com.royalpay.payment.tools.tasksupport.TaskFinishNotifyEvent;
|
|
|
|
import au.com.royalpay.payment.tools.tasksupport.TaskFinishNotifyEvent;
|
|
|
|
import au.com.royalpay.payment.tools.utils.DateVaildUtil;
|
|
|
|
import au.com.royalpay.payment.tools.utils.DateVaildUtil;
|
|
|
@ -321,7 +323,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
JSONObject client = clientManager.getClientInfo(clientId);
|
|
|
|
JSONObject client = clientManager.getClientInfo(clientId);
|
|
|
|
Assert.notNull(client, "Client ID invalid");
|
|
|
|
Assert.notNull(client, "Client ID invalid");
|
|
|
|
checkOrgPermission(manager, client);
|
|
|
|
checkOrgPermission(manager, client);
|
|
|
|
List<JSONObject> transactions = transactionMapper.listTransactionsOfMergeSettleClearingOrder(reportDate,clientId,
|
|
|
|
List<JSONObject> transactions = transactionMapper.listTransactionsOfMergeSettleClearingOrder(reportDate, clientId,
|
|
|
|
new PageBounds(Order.formString("order_id.asc")));
|
|
|
|
new PageBounds(Order.formString("order_id.asc")));
|
|
|
|
clearClient.put("report", transactions);
|
|
|
|
clearClient.put("report", transactions);
|
|
|
|
List<JSONObject> channels = clearingDetailAnalysisMapper.listReportChannelsOfMergeSettle(reportDate, clientId);
|
|
|
|
List<JSONObject> channels = clearingDetailAnalysisMapper.listReportChannelsOfMergeSettle(reportDate, clientId);
|
|
|
@ -536,15 +538,16 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<ABAFile> getAba(Date dt, String bank, List<JSONObject> logs) {
|
|
|
|
public List<ABAFile> getAba(Date dt, List<JSONObject> logs) {
|
|
|
|
List<ABAFile> files = new ArrayList<>();
|
|
|
|
List<ABAFile> files = new ArrayList<>();
|
|
|
|
for (JSONObject log : logs) {
|
|
|
|
for (JSONObject log : logs) {
|
|
|
|
List<JSONObject> details = clearingDetailMapper.listReportsOfSettlement(log.getIntValue("clearing_id"));
|
|
|
|
List<JSONObject> details = clearingDetailMapper.listReportsOfSettlement(log.getIntValue("clearing_id"));
|
|
|
|
details = mergeBatchSettleClients(details);
|
|
|
|
details = mergeBatchSettleClients(details);
|
|
|
|
String remark = extractSettleRemark(log);
|
|
|
|
String remark = extractSettleRemark(log);
|
|
|
|
files.addAll(generateSettleAbaFiles(dt, details, log.getDate("operate_time"), remark));
|
|
|
|
BalanceGroup group = BalanceGroup.valueOf(log.getString("balance_group"));
|
|
|
|
|
|
|
|
files.addAll(generateSettleAbaFiles(dt, group, details, log.getDate("operate_time"), remark));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return files.stream().filter(file -> bank.equals(file.bank())).collect(Collectors.toList());
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String extractSettleRemark(JSONObject log) {
|
|
|
|
public String extractSettleRemark(JSONObject log) {
|
|
|
@ -589,7 +592,8 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
for (JSONObject log : logs) {
|
|
|
|
for (JSONObject log : logs) {
|
|
|
|
List<JSONObject> details = clearingDetailMapper.listReportsOfSettlement(log.getIntValue("clearing_id"));
|
|
|
|
List<JSONObject> details = clearingDetailMapper.listReportsOfSettlement(log.getIntValue("clearing_id"));
|
|
|
|
details = mergeBatchSettleClients(details);
|
|
|
|
details = mergeBatchSettleClients(details);
|
|
|
|
files.addAll(generateSettleAbaFiles(dt, details, log.getDate("operate_time"), extractSettleRemark(log)));
|
|
|
|
BalanceGroup group = BalanceGroup.valueOf(log.getString("balance_group"));
|
|
|
|
|
|
|
|
files.addAll(generateSettleAbaFiles(dt, group, details, log.getDate("operate_time"), extractSettleRemark(log)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OutputStream ous = resp.getOutputStream();
|
|
|
|
OutputStream ous = resp.getOutputStream();
|
|
|
|
if (files.size() == 1) {
|
|
|
|
if (files.size() == 1) {
|
|
|
@ -633,7 +637,8 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
resp.addHeader("Content-Disposition", "attachment; filename=" + zipName);
|
|
|
|
resp.addHeader("Content-Disposition", "attachment; filename=" + zipName);
|
|
|
|
OutputStream ous = resp.getOutputStream();
|
|
|
|
OutputStream ous = resp.getOutputStream();
|
|
|
|
|
|
|
|
|
|
|
|
List<ABAFile> abaFiles = generateSettleAbaFiles(settleDate, details, opTime, extractSettleRemark(clearing));
|
|
|
|
BalanceGroup group = BalanceGroup.valueOf(clearing.getString("balance_group"));
|
|
|
|
|
|
|
|
List<ABAFile> abaFiles = generateSettleAbaFiles(settleDate, group, details, opTime, extractSettleRemark(clearing));
|
|
|
|
try (ZipOutputStream zos = new ZipOutputStream(ous)) {
|
|
|
|
try (ZipOutputStream zos = new ZipOutputStream(ous)) {
|
|
|
|
for (ABAFile aba : abaFiles) {
|
|
|
|
for (ABAFile aba : abaFiles) {
|
|
|
|
zos.putNextEntry(new ZipEntry(aba.filename()));
|
|
|
|
zos.putNextEntry(new ZipEntry(aba.filename()));
|
|
|
@ -644,16 +649,16 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<ABAFile> generateSettleAbaFiles(Date dt, List<JSONObject> settlements, Date operateTime, String remark) {
|
|
|
|
private List<ABAFile> generateSettleAbaFiles(Date dt, BalanceGroup group, List<JSONObject> settlements, Date operateTime, String remark) {
|
|
|
|
List<String> banks = settlements.stream().map(detail -> detail.getString("settle_bank")).distinct().collect(Collectors.toList());
|
|
|
|
List<String> banks = settlements.stream().map(detail -> detail.getString("settle_bank")).distinct().collect(Collectors.toList());
|
|
|
|
return banks.stream().map(bank -> generateSettleAbaFile(bank, dt, settlements))
|
|
|
|
return banks.stream().map(bank -> generateSettleAbaFile(bank, group, dt, settlements))
|
|
|
|
.peek(file -> file.setOperateTime(operateTime))
|
|
|
|
.peek(file -> file.setOperateTime(operateTime))
|
|
|
|
.peek(file -> file.setRemark(remark))
|
|
|
|
.peek(file -> file.setRemark(remark))
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ABAFile generateSettleAbaFile(String bank, Date dt, List<JSONObject> settlements) {
|
|
|
|
private ABAFile generateSettleAbaFile(String bank, BalanceGroup group, Date dt, List<JSONObject> settlements) {
|
|
|
|
ABAFile aba = ABATemplate.getConfig().initFile(bank, dt);
|
|
|
|
ABAFile aba = ABATemplate.getConfig().initFile(group, bank, dt);
|
|
|
|
for (JSONObject settle : settlements) {
|
|
|
|
for (JSONObject settle : settlements) {
|
|
|
|
if (!bank.equals(settle.getString("settle_bank"))) {
|
|
|
|
if (!bank.equals(settle.getString("settle_bank"))) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
@ -890,7 +895,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
if (clearClient == null) {
|
|
|
|
if (clearClient == null) {
|
|
|
|
throw new NotFoundException();
|
|
|
|
throw new NotFoundException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<JSONObject> transactions = transactionMapper.listTransactionsOfMergeSettleClearingOrder(reportDate,client_id,
|
|
|
|
List<JSONObject> transactions = transactionMapper.listTransactionsOfMergeSettleClearingOrder(reportDate, client_id,
|
|
|
|
new PageBounds(Order.formString("order_id.asc")));
|
|
|
|
new PageBounds(Order.formString("order_id.asc")));
|
|
|
|
|
|
|
|
|
|
|
|
String timezone_client = client.getString("timezone");
|
|
|
|
String timezone_client = client.getString("timezone");
|
|
|
@ -1026,10 +1031,10 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void exportListClearingTransactions(int client_id, String clearingDetailId, JSONObject partner, HttpServletResponse resp) {
|
|
|
|
public void exportListClearingTransactions(int clientId, String clearingDetailId, JSONObject partner, HttpServletResponse resp) {
|
|
|
|
OutputStream ous = null;
|
|
|
|
OutputStream ous = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
JSONObject clearTransation = listClearingTransactions(client_id, clearingDetailId, partner);
|
|
|
|
JSONObject clearTransation = listClearingTransactions(clientId, clearingDetailId, partner);
|
|
|
|
resp.setContentType("application/octet-stream;");
|
|
|
|
resp.setContentType("application/octet-stream;");
|
|
|
|
Date reportDate = clearTransation.getDate("report_date");
|
|
|
|
Date reportDate = clearTransation.getDate("report_date");
|
|
|
|
resp.addHeader("Content-Disposition",
|
|
|
|
resp.addHeader("Content-Disposition",
|
|
|
@ -1114,7 +1119,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
settle.getBigDecimal("settle_amount").setScale(2, BigDecimal.ROUND_DOWN).toPlainString() :
|
|
|
|
settle.getBigDecimal("settle_amount").setScale(2, BigDecimal.ROUND_DOWN).toPlainString() :
|
|
|
|
"-" + settle.getBigDecimal("settle_amount").setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
|
|
|
|
"-" + settle.getBigDecimal("settle_amount").setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
|
|
|
|
cell.setCellStyle(!"Credit".equals(settle.getString("transaction_type")) ? analysisStyle2 : null);
|
|
|
|
cell.setCellStyle(!"Credit".equals(settle.getString("transaction_type")) ? analysisStyle2 : null);
|
|
|
|
row.createCell(15, Cell.CELL_TYPE_STRING).setCellValue(settle.containsKey("order_detail")?settle.getString("order_detail"):settle.getString("remark"));
|
|
|
|
row.createCell(15, Cell.CELL_TYPE_STRING).setCellValue(settle.containsKey("order_detail") ? settle.getString("order_detail") : settle.getString("remark"));
|
|
|
|
String clientDevId = StringUtils.defaultString(settle.getString("dev_id"), "-");
|
|
|
|
String clientDevId = StringUtils.defaultString(settle.getString("dev_id"), "-");
|
|
|
|
JSONObject device = clientDeviceMapper.find(settle.getString("dev_id"));
|
|
|
|
JSONObject device = clientDeviceMapper.find(settle.getString("dev_id"));
|
|
|
|
String clientDevRemark = "-";
|
|
|
|
String clientDevRemark = "-";
|
|
|
@ -1174,7 +1179,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
Sheet sheet = wb.createSheet("Merchant_Settlement_Info_" + reportDate);
|
|
|
|
Sheet sheet = wb.createSheet("Merchant_Settlement_Info_" + reportDate);
|
|
|
|
int rowNum = 0;
|
|
|
|
int rowNum = 0;
|
|
|
|
Row row = sheet.createRow(rowNum);
|
|
|
|
Row row = sheet.createRow(rowNum);
|
|
|
|
String[] title = {"Client Moniker","Short Name","order Id", "Client Order Id", "Transaction Time", "Channel", "Gateway", "Exchange Rate", "Transaction Type", "Currency",
|
|
|
|
String[] title = {"Client Moniker", "Short Name", "order Id", "Client Order Id", "Transaction Time", "Channel", "Gateway", "Exchange Rate", "Transaction Type", "Currency",
|
|
|
|
"Input Amount", "Total Amount", "Clearing Amount(AUD)", "Sruchange Rate", "Surcharge(AUD)", "GST(AUD)", "Settle Amount(AUD)", "Remark", "Dev No", "Dev Remark"};
|
|
|
|
"Input Amount", "Total Amount", "Clearing Amount(AUD)", "Sruchange Rate", "Surcharge(AUD)", "GST(AUD)", "Settle Amount(AUD)", "Remark", "Dev No", "Dev Remark"};
|
|
|
|
String[] analysis = {"Total Credit(AUD)", "Total Debit(AUD)", "Gross Amount(AUD)", "Total GST(AUD)", "Total Charge(AUD)", "Net Amount(AUD)"};
|
|
|
|
String[] analysis = {"Total Credit(AUD)", "Total Debit(AUD)", "Gross Amount(AUD)", "Total GST(AUD)", "Total Charge(AUD)", "Net Amount(AUD)"};
|
|
|
|
for (int i = 0; i < title.length; i++) {
|
|
|
|
for (int i = 0; i < title.length; i++) {
|
|
|
@ -1380,7 +1385,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
attachList.add(attach1);
|
|
|
|
attachList.add(attach1);
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject attach2 = new JSONObject();
|
|
|
|
JSONObject attach2 = new JSONObject();
|
|
|
|
List<ABAFile> abaFileList = getAba(date, "CBA", clearLogs);
|
|
|
|
List<ABAFile> abaFileList = getAba(date, clearLogs);
|
|
|
|
String fileName2 = "Merchant_Settlement_Info_aba_" + DateFormatUtils.format(date, "yyyyMMdd");
|
|
|
|
String fileName2 = "Merchant_Settlement_Info_aba_" + DateFormatUtils.format(date, "yyyyMMdd");
|
|
|
|
if (abaFileList.size() > 1) {
|
|
|
|
if (abaFileList.size() > 1) {
|
|
|
|
fileName2 += ".zip";
|
|
|
|
fileName2 += ".zip";
|
|
|
@ -1429,7 +1434,12 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
settleMailRecord.put("notice_status", 0);
|
|
|
|
settleMailRecord.put("notice_status", 0);
|
|
|
|
logSettleMailMapper.save(settleMailRecord);
|
|
|
|
logSettleMailMapper.save(settleMailRecord);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sendTaskFinishMessages(ManagerRole.FINANCIAL_STAFF, "清算文件已发送清算方", "发送清算通知");
|
|
|
|
String detailDescription = clearLogs.stream()
|
|
|
|
|
|
|
|
.map(log -> String.format("[%s]%s", log.getString("clearing_id"),
|
|
|
|
|
|
|
|
ExtParamsUtils.getExtParamsValue(log.getString("plan_detail"),
|
|
|
|
|
|
|
|
detail -> StringUtils.defaultIfEmpty(detail.getString("remark"), detail.getString("plan_id")))))
|
|
|
|
|
|
|
|
.collect(Collectors.joining(","));
|
|
|
|
|
|
|
|
sendTaskFinishMessages(ManagerRole.FINANCIAL_STAFF, "清算文件已发送清算方:"+detailDescription, "发送清算通知");
|
|
|
|
if (autoMarkSent) {
|
|
|
|
if (autoMarkSent) {
|
|
|
|
if (!clearIds.isEmpty()) {
|
|
|
|
if (!clearIds.isEmpty()) {
|
|
|
|
clearingLogMapper.lockSettlementsById(clearLogs.stream().map(log -> log.getString("clearing_id")).collect(Collectors.toList()));
|
|
|
|
clearingLogMapper.lockSettlementsById(clearLogs.stream().map(log -> log.getString("clearing_id")).collect(Collectors.toList()));
|
|
|
@ -1523,7 +1533,8 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
throw new ForbiddenException("Settlement log has been sent and unable to edit");
|
|
|
|
throw new ForbiddenException("Settlement log has been sent and unable to edit");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ABAConfig config = ABATemplate.getConfig();
|
|
|
|
ABAConfig config = ABATemplate.getConfig();
|
|
|
|
String defaultBank = config.getRemainsTo();
|
|
|
|
BalanceGroup group = BalanceGroup.valueOf(log.getString("balance_group"));
|
|
|
|
|
|
|
|
String defaultBank = config.getRemainsTo(group);
|
|
|
|
clearingDetailMapper.updateAllBanks(defaultBank, clearingId);
|
|
|
|
clearingDetailMapper.updateAllBanks(defaultBank, clearingId);
|
|
|
|
List<JSONObject> details = clearingDetailMapper.listReportsOfSettlement(clearingId);
|
|
|
|
List<JSONObject> details = clearingDetailMapper.listReportsOfSettlement(clearingId);
|
|
|
|
details = mergeBatchSettleClients(details);
|
|
|
|
details = mergeBatchSettleClients(details);
|
|
|
@ -1547,6 +1558,9 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
if (base == null) {
|
|
|
|
if (base == null) {
|
|
|
|
throw new BadRequestException("Invalid bank code:" + bank);
|
|
|
|
throw new BadRequestException("Invalid bank code:" + bank);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (base.acceptBalanceGroup(group)) {
|
|
|
|
|
|
|
|
throw new BadRequestException("Balance group not match:" + group + ":" + bank);
|
|
|
|
|
|
|
|
}
|
|
|
|
BigDecimal bankAmount = bankDistribution.getBigDecimal(bank);
|
|
|
|
BigDecimal bankAmount = bankDistribution.getBigDecimal(bank);
|
|
|
|
for (JSONObject detail : details) {
|
|
|
|
for (JSONObject detail : details) {
|
|
|
|
String detailBank = detail.getString("settle_bank");
|
|
|
|
String detailBank = detail.getString("settle_bank");
|
|
|
@ -1639,6 +1653,15 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public JSONObject findSettleLog(int clearingId) {
|
|
|
|
|
|
|
|
JSONObject clearing = clearingLogMapper.findById(clearingId);
|
|
|
|
|
|
|
|
if (clearing == null) {
|
|
|
|
|
|
|
|
throw new NotFoundException("Settle record not found:" + clearingId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return clearing;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void releaseDistributedSurcharge(JSONObject clearingDetail) {
|
|
|
|
private void releaseDistributedSurcharge(JSONObject clearingDetail) {
|
|
|
|
int clientId = clearingDetail.getIntValue("client_id");
|
|
|
|
int clientId = clearingDetail.getIntValue("client_id");
|
|
|
|
BigDecimal distributedSurcharge = clearingDetail.getBigDecimal("distributed_surcharge");
|
|
|
|
BigDecimal distributedSurcharge = clearingDetail.getBigDecimal("distributed_surcharge");
|
|
|
|