From 06f5ed53e6029dd94769df114740a6946c5ea139 Mon Sep 17 00:00:00 2001 From: yixian Date: Mon, 7 Jun 2021 14:59:51 +0800 Subject: [PATCH] customized settle aba file download --- .../manage/dev/web/TestController.java | 1 - .../clearing/core/CleanService.java | 2 ++ .../clearing/core/impl/CleanServiceImpl.java | 35 +++++++++++++++++-- .../clearing/web/SettlementDevController.java | 9 +++-- .../log/CustomizedSettleLogMapper.java | 14 ++++++++ .../payment/manage/valid/TestUri.java | 11 ++++++ 6 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 src/main/java/au/com/royalpay/payment/manage/mappers/log/CustomizedSettleLogMapper.java create mode 100644 src/test/java/au/com/royalpay/payment/manage/valid/TestUri.java diff --git a/src/main/java/au/com/royalpay/payment/manage/dev/web/TestController.java b/src/main/java/au/com/royalpay/payment/manage/dev/web/TestController.java index 448dbf857..d58a4ebff 100644 --- a/src/main/java/au/com/royalpay/payment/manage/dev/web/TestController.java +++ b/src/main/java/au/com/royalpay/payment/manage/dev/web/TestController.java @@ -45,7 +45,6 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateUtils; import org.apache.http.util.TextUtils; -import org.apache.ibatis.annotations.Mapper; import org.joda.time.DateTime; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/CleanService.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/CleanService.java index b4d478137..0581a03e7 100644 --- a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/CleanService.java +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/CleanService.java @@ -56,6 +56,8 @@ public interface CleanService { void settlementAba(Date date, HttpServletResponse response) throws IOException; + void getCustomizedSettleABA(int logId, HttpServletResponse response); + void getSettlementFilesForBatch(String batchId, HttpServletResponse resp) throws IOException; List getCleanLogs(ClearingLogQuery query, JSONObject manager); diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/CleanServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/CleanServiceImpl.java index 4d7667f47..478b3ef5d 100644 --- a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/CleanServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/CleanServiceImpl.java @@ -104,7 +104,7 @@ import static au.com.royalpay.payment.manage.permission.utils.OrgCheckUtils.chec */ @Service public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider, ApplicationEventPublisherAware { - private Logger logger = LoggerFactory.getLogger(getClass()); + private final Logger logger = LoggerFactory.getLogger(getClass()); @Resource private SettlementSupport settlementSupport; @Resource @@ -114,6 +114,8 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider @Resource private ClearingDetailMapper clearingDetailMapper; @Resource + private CustomizedSettleLogMapper customizedSettleLogMapper; + @Resource private ClearingDetailAnalysisMapper clearingDetailAnalysisMapper; @Resource private TaskManualSettleMapper taskManualSettleMapper; @@ -665,6 +667,33 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider } } + @Override + public void getCustomizedSettleABA(int logId, HttpServletResponse response) { + JSONObject log = customizedSettleLogMapper.find(logId); + if (log == null) { + throw new NotFoundException("Settle log not found"); + } + String bank = log.getString("settle_bank"); + BalanceGroup group = BalanceGroup.valueOf(log.getString("balance_group")); + JSONObject settle = new JSONObject(); + settle.put("settle_bank", bank); + settle.put("clearing_amount", log.getBigDecimal("amount")); + settle.put("client_id", log.getIntValue("client_id")); + settle.put("bsb_no", log.getString("bsb_no")); + settle.put("account_no", log.getString("account_no")); + settle.put("account_name", log.getString("account_name")); + settle.put("client_moniker", log.getString("client_moniker")); + ABAFile file = generateSettleAbaFile(bank, group, new Date(), Collections.singletonList(settle)); + response.setContentType("application/octet-stream;"); + response.addHeader("Content-Disposition", "attachment; filename=" + file.filename()); + try (OutputStream ous = response.getOutputStream()) { + ous.write(file.output(1)); + ous.flush(); + } catch (IOException e) { + throw new ServerErrorException("Output failed", e); + } + } + @Override public void getSettlementFilesForBatch(String batchId, HttpServletResponse resp) throws IOException { int clearingId = Integer.parseInt(batchId); @@ -1667,7 +1696,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider taskManualSettleMapper.rollbackExecutedTask(clearingId); clearingDetailMapper.deleteSettleLogs(clearingId); clearingLogMapper.deleteSettleLogs(clearingId); - }finally { + } finally { locker.unlock("settle_task"); } } @@ -1731,7 +1760,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider public TransactionStatus getTransactionStatus(String transactionId) { TransactionStatus transactionStatus = transactionMapper.getTransactionStatusById(transactionId); if (transactionStatus == null) { - throw new ParamInvalidException("date","The transaction was not found"); + throw new ParamInvalidException("date", "The transaction was not found"); } return transactionStatus.toSet(); } diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/SettlementDevController.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/SettlementDevController.java index a0124f00c..f2ca28d44 100644 --- a/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/SettlementDevController.java +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/SettlementDevController.java @@ -30,8 +30,8 @@ import java.util.List; @RestController @ManagerMapping(value = "/sys/settlement", role = {ManagerRole.ADMIN, ManagerRole.OPERATOR, ManagerRole.FINANCIAL_STAFF}, method = RequestMethod.GET) public class SettlementDevController { - private DateFormat monthFormat = new SimpleDateFormat("yyyyMM"); - private DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + private final DateFormat monthFormat = new SimpleDateFormat("yyyyMM"); + private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); @Resource private CleanService cleanService; @@ -170,6 +170,11 @@ public class SettlementDevController { } } + @GetMapping("/customized_settle/{logId}/aba_file") + public void getCustomizedSettleABAFile(@PathVariable int logId,HttpServletResponse response){ + cleanService.getCustomizedSettleABA(logId, response); + } + @GetMapping("/settle_batches/{batchId}/settle_files") public void getSettlementFilesForBatch(@PathVariable String batchId, HttpServletResponse resp) throws IOException { cleanService.getSettlementFilesForBatch(batchId, resp); diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/log/CustomizedSettleLogMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/log/CustomizedSettleLogMapper.java new file mode 100644 index 000000000..0d34da48e --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/log/CustomizedSettleLogMapper.java @@ -0,0 +1,14 @@ +package au.com.royalpay.payment.manage.mappers.log; + +import com.alibaba.fastjson.JSONObject; +import com.yixsoft.support.mybatis.autosql.annotations.AutoMapper; +import com.yixsoft.support.mybatis.autosql.annotations.AutoSql; +import com.yixsoft.support.mybatis.autosql.annotations.SqlType; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator; + +@AutoMapper(tablename = "log_settle_customized", pkName = "log_id", keyGenerator = Jdbc3KeyGenerator.class) +public interface CustomizedSettleLogMapper { + @AutoSql(SqlType.SELECT) + JSONObject find(@Param("log_id") int logId); +} diff --git a/src/test/java/au/com/royalpay/payment/manage/valid/TestUri.java b/src/test/java/au/com/royalpay/payment/manage/valid/TestUri.java new file mode 100644 index 000000000..a85243729 --- /dev/null +++ b/src/test/java/au/com/royalpay/payment/manage/valid/TestUri.java @@ -0,0 +1,11 @@ +package au.com.royalpay.payment.manage.valid; + +import org.junit.jupiter.api.Test; +import org.springframework.web.util.UriComponentsBuilder; + +public class TestUri { + @Test + void test(){ + UriComponentsBuilder.fromHttpUrl("https://shop-1587029219413.rpaygroup.com/#/payment/result?url=https://shop-au.rpaygroup.com/geekforbest/v1/shop/payment/orders/9296a2ea-4f8f-4701-b9ae-e49718387417/transactions/d1878f49-2039-45ce-9458-667e6272d511"); + } +}