|
|
|
@ -683,6 +683,18 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
|
if (log == null) {
|
|
|
|
|
throw new NotFoundException("Settle log not found");
|
|
|
|
|
}
|
|
|
|
|
ABAFile file = buildCustomizedABAFile(log);
|
|
|
|
|
response.setContentType("application/octet-stream;");
|
|
|
|
|
response.addHeader("Content-Disposition", "attachment; filename=" + file.filename());
|
|
|
|
|
try (OutputStream ous = response.getOutputStream()) {
|
|
|
|
|
ous.write(file.output(1));
|
|
|
|
|
ous.flush();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new ServerErrorException("Output failed", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ABAFile buildCustomizedABAFile(JSONObject log) {
|
|
|
|
|
String bank = log.getString("settle_bank");
|
|
|
|
|
BalanceGroup group = BalanceGroup.valueOf(log.getString("balance_group"));
|
|
|
|
|
JSONObject settle = new JSONObject();
|
|
|
|
@ -694,15 +706,64 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
|
|
|
|
|
settle.put("account_name", log.getString("account_name"));
|
|
|
|
|
settle.put("client_moniker", log.getString("client_moniker"));
|
|
|
|
|
ABAFile file = generateSettleAbaFile(bank, group, new Date(), Collections.singletonList(settle));
|
|
|
|
|
response.setContentType("application/octet-stream;");
|
|
|
|
|
String filename = String.format("[%s]Manual_Settle_%s_%s.aba", logId, log.getString("client_moniker"), DateTime.now().toString("yyyyMMdd"));
|
|
|
|
|
response.addHeader("Content-Disposition", "attachment; filename=" + filename);
|
|
|
|
|
try (OutputStream ous = response.getOutputStream()) {
|
|
|
|
|
ous.write(file.output(1));
|
|
|
|
|
ous.flush();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new ServerErrorException("Output failed", e);
|
|
|
|
|
String filename = String.format("[%s]Manual_Settle_%s_%s.aba", log.getIntValue("log_id"), log.getString("client_moniker"), DateTime.now().toString("yyyyMMdd"));
|
|
|
|
|
file.setFilename(filename);
|
|
|
|
|
return file;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public JSONObject sendCustomizedSettleMail(List<Integer> logIds) {
|
|
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
|
try {
|
|
|
|
|
Date date = DateTime.now().withTimeAtStartOfDay().toDate();
|
|
|
|
|
String title = (PlatformEnvironment.getEnv().isDebug() ? "[TEST]" : "") + "Royalpay Manual Settlement Files " + DateFormatUtils.format(date, "yyyyMMdd");
|
|
|
|
|
List<JSONObject> customizedLogs = logIds.stream().map(customizedSettleLogMapper::find)
|
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
List<ABAFile> abaFileList = customizedLogs.stream().map(this::buildCustomizedABAFile).collect(Collectors.toList());
|
|
|
|
|
List<JSONObject> attachList = abaFileList.stream()
|
|
|
|
|
.map(aba -> new JSONObject(Map.of("name", aba.filename(),
|
|
|
|
|
"content", Base64.encodeBase64String(aba.output(0)))))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
Context ctx = new Context();
|
|
|
|
|
ctx.setVariable("date", DateFormatUtils.format(date, "dd-MM-yyyy"));
|
|
|
|
|
ctx.setVariable("abaFiles", abaFileList);
|
|
|
|
|
BigDecimal total = abaFileList.stream().map(ABAFile::getTotalSettleAmount).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
|
|
|
|
|
ctx.setVariable("totalAmount", total.setScale(2, RoundingMode.DOWN).toPlainString());
|
|
|
|
|
final String content = thymeleaf.process("mail/settlement_mail", ctx);
|
|
|
|
|
// 测试用地址
|
|
|
|
|
JSONObject config = sysConfigManager.getSysConfig();
|
|
|
|
|
String mailId = mailService.sendEmail(title, config.getString("settle_mail_to"), config.getString("settle_mail_cc"), content, attachList);
|
|
|
|
|
|
|
|
|
|
JSONObject settleMailRecord = new JSONObject();
|
|
|
|
|
settleMailRecord.put("send_date", new Date());
|
|
|
|
|
settleMailRecord.put("clearing_date", date);
|
|
|
|
|
settleMailRecord.put("email_id", mailId);
|
|
|
|
|
if (StringUtils.isEmpty(mailId)) {
|
|
|
|
|
result.put("result", 1);
|
|
|
|
|
result.put("msg", "System error");
|
|
|
|
|
settleMailRecord.put("mail_status", 0);
|
|
|
|
|
settleMailRecord.put("notice_status", 0);
|
|
|
|
|
logSettleMailMapper.save(settleMailRecord);
|
|
|
|
|
return result;
|
|
|
|
|
} else {
|
|
|
|
|
settleMailRecord.put("mail_status", 1);
|
|
|
|
|
settleMailRecord.put("notice_status", 0);
|
|
|
|
|
logSettleMailMapper.save(settleMailRecord);
|
|
|
|
|
}
|
|
|
|
|
String detailDescription = customizedLogs.stream()
|
|
|
|
|
.map(log -> String.format("[%s]%s-%s", log.getString("log_id"),
|
|
|
|
|
log.getString("client_moniker"), log.getBigDecimal("amount")))
|
|
|
|
|
.collect(Collectors.joining(","));
|
|
|
|
|
sendTaskFinishMessages(ManagerRole.FINANCIAL_STAFF, "人工清算文件已发送清算方:" + detailDescription, "发送清算通知");
|
|
|
|
|
} catch (URISyntaxException | IOException e) {
|
|
|
|
|
logger.error("调用服务发送邮件时错误", e);
|
|
|
|
|
throw new ServerErrorException("IOError", e);
|
|
|
|
|
}
|
|
|
|
|
result.put("result", 0);
|
|
|
|
|
result.put("msg", "已发送");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|