settle page, download single settle batch files

master
yixian 6 years ago
parent 59259a6c25
commit b6e7f93c4d

@ -49,6 +49,8 @@ public interface CleanService {
void settlementAba(Date date, HttpServletResponse response) throws IOException; void settlementAba(Date date, HttpServletResponse response) throws IOException;
void getSettlementFilesForBatch(String batchId, HttpServletResponse resp) throws IOException;
List<JSONObject> getCleanLogs(ClearingLogQuery query, JSONObject manager); List<JSONObject> getCleanLogs(ClearingLogQuery query, JSONObject manager);
JSONObject getCleanLogsInClients(ClearingLogQuery query, JSONObject manager); JSONObject getCleanLogsInClients(ClearingLogQuery query, JSONObject manager);

@ -382,20 +382,24 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
ZipOutputStream zos = new ZipOutputStream(ous); ZipOutputStream zos = new ZipOutputStream(ous);
logger.info("using newest version test"); logger.info("using newest version test");
for (JSONObject log : logs) { for (JSONObject log : logs) {
String dateString = DateFormatUtils.format(log.getDate("operate_time"), "yyyyMMddHHmmss");
List<JSONObject> details = clearingDetailMapper.listReportsOfSettlement(log.getIntValue("clearing_id")); List<JSONObject> details = clearingDetailMapper.listReportsOfSettlement(log.getIntValue("clearing_id"));
List<String> bankList = details.stream().map(detail -> detail.getString("settle_bank")).distinct().collect(Collectors.toList()); exportAllBankXlsFiles(zos, details, log.getDate("operate_time"));
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);
}
} }
zos.flush(); zos.flush();
IOUtils.closeQuietly(zos); 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 @Override
public List<JSONObject> getXlsx(Date dt, String bank) throws IOException { public List<JSONObject> getXlsx(Date dt, String bank) throws IOException {
List<JSONObject> logs = clearingLogMapper.findByDate(dt); 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 { private byte[] generateSettleXlsxFile(Date dt, List<JSONObject> settlements, String bank) throws IOException {
Workbook wb = new XSSFWorkbook(); try (Workbook wb = new XSSFWorkbook()) {
Sheet sheet = wb.createSheet("Merchant_Settlement_Info_" + DateFormatUtils.format(dt, "yyyyMM")); Sheet sheet = wb.createSheet("Merchant_Settlement_Info_" + DateFormatUtils.format(dt, "yyyyMMdd"));
int rowNum = 0; int rowNum = 0;
for (JSONObject settle : settlements) { for (JSONObject settle : settlements) {
if (settle.getBigDecimal("clearing_amount").compareTo(BigDecimal.ZERO) == 0) { if (settle.getBigDecimal("clearing_amount").compareTo(BigDecimal.ZERO) == 0) {
continue; continue;
} }
if (bank != null && !Objects.equals(settle.getString("settle_bank"), bank)) { if (bank != null && !Objects.equals(settle.getString("settle_bank"), bank)) {
continue; 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++); ByteArrayOutputStream bos = new ByteArrayOutputStream();
row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue(settle.getString("bsb_no")); wb.write(bos);
row.createCell(1, Cell.CELL_TYPE_STRING).setCellValue(settle.getString("account_no")); bos.flush();
row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(settle.getString("account_name")); return bos.toByteArray();
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();
} }
@Override @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) { 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()); 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()); return banks.stream().map(bank -> generateSettleAbaFile(bank, dt, settlements)).peek(file -> file.setOperateTime(operateTime)).collect(Collectors.toList());

@ -156,6 +156,11 @@ public class SettlementDevController {
} }
} }
@RequestMapping("/settle_batches/{batchId}/settle_files")
public void getSettlementFilesForBatch(@PathVariable String batchId, HttpServletResponse resp) throws IOException {
cleanService.getSettlementFilesForBatch(batchId, resp);
}
@RequestMapping("/details/{detailId}") @RequestMapping("/details/{detailId}")
public JSONObject settlementDetail(@PathVariable int detailId, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { public JSONObject settlementDetail(@PathVariable int detailId, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) {
return cleanService.getCleanLogTransactions(detailId, manager); return cleanService.getCleanLogTransactions(detailId, manager);

@ -23,13 +23,13 @@ define(['angular', 'decimal', 'uiBootstrap', 'uiRouter', 'angularEcharts'], func
}).state('date_setting', { }).state('date_setting', {
url: '/date_setting', url: '/date_setting',
templateUrl: '/static/analysis/templates/settle_date_config.html', templateUrl: '/static/analysis/templates/settle_date_config.html',
/* onEnter: ['$uibModal', function ($uibModal) { /* onEnter: ['$uibModal', function ($uibModal) {
$uibModal.open({ $uibModal.open({
templateUrl: '/static/analysis/templates/settle_date_config.html', templateUrl: '/static/analysis/templates/settle_date_config.html',
controller: 'settleDateConfigCtrl', controller: 'settleDateConfigCtrl',
size: 'lg' size: 'lg'
}) })
}],*/ }],*/
controller: 'settleDateConfigCtrl', controller: 'settleDateConfigCtrl',
}).state('clearingLogs.settlementDetail', { }).state('clearingLogs.settlementDetail', {
url: '/settles/{date}', url: '/settles/{date}',
@ -247,9 +247,9 @@ define(['angular', 'decimal', 'uiBootstrap', 'uiRouter', 'angularEcharts'], func
$scope.noticeResend = false; $scope.noticeResend = false;
$scope.analysisFilter = {}; $scope.analysisFilter = {};
$scope.currentAnalysis = $scope.detail; $scope.currentAnalysis = $scope.detail;
$scope.pageCtrl = {visible:{}}; $scope.pageCtrl = {visible: {}};
function getAnalysisTemplate() { function getAnalysisTemplate() {
return [ return [
{settleDays: 1, clients: 0, settleAmount: 0, settles: []}, {settleDays: 1, clients: 0, settleAmount: 0, settles: []},
{settleDays: 2, clients: 0, settleAmount: 0, settles: []}, {settleDays: 2, clients: 0, settleAmount: 0, settles: []},
@ -257,6 +257,10 @@ define(['angular', 'decimal', 'uiBootstrap', 'uiRouter', 'angularEcharts'], func
]; ];
} }
$scope.reloadPage = function () {
$state.reload();
};
$scope.settleAnalysis = getAnalysisTemplate(); $scope.settleAnalysis = getAnalysisTemplate();
$scope.batchAnalysis = { $scope.batchAnalysis = {
@ -269,7 +273,7 @@ define(['angular', 'decimal', 'uiBootstrap', 'uiRouter', 'angularEcharts'], func
$scope.endIndexMap = {}; $scope.endIndexMap = {};
$scope.initEndIndex = 20; $scope.initEndIndex = 20;
$scope.more = function(key) { $scope.more = function (key) {
var endIndex = $scope.endIndexMap[key] + $scope.initEndIndex; var endIndex = $scope.endIndexMap[key] + $scope.initEndIndex;
$scope.endIndexMap[key] = endIndex; $scope.endIndexMap[key] = endIndex;
@ -279,7 +283,7 @@ define(['angular', 'decimal', 'uiBootstrap', 'uiRouter', 'angularEcharts'], func
}; };
$scope.packup = function(key) { $scope.packup = function (key) {
$scope.endIndexMap[key] = $scope.initEndIndex; $scope.endIndexMap[key] = $scope.initEndIndex;
var length = $scope.clientsMap[key].clients; var length = $scope.clientsMap[key].clients;
if (length <= $scope.initEndIndex) if (length <= $scope.initEndIndex)
@ -292,7 +296,6 @@ define(['angular', 'decimal', 'uiBootstrap', 'uiRouter', 'angularEcharts'], func
}; };
angular.forEach($scope.detail.details, function (settleItem) { angular.forEach($scope.detail.details, function (settleItem) {
var settleDays = settleItem.clear_days; var settleDays = settleItem.clear_days;
attachAnalysis($scope.settleAnalysis[Math.min(settleDays - 1, 2)]); attachAnalysis($scope.settleAnalysis[Math.min(settleDays - 1, 2)]);
@ -305,14 +308,14 @@ define(['angular', 'decimal', 'uiBootstrap', 'uiRouter', 'angularEcharts'], func
} }
}); });
$scope.clientsMap = $scope.settleAnalysis; $scope.clientsMap = $scope.settleAnalysis;
for (var key in $scope.clientsMap) { for (var key in $scope.clientsMap) {
$scope.endIndexMap[key] = $scope.initEndIndex; $scope.endIndexMap[key] = $scope.initEndIndex;
var length = $scope.clientsMap[key].clients; var length = $scope.clientsMap[key].clients;
if (length <= $scope.initEndIndex) if (length <= $scope.initEndIndex)
$scope.endIndexMap[key] = length; $scope.endIndexMap[key] = length;
} }
var nowStr = $filter('date')(new Date(), "yyyy-MM-dd"); var nowStr = $filter('date')(new Date(), "yyyy-MM-dd");

@ -40,6 +40,9 @@
ng-disabled="noticeResend"> ng-disabled="noticeResend">
Send Settlement Notice Send Settlement Notice
</button> </button>
<button class="btn btn-success pull-right" ng-click="reloadPage()">
<i class="fa fa-refresh"></i>Reload
</button>
</div> </div>
</div> </div>
@ -152,6 +155,11 @@
</div> </div>
</div> </div>
</div> </div>
<div class="box-footer" ng-if="analysisFilter.clearing_id!=null">
<a class="btn btn-primary" ng-href="/sys/settlement/settle_batches/{{analysisFilter.clearing_id}}/settle_files" target="_blank">
Download Files
</a>
</div>
</div> </div>
<div class="row"> <div class="row">

Loading…
Cancel
Save