|
|
|
@ -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);
|
|
|
|
|