Merge branch 'develop'

master
yixian 5 years ago
commit 1ed31f8b9d

@ -50,7 +50,7 @@ public interface CleanService {
List<JSONObject> getSettleLogs(Date dt, List<String> clearIds);
List<ABAFile> getAba(Date dt, String bank, List<JSONObject> logs) throws IOException;
List<ABAFile> getAba(Date dt, List<JSONObject> logs) throws IOException;
void settlementAba(Date date, HttpServletResponse response) throws IOException;
@ -105,4 +105,6 @@ public interface CleanService {
void undoSettle(Date date, int clearingId);
ByteArrayResource downloadBatchSettleReportXlsx(int batchId);
JSONObject findSettleLog(int clearingId);
}

@ -3,6 +3,7 @@ package au.com.royalpay.payment.manage.management.clearing.core.impl;
import au.com.royalpay.payment.core.PaymentApi;
import au.com.royalpay.payment.core.exceptions.InvalidShortIdException;
import au.com.royalpay.payment.core.tasksupport.SettlementSupport;
import au.com.royalpay.payment.core.utils.ExtParamsUtils;
import au.com.royalpay.payment.manage.management.clearing.core.CleanService;
import au.com.royalpay.payment.manage.mappers.log.*;
import au.com.royalpay.payment.manage.mappers.payment.TaskManualSettleMapper;
@ -32,6 +33,7 @@ import au.com.royalpay.payment.tools.exceptions.ForbiddenException;
import au.com.royalpay.payment.tools.exceptions.NotFoundException;
import au.com.royalpay.payment.tools.locale.LocaleSupport;
import au.com.royalpay.payment.tools.lock.Locker;
import au.com.royalpay.payment.tools.merchants.beans.BalanceGroup;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
import au.com.royalpay.payment.tools.tasksupport.TaskFinishNotifyEvent;
import au.com.royalpay.payment.tools.utils.DateVaildUtil;
@ -321,7 +323,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
JSONObject client = clientManager.getClientInfo(clientId);
Assert.notNull(client, "Client ID invalid");
checkOrgPermission(manager, client);
List<JSONObject> transactions = transactionMapper.listTransactionsOfMergeSettleClearingOrder(reportDate,clientId,
List<JSONObject> transactions = transactionMapper.listTransactionsOfMergeSettleClearingOrder(reportDate, clientId,
new PageBounds(Order.formString("order_id.asc")));
clearClient.put("report", transactions);
List<JSONObject> channels = clearingDetailAnalysisMapper.listReportChannelsOfMergeSettle(reportDate, clientId);
@ -536,15 +538,16 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
}
@Override
public List<ABAFile> getAba(Date dt, String bank, List<JSONObject> logs) {
public List<ABAFile> getAba(Date dt, List<JSONObject> logs) {
List<ABAFile> files = new ArrayList<>();
for (JSONObject log : logs) {
List<JSONObject> details = clearingDetailMapper.listReportsOfSettlement(log.getIntValue("clearing_id"));
details = mergeBatchSettleClients(details);
String remark = extractSettleRemark(log);
files.addAll(generateSettleAbaFiles(dt, details, log.getDate("operate_time"), remark));
BalanceGroup group = BalanceGroup.valueOf(log.getString("balance_group"));
files.addAll(generateSettleAbaFiles(dt, group, details, log.getDate("operate_time"), remark));
}
return files.stream().filter(file -> bank.equals(file.bank())).collect(Collectors.toList());
return files;
}
public String extractSettleRemark(JSONObject log) {
@ -589,7 +592,8 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
for (JSONObject log : logs) {
List<JSONObject> details = clearingDetailMapper.listReportsOfSettlement(log.getIntValue("clearing_id"));
details = mergeBatchSettleClients(details);
files.addAll(generateSettleAbaFiles(dt, details, log.getDate("operate_time"), extractSettleRemark(log)));
BalanceGroup group = BalanceGroup.valueOf(log.getString("balance_group"));
files.addAll(generateSettleAbaFiles(dt, group, details, log.getDate("operate_time"), extractSettleRemark(log)));
}
OutputStream ous = resp.getOutputStream();
if (files.size() == 1) {
@ -633,7 +637,8 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
resp.addHeader("Content-Disposition", "attachment; filename=" + zipName);
OutputStream ous = resp.getOutputStream();
List<ABAFile> abaFiles = generateSettleAbaFiles(settleDate, details, opTime, extractSettleRemark(clearing));
BalanceGroup group = BalanceGroup.valueOf(clearing.getString("balance_group"));
List<ABAFile> abaFiles = generateSettleAbaFiles(settleDate, group, details, opTime, extractSettleRemark(clearing));
try (ZipOutputStream zos = new ZipOutputStream(ous)) {
for (ABAFile aba : abaFiles) {
zos.putNextEntry(new ZipEntry(aba.filename()));
@ -644,16 +649,16 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
}
}
private List<ABAFile> generateSettleAbaFiles(Date dt, List<JSONObject> settlements, Date operateTime, String remark) {
private List<ABAFile> generateSettleAbaFiles(Date dt, BalanceGroup group, List<JSONObject> settlements, Date operateTime, String remark) {
List<String> banks = settlements.stream().map(detail -> detail.getString("settle_bank")).distinct().collect(Collectors.toList());
return banks.stream().map(bank -> generateSettleAbaFile(bank, dt, settlements))
return banks.stream().map(bank -> generateSettleAbaFile(bank, group, dt, settlements))
.peek(file -> file.setOperateTime(operateTime))
.peek(file -> file.setRemark(remark))
.collect(Collectors.toList());
}
private ABAFile generateSettleAbaFile(String bank, Date dt, List<JSONObject> settlements) {
ABAFile aba = ABATemplate.getConfig().initFile(bank, dt);
private ABAFile generateSettleAbaFile(String bank, BalanceGroup group, Date dt, List<JSONObject> settlements) {
ABAFile aba = ABATemplate.getConfig().initFile(group, bank, dt);
for (JSONObject settle : settlements) {
if (!bank.equals(settle.getString("settle_bank"))) {
continue;
@ -890,7 +895,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
if (clearClient == null) {
throw new NotFoundException();
}
List<JSONObject> transactions = transactionMapper.listTransactionsOfMergeSettleClearingOrder(reportDate,client_id,
List<JSONObject> transactions = transactionMapper.listTransactionsOfMergeSettleClearingOrder(reportDate, client_id,
new PageBounds(Order.formString("order_id.asc")));
String timezone_client = client.getString("timezone");
@ -1026,10 +1031,10 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
}
@Override
public void exportListClearingTransactions(int client_id, String clearingDetailId, JSONObject partner, HttpServletResponse resp) {
public void exportListClearingTransactions(int clientId, String clearingDetailId, JSONObject partner, HttpServletResponse resp) {
OutputStream ous = null;
try {
JSONObject clearTransation = listClearingTransactions(client_id, clearingDetailId, partner);
JSONObject clearTransation = listClearingTransactions(clientId, clearingDetailId, partner);
resp.setContentType("application/octet-stream;");
Date reportDate = clearTransation.getDate("report_date");
resp.addHeader("Content-Disposition",
@ -1114,7 +1119,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
settle.getBigDecimal("settle_amount").setScale(2, BigDecimal.ROUND_DOWN).toPlainString() :
"-" + settle.getBigDecimal("settle_amount").setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
cell.setCellStyle(!"Credit".equals(settle.getString("transaction_type")) ? analysisStyle2 : null);
row.createCell(15, Cell.CELL_TYPE_STRING).setCellValue(settle.containsKey("order_detail")?settle.getString("order_detail"):settle.getString("remark"));
row.createCell(15, Cell.CELL_TYPE_STRING).setCellValue(settle.containsKey("order_detail") ? settle.getString("order_detail") : settle.getString("remark"));
String clientDevId = StringUtils.defaultString(settle.getString("dev_id"), "-");
JSONObject device = clientDeviceMapper.find(settle.getString("dev_id"));
String clientDevRemark = "-";
@ -1174,7 +1179,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
Sheet sheet = wb.createSheet("Merchant_Settlement_Info_" + reportDate);
int rowNum = 0;
Row row = sheet.createRow(rowNum);
String[] title = {"Client Moniker","Short Name","order Id", "Client Order Id", "Transaction Time", "Channel", "Gateway", "Exchange Rate", "Transaction Type", "Currency",
String[] title = {"Client Moniker", "Short Name", "order Id", "Client Order Id", "Transaction Time", "Channel", "Gateway", "Exchange Rate", "Transaction Type", "Currency",
"Input Amount", "Total Amount", "Clearing Amount(AUD)", "Sruchange Rate", "Surcharge(AUD)", "GST(AUD)", "Settle Amount(AUD)", "Remark", "Dev No", "Dev Remark"};
String[] analysis = {"Total Credit(AUD)", "Total Debit(AUD)", "Gross Amount(AUD)", "Total GST(AUD)", "Total Charge(AUD)", "Net Amount(AUD)"};
for (int i = 0; i < title.length; i++) {
@ -1380,7 +1385,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
attachList.add(attach1);
JSONObject attach2 = new JSONObject();
List<ABAFile> abaFileList = getAba(date, "CBA", clearLogs);
List<ABAFile> abaFileList = getAba(date, clearLogs);
String fileName2 = "Merchant_Settlement_Info_aba_" + DateFormatUtils.format(date, "yyyyMMdd");
if (abaFileList.size() > 1) {
fileName2 += ".zip";
@ -1429,7 +1434,12 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
settleMailRecord.put("notice_status", 0);
logSettleMailMapper.save(settleMailRecord);
}
sendTaskFinishMessages(ManagerRole.FINANCIAL_STAFF, "清算文件已发送清算方", "发送清算通知");
String detailDescription = clearLogs.stream()
.map(log -> String.format("[%s]%s", log.getString("clearing_id"),
ExtParamsUtils.getExtParamsValue(log.getString("plan_detail"),
detail -> StringUtils.defaultIfEmpty(detail.getString("remark"), detail.getString("plan_id")))))
.collect(Collectors.joining(","));
sendTaskFinishMessages(ManagerRole.FINANCIAL_STAFF, "清算文件已发送清算方:"+detailDescription, "发送清算通知");
if (autoMarkSent) {
if (!clearIds.isEmpty()) {
clearingLogMapper.lockSettlementsById(clearLogs.stream().map(log -> log.getString("clearing_id")).collect(Collectors.toList()));
@ -1523,7 +1533,8 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
throw new ForbiddenException("Settlement log has been sent and unable to edit");
}
ABAConfig config = ABATemplate.getConfig();
String defaultBank = config.getRemainsTo();
BalanceGroup group = BalanceGroup.valueOf(log.getString("balance_group"));
String defaultBank = config.getRemainsTo(group);
clearingDetailMapper.updateAllBanks(defaultBank, clearingId);
List<JSONObject> details = clearingDetailMapper.listReportsOfSettlement(clearingId);
details = mergeBatchSettleClients(details);
@ -1547,6 +1558,9 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
if (base == null) {
throw new BadRequestException("Invalid bank code:" + bank);
}
if (base.acceptBalanceGroup(group)) {
throw new BadRequestException("Balance group not match:" + group + ":" + bank);
}
BigDecimal bankAmount = bankDistribution.getBigDecimal(bank);
for (JSONObject detail : details) {
String detailBank = detail.getString("settle_bank");
@ -1639,6 +1653,15 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
}
}
@Override
public JSONObject findSettleLog(int clearingId) {
JSONObject clearing = clearingLogMapper.findById(clearingId);
if (clearing == null) {
throw new NotFoundException("Settle record not found:" + clearingId);
}
return clearing;
}
private void releaseDistributedSurcharge(JSONObject clearingDetail) {
int clientId = clearingDetail.getIntValue("client_id");
BigDecimal distributedSurcharge = clearingDetail.getBigDecimal("distributed_surcharge");

@ -6,6 +6,7 @@ import au.com.royalpay.payment.manage.permission.manager.RequireManager;
import au.com.royalpay.payment.manage.support.abafile.ABATemplate;
import au.com.royalpay.payment.tools.CommonConsts;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.merchants.beans.BalanceGroup;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
import com.alibaba.fastjson.JSONObject;
import org.springframework.core.io.ByteArrayResource;
@ -56,11 +57,13 @@ public class SettlementDevController {
}
}
@GetMapping("/available_banks")
public JSONObject getAvailableBanks() {
List<String> banks = ABATemplate.getConfig().availableBanks();
@GetMapping("/clearings/{clearingId}/available_banks")
public JSONObject getAvailableBanks(@PathVariable int clearingId) {
JSONObject clearing = cleanService.findSettleLog(clearingId);
BalanceGroup group = BalanceGroup.valueOf(clearing.getString("balance_group"));
List<String> banks = ABATemplate.getConfig().availableBanks(group);
JSONObject res = new JSONObject();
res.put("remains_to", ABATemplate.getConfig().getRemainsTo());
res.put("remains_to", ABATemplate.getConfig().getRemainsTo(group));
res.put("banks", banks);
return res;
}

@ -1,9 +1,12 @@
package au.com.royalpay.payment.manage.support.abafile;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.merchants.beans.BalanceGroup;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.*;
import java.util.stream.Collectors;
/**
* Create by yixian at 2018-06-25 17:39
@ -12,24 +15,24 @@ import java.util.*;
public class ABAConfig {
private Map<String, ABABase> bank = new HashMap<>();
private String defaultBank;
private String remainsTo;
public ABAFile initFile(String bank, Date settleDate) {
public ABAFile initFile(BalanceGroup group, String bank, Date settleDate) {
ABABase base = this.bank.get(bank);
if (base == null) {
throw new BadRequestException("Invalid bank:" + bank);
}
if (!base.acceptBalanceGroup(group)) {
throw new BadRequestException("Balance group not match:" + group + "," + bank);
}
return base.initFile(settleDate);
}
public String getDefaultBank() {
return defaultBank;
}
public ABAConfig setDefaultBank(String defaultBank) {
this.defaultBank = defaultBank;
return this;
public String getRemainsTo(BalanceGroup group) {
return bank.entrySet().stream()
.filter(entry -> entry.getValue().acceptBalanceGroup(group))
.filter(entry -> !entry.getValue().isManualSending())
.map(Map.Entry::getKey)
.findFirst().orElse(null);
}
public Map<String, ABABase> getBank() {
@ -45,17 +48,11 @@ public class ABAConfig {
return this;
}
public String getRemainsTo() {
return remainsTo;
}
public ABAConfig setRemainsTo(String remainsTo) {
this.remainsTo = remainsTo;
return this;
}
public List<String> availableBanks() {
return new ArrayList<>(bank.keySet());
public List<String> availableBanks(BalanceGroup group) {
return bank.entrySet().stream()
.filter(entry -> entry.getValue().acceptBalanceGroup(group))
.map(Map.Entry::getKey)
.collect(Collectors.toList());
}
public static class ABABase {
@ -65,6 +62,7 @@ public class ABAConfig {
private String bsb;
private String accountNo;
private String accountName;
private BalanceGroup[] balanceGroup;
public ABAFile initFile(Date settleDate) {
return new ABAFile(this, settleDate);
@ -123,5 +121,18 @@ public class ABAConfig {
this.accountName = accountName;
return this;
}
public BalanceGroup[] getBalanceGroup() {
return balanceGroup;
}
public ABABase setBalanceGroup(BalanceGroup[] balanceGroup) {
this.balanceGroup = balanceGroup;
return this;
}
public boolean acceptBalanceGroup(BalanceGroup group) {
return ArrayUtils.contains(balanceGroup, group);
}
}
}

@ -13,7 +13,6 @@ import javax.annotation.PostConstruct;
@EnableConfigurationProperties(ABAConfig.class)
public class ABATemplate {
private static ABATemplate tpl;
@Autowired
private ABAConfig config;
@PostConstruct
@ -24,4 +23,10 @@ public class ABATemplate {
public static ABAConfig getConfig() {
return tpl.config;
}
@Autowired
public ABATemplate setConfig(ABAConfig config) {
this.config = config;
return this;
}
}

@ -121,26 +121,39 @@ settle:
bank:
ANZ:
account-name: Tunnel Show Pty Ltd
account-no: 837022519
apca: 514624
account-no: '837022519'
apca: '514624'
bank: ANZ
bsb: 13006
bsb: '013006'
manual-sending: true
balance-group:
- NORMAL_CROSS_BORDER
CBA:
account-name: Tunnel Show Pty Ltd
account-no: 11655861
apca: 301500
account-no: '11655861'
apca: '301500'
bank: CBA
bsb: 63109
bsb: '063109'
balance-group:
- NORMAL_CROSS_BORDER
NAB:
account-name: Tunnel Show Pty Ltd
account-no: 837022519
apca: 514624
account-no: '837022519'
apca: '514624'
bank: NAB
bsb: 13006
bsb: '013006'
manual-sending: true
default-bank: CBA
remains-to: ANZ
balance-group:
- NORMAL_CROSS_BORDER
CARD:
account-name: UPay Pty Ltd
account-no: '13677888'
apca: '301500'
bank: CBA
bsb: '063010'
balance-group:
- RPAY_SVC_CARD
- RPAY_SVC_DIRECTDEBIT
spring:
mail:
host: smtp.office365.com

@ -387,7 +387,7 @@ define(['angular', 'decimal', 'uiBootstrap', 'uiRouter', 'angularEcharts'], func
};
$scope.distributeBankDialog = function () {
var log = $scope.getCurrentLog();
let log = $scope.getCurrentLog();
$uibModal.open({
templateUrl: '/static/analysis/templates/settlement_bank_distribution_dialog.html',
controller: 'bankDistributionDialogCtrl',
@ -396,7 +396,7 @@ define(['angular', 'decimal', 'uiBootstrap', 'uiRouter', 'angularEcharts'], func
return log;
},
banksConfig: ['$http', function ($http) {
return $http.get('/sys/settlement/available_banks')
return $http.get('/sys/settlement/clearings/' + log.clearing_id + '/available_banks')
}],
settleDate: function () {
return $stateParams.date;
@ -496,24 +496,24 @@ define(['angular', 'decimal', 'uiBootstrap', 'uiRouter', 'angularEcharts'], func
$scope.settleLogs = settleLogs.map(log => {
let info = {
'id': log.clearing_id,
'time':log.operate_time,
'amount':log.net_amount,
'time': log.operate_time,
'amount': log.net_amount,
'remark': log.plan_detail.remark || log.plan_detail.plan_id,
'send': false
};
return info
});
$scope.sumSelectedAmount = function(){
let sendingLogs = $scope.settleLogs.filter(log=>log.send);
if(sendingLogs.length){
return sendingLogs.map(log=>log.amount).reduce((m1,m2)=>m1+m2);
}else{
return $scope.settleLogs.map(log=>log.amount).reduce((m1,m2)=>m1+m2);
$scope.sumSelectedAmount = function () {
let sendingLogs = $scope.settleLogs.filter(log => log.send);
if (sendingLogs.length) {
return sendingLogs.map(log => log.amount).reduce((m1, m2) => m1 + m2);
} else {
return $scope.settleLogs.map(log => log.amount).reduce((m1, m2) => m1 + m2);
}
};
$scope.config = {mark_sent: true};
$scope.switchSendFlag=function(info){
info.send=!info.send
$scope.switchSendFlag = function (info) {
info.send = !info.send
};
$scope.sendCheckCodeButton = false;
$scope.sendMailButton = false;
@ -522,7 +522,10 @@ define(['angular', 'decimal', 'uiBootstrap', 'uiRouter', 'angularEcharts'], func
$scope.error_msg = '正在发送,请稍后。';
$scope.sendMailButton = true;
$http.post('/sys/settlement/reports/' + $stateParams.date + '/send_settlement_xlsx',
{clearing_ids:$scope.settleLogs.filter(log=>log.send).map(log=>log.id),mark_sent:$scope.config.mark_sent}).then(function (resp) {
{
clearing_ids: $scope.settleLogs.filter(log => log.send).map(log => log.id),
mark_sent: $scope.config.mark_sent
}).then(function (resp) {
$scope.error_msg = resp.data.msg;
$scope.sendMailButton = false;
if (resp.data.result == 0) {

@ -1,7 +1,7 @@
$(function () {
let $container = $('.card-input-box')[0];
let ctrl = {ready: false, pending: false}
let cardFrame = window.channel_account_id ? new TokenInputFrame($container, window.channel_account_id) : new CardInputFrame($container);
let cardFrame = new CardInputFrame($container, window.card_input_appid, window.card_input_token);
let $errorMsgBox = $('#errorMsgBox');
let loading = $('.loading-container');
cardFrame.onSuccess = function (secretData) {

@ -0,0 +1,34 @@
package au.com.royalpay.payment.manage.task;
import au.com.royalpay.payment.channels.rpaypaymentsvc.runtime.RPayPaymentCardSvcApi;
import au.com.royalpay.payment.manage.mappers.system.ManagerMapper;
import au.com.royalpay.payment.manage.tradelog.refund.RefundService;
import com.alibaba.fastjson.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.annotation.Resource;
import java.math.BigDecimal;
/**
* Create by davep at 2020-04-17 15:37
*/
@SpringBootTest
@ActiveProfiles("officedev,wechat,jd,alipay,bestpay,rpay,yeepay,lakala,rppaysvc")
@RunWith(SpringJUnit4ClassRunner.class)
public class RefundTest {
@Resource
private RPayPaymentCardSvcApi rPayPaymentCardSvcApi;
@Resource
private ManagerMapper managerMapper;
@Test
public void test() throws InterruptedException {
String refundId = "8956ae96-44c0-48e8-9865-865c05fd3831";
rPayPaymentCardSvcApi.checkRefundStatus(refundId);
Thread.sleep(60_000);
}
}

@ -35,7 +35,7 @@ public class SettleMailTest {
public void parse() throws IOException {
Date date = DateUtils.truncate(new Date(), Calendar.DATE);
final ArrayList<String> clearIds = new ArrayList<>();
List<ABAFile> abaFileList = cleanService.getAba(date, "CBA", cleanService.getSettleLogs(date, clearIds));
List<ABAFile> abaFileList = cleanService.getAba(date, cleanService.getSettleLogs(date, clearIds));
Context ctx = new Context();
ctx.setVariable("date", DateFormatUtils.format(date, "dd-MM-yyyy"));

Loading…
Cancel
Save