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

master
yixian 5 years ago
parent 1a9a653274
commit 3e0a5f8690

@ -3,7 +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.tradelog.beans.ClearingLogQuery;
import com.alibaba.fastjson.JSONObject;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.InputStreamResource;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
@ -96,5 +96,5 @@ public interface CleanService {
void undoSettle(Date date, int clearingId);
ByteArrayResource downloadBatchSettleReportXlsx(int batchId);
InputStreamResource downloadBatchSettleReportXlsx(int batchId);
}

@ -63,6 +63,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.InputStreamResource;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.format.number.CurrencyStyleFormatter;
import org.springframework.stereotype.Service;
@ -1362,7 +1363,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
}
@Override
public ByteArrayResource downloadBatchSettleReportXlsx(int batchId) {
public InputStreamResource downloadBatchSettleReportXlsx(int batchId) {
List<JSONObject> mchList = clearingDetailMapper.batchReport(batchId);
if (mchList.isEmpty()) {
throw new NotFoundException("No batch found");
@ -1384,7 +1385,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
try (ByteArrayOutputStream bout = new ByteArrayOutputStream()) {
builder.build(bout);
bout.flush();
return new ByteArrayResource(bout.toByteArray()) {
return new InputStreamResource(new ByteArrayInputStream(bout.toByteArray())) {
@Override
public String getFilename() {
return "settle_report_" + DateFormatUtils.format(mchList.get(0).getDate("report_date"), "yyyyMMdd") + "_" + batchId + ".xlsx";

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

Loading…
Cancel
Save