From 53797f86541169b1954e393bec68e2254d1b1cd8 Mon Sep 17 00:00:00 2001 From: yixian Date: Tue, 14 Jul 2020 16:29:04 +1000 Subject: [PATCH 1/4] settle tasks api --- .../analysis/beans/ato/ATOBulkData.java | 2 -- .../clearing/core/PriorityListManager.java | 2 +- .../core/impl/PriorityListManagerImpl.java | 8 ++++--- .../clearing/web/SettleTasksController.java | 4 ++-- src/main/ui/static/analysis/settle_tasks.js | 23 ++++++++++++++----- .../manage/process/ato/ExportATOReport.java | 6 ++--- 6 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/beans/ato/ATOBulkData.java b/src/main/java/au/com/royalpay/payment/manage/analysis/beans/ato/ATOBulkData.java index c36d06253..13428a179 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/beans/ato/ATOBulkData.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/beans/ato/ATOBulkData.java @@ -1,7 +1,5 @@ package au.com.royalpay.payment.manage.analysis.beans.ato; -import org.apache.commons.lang3.StringUtils; - import java.util.ArrayList; import java.util.Date; import java.util.List; diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/PriorityListManager.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/PriorityListManager.java index f9dac7ecf..513362ae1 100644 --- a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/PriorityListManager.java +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/PriorityListManager.java @@ -8,7 +8,7 @@ import java.util.List; public interface PriorityListManager { List listPriorityMerchants(); - void setMerchantPriority(String clientMoniker, JSONObject manager); + JSONObject setMerchantPriority(String clientMoniker, JSONObject manager); void removePriorityMerchant(String clientMoniker, JSONObject manager); diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/PriorityListManagerImpl.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/PriorityListManagerImpl.java index 1f682d8a1..5745f2e08 100644 --- a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/PriorityListManagerImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/PriorityListManagerImpl.java @@ -3,6 +3,7 @@ package au.com.royalpay.payment.manage.management.clearing.core.impl; import au.com.royalpay.payment.manage.management.clearing.beans.PriorityModifyLog; import au.com.royalpay.payment.manage.management.clearing.core.PriorityListManager; import au.com.royalpay.payment.manage.mappers.system.SysSettlePlanMapper; +import au.com.royalpay.payment.tools.exceptions.BadRequestException; import au.com.royalpay.payment.tools.exceptions.NotFoundException; import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider; import au.com.royalpay.payment.tools.utils.id.IdUtil; @@ -47,8 +48,8 @@ public class PriorityListManagerImpl implements PriorityListManager { } @Override - public void setMerchantPriority(String clientMoniker, JSONObject manager) { - JSONObject client = mchInfoProvider.getClientInfoByMoniker(clientMoniker); + public JSONObject setMerchantPriority(String clientMoniker, JSONObject manager) { + JSONObject client = MonikerStringUtils.getSimplifiedClientsInfo(mchInfoProvider, clientMoniker); if (client == null) { throw new NotFoundException("Client " + clientMoniker + " not found"); } @@ -57,7 +58,7 @@ public class PriorityListManagerImpl implements PriorityListManager { List monikerList = MonikerStringUtils.splitStringArray(clientMonikers).collect(Collectors.toList()); if (monikerList.stream().anyMatch(moniker -> moniker.equalsIgnoreCase(clientMoniker))) { logger.debug("{} exists,ignore", clientMoniker); - return; + throw new BadRequestException("Client exists"); } monikerList.add(clientMoniker.toUpperCase()); String joinedMonikers = String.join(",", monikerList); @@ -74,6 +75,7 @@ public class PriorityListManagerImpl implements PriorityListManager { mongoTemplate.insert(log); } catch (Exception ignore) { } + return client; } @Override diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/SettleTasksController.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/SettleTasksController.java index f015e4000..8b0d6e390 100644 --- a/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/SettleTasksController.java +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/SettleTasksController.java @@ -49,8 +49,8 @@ public class SettleTasksController { } @PutMapping("/priority_merchants/{clientMoniker}") - public void setMerchantPriority(@PathVariable String clientMoniker, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { - priorityListManager.setMerchantPriority(clientMoniker, manager); + public JSONObject setMerchantPriority(@PathVariable String clientMoniker, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { + return priorityListManager.setMerchantPriority(clientMoniker, manager); } @DeleteMapping("/priority_merchants/{clientMoniker}") diff --git a/src/main/ui/static/analysis/settle_tasks.js b/src/main/ui/static/analysis/settle_tasks.js index c43e87b01..ff8385f16 100644 --- a/src/main/ui/static/analysis/settle_tasks.js +++ b/src/main/ui/static/analysis/settle_tasks.js @@ -152,7 +152,7 @@ define(['angular', 'uiBootstrap', 'uiRouter'], function (angular) { tasks.push(submitTask) } $http.post('/sys/settle_tasks', tasks).then(function (resp) { - commonDialog.alert({type: 'success', title: 'Success', content: resp.data.message}) + commonDialog.alert({type: 'success', title: 'Success', content: 'Task submitted'}) ctrl.update_task = $interval(function () { $scope.checkProgressStatus() }, 5000); @@ -198,18 +198,29 @@ define(['angular', 'uiBootstrap', 'uiRouter'], function (angular) { if (!$scope.input.moniker) { return; } - $http.put('/sys/settle_tasks/priority_merchants/' + $scope.input.moniker).then(function () { + $http.put('/sys/settle_tasks/priority_merchants/' + $scope.input.moniker).then(function (res) { + commonDialog.alert({ + type: 'success', + title: 'Client Added', + content: res.data.client_moniker + ' added into priority list' + }); $scope.loadPriorities(); }, function (res) { commonDialog.alert({type: 'error', title: 'Error', content: res.data.message}) }) }; $scope.dropPriorityClient = function (client) { - $http['delete']('/sys/settle_tasks/priority_merchants/' + client.client_moniker).then(function () { - $scope.loadPriorities(); - }, function (res) { - commonDialog.alert({type: 'error', title: 'Error', content: res.data.message}) + commonDialog.confirm({ + title: 'Disable client priority', + content: 'Disabling ' + client.client_moniker + ' in priority list, confirm?' + }).then(function () { + $http['delete']('/sys/settle_tasks/priority_merchants/' + client.client_moniker).then(function () { + $scope.loadPriorities(); + }, function (res) { + commonDialog.alert({type: 'error', title: 'Error', content: res.data.message}) + }) }) + }; $scope.listHistory = function () { $uibModal.open({ diff --git a/src/test/java/au/com/royalpay/payment/manage/process/ato/ExportATOReport.java b/src/test/java/au/com/royalpay/payment/manage/process/ato/ExportATOReport.java index c44733b06..2ef7e38c0 100644 --- a/src/test/java/au/com/royalpay/payment/manage/process/ato/ExportATOReport.java +++ b/src/test/java/au/com/royalpay/payment/manage/process/ato/ExportATOReport.java @@ -19,7 +19,7 @@ import java.nio.charset.StandardCharsets; * Create by yixian at 2018-08-31 14:40 */ @SpringBootTest -@ActiveProfiles({"proxy", "wechat","alipay","bestpay","rpay","jd","yeepay"}) +@ActiveProfiles({"proxy", "wechat", "alipay", "common", "rppaysvc", "rpay"}) @TestPropertySource(properties = {"spring.datasource.username=root", "spring.datasource.password=ZOIBhellor0yalpay"}) @RunWith(SpringRunner.class) public class ExportATOReport { @@ -28,7 +28,7 @@ public class ExportATOReport { @Test public void export() throws IOException { - String content = atoReportService.exportBTTPSFile(DateTime.parse("2018-07-01").toDate(), DateTime.parse("2019-06-30").toDate()); - FileUtils.write(new File("C:\\Users\\davep\\Documents\\royalpay2018070120190630.bttps"), content, StandardCharsets.US_ASCII); + String content = atoReportService.exportBTTPSFile(DateTime.parse("2019-07-01").toDate(), DateTime.parse("2020-06-30").toDate()); + FileUtils.write(new File("/Users/yixian/documents/royalpay2019070120200630.bttps"), content, StandardCharsets.US_ASCII); } } From afb05d299d59b7a061bc26a65e9160ab41446d89 Mon Sep 17 00:00:00 2001 From: dulingling Date: Tue, 14 Jul 2020 20:27:50 +0800 Subject: [PATCH 2/4] =?UTF-8?q?upd:=E5=95=86=E6=88=B7=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=B7=BB=E5=8A=A0=E6=A0=87=E6=B3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../ui/static/application/templates/clientAuthentication.html | 2 +- .../static/payment/kyc/templates/bd_help_client_detail.html | 2 +- .../payment/kyc/templates/compliance_audit_client_detail.html | 2 +- src/main/ui/static/payment/partner/templates/add_partner.html | 2 +- .../payment/partner/templates/add_sub_partner_dialog.html | 2 +- .../payment/partner/templates/client_partner_detail.html | 4 ++-- .../static/payment/partner/templates/client_partner_edit.html | 2 +- .../ui/static/payment/partner/templates/partner_detail.html | 2 +- .../ui/static/payment/partner/templates/partner_edit.html | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 3bf8a85fd..b2b5f7715 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ 4.0.0 manage - 2.3.38 + 2.3.39 UTF-8 2.4.0 diff --git a/src/main/ui/static/application/templates/clientAuthentication.html b/src/main/ui/static/application/templates/clientAuthentication.html index 641f22bea..04c028239 100644 --- a/src/main/ui/static/application/templates/clientAuthentication.html +++ b/src/main/ui/static/application/templates/clientAuthentication.html @@ -306,7 +306,7 @@
-
Address Information
+
Address Information(Registered address on your business license.)
diff --git a/src/main/ui/static/payment/kyc/templates/bd_help_client_detail.html b/src/main/ui/static/payment/kyc/templates/bd_help_client_detail.html index fd27917f5..498f552a5 100644 --- a/src/main/ui/static/payment/kyc/templates/bd_help_client_detail.html +++ b/src/main/ui/static/payment/kyc/templates/bd_help_client_detail.html @@ -244,7 +244,7 @@
-
Address Information
+
Address Information(Registered address on your business license.)
diff --git a/src/main/ui/static/payment/kyc/templates/compliance_audit_client_detail.html b/src/main/ui/static/payment/kyc/templates/compliance_audit_client_detail.html index bd4341b6e..d869efd30 100644 --- a/src/main/ui/static/payment/kyc/templates/compliance_audit_client_detail.html +++ b/src/main/ui/static/payment/kyc/templates/compliance_audit_client_detail.html @@ -177,7 +177,7 @@
-
Address Information
+
Address Information(Registered address on your business license.)
diff --git a/src/main/ui/static/payment/partner/templates/add_partner.html b/src/main/ui/static/payment/partner/templates/add_partner.html index 48de51dcf..00c19aeae 100644 --- a/src/main/ui/static/payment/partner/templates/add_partner.html +++ b/src/main/ui/static/payment/partner/templates/add_partner.html @@ -993,7 +993,7 @@
-
Address Information
+
Address Information(Registered address on your business license.)
-
Address Information
+
Address Information(Registered address on your business license.)
diff --git a/src/main/ui/static/payment/partner/templates/client_partner_detail.html b/src/main/ui/static/payment/partner/templates/client_partner_detail.html index e13c7127f..4ee9c4cbe 100644 --- a/src/main/ui/static/payment/partner/templates/client_partner_detail.html +++ b/src/main/ui/static/payment/partner/templates/client_partner_detail.html @@ -506,7 +506,7 @@
-
Address Information
+
Address Information(Registered address on your business license.)
@@ -1157,7 +1157,7 @@
-
Address Information
+
Address Information(Registered address on your business license.)
diff --git a/src/main/ui/static/payment/partner/templates/client_partner_edit.html b/src/main/ui/static/payment/partner/templates/client_partner_edit.html index 40b9b1cbf..504ef2ad2 100644 --- a/src/main/ui/static/payment/partner/templates/client_partner_edit.html +++ b/src/main/ui/static/payment/partner/templates/client_partner_edit.html @@ -618,7 +618,7 @@
-
Address Information
+
Address Information(Registered address on your business license.)
diff --git a/src/main/ui/static/payment/partner/templates/partner_detail.html b/src/main/ui/static/payment/partner/templates/partner_detail.html index ec6410f06..e12e54143 100644 --- a/src/main/ui/static/payment/partner/templates/partner_detail.html +++ b/src/main/ui/static/payment/partner/templates/partner_detail.html @@ -1082,7 +1082,7 @@
-
Address Information
+
Address Information(Registered address on your business license.)
diff --git a/src/main/ui/static/payment/partner/templates/partner_edit.html b/src/main/ui/static/payment/partner/templates/partner_edit.html index 10b1aaf8d..dd4cd207e 100644 --- a/src/main/ui/static/payment/partner/templates/partner_edit.html +++ b/src/main/ui/static/payment/partner/templates/partner_edit.html @@ -901,7 +901,7 @@
-
Address Information
+
Address Information(Registered address on your business license.)
From 2504c2c91e378e811cf4ebd8b053d03aae12e889 Mon Sep 17 00:00:00 2001 From: dulingling Date: Tue, 14 Jul 2020 20:30:01 +0800 Subject: [PATCH 3/4] =?UTF-8?q?upd:=E5=8D=87=E7=BA=A7=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b2b5f7715..4b2b5895f 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ 4.0.0 manage - 2.3.39 + 2.3.40 UTF-8 2.4.0 From cd858be89a6a9becd26b8bef862d35d010f8c77c Mon Sep 17 00:00:00 2001 From: yixian Date: Wed, 15 Jul 2020 01:21:15 +1000 Subject: [PATCH 4/4] ato report task --- .../analysis/core/ATOReportService.java | 10 + .../core/impls/ATOReportServiceImpl.java | 182 +++++++++++++++++- .../manage/dev/web/TestController.java | 25 +-- 3 files changed, 205 insertions(+), 12 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/ATOReportService.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/ATOReportService.java index b1b018dcd..bfa668ac7 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/core/ATOReportService.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/ATOReportService.java @@ -1,5 +1,9 @@ package au.com.royalpay.payment.manage.analysis.core; +import com.alibaba.fastjson.JSONObject; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.util.Date; /** @@ -8,4 +12,10 @@ import java.util.Date; public interface ATOReportService { String exportBTTPSFile(Date from, Date to); + + void startExportTask(Date from, Date to); + + JSONObject taskStatus(); + + void downloadFile(HttpServletResponse resp) throws IOException; } diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/ATOReportServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/ATOReportServiceImpl.java index ecc98a8cd..2ab4bf43f 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/ATOReportServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/ATOReportServiceImpl.java @@ -4,26 +4,40 @@ import au.com.royalpay.payment.manage.analysis.beans.ato.*; import au.com.royalpay.payment.manage.analysis.core.ATOReportService; import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper; import au.com.royalpay.payment.manage.mappers.system.ClientMapper; +import au.com.royalpay.payment.tools.connections.attachment.core.AttachmentClient; +import au.com.royalpay.payment.tools.env.PlatformEnvironment; +import au.com.royalpay.payment.tools.exceptions.BadRequestException; import au.com.royalpay.payment.tools.exceptions.ServerErrorException; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import org.apache.commons.codec.Charsets; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateFormatUtils; import org.joda.time.DateTime; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.http.ContentDisposition; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.OutputStream; +import java.nio.charset.StandardCharsets; +import java.time.Duration; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** * Create by yixian at 2018-08-31 1:23 @@ -38,6 +52,16 @@ public class ATOReportServiceImpl implements ATOReportService { @Value("classpath:data/category/billbuddyindustry.json") private org.springframework.core.io.Resource industryResource; private Map industryMap; + private final StringRedisTemplate redisTemplate; + private final String prefix; + private final AttachmentClient client; + private Progress progress; + + public ATOReportServiceImpl(StringRedisTemplate redisTemplate, @Value("${app.redis.prefix}") String prefix, AttachmentClient client) { + this.redisTemplate = redisTemplate; + this.prefix = prefix; + this.client = client; + } @PostConstruct public void loadIndustryConfiguration() throws IOException { @@ -102,14 +126,90 @@ public class ATOReportServiceImpl implements ATOReportService { return data.outputBTTPS(); } + private String progressKey() { + return prefix + ":tasks:exporting-bttps"; + } + + private String reportFileKey() { + return prefix + ":caching:exporting-bttps-file"; + } + + @Override + public void startExportTask(Date from, Date to) { + if (progress != null && !progress.isFinished()) { + throw new BadRequestException("In Progress"); + } + if (redisTemplate.boundValueOps(progressKey()).get() != null) { + throw new BadRequestException("In Progress"); + } + new Thread(() -> { + progress = new Progress(); + try { + String content = exportBTTPSFile(from, to); + byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8); + progress.setStatus("Uploading,filesize:" + contentBytes.length); + String filename = "royalpay_ato_report_" + new DateTime(from).toString("yyyyMMdd") + "_to_" + new DateTime(to).toString("yyyyMMdd") + ".bttps"; + JSONObject file = client.uploadFile(new ByteArrayInputStream(contentBytes), filename, true); + String fileid = file.getString("fileid"); + logger.info("uploaded ATO report to {}", fileid); + progress.setFileid(fileid); + redisTemplate.boundValueOps(reportFileKey()).set(file.toJSONString(), Duration.ofDays(1)); + } catch (Exception e) { + progress.setStatus(e.getMessage()); + synchronizeProgress(); + } finally { + progress.setFinished(); + synchronizeProgress(); + } + }).start(); + } + + @Override + public JSONObject taskStatus() { + String status = redisTemplate.boundValueOps(progressKey()).get(); + if (status != null) { + JSONObject std = JSON.parseObject(status); + std.remove("fileid"); + return std; + } else { + String file = redisTemplate.boundValueOps(reportFileKey()).get(); + JSONObject std = new JSONObject(); + if (file != null) { + std.put("success", true); + std.put("finished", true); + } + return std; + } + } + + @Override + public void downloadFile(HttpServletResponse resp) throws IOException { + String file = redisTemplate.boundValueOps(reportFileKey()).get(); + if (file != null) { + JSONObject fileInfo = JSON.parseObject(file); + String filename = StringUtils.substringAfterLast(fileInfo.getString("url"), "/"); + resp.setHeader(HttpHeaders.CONTENT_DISPOSITION, ContentDisposition.builder("attachment").filename(filename).build().toString()); + resp.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); + try (OutputStream out = resp.getOutputStream()) { + client.getFileContent(fileInfo.getString("fileid"), out); + out.flush(); + } + } else { + throw new BadRequestException("No file available"); + } + } + private void loadMonthTransactions(ReportingPartyData reportingParty, DateTime startOfMon, DateTime endOfMon) { List clients = clientMapper.listClientsWithTransactionsSettled(startOfMon.toDate(), endOfMon.toDate()); + if (progress != null) { + progress.setMonth(startOfMon, clients); + } clients.parallelStream().forEach(clientId -> loadClientMonthTransactions(reportingParty, clientId, startOfMon, endOfMon)); } private void loadClientMonthTransactions(ReportingPartyData reportingParty, Integer clientId, DateTime startOfMon, DateTime endOfMon) { BusinessData biz = reportingParty.findBusiness(clientId); - logger.debug("Exporting date range for client[{}]:{} ~ {}",clientId,startOfMon.toString("yyyy-MM-dd"), endOfMon.toString("yyyy-MM-dd")); + logger.debug("Exporting date range for client[{}]:{} ~ {}", clientId, startOfMon.toString("yyyy-MM-dd"), endOfMon.toString("yyyy-MM-dd")); if (biz == null) { JSONObject cli = clientMapper.findClientIgnoreInvalid(clientId); AddressInfo addr = new AddressInfo(cli.getString("address"), cli.getString("suburb"), cli.getString("state"), cli.getString("postcode"), cli.getString("country")); @@ -128,5 +228,85 @@ public class ATOReportServiceImpl implements ATOReportService { for (JSONObject analysis : analysisList) { biz.addTransaction(new TransactionSummaryData(analysis, startOfMon, endOfMon)); } + if (progress != null) { + progress.markClientFinished(clientId); + } + } + + private void synchronizeProgress() { + redisTemplate.boundValueOps(progressKey()).set(JSON.toJSONString(progress), Duration.ofMinutes(5)); + } + + public static class Progress { + private String currentMonth; + private Map clientsStatus; + private final String server; + private String fileid; + private boolean finished; + + private String status; + + public Progress() { + status = "Init"; + server = PlatformEnvironment.getEnv().appName(); + } + + public void setMonth(DateTime start, List clients) { + currentMonth = start.toString("yyyy-MM"); + clientsStatus = clients.stream().collect(ConcurrentHashMap::new, (map, cid) -> map.put(cid, false), Map::putAll); + } + + public String getFileid() { + return fileid; + } + + public Progress setFileid(String fileid) { + this.fileid = fileid; + return this; + } + + public boolean isFinished() { + return finished; + } + + public boolean isSuccess() { + return fileid != null; + } + + public void setFinished() { + this.finished = true; + } + + public String getStatus() { + return status; + } + + public int getProgress() { + if (clientsStatus == null || clientsStatus.isEmpty()) { + return 0; + } + int total = clientsStatus.size(); + long finishedCount = clientsStatus.values().stream().filter(success -> success).count(); + return (int) finishedCount * 100 / total; + } + + public String getCurrentMonth() { + return currentMonth; + } + + public String getServer() { + return server; + } + + public Progress setStatus(String status) { + this.status = status; + return this; + } + + public void markClientFinished(Integer clientId) { + if (clientsStatus != null) { + clientsStatus.put(clientId, true); + } + } } } 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 738a378f5..4e871d2e2 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 @@ -55,7 +55,6 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.ui.Model; import org.springframework.util.Assert; -import org.springframework.util.MimeTypeUtils; import org.springframework.validation.Errors; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; @@ -67,10 +66,8 @@ import javax.validation.Valid; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.io.OutputStream; import java.math.BigDecimal; import java.net.URISyntaxException; -import java.nio.charset.StandardCharsets; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; @@ -504,17 +501,23 @@ public class TestController { } - @ManagerMapping(value = "/reports/ato_reports/royalpay_ato_report_{year}.bttps", role = ManagerRole.DEVELOPER, method = RequestMethod.GET) + @ManagerMapping(value = "/reports/ato_reports/royalpay_ato_report_{year}.bttps", role = ManagerRole.DEVELOPER, method = RequestMethod.POST) @ReadOnlyConnection - public void downloadATOReport(@PathVariable String year, HttpServletResponse resp) throws IOException { + public JSONObject exportATOReport(@PathVariable String year) { DateTime from = DateTime.parse(year + "-07-01"); DateTime to = from.plusYears(1).plusDays(-1); - String atoReport = atoReportService.exportBTTPSFile(from.toDate(), to.toDate()); - resp.setContentType(MimeTypeUtils.APPLICATION_OCTET_STREAM_VALUE); - try (OutputStream out = resp.getOutputStream()) { - out.write(atoReport.getBytes(StandardCharsets.UTF_8)); - out.flush(); - } + atoReportService.startExportTask(from.toDate(), to.toDate()); + return atoReportService.taskStatus(); + } + + @ManagerMapping(value = "/reports/ato_reports/royalpay_ato_report", role = ManagerRole.DEVELOPER, method = RequestMethod.GET) + public JSONObject exportATOStatus() { + return atoReportService.taskStatus(); + } + + @ManagerMapping(value = "/reports/ato_reports/royalpay_ato_report.bttps", role = ManagerRole.DEVELOPER, method = RequestMethod.GET) + public void downloadReport(HttpServletResponse response) throws IOException { + atoReportService.downloadFile(response); } @ManagerMapping(value = "/custom_declare_check/{reportId}/detail", method = RequestMethod.GET, role = ManagerRole.DEVELOPER)