From ac75df6ead66ea64abc3c0f0220c0641082c2186 Mon Sep 17 00:00:00 2001 From: yixian Date: Mon, 20 Aug 2018 10:36:07 +0800 Subject: [PATCH] apply interceptor --- .../clearing/core/impl/CleanServiceImpl.java | 8 +- .../manage/support/abafile/ABAFile.java | 6 ++ .../templates/mail/settlement_mail.html | 39 ++++---- .../manage/process/alipay/FixAlipayData.java | 94 +++++++++++++++++++ .../process/custom/ManualReportCustom.java | 54 +++++++++++ 5 files changed, 182 insertions(+), 19 deletions(-) create mode 100644 src/test/java/au/com/royalpay/payment/manage/process/alipay/FixAlipayData.java create mode 100644 src/test/java/au/com/royalpay/payment/manage/process/custom/ManualReportCustom.java diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/CleanServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/CleanServiceImpl.java index 745a34693..b419e9a95 100644 --- a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/CleanServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/CleanServiceImpl.java @@ -943,9 +943,6 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider model.put("date", DateFormatUtils.format(date, "dd-MM-yyyy")); // todo themeleaf - Context ctx = new Context(); - ctx.setVariable("date", DateFormatUtils.format(date, "dd-MM-yyyy")); - final String content = thymeleaf.process("mail/settlement_mail", ctx); // final String content = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, // "mail/settlement_mail.vm", "utf-8", model); @@ -984,6 +981,11 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider } attach2.put("name", fileName2); attachList.add(attach2); + + Context ctx = new Context(); + ctx.setVariable("date", DateFormatUtils.format(date, "dd-MM-yyyy")); + ctx.setVariable("abaFiles", abaFileList); + final String content = thymeleaf.process("mail/settlement_mail", ctx); // 测试用地址 // String mailId = mailService.sendEmail(title, "164851225@qq.com", "1029811920@qq.com", content, // attachList); diff --git a/src/main/java/au/com/royalpay/payment/manage/support/abafile/ABAFile.java b/src/main/java/au/com/royalpay/payment/manage/support/abafile/ABAFile.java index 7c55303b1..b0be420c8 100644 --- a/src/main/java/au/com/royalpay/payment/manage/support/abafile/ABAFile.java +++ b/src/main/java/au/com/royalpay/payment/manage/support/abafile/ABAFile.java @@ -9,6 +9,7 @@ import org.springframework.util.Assert; import java.io.PrintWriter; import java.io.StringWriter; import java.math.BigDecimal; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -56,6 +57,11 @@ public class ABAFile { return out.toString().getBytes(); } + public String getTotalSettleAmountStr() { + DecimalFormat format = new DecimalFormat("#.##0.00"); + return format.format(totalSettleAmount); + } + private String generateFinalLine() { StringBuilder lineBuilder = new StringBuilder(baseLine); lineBuilder.replace(0, 1, "7"); diff --git a/src/main/resources/templates/mail/settlement_mail.html b/src/main/resources/templates/mail/settlement_mail.html index 2646fe311..5ed1b6648 100644 --- a/src/main/resources/templates/mail/settlement_mail.html +++ b/src/main/resources/templates/mail/settlement_mail.html @@ -1,22 +1,29 @@
-

Dear Flexewallet,

-
-
-

Please find the attached settlement files data up to

-
-
-

Best Regards,

-

RoyalPay Finance team

-

Tunnel Show Pty Ltd trading as RoyalPay

-

Representative of AFS Licensee 448066

-

------------------------------

-

Lv.11,15 William Street, Melbourne 3000

-

Lv.14, 383 Kent Street, Sydney, NSW 2000

-

P: 1300 1077 50

-

E: settlement@royalpay.com.au

-

www.royalpay.com.au

+

Dear Flexewallet,

+
+
+

Please find the attached settlement files data up to

+

+

File Validation:

+

+

+

+
+
+

Best Regards,

+

RoyalPay Finance team

+

Tunnel Show Pty Ltd trading as RoyalPay

+

Representative of AFS Licensee 448066

+

------------------------------

+

Lv.11,15 William Street, Melbourne 3000

+

Lv.14, 383 Kent Street, Sydney, NSW 2000

+

P: 1300 1077 50

+

E: settlement@royalpay.com.au

+

www.royalpay.com.au

diff --git a/src/test/java/au/com/royalpay/payment/manage/process/alipay/FixAlipayData.java b/src/test/java/au/com/royalpay/payment/manage/process/alipay/FixAlipayData.java new file mode 100644 index 000000000..e223a5c45 --- /dev/null +++ b/src/test/java/au/com/royalpay/payment/manage/process/alipay/FixAlipayData.java @@ -0,0 +1,94 @@ +package au.com.royalpay.payment.manage.process.alipay; + +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.StringUtils; +import org.apache.poi.openxml4j.exceptions.InvalidFormatException; +import org.apache.poi.ss.usermodel.*; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** + * Create by yixian at 2018-08-14 21:41 + */ +@SpringBootTest +@ActiveProfiles({"proxy"}) +@RunWith(SpringRunner.class) +public class FixAlipayData { + @Resource + private JdbcTemplate jdbcTemplate; + private String fileLocation = "C:\\Users\\yixian\\Documents\\royalpay\\2018\\alipayfix\\2088721525235246_20180815110000000032102003900557154_result - 副本.xls"; + private String fileTarget = "C:\\Users\\yixian\\Documents\\royalpay\\2018\\alipayfix\\fixed_2088721525235246_20180815110000000032102003900557154_result.xls"; + private Logger logger = LoggerFactory.getLogger(getClass()); + + @Test + public void fix() throws IOException, InvalidFormatException { + Workbook wb = WorkbookFactory.create(new File(fileLocation)); + Sheet sheet = wb.getSheetAt(0); + final int startRow = 6; + int rowNum = startRow; + String compName; + while ((compName = mchCompName(sheet, rowNum)) != null) { + logger.info("row:" + rowNum + ",company name=" + compName); + final String corpName = compName; + Row row = sheet.getRow(rowNum++); + String shortName = row.getCell(2).getStringCellValue(); + List> clients = jdbcTemplate.queryForList("select c.company_name,c.short_name,c.ali_sub_merchant_id,c.alipayindustry,c.country,c.address,c.state,l.latitude,l.longitude from sys_clients c" + + " left join sys_clients_locations l on l.client_id=c.client_id where c.short_name=?", shortName); + if (clients.isEmpty()) { + clients = jdbcTemplate.queryForList("select c.company_name,c.short_name,c.ali_sub_merchant_id,c.alipayindustry,c.country,c.address,c.state,l.latitude,l.longitude from sys_clients c" + + " left join sys_clients_locations l on l.client_id=c.client_id where c.company_name=?", corpName); + if (clients.isEmpty()) { + continue; + } + } + Optional> cliOpts = clients.stream() + .filter(cli -> new JSONObject(cli).getString("company_name").equals(corpName)) + .findFirst(); + JSONObject client = new JSONObject(cliOpts.isPresent() ? cliOpts.get() : clients.get(0)); + + String moniker = client.getString("ali_sub_merchant_id"); + logger.info("updating to xlsx:" + moniker); + row.getCell(4).setCellValue(moniker); + row.getCell(5).setCellValue(moniker); + String mcc = client.getString("alipayindustry"); + row.getCell(7).setCellValue(StringUtils.isEmpty(mcc) ? "5311" : mcc); + row.getCell(8).setCellValue("Australia"); + if (StringUtils.isNoneEmpty(client.getString("address"), client.getString("state"))) { + row.getCell(9).setCellValue(client.getString("address") + "," + client.getString("state")); + } + if (client.getString("latitude") != null) { + row.getCell(29).setCellValue(client.getBigDecimal("latitude").setScale(8, BigDecimal.ROUND_DOWN).toPlainString()); + row.getCell(30).setCellValue(client.getBigDecimal("longitude").setScale(8, BigDecimal.ROUND_DOWN).toPlainString()); + } + logger.info("finished update row:" + (rowNum - 1)); + } + wb.write(new FileOutputStream(fileTarget)); + } + + private String mchCompName(Sheet sheet, int rowNum) { + Row row = sheet.getRow(rowNum); + if (row == null) { + return null; + } + Cell cell = row.getCell(1); + if (cell == null) { + return null; + } + return cell.getStringCellValue(); + } +} diff --git a/src/test/java/au/com/royalpay/payment/manage/process/custom/ManualReportCustom.java b/src/test/java/au/com/royalpay/payment/manage/process/custom/ManualReportCustom.java new file mode 100644 index 000000000..4e73e741f --- /dev/null +++ b/src/test/java/au/com/royalpay/payment/manage/process/custom/ManualReportCustom.java @@ -0,0 +1,54 @@ +package au.com.royalpay.payment.manage.process.custom; + +import au.com.royalpay.payment.channels.alipay.runtime.impls.AlipayCustomDeclaringTaskProcessor; +import au.com.royalpay.payment.core.mappers.PmtCustomReportsDetailMapper; +import au.com.royalpay.payment.core.mappers.PmtCustomReportsMapper; +import au.com.royalpay.payment.core.mappers.PmtOrderMapper; +import au.com.royalpay.payment.manage.mappers.custom.CustomReportDetailsMapper; +import au.com.royalpay.payment.manage.mappers.custom.CustomReportsMapper; +import com.alibaba.fastjson.JSONObject; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.util.List; + +/** + * Create by yixian at 2018-08-14 20:28 + */ +@SpringBootTest +@ActiveProfiles({"proxy", "alipay"}) +@TestPropertySource(properties = {"spring.datasource.username=root", "spring.datasource.password=ZOIBhellor0yalpay"}) +@RunWith(SpringRunner.class) +public class ManualReportCustom { + + @Autowired + private AlipayCustomDeclaringTaskProcessor processor; + @Resource + private PmtCustomReportsMapper pmtCustomReportsMapper; + @Resource + private PmtOrderMapper pmtOrderMapper; + @Resource + private PmtCustomReportsDetailMapper pmtCustomReportsDetailMapper; + + @Test + public void test() { + String reportId = "05482201808142036430702208"; + List customs = pmtCustomReportsMapper.findReport(reportId); + List sub = pmtCustomReportsDetailMapper.listSubReports(reportId); + JSONObject order = pmtOrderMapper.find(reportId); + + JSONObject task = new JSONObject(); + task.put("channel", order.getString("channel")); + task.put("merchant_id", order.getString("merchant_id")); + task.put("sub_orders", sub); + task.put("report", customs.stream().filter(rep -> rep.getIntValue("report_status") == 2) + .findFirst().orElseThrow(() -> new RuntimeException("No Failure Reports"))); + processor.process(task); + } +}