|
|
|
@ -382,20 +382,24 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
|
ZipOutputStream zos = new ZipOutputStream(ous);
|
|
|
|
|
logger.info("using newest version test");
|
|
|
|
|
for (JSONObject log : logs) {
|
|
|
|
|
String dateString = DateFormatUtils.format(log.getDate("operate_time"), "yyyyMMddHHmmss");
|
|
|
|
|
List<JSONObject> details = clearingDetailMapper.listReportsOfSettlement(log.getIntValue("clearing_id"));
|
|
|
|
|
List<String> bankList = details.stream().map(detail -> detail.getString("settle_bank")).distinct().collect(Collectors.toList());
|
|
|
|
|
for (String bank : bankList) {
|
|
|
|
|
String filename = "Merchant_Settlement_Info_" + dateString + "_" + bank + ".xlsx";
|
|
|
|
|
zos.putNextEntry(new ZipEntry(filename));
|
|
|
|
|
byte[] xlsx = generateSettleXlsxFile(dt, details, bank);
|
|
|
|
|
IOUtils.write(xlsx, zos);
|
|
|
|
|
}
|
|
|
|
|
exportAllBankXlsFiles(zos, details, log.getDate("operate_time"));
|
|
|
|
|
}
|
|
|
|
|
zos.flush();
|
|
|
|
|
IOUtils.closeQuietly(zos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void exportAllBankXlsFiles(ZipOutputStream zos, List<JSONObject> details, Date operateTime) throws IOException {
|
|
|
|
|
String dateString = DateFormatUtils.format(operateTime, "yyyyMMddHHmmss");
|
|
|
|
|
List<String> bankList = details.stream().map(detail -> detail.getString("settle_bank")).distinct().collect(Collectors.toList());
|
|
|
|
|
for (String bank : bankList) {
|
|
|
|
|
String filename = "Merchant_Settlement_Info_" + dateString + "_" + bank + ".xlsx";
|
|
|
|
|
zos.putNextEntry(new ZipEntry(filename));
|
|
|
|
|
byte[] xlsx = generateSettleXlsxFile(operateTime, details, bank);
|
|
|
|
|
IOUtils.write(xlsx, zos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<JSONObject> getXlsx(Date dt, String bank) throws IOException {
|
|
|
|
|
List<JSONObject> logs = clearingLogMapper.findByDate(dt);
|
|
|
|
@ -441,26 +445,27 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
for (JSONObject settle : settlements) {
|
|
|
|
|
if (settle.getBigDecimal("clearing_amount").compareTo(BigDecimal.ZERO) == 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (bank != null && !Objects.equals(settle.getString("settle_bank"), bank)) {
|
|
|
|
|
continue;
|
|
|
|
|
try (Workbook wb = new XSSFWorkbook()) {
|
|
|
|
|
Sheet sheet = wb.createSheet("Merchant_Settlement_Info_" + DateFormatUtils.format(dt, "yyyyMMdd"));
|
|
|
|
|
int rowNum = 0;
|
|
|
|
|
for (JSONObject settle : settlements) {
|
|
|
|
|
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"));
|
|
|
|
|
row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(settle.getString("account_name"));
|
|
|
|
|
row.createCell(3, Cell.CELL_TYPE_STRING).setCellValue(settle.getBigDecimal("clearing_amount").setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
|
|
|
|
|
}
|
|
|
|
|
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"));
|
|
|
|
|
row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(settle.getString("account_name"));
|
|
|
|
|
row.createCell(3, Cell.CELL_TYPE_STRING).setCellValue(settle.getBigDecimal("clearing_amount").setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
|
|
|
|
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
|
|
wb.write(bos);
|
|
|
|
|
bos.flush();
|
|
|
|
|
return bos.toByteArray();
|
|
|
|
|
}
|
|
|
|
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
|
|
wb.write(bos);
|
|
|
|
|
bos.flush();
|
|
|
|
|
return bos.toByteArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -501,6 +506,32 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void getSettlementFilesForBatch(String batchId, HttpServletResponse resp) throws IOException {
|
|
|
|
|
int clearingId = Integer.parseInt(batchId);
|
|
|
|
|
JSONObject clearing = clearingLogMapper.findById(clearingId);
|
|
|
|
|
if (clearing == null) {
|
|
|
|
|
throw new NotFoundException("Clearing batch " + batchId + " not found");
|
|
|
|
|
}
|
|
|
|
|
List<JSONObject> details = clearingDetailMapper.listReportsOfSettlement(clearingId);
|
|
|
|
|
Date settleDate = clearing.getDate("settle_date");
|
|
|
|
|
Date opTime = clearing.getDate("operate_time");
|
|
|
|
|
String zipName = "Merchant_Settlement_Info_" + DateFormatUtils.format(opTime, "yyyyMMddHHmmss") + "_all.zip";
|
|
|
|
|
resp.setContentType("application/octet-stream;");
|
|
|
|
|
resp.addHeader("Content-Disposition", "attachment; filename=" + zipName);
|
|
|
|
|
OutputStream ous = resp.getOutputStream();
|
|
|
|
|
|
|
|
|
|
List<ABAFile> abaFiles = generateSettleAbaFiles(settleDate, details, opTime);
|
|
|
|
|
try (ZipOutputStream zos = new ZipOutputStream(ous)) {
|
|
|
|
|
for (ABAFile aba : abaFiles) {
|
|
|
|
|
zos.putNextEntry(new ZipEntry(aba.filename()));
|
|
|
|
|
IOUtils.write(aba.output(1), zos);
|
|
|
|
|
}
|
|
|
|
|
exportAllBankXlsFiles(zos, details, opTime);
|
|
|
|
|
zos.flush();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|