From 4ea0eafdffa68cf735d9e5911e88fa207ead8ea9 Mon Sep 17 00:00:00 2001 From: luoyang Date: Wed, 11 Mar 2020 13:43:16 +0800 Subject: [PATCH 01/12] add partner tarde clientMoniker shortName --- .../ui/static/payment/tradelog/templates/balance_report.html | 4 ++++ .../static/payment/tradelog/templates/partner_trade_logs.html | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/main/ui/static/payment/tradelog/templates/balance_report.html b/src/main/ui/static/payment/tradelog/templates/balance_report.html index 168f8dbec..344e0591c 100644 --- a/src/main/ui/static/payment/tradelog/templates/balance_report.html +++ b/src/main/ui/static/payment/tradelog/templates/balance_report.html @@ -489,6 +489,8 @@ + + @@ -507,6 +509,8 @@ + + + + @@ -607,6 +609,8 @@ + +
Client MonikerShort Name Date/Time Description Currency
Client MonikerShort Name Client Order ID Order ID Amount
Date: Wed, 11 Mar 2020 15:06:46 +0800 Subject: [PATCH 02/12] =?UTF-8?q?fix=20=E5=A2=9E=E5=8A=A0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E8=B4=A6=E5=8F=B7leoh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../manage/appclient/core/impls/RetailRSvcServiceImpl.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 597eeb11a..9246a3a01 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ 4.0.0 manage - 1.3.94 + 1.3.95 UTF-8 1.8.0 diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailRSvcServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailRSvcServiceImpl.java index 1e220b6c3..52a213a94 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailRSvcServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailRSvcServiceImpl.java @@ -48,7 +48,9 @@ public class RetailRSvcServiceImpl implements RetailRSvcService { String clientType = device.getString("client_type"); deviceSupport.findRegister(clientType); JSONObject clientConfig = clientConfigMapper.find(device.getIntValue("client_id")); - if (!debug && !clientConfig.getBooleanValue("geek_shop_status") && device.getIntValue("client_id") != 9) { + if (!debug && !clientConfig.getBooleanValue("geek_shop_status") + && device.getIntValue("client_id") != 9 + && device.getIntValue("client_id") != 4181) { throw new NotFoundException(); } JSONObject svcInfo = commonIncrementalChannelMapper.findIncreamentalChannelBySourceCode(sourceCode); From 6efe8ce301dd52f31772c506a7e7db1f05ac038d Mon Sep 17 00:00:00 2001 From: luoyang Date: Wed, 11 Mar 2020 15:28:50 +0800 Subject: [PATCH 03/12] =?UTF-8?q?add=20=E5=95=86=E6=88=B7=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E9=85=8D=E7=BD=AE=20hide=5Fmch=5Fdevice=20?= =?UTF-8?q?=E9=9A=90=E8=97=8F=E8=AE=BE=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../manage/merchants/core/impls/ClientManagerImpl.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9246a3a01..6d12444c0 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ 4.0.0 manage - 1.3.95 + 1.3.96 UTF-8 1.8.0 diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java index aee9245cc..8814fd540 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java @@ -2684,6 +2684,10 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid checkOrgPermission(manager, client); JSONObject params = new JSONObject(); params.put("client_id", client.getIntValue("client_id")); + JSONObject mchConfig = merchantInfoProvider.getMchExtParams(client.getIntValue("client_id")); + if (mchConfig.getBooleanValue("hide_mch_device")) { + return new JSONObject(); + } if (remark != null) { params.put("remark", remark); } @@ -2707,6 +2711,10 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid throw new InvalidShortIdException(); } checkOrgPermission(null, client); + JSONObject mchConfig = merchantInfoProvider.getMchExtParams(client.getIntValue("client_id")); + if (mchConfig.getBooleanValue("hide_mch_device")) { + return new JSONObject(); + } JSONObject params = new JSONObject(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); sdf.setTimeZone(TimeZone.getTimeZone(client.getString("timezone") != null ? client.getString("timezone") : "Australia/Melbourne")); From 386b748ff45cd228e5d4db1771c65596f0975ce4 Mon Sep 17 00:00:00 2001 From: yixian Date: Thu, 12 Mar 2020 14:10:06 +0800 Subject: [PATCH 04/12] feat(settle report): download settle report excel from ui --- .../clearing/core/CleanService.java | 3 + .../clearing/core/impl/CleanServiceImpl.java | 38 ++++ .../clearing/web/SettlementDevController.java | 15 +- .../mappers/log/ClearingDetailMapper.java | 2 + .../manage/support/poi/CellStyleFactory.java | 56 ++++++ .../manage/support/poi/ExcelFileBuilder.java | 72 +++++++ .../manage/support/poi/ExcelTemplate.java | 186 ++++++++++++++++++ .../manage/support/poi/FontFactory.java | 36 ++++ .../payment/manage/support/poi/PoiUtils.java | 75 +++++++ .../mappers/log/ClearingDetailMapper.xml | 31 +++ src/main/ui/static/analysis/clearing-log.js | 8 + .../analysis/templates/settlement_detail.html | 3 + .../templates/settlement_send_check_code.html | 51 ++--- 13 files changed, 550 insertions(+), 26 deletions(-) create mode 100644 src/main/java/au/com/royalpay/payment/manage/support/poi/CellStyleFactory.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/support/poi/ExcelFileBuilder.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/support/poi/ExcelTemplate.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/support/poi/FontFactory.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/support/poi/PoiUtils.java diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/CleanService.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/CleanService.java index 254ef3f7d..7b7f180d3 100644 --- a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/CleanService.java +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/CleanService.java @@ -3,6 +3,7 @@ package au.com.royalpay.payment.manage.management.clearing.core; import au.com.royalpay.payment.manage.support.abafile.ABAFile; import au.com.royalpay.payment.manage.tradelog.beans.ClearingLogQuery; import com.alibaba.fastjson.JSONObject; +import org.springframework.core.io.ByteArrayResource; import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletResponse; @@ -94,4 +95,6 @@ public interface CleanService { void lockClearingLog(Date date, int clearingId); void undoSettle(Date date, int clearingId); + + ByteArrayResource downloadBatchSettleReportXlsx(int batchId); } 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 620238f22..2b372ee3f 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 @@ -17,6 +17,9 @@ 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.support.abafile.SettleRemarkTemplateDescriber; +import au.com.royalpay.payment.manage.support.poi.ExcelFileBuilder; +import au.com.royalpay.payment.manage.support.poi.ExcelTemplate; +import au.com.royalpay.payment.manage.support.poi.FontFactory; import au.com.royalpay.payment.manage.tradelog.beans.ClearingLogQuery; import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApi; import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApiProvider; @@ -59,6 +62,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisherAware; +import org.springframework.core.io.ByteArrayResource; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.format.number.CurrencyStyleFormatter; import org.springframework.stereotype.Service; @@ -1357,6 +1361,40 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider clearingLogMapper.deleteSettleLogs(clearingId); } + @Override + public ByteArrayResource downloadBatchSettleReportXlsx(int batchId) { + List mchList = clearingDetailMapper.batchReport(batchId); + if (mchList.isEmpty()) { + throw new NotFoundException("No batch found"); + } + ExcelTemplate template = new ExcelTemplate() + .addSheet("Report") + .addStringColumn("client_moniker").setFontFactory(new FontFactory(true)).ok() + .addStringColumn("short_name").ok() + .addStringColumn("org_name").ok() + .addStringColumn("bd_user_name").ok() + .addStringColumn("city").ok() + .addStringColumn("clean_days").ok() + .addColumn(Cell.CELL_TYPE_NUMERIC, "clearing_amount", json -> json.getBigDecimal("clearing_amount").setScale(2, RoundingMode.DOWN).toPlainString()).setCellStyle(ExcelTemplate.STYLE_RIGHT).ok() + .addDateColumn("yyyy-MM-dd", "settle_date_from").ok() + .addDateColumn("yyyy-MM-dd", "settle_date_to").ok() + .build(); + ExcelFileBuilder builder = new ExcelFileBuilder(template); + builder.bindSingleSheetData(mchList); + try (ByteArrayOutputStream bout = new ByteArrayOutputStream()) { + builder.build(bout); + bout.flush(); + return new ByteArrayResource(bout.toByteArray()) { + @Override + public String getFilename() { + return "settle_report_" + DateFormatUtils.format(mchList.get(0).getDate("report_date"), "yyyyMMdd") + "_" + batchId + ".xlsx"; + } + }; + } catch (IOException e) { + throw new RuntimeException("Export excel failed", e); + } + } + private void releaseDistributedSurcharge(JSONObject clearingDetail) { int clientId = clearingDetail.getIntValue("client_id"); BigDecimal distributedSurcharge = clearingDetail.getBigDecimal("distributed_surcharge"); diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/SettlementDevController.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/SettlementDevController.java index 03a392d5b..287d38b07 100644 --- a/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/SettlementDevController.java +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/SettlementDevController.java @@ -4,10 +4,12 @@ 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.permission.manager.RequireManager; 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; +import au.com.royalpay.payment.tools.permission.enums.ManagerRole; import com.alibaba.fastjson.JSONObject; +import org.springframework.core.io.ByteArrayResource; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -148,7 +150,7 @@ public class SettlementDevController { return cleanService.findLogSettleByDate(dt); } - @RequestMapping("/reports/{date}/settlement_aba") + @GetMapping("/reports/{date}/settlement_aba") public void getSettlementABA(@PathVariable String date, HttpServletResponse resp) throws IOException { try { Date dt = dateFormat.parse(date); @@ -158,12 +160,17 @@ public class SettlementDevController { } } - @RequestMapping("/settle_batches/{batchId}/settle_files") + @GetMapping("/settle_batches/{batchId}/settle_files") public void getSettlementFilesForBatch(@PathVariable String batchId, HttpServletResponse resp) throws IOException { cleanService.getSettlementFilesForBatch(batchId, resp); } - @RequestMapping("/details/{detailId}") + @GetMapping("/settle_batches/{batchId}/settle_report_xlsx") + public ByteArrayResource getSettlementReportForBatch(@PathVariable int batchId) { + return cleanService.downloadBatchSettleReportXlsx(batchId); + } + + @GetMapping("/details/{detailId}") public JSONObject settlementDetail(@PathVariable int detailId, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { return cleanService.getCleanLogTransactions(detailId, manager); } diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/log/ClearingDetailMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/log/ClearingDetailMapper.java index 0d2a4b4a8..89a8d9953 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/log/ClearingDetailMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/log/ClearingDetailMapper.java @@ -49,4 +49,6 @@ public interface ClearingDetailMapper { @AutoSql(type = SqlType.DELETE) void deleteSettleLogs(@Param("clearing_id") int clearingId); + + List batchReport(@Param("clearing_id") int clearingId); } diff --git a/src/main/java/au/com/royalpay/payment/manage/support/poi/CellStyleFactory.java b/src/main/java/au/com/royalpay/payment/manage/support/poi/CellStyleFactory.java new file mode 100644 index 000000000..fc50524ea --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/support/poi/CellStyleFactory.java @@ -0,0 +1,56 @@ +package au.com.royalpay.payment.manage.support.poi; + +import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.Font; +import org.apache.poi.ss.usermodel.Workbook; + +/** + * Create by davep at 2020-03-12 13:27 + */ +public class CellStyleFactory { + private final short borderTop; + private final short borderBottom; + private final short borderLeft; + private final short borderRight; + private final short align; + private final short valign; + + public CellStyleFactory(short borderTop, short borderBottom, short borderLeft, short borderRight, short align, short valign) { + this.borderTop = borderTop; + this.borderBottom = borderBottom; + this.borderLeft = borderLeft; + this.borderRight = borderRight; + this.align = align; + this.valign = valign; + } + + public CellStyleFactory(short borderTopBottom, short borderLeftRight, short align, short valign) { + this(borderTopBottom, borderTopBottom, borderLeftRight, borderLeftRight, align, valign); + } + + public CellStyleFactory(short border, short align, short valign) { + this(border, border, align, valign); + } + + public CellStyleFactory(short border, short align) { + this(border, border, align, CellStyle.VERTICAL_CENTER); + } + + public CellStyle buildCellStyle(Workbook workbook, Font font) { + CellStyle style = workbook.createCellStyle(); + style.setBorderBottom(borderBottom); + style.setBorderRight(borderRight); + style.setBorderLeft(borderLeft); + style.setBorderTop(borderTop); + style.setAlignment(align); + style.setVerticalAlignment(valign); + if (font != null) { + style.setFont(font); + } + return style; + } + + public CellStyle buildCellStyle(Workbook workbook) { + return buildCellStyle(workbook, null); + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/support/poi/ExcelFileBuilder.java b/src/main/java/au/com/royalpay/payment/manage/support/poi/ExcelFileBuilder.java new file mode 100644 index 000000000..b63e14efe --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/support/poi/ExcelFileBuilder.java @@ -0,0 +1,72 @@ +package au.com.royalpay.payment.manage.support.poi; + + +import com.alibaba.fastjson.JSONObject; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Create by davep at 2020-03-12 11:59 + */ +public class ExcelFileBuilder { + private ExcelTemplate template; + private Map> sheetsData; + private boolean blocked = false; + + public ExcelFileBuilder(ExcelTemplate template) { + this.template = template; + this.sheetsData = new HashMap<>(); + } + + public ExcelFileBuilder bindData(String sheetName, List data) { + checkBlock(); + if (template.hasSheet(sheetName)) { + sheetsData.put(sheetName, data); + } else { + throw new IllegalArgumentException("Sheet name '" + sheetName + "' not exists"); + } + return this; + } + + public void checkBlock() { + if (blocked) { + throw new IllegalStateException("Builder blocked"); + } + } + + public ExcelFileBuilder bindSingleSheetData(List data) { + if (template.getSheets().size() == 1) { + String name = new ArrayList<>(template.getSheets().keySet()).get(0); + bindData(name, data); + } else { + throw new IllegalArgumentException("There are more than one sheet"); + } + return this; + } + + public void build(OutputStream out) { + blocked = true; + try (Workbook workbook = new XSSFWorkbook()) { + Map sheetTpls = template.getSheets(); + for (Map.Entry sheetTpl : sheetTpls.entrySet()) { + Sheet sheet = workbook.createSheet(sheetTpl.getKey()); + List data = sheetsData.get(sheetTpl.getKey()); + if (data == null) { + continue; + } + sheetTpl.getValue().buildSheet(sheet, data); + } + workbook.write(out); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/support/poi/ExcelTemplate.java b/src/main/java/au/com/royalpay/payment/manage/support/poi/ExcelTemplate.java new file mode 100644 index 000000000..c7ca5f24c --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/support/poi/ExcelTemplate.java @@ -0,0 +1,186 @@ +package au.com.royalpay.payment.manage.support.poi; + +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.time.DateFormatUtils; +import org.apache.poi.ss.usermodel.*; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * Create by davep at 2020-03-12 11:59 + */ +public class ExcelTemplate { + public static final CellStyleFactory STYLE_LEFT = new CellStyleFactory(CellStyle.BORDER_MEDIUM, CellStyle.ALIGN_LEFT); + public static final CellStyleFactory STYLE_RIGHT = new CellStyleFactory(CellStyle.BORDER_MEDIUM, CellStyle.ALIGN_RIGHT); + private Map sheets; + + public ExcelTemplate() { + this.sheets = new LinkedHashMap<>(); + } + + public SheetTemplate addSheet(String name) { + SheetTemplate sheetTpl = new SheetTemplate(this, name); + sheets.put(name, sheetTpl); + return sheetTpl; + } + + protected Map getSheets() { + return sheets; + } + + protected boolean hasSheet(String sheetName) { + return sheets.containsKey(sheetName); + } + + public static class SheetTemplate { + private ExcelTemplate parent; + private String name; + private List columns; + + private SheetTemplate(ExcelTemplate parent, String name) { + this.parent = parent; + this.name = name; + this.columns = new ArrayList<>(); + } + + public ExcelTemplate build() { + return parent; + } + + public SheetTemplate newSheet(String name) { + return parent.addSheet(name); + } + + public ColumnTemplate addColumn(int columnType, String name, ValueProvider provider) { + ColumnTemplate col = new ColumnTemplate(this, name, columnType, provider); + columns.add(col); + return col; + } + + public ColumnTemplate addDateColumn(String pattern, String name) { + return addDateColumn(pattern, name, name); + } + + public ColumnTemplate addDateColumn(String pattern, String name, String key) { + return this.addColumn(Cell.CELL_TYPE_STRING, name, json -> DateFormatUtils.format(json.getDate(key), pattern)); + } + + public ColumnTemplate addNumberColumn(String name) { + return this.addNumberColumn(name, name); + } + + public ColumnTemplate addNumberColumn(String name, String key) { + return this.addColumn(Cell.CELL_TYPE_NUMERIC, name, json -> json.getString(key)); + } + + public ColumnTemplate addStringColumn(String name) { + return this.addStringColumn(name, name); + } + + public ColumnTemplate addStringColumn(String name, String key) { + return this.addColumn(Cell.CELL_TYPE_STRING, name, json -> json.getString(key)); + } + + public ColumnTemplate addAutoTypeColumn(String name, ValueProvider provider) { + ColumnTemplate col = new ColumnTemplate(this, name, null, provider); + columns.add(col); + return col; + } + + protected String getName() { + return name; + } + + protected List getColumns() { + return columns; + } + + public void buildSheet(Sheet sheet, List data) { + int rowNum = 0; + Row titleRow = sheet.createRow(rowNum); + rowNum++; + Workbook workbook = sheet.getWorkbook(); + Font boldFont = PoiUtils.initBoldFont(workbook); + CellStyle titleStyle = new CellStyleFactory(CellStyle.BORDER_MEDIUM, CellStyle.ALIGN_CENTER).buildCellStyle(workbook, boldFont); + for (int i = 0, len = columns.size(); i < len; i++) { + ColumnTemplate col = columns.get(i); + Cell cell = titleRow.createCell(i, Cell.CELL_TYPE_STRING); + cell.setCellStyle(titleStyle); + cell.setCellValue(col.name); + } + for (JSONObject item : data) { + Row dataRow = sheet.createRow(rowNum); + rowNum++; + for (int i = 0, len = columns.size(); i < len; i++) { + ColumnTemplate col = columns.get(i); + col.buildCell(dataRow, i, item); + } + } + } + } + + public static class ColumnTemplate { + private SheetTemplate parent; + private String name; + private ValueProvider valueProvider; + private Integer columnType; + private CellStyleFactory cellStyle; + private FontFactory fontFactory; + + public ColumnTemplate(SheetTemplate parent, String name, Integer columnType, ValueProvider valueProvider) { + this.parent = parent; + this.name = name; + this.columnType = columnType; + this.valueProvider = valueProvider; + } + + public ColumnTemplate setCellStyle(CellStyleFactory cellStyle) { + this.cellStyle = cellStyle; + return this; + } + + public SheetTemplate ok() { + return parent; + } + + protected void buildCell(Row row, int columnNum, JSONObject data) { + Object value = valueProvider.getValue(data); + if (value == null) { + row.createCell(columnNum, Cell.CELL_TYPE_BLANK); + return; + } + if (columnType == null) { + columnType = PoiUtils.convertCellType(value.getClass()); + } + CellStyle style = initCellStyle(row.getSheet().getWorkbook(), columnType); + Cell cell = row.createCell(columnNum, columnType); + cell.setCellStyle(style); + PoiUtils.setCellValue(cell, value); + } + + private CellStyle initCellStyle(Workbook workbook, Integer columnType) { + Font font = fontFactory != null ? fontFactory.buildFont(workbook) : null; + if (cellStyle == null) { + if (columnType == Cell.CELL_TYPE_NUMERIC || this.columnType == Cell.CELL_TYPE_BOOLEAN) { + return STYLE_RIGHT.buildCellStyle(workbook, font); + } else { + return STYLE_LEFT.buildCellStyle(workbook, font); + } + } else { + return cellStyle.buildCellStyle(workbook, font); + } + } + + public ColumnTemplate setFontFactory(FontFactory fontFactory) { + this.fontFactory = fontFactory; + return this; + } + } + + public interface ValueProvider { + T getValue(JSONObject item); + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/support/poi/FontFactory.java b/src/main/java/au/com/royalpay/payment/manage/support/poi/FontFactory.java new file mode 100644 index 000000000..676270686 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/support/poi/FontFactory.java @@ -0,0 +1,36 @@ +package au.com.royalpay.payment.manage.support.poi; + +import org.apache.poi.ss.usermodel.Font; +import org.apache.poi.ss.usermodel.Workbook; + +/** + * Create by davep at 2020-03-12 13:27 + */ +public class FontFactory { + private boolean bold; + private short color; + private boolean italic; + + public FontFactory(boolean bold, short color, boolean italic) { + this.bold = bold; + this.color = color; + this.italic = italic; + } + + public FontFactory(boolean bold, boolean italic) { + this(bold, Font.COLOR_NORMAL, italic); + } + + public FontFactory(boolean bold) { + this(bold, false); + } + + public Font buildFont(Workbook workbook) { + Font font = workbook.createFont(); + font.setBold(bold); + font.setColor(color); + font.setItalic(italic); + return font; + } + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/support/poi/PoiUtils.java b/src/main/java/au/com/royalpay/payment/manage/support/poi/PoiUtils.java new file mode 100644 index 000000000..cf491faf4 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/support/poi/PoiUtils.java @@ -0,0 +1,75 @@ +package au.com.royalpay.payment.manage.support.poi; + +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.Font; +import org.apache.poi.ss.usermodel.Workbook; + +import java.time.temporal.ChronoUnit; +import java.time.temporal.Temporal; +import java.time.temporal.TemporalField; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * Create by davep at 2020-03-12 12:43 + */ +public class PoiUtils { + private static final Map, Class> PRIMITIVE_CLASSES = new HashMap<>(); + + static { + PRIMITIVE_CLASSES.put(boolean.class, Boolean.class); + PRIMITIVE_CLASSES.put(byte.class, Byte.class); + PRIMITIVE_CLASSES.put(short.class, Short.class); + PRIMITIVE_CLASSES.put(char.class, Character.class); + PRIMITIVE_CLASSES.put(int.class, Integer.class); + PRIMITIVE_CLASSES.put(long.class, Long.class); + PRIMITIVE_CLASSES.put(float.class, Float.class); + PRIMITIVE_CLASSES.put(double.class, Double.class); + PRIMITIVE_CLASSES.put(void.class, Void.class); + } + + public static Font initBoldFont(Workbook workbook) { + Font font = workbook.createFont(); + font.setBold(true); + return font; + } + + + public static int convertCellType(Class valueClass) { + if (valueClass.isPrimitive()) { + valueClass = PRIMITIVE_CLASSES.get(valueClass); + } + if (Number.class.isAssignableFrom(valueClass)) { + return Cell.CELL_TYPE_NUMERIC; + } + if (Date.class.isAssignableFrom(valueClass) || Temporal.class.isAssignableFrom(valueClass)) { + return Cell.CELL_TYPE_NUMERIC; + } + if (Boolean.class.isAssignableFrom(valueClass)) { + return Cell.CELL_TYPE_BOOLEAN; + } + return Cell.CELL_TYPE_STRING; + } + + public static void setCellValue(Cell cell, Object value) { + Class valueClass = value.getClass(); + if (valueClass.isPrimitive()) { + valueClass = PRIMITIVE_CLASSES.get(valueClass); + } + if (Number.class.isAssignableFrom(valueClass)) { + cell.setCellValue((double) value); + return; + } + if (Date.class.isAssignableFrom(valueClass)) { + cell.setCellValue(((Date) value).getTime() / 1000); + return; + } + if (Boolean.class.isAssignableFrom(valueClass)) { + cell.setCellValue((boolean) value); + return; + } + cell.setCellValue(value.toString()); + } +} diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/log/ClearingDetailMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/log/ClearingDetailMapper.xml index cd6d3e435..8170880c7 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/log/ClearingDetailMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/log/ClearingDetailMapper.xml @@ -86,4 +86,35 @@ and report_date <= #{end} + \ No newline at end of file diff --git a/src/main/ui/static/analysis/clearing-log.js b/src/main/ui/static/analysis/clearing-log.js index ab22ba781..ab825af23 100644 --- a/src/main/ui/static/analysis/clearing-log.js +++ b/src/main/ui/static/analysis/clearing-log.js @@ -503,6 +503,14 @@ define(['angular', 'decimal', 'uiBootstrap', 'uiRouter', 'angularEcharts'], func }; 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.config = {mark_sent: true}; $scope.switchSendFlag=function(info){ info.send=!info.send diff --git a/src/main/ui/static/analysis/templates/settlement_detail.html b/src/main/ui/static/analysis/templates/settlement_detail.html index 3e8a67a2e..34cfedcad 100644 --- a/src/main/ui/static/analysis/templates/settlement_detail.html +++ b/src/main/ui/static/analysis/templates/settlement_detail.html @@ -159,6 +159,9 @@ Download Files + + Download Settle Report + diff --git a/src/main/ui/static/analysis/templates/settlement_send_check_code.html b/src/main/ui/static/analysis/templates/settlement_send_check_code.html index fe998b758..60fab4250 100644 --- a/src/main/ui/static/analysis/templates/settlement_send_check_code.html +++ b/src/main/ui/static/analysis/templates/settlement_send_check_code.html @@ -2,36 +2,43 @@

Send Settlement Email