distribute bank

master
yixian 6 years ago
parent 20addb778a
commit 0de03e2364

@ -84,4 +84,8 @@ public interface CleanService {
JSONObject findLogSettleByDate(Date date);
JSONObject validTransactions(Date dt, boolean fix, boolean b, boolean b1);
void distributeBank(Date dt, int clearingId, JSONObject bankDistribution);
void lockClearingLog(Date dt, int clearingId);
}

@ -15,6 +15,7 @@ import au.com.royalpay.payment.manage.merchants.core.ClientManager;
import au.com.royalpay.payment.manage.notice.core.MailService;
import au.com.royalpay.payment.manage.signin.beans.TodoNotice;
import au.com.royalpay.payment.manage.signin.core.ManagerTodoNoticeProvider;
import au.com.royalpay.payment.manage.support.abafile.ABAConfig;
import au.com.royalpay.payment.manage.support.abafile.ABAFile;
import au.com.royalpay.payment.manage.support.abafile.ABATemplate;
import au.com.royalpay.payment.manage.tradelog.beans.ClearingLogQuery;
@ -57,6 +58,7 @@ import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.format.number.CurrencyStyleFormatter;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.thymeleaf.context.Context;
@ -223,6 +225,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
return data;
}).collect(Collectors.toList());
log.put("bank_statistics", bankStatistics);
log.put("editable", DateUtils.isSameDay(log.getDate("settle_date"), new Date()) && log.getBooleanValue("editable"));
}
total.put("logs", logs);
total.put("details", details);
@ -998,6 +1001,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
}
}
sendTaskFinishMessages(ManagerRole.FINANCIAL_STAFF, "清算文件已发送清算方", "发送清算通知");
clearingLogMapper.lockSettlements(date);
} catch (IOException e) {
logger.error("生成excel字节数组发生错误");
} catch (URISyntaxException e) {
@ -1070,6 +1074,60 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
return report;
}
@Override
@Transactional
public void distributeBank(Date date, int clearingId, JSONObject bankDistribution) {
if (!DateUtils.isSameDay(date, new Date())) {
throw new ForbiddenException("Only today's settlement file can be modified");
}
JSONObject log = clearingLogMapper.findById(clearingId);
if (log == null || !DateUtils.isSameDay(log.getDate("settle_date"), date)) {
throw new NotFoundException("Settlement log not found");
}
if (!log.getBooleanValue("editable")) {
throw new ForbiddenException("Settlement log has been sent and unable to edit");
}
ABAConfig config = ABATemplate.getConfig();
String defaultBank = config.getRemainsTo();
clearingDetailMapper.updateAllBanks(defaultBank, clearingId);
List<JSONObject> details = clearingDetailMapper.listReportsOfSettlement(clearingId);
details.sort((log1, log2) -> log2.getBigDecimal("clearing_amount").compareTo(log1.getBigDecimal("clearing_amount")));
bankDistribution.remove(defaultBank);
for (String bank : bankDistribution.keySet()) {
List<String> detailIds = new ArrayList<>();
ABAConfig.ABABase base = config.getBankBase(bank);
if (base == null) {
throw new BadRequestException("Invalid bank code:" + bank);
}
BigDecimal bankAmount = bankDistribution.getBigDecimal(bank);
for (JSONObject detail : details) {
String detailBank = detail.getString("settle_bank");
if (defaultBank.equals(detailBank)) {
BigDecimal amount = detail.getBigDecimal("clearing_amount");
if (amount.compareTo(BigDecimal.ZERO) > 0 && bankAmount.compareTo(amount) > 0) {
detailIds.add(detail.getString("clear_detail_id"));
bankAmount = bankAmount.subtract(amount);
detail.put("settle_bank", bank);
}
}
}
clearingDetailMapper.updateBanks(bank, detailIds);
}
}
@Override
public void lockClearingLog(Date date, int clearingId) {
if (!DateUtils.isSameDay(date, new Date())) {
throw new ForbiddenException("Only today's settlement file can be modified");
}
JSONObject log = clearingLogMapper.findById(clearingId);
if (log == null || !DateUtils.isSameDay(log.getDate("settle_date"), date)) {
throw new NotFoundException("Settlement log not found");
}
clearingLogMapper.setLogEditable(false, clearingId);
}
private byte[] getZipByteArr(List<JSONObject> fileByteArrWithName) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(bos);

@ -2,6 +2,7 @@ package au.com.royalpay.payment.manage.management.clearing.web;
import au.com.royalpay.payment.manage.management.clearing.core.CleanService;
import au.com.royalpay.payment.manage.permission.manager.ManagerMapping;
import au.com.royalpay.payment.manage.support.abafile.ABATemplate;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
import au.com.royalpay.payment.tools.CommonConsts;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
@ -49,6 +50,35 @@ public class SettlementDevController {
}
}
@GetMapping("/available_banks")
public JSONObject getAvailableBanks() {
List<String> banks = ABATemplate.getConfig().availableBanks();
JSONObject res = new JSONObject();
res.put("remains_to", ABATemplate.getConfig().getRemainsTo());
res.put("banks", banks);
return res;
}
@PutMapping("/reports/{date}/clearings/{clearingId}/bank_distribution")
public void modifyClearingBank(@PathVariable String date, @PathVariable int clearingId, @RequestBody JSONObject bankDistribution) {
try {
Date dt = dateFormat.parse(date);
cleanService.distributeBank(dt, clearingId, bankDistribution);
} catch (ParseException e) {
throw new BadRequestException("error.payment.valid.invalid_date_format");
}
}
@PutMapping("/reports/{date}/clearings/{clearingId}/lock")
public void lockClearingLog(@PathVariable String date,@PathVariable int clearingId){
try {
Date dt = dateFormat.parse(date);
cleanService.lockClearingLog(dt, clearingId);
} catch (ParseException e) {
throw new BadRequestException("error.payment.valid.invalid_date_format");
}
}
@RequestMapping("/reports/{date}/settlement_csv")
public void getSettlementCsv(@PathVariable String date, HttpServletResponse resp) throws IOException {
try {
@ -79,23 +109,23 @@ public class SettlementDevController {
}
}
@ManagerMapping(value = "/reports/{date}/send_settlement_xlsx/{checkCode}",role = {ManagerRole.FINANCIAL_STAFF})
@ManagerMapping(value = "/reports/{date}/send_settlement_xlsx/{checkCode}", role = {ManagerRole.FINANCIAL_STAFF})
public JSONObject sendSettlementMail(@PathVariable("date") String date, @PathVariable("checkCode") String checkCode) {
Date dt = null;
try {
dt = dateFormat.parse(date);
} catch (ParseException e) {
}
return cleanService.sendSettlementMail(dt,checkCode);
return cleanService.sendSettlementMail(dt, checkCode);
}
@ManagerMapping(value = "/reports/send_checkcode",role = {ManagerRole.FINANCIAL_STAFF})
public void sendCheckCode(@ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager){
cleanService.sendCheckCode(new Date(),manager);
@ManagerMapping(value = "/reports/send_checkcode", role = {ManagerRole.FINANCIAL_STAFF})
public void sendCheckCode(@ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) {
cleanService.sendCheckCode(new Date(), manager);
}
@RequestMapping(value = "/reports/{date}/send_status")
public JSONObject sendStatus(@PathVariable String date){
public JSONObject sendStatus(@PathVariable String date) {
Date dt = null;
try {
dt = dateFormat.parse(date);

@ -40,4 +40,9 @@ public interface ClearingDetailMapper {
JSONObject listReportByDate(@Param("report_date") Date date, @Param("client_id") int clientId);
PageList<JSONObject> listClientSettlementLog(JSONObject params, PageBounds pagination);
void updateAllBanks(@Param("settle_bank") String bank, @Param("clearing_id") int clearingId);
@AutoSql(type = SqlType.UPDATE)
void updateBanks(@Param("settle_bank") String bank,@Param("clear_detail_id") List<String> clearingDetailIds);
}

@ -31,11 +31,19 @@ public interface ClearingLogMapper {
@AutoSql(type = SqlType.UPDATE)
void update(JSONObject update);
List<JSONObject> getSettlementChannelsMonthReport(@Param("year") int year, @Param("month") int month);
List<JSONObject> getSettlementChannelsMonthReport(@Param("year") int year, @Param("month") int month);
List<JSONObject> getMondayClearing(@Param("begin") Date begin, @Param("end") Date end);
List<JSONObject> getSettlementChannelsDailyReport(@Param("date") Date date);
JSONObject getSettleDataDailyReport(@Param("date") Date date);
void lockSettlements(@Param("date") Date date);
@AutoSql(type = SqlType.SELECT)
JSONObject findById(@Param("clearing_id") int clearingId);
@AutoSql(type = SqlType.UPDATE)
void setLogEditable(@Param("editable") boolean editable, @Param("clearing_id") int clearingId);
}

@ -3,9 +3,7 @@ package au.com.royalpay.payment.manage.support.abafile;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
/**
* Create by yixian at 2018-06-25 17:39
@ -15,6 +13,7 @@ public class ABAConfig {
private Map<String, ABABase> bank = new HashMap<>();
private String defaultBank;
private String remainsTo;
public ABAFile initFile(String bank, Date settleDate) {
ABABase base = this.bank.get(bank);
@ -37,11 +36,28 @@ public class ABAConfig {
return bank;
}
public ABABase getBankBase(String bank) {
return this.bank.get(bank);
}
public ABAConfig setBank(Map<String, ABABase> bank) {
this.bank = bank;
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 static class ABABase {
private boolean manualSending = false;
private String bank;

@ -115,6 +115,7 @@ royalpay.sms.appkey=43390d81e20c5191c278fbf4cd275be2
#清算银行配置
settle.abafile.default-bank=CBA
settle.abafile.remains-to=ANZ
settle.abafile.bank.CBA.bank=CBA
settle.abafile.bank.CBA.apca=301500

@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="au.com.royalpay.payment.manage.mappers.log.ClearingDetailMapper">
<update id="updateAllBanks">
update log_clearing_detail set settle_bank=#{bank} where clearing_id=#{clearing_id}
</update>
<select id="listReports" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[
SELECT

@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="au.com.royalpay.payment.manage.mappers.log.ClearingLogMapper">
<update id="lockSettlements">
update log_clearing set editable=0 where settle_date=#{date}
</update>
<select id="findByDate" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[
SELECT *

Loading…
Cancel
Save