feat(settle report): download settle report excel from ui

master
yixian 5 years ago
parent 3e0a5f8690
commit 5af9537a6c

@ -3,6 +3,7 @@ package au.com.royalpay.payment.manage.management.clearing.core;
import au.com.royalpay.payment.manage.support.abafile.ABAFile; import au.com.royalpay.payment.manage.support.abafile.ABAFile;
import au.com.royalpay.payment.manage.tradelog.beans.ClearingLogQuery; import au.com.royalpay.payment.manage.tradelog.beans.ClearingLogQuery;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.InputStreamResource; import org.springframework.core.io.InputStreamResource;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -96,5 +97,5 @@ public interface CleanService {
void undoSettle(Date date, int clearingId); void undoSettle(Date date, int clearingId);
InputStreamResource downloadBatchSettleReportXlsx(int batchId); ByteArrayResource downloadBatchSettleReportXlsx(int batchId);
} }

@ -1363,7 +1363,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
} }
@Override @Override
public InputStreamResource downloadBatchSettleReportXlsx(int batchId) { public ByteArrayResource downloadBatchSettleReportXlsx(int batchId) {
List<JSONObject> mchList = clearingDetailMapper.batchReport(batchId); List<JSONObject> mchList = clearingDetailMapper.batchReport(batchId);
if (mchList.isEmpty()) { if (mchList.isEmpty()) {
throw new NotFoundException("No batch found"); throw new NotFoundException("No batch found");
@ -1385,7 +1385,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
try (ByteArrayOutputStream bout = new ByteArrayOutputStream()) { try (ByteArrayOutputStream bout = new ByteArrayOutputStream()) {
builder.build(bout); builder.build(bout);
bout.flush(); bout.flush();
return new InputStreamResource(new ByteArrayInputStream(bout.toByteArray())) { return new ByteArrayResource(bout.toByteArray()) {
@Override @Override
public String getFilename() { public String getFilename() {
return "settle_report_" + DateFormatUtils.format(mchList.get(0).getDate("report_date"), "yyyyMMdd") + "_" + batchId + ".xlsx"; return "settle_report_" + DateFormatUtils.format(mchList.get(0).getDate("report_date"), "yyyyMMdd") + "_" + batchId + ".xlsx";

@ -8,6 +8,7 @@ import au.com.royalpay.payment.tools.CommonConsts;
import au.com.royalpay.payment.tools.exceptions.BadRequestException; import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole; import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.InputStreamResource; import org.springframework.core.io.InputStreamResource;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -167,7 +168,7 @@ public class SettlementDevController {
} }
@GetMapping("/settle_batches/{batchId}/settle_report_xlsx") @GetMapping("/settle_batches/{batchId}/settle_report_xlsx")
public ResponseEntity<InputStreamResource> getSettlementReportForBatch(@PathVariable int batchId) { public ResponseEntity<ByteArrayResource> getSettlementReportForBatch(@PathVariable int batchId) {
return ResponseEntity.ok().contentType(MediaType.APPLICATION_OCTET_STREAM) return ResponseEntity.ok().contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(cleanService.downloadBatchSettleReportXlsx(batchId)); .body(cleanService.downloadBatchSettleReportXlsx(batchId));
} }

Loading…
Cancel
Save