|
|
|
@ -4,11 +4,8 @@ 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.TaskManualSettleMapper;
|
|
|
|
|
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;
|
|
|
|
@ -19,7 +16,9 @@ import au.com.royalpay.payment.manage.merchants.core.ClientManager;
|
|
|
|
|
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.ABAConfig;
|
|
|
|
|
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 +33,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 +47,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;
|
|
|
|
@ -67,18 +59,15 @@ import org.springframework.context.ApplicationEventPublisherAware;
|
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
|
import org.springframework.format.number.CurrencyStyleFormatter;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
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 +79,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;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -112,6 +98,8 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
|
@Resource
|
|
|
|
|
private ClearingDetailAnalysisMapper clearingDetailAnalysisMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private TaskManualSettleMapper taskManualSettleMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private ValidationLogMapper validationLogMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private ManagerMapper managerMapper;
|
|
|
|
@ -226,8 +214,25 @@ 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")));
|
|
|
|
|
}
|
|
|
|
|
int clearingId = log.getIntValue("clearing_id");
|
|
|
|
|
List<JSONObject> logDetails = clearingDetailMapper.listReportsOfSettlement(clearingId);
|
|
|
|
|
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("clearing_amount"))
|
|
|
|
|
.reduce(BigDecimal::add)
|
|
|
|
|
);
|
|
|
|
|
return data;
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
log.put("bank_statistics", bankStatistics);
|
|
|
|
|
log.put("editable", DateUtils.isSameDay(log.getDate("settle_date"), new Date()) && log.getBooleanValue("editable"));
|
|
|
|
|
log.put("channel_analysis", clearingDetailAnalysisMapper.analysisChannelReport(clearingId));
|
|
|
|
|
}
|
|
|
|
|
total.put("logs", logs);
|
|
|
|
|
total.put("details", details);
|
|
|
|
|
List<JSONObject> channels = clearingDetailAnalysisMapper.analysisChannelReportDaily(settleDate);
|
|
|
|
|
total.put("channel_analysis", channels);
|
|
|
|
@ -340,7 +345,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
|
String filename = "Merchant_Settlement_Info_" + dateString + RandomStringUtils.random(8, false, true) + ".xlsx";
|
|
|
|
|
zos.putNextEntry(new ZipEntry(filename));
|
|
|
|
|
List<JSONObject> details = clearingDetailMapper.listReportsOfSettlement(log.getIntValue("clearing_id"));
|
|
|
|
|
byte[] xlsx = generateSettleXlsxFile(dt, details);
|
|
|
|
|
byte[] xlsx = generateSettleXlsxFile(dt, details, null);
|
|
|
|
|
IOUtils.write(xlsx, zos);
|
|
|
|
|
}
|
|
|
|
|
zos.flush();
|
|
|
|
@ -348,7 +353,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<JSONObject> getXlsx(Date dt) throws IOException {
|
|
|
|
|
public List<JSONObject> getXlsx(Date dt, String bank) throws IOException {
|
|
|
|
|
List<JSONObject> logs = clearingLogMapper.findByDate(dt);
|
|
|
|
|
if (logs.isEmpty()) {
|
|
|
|
|
throw new NotFoundException();
|
|
|
|
@ -360,7 +365,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
|
String filename = "Merchant_Settlement_Info_" + DateFormatUtils.format(dt, "yyyyMMdd") + "_" + fileIndex + ".xlsx";
|
|
|
|
|
JSONObject file = new JSONObject();
|
|
|
|
|
file.put("name", filename);
|
|
|
|
|
file.put("byteArr", generateSettleXlsxFile(dt, clearingDetailMapper.listReportsOfSettlement(log.getIntValue("clearing_id"))));
|
|
|
|
|
file.put("byteArr", generateSettleXlsxFile(dt, clearingDetailMapper.listReportsOfSettlement(log.getIntValue("clearing_id")), bank));
|
|
|
|
|
result.add(file);
|
|
|
|
|
fileIndex++;
|
|
|
|
|
}
|
|
|
|
@ -369,7 +374,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
|
String filename = "Merchant_Settlement_Info_" + DateFormatUtils.format(dt, "yyyyMMdd") + ".xlsx";
|
|
|
|
|
JSONObject file = new JSONObject();
|
|
|
|
|
file.put("name", filename);
|
|
|
|
|
file.put("byteArr", generateSettleXlsxFile(dt, clearingDetailMapper.listReportsOfSettlement(log.getIntValue("clearing_id"))));
|
|
|
|
|
file.put("byteArr", generateSettleXlsxFile(dt, clearingDetailMapper.listReportsOfSettlement(log.getIntValue("clearing_id")), bank));
|
|
|
|
|
result.add(file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -378,37 +383,20 @@ 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
|
|
|
|
|
List<ABAFile> files = new ArrayList<>();
|
|
|
|
|
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);
|
|
|
|
|
files.addAll(generateSettleAbaFiles(dt, details, log.getDate("operate_time")));
|
|
|
|
|
}
|
|
|
|
|
} 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
return files.stream().filter(file -> bank.equals(file.bank())).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private byte[] generateSettleXlsxFile(Date dt, List<JSONObject> settlements) throws IOException {
|
|
|
|
|
private byte[] generateSettleXlsxFile(Date dt, List<JSONObject> settlements, String bank) throws IOException {
|
|
|
|
|
Workbook wb = new XSSFWorkbook();
|
|
|
|
|
Sheet sheet = wb.createSheet("Merchant_Settlement_Info_" + DateFormatUtils.format(dt, "yyyyMM"));
|
|
|
|
|
int rowNum = 0;
|
|
|
|
@ -416,6 +404,9 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
|
if (settle.getBigDecimal("clearing_amount").compareTo(BigDecimal.ZERO) == 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (bank != null && !Objects.equals(settle.getString("settle_bank"), bank)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
Row row = sheet.createRow(rowNum++);
|
|
|
|
|
row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue(settle.getString("bsb_no"));
|
|
|
|
|
row.createCell(1, Cell.CELL_TYPE_STRING).setCellValue(settle.getString("account_no"));
|
|
|
|
@ -434,34 +425,56 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
|
if (logs.isEmpty()) {
|
|
|
|
|
throw new NotFoundException();
|
|
|
|
|
}
|
|
|
|
|
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")));
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
OutputStream ous = resp.getOutputStream();
|
|
|
|
|
ZipOutputStream zos = new ZipOutputStream(ous);
|
|
|
|
|
int index = 1;
|
|
|
|
|
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";
|
|
|
|
|
Map<String, Integer> bankCounts = new HashMap<>();
|
|
|
|
|
for (ABAFile file : files) {
|
|
|
|
|
String filename = file.filename();
|
|
|
|
|
zos.putNextEntry(new ZipEntry(filename));
|
|
|
|
|
List<JSONObject> details = clearingDetailMapper.listReportsOfSettlement(log.getIntValue("clearing_id"));
|
|
|
|
|
byte[] file = generateSettleAbaFile(dt, details, index++);
|
|
|
|
|
IOUtils.write(file, zos);
|
|
|
|
|
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 byte[] generateSettleAbaFile(Date dt, List<JSONObject> settlements, int index) {
|
|
|
|
|
ABAFile aba = new ABAFile(dt, index);
|
|
|
|
|
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 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,10 +487,10 @@ 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 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);
|
|
|
|
@ -497,9 +510,9 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
|
String transactionTime = DateFormatUtils.format(transaction.getDate("transaction_time"), "dd/MM/yyyy h:mm:ss a", Locale.ENGLISH);
|
|
|
|
|
int multiply = "Credit".equals(transaction.getString("transaction_type")) ? 1 : -1;
|
|
|
|
|
BigDecimal transactionAmount = transaction.getBigDecimal("transaction_amount").multiply(BigDecimal.valueOf(multiply)).setScale(2,
|
|
|
|
|
BigDecimal.ROUND_HALF_DOWN);
|
|
|
|
|
RoundingMode.HALF_DOWN);
|
|
|
|
|
BigDecimal clearingAmount = transaction.getBigDecimal("clearing_amount").multiply(BigDecimal.valueOf(multiply)).setScale(2,
|
|
|
|
|
BigDecimal.ROUND_HALF_DOWN);
|
|
|
|
|
RoundingMode.HALF_DOWN);
|
|
|
|
|
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"};
|
|
|
|
@ -708,16 +721,17 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
|
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));
|
|
|
|
|
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;
|
|
|
|
@ -925,7 +939,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
|
String fileName1 = "Merchant_Settlement_Info_xlsx_" + DateFormatUtils.format(date, "yyyyMMdd");
|
|
|
|
|
List<JSONObject> attachList = new ArrayList<>();
|
|
|
|
|
JSONObject attach1 = new JSONObject();
|
|
|
|
|
List<JSONObject> xlsxFileList = getXlsx(date);
|
|
|
|
|
List<JSONObject> xlsxFileList = getXlsx(date, "CBA");
|
|
|
|
|
if (xlsxFileList.size() > 1) {
|
|
|
|
|
fileName1 += ".zip";
|
|
|
|
|
attach1.put("content", Base64.encodeBase64String(getZipByteArr(xlsxFileList)));
|
|
|
|
@ -937,15 +951,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);
|
|
|
|
@ -987,6 +1009,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sendTaskFinishMessages(ManagerRole.FINANCIAL_STAFF, "清算文件已发送清算方", "发送清算通知");
|
|
|
|
|
clearingLogMapper.lockSettlements(date);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
logger.error("生成excel字节数组发生错误");
|
|
|
|
|
} catch (URISyntaxException e) {
|
|
|
|
@ -1059,6 +1082,81 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
|
return report;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
public void distributeBank(Date date, int clearingId, JSONObject bankDistribution) {
|
|
|
|
|
if (!DateUtils.isSameDay(date, new Date())) {
|
|
|
|
|
throw new ForbiddenException("Only today's settlement file can be modified");
|
|
|
|
|
}
|
|
|
|
|
JSONObject log = clearingLogMapper.findById(clearingId);
|
|
|
|
|
if (log == null || !DateUtils.isSameDay(log.getDate("settle_date"), date)) {
|
|
|
|
|
throw new NotFoundException("Settlement log not found");
|
|
|
|
|
}
|
|
|
|
|
if (!log.getBooleanValue("editable")) {
|
|
|
|
|
throw new ForbiddenException("Settlement log has been sent and unable to edit");
|
|
|
|
|
}
|
|
|
|
|
ABAConfig config = ABATemplate.getConfig();
|
|
|
|
|
String defaultBank = config.getRemainsTo();
|
|
|
|
|
clearingDetailMapper.updateAllBanks(defaultBank, clearingId);
|
|
|
|
|
List<JSONObject> details = clearingDetailMapper.listReportsOfSettlement(clearingId);
|
|
|
|
|
details.sort((log1, log2) -> log2.getBigDecimal("clearing_amount").compareTo(log1.getBigDecimal("clearing_amount")));
|
|
|
|
|
bankDistribution.remove(defaultBank);
|
|
|
|
|
for (String bank : bankDistribution.keySet()) {
|
|
|
|
|
List<String> detailIds = new ArrayList<>();
|
|
|
|
|
ABAConfig.ABABase base = config.getBankBase(bank);
|
|
|
|
|
if (base == null) {
|
|
|
|
|
throw new BadRequestException("Invalid bank code:" + bank);
|
|
|
|
|
}
|
|
|
|
|
BigDecimal bankAmount = bankDistribution.getBigDecimal(bank);
|
|
|
|
|
for (JSONObject detail : details) {
|
|
|
|
|
String detailBank = detail.getString("settle_bank");
|
|
|
|
|
if (defaultBank.equals(detailBank)) {
|
|
|
|
|
BigDecimal amount = detail.getBigDecimal("clearing_amount");
|
|
|
|
|
if (amount.compareTo(BigDecimal.ZERO) > 0 && bankAmount.compareTo(amount) > 0) {
|
|
|
|
|
detailIds.add(detail.getString("clear_detail_id"));
|
|
|
|
|
bankAmount = bankAmount.subtract(amount);
|
|
|
|
|
detail.put("settle_bank", bank);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
clearingDetailMapper.updateBanks(bank, detailIds);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void lockClearingLog(Date date, int clearingId) {
|
|
|
|
|
if (!DateUtils.isSameDay(date, new Date())) {
|
|
|
|
|
throw new ForbiddenException("Only today's settlement file can be modified");
|
|
|
|
|
}
|
|
|
|
|
JSONObject log = clearingLogMapper.findById(clearingId);
|
|
|
|
|
if (log == null || !DateUtils.isSameDay(log.getDate("settle_date"), date)) {
|
|
|
|
|
throw new NotFoundException("Settlement log not found");
|
|
|
|
|
}
|
|
|
|
|
clearingLogMapper.setLogEditable(false, clearingId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
public void undoSettle(Date date, int clearingId) {
|
|
|
|
|
if (!DateUtils.isSameDay(date, new Date())) {
|
|
|
|
|
throw new ForbiddenException("Only today's settlement file can be modified");
|
|
|
|
|
}
|
|
|
|
|
JSONObject log = clearingLogMapper.findById(clearingId);
|
|
|
|
|
if (log == null || !DateUtils.isSameDay(log.getDate("settle_date"), date)) {
|
|
|
|
|
throw new NotFoundException("Settlement log not found");
|
|
|
|
|
}
|
|
|
|
|
if (!log.getBooleanValue("editable")) {
|
|
|
|
|
throw new ForbiddenException("Settlement log has been sent and unable to edit");
|
|
|
|
|
}
|
|
|
|
|
transactionMapper.deleteSettlementTransaction(clearingId);
|
|
|
|
|
transactionMapper.removeSettleRemark(clearingId);
|
|
|
|
|
clearingDetailAnalysisMapper.clearAnalysis(clearingId);
|
|
|
|
|
taskManualSettleMapper.rollbackExecutedTask(clearingId);
|
|
|
|
|
clearingDetailMapper.deleteSettleLogs(clearingId);
|
|
|
|
|
clearingLogMapper.deleteSettleLogs(clearingId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private byte[] getZipByteArr(List<JSONObject> fileByteArrWithName) throws IOException {
|
|
|
|
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
|
|
ZipOutputStream zos = new ZipOutputStream(bos);
|
|
|
|
|