From c5059d5917e7afef715f29e391b30555e1d9da24 Mon Sep 17 00:00:00 2001 From: yuan <1551130722@qq.com> Date: Thu, 21 Jun 2018 18:45:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=A4=E6=98=93=E9=A2=9D?= =?UTF-8?q?=E5=91=A8=E6=9C=9F=E6=80=A7=E5=AF=B9=E6=AF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impls/AreaMerchantTradeAnalysisImpl.java | 175 +++++++++++++++--- .../CustomerAndOrdersStatisticsMapper.java | 2 + .../mappers/TransactionAnalysisMapper.java | 2 + .../CustomerAndOrdersStatisticsMapper.xml | 42 ++++- .../mappers/TransactionAnalysisMapper.xml | 33 +++- 5 files changed, 229 insertions(+), 25 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/AreaMerchantTradeAnalysisImpl.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/AreaMerchantTradeAnalysisImpl.java index f68b05a02..704a82249 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/AreaMerchantTradeAnalysisImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/AreaMerchantTradeAnalysisImpl.java @@ -23,7 +23,12 @@ import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.OutputStream; +import java.math.BigDecimal; +import java.text.NumberFormat; import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; /** * Created by yuan on 2018/6/5. @@ -68,13 +73,21 @@ public class AreaMerchantTradeAnalysisImpl implements AreaMerchantTradeAnalysis{ JSONObject params = queryBean.toParams(); orgManager.checkOrgIds(manager,params); PageList clientAmount = null; + List clientAmountLastCycle = null; + if(params.containsKey("begin") && params.containsKey("end")){ if (params.getDate("end").after(new Date()) && params.getDate("begin").compareTo(DateUtils.addDays(params.getDate("end"), -1))==0){ clientAmount = transactionAnalysisMapper.getAreaMerchantAmountAnalysis(params,new PageBounds()); + clientAmountLastCycle = transactionAnalysisMapper.getAreaMerchantAmountByCycle(params); }else { clientAmount = customerAndOrdersStatisticsMapper.getAreaMerchantTradeAnalysis(params,new PageBounds()); + clientAmountLastCycle = customerAndOrdersStatisticsMapper.getAreaMerchantTradeByLastCycle(params); } } + Map cycleMap = clientAmountLastCycle.stream().collect( + Collectors.toMap(cylce -> cylce.getString("client_moniker"), cylce -> cylce)); + List allAmount = clientAmount.stream().map(amount -> {return toAmount(cycleMap.get(amount.getString("client_moniker")), amount);}).collect(Collectors.toList()); + HSSFWorkbook workbook = new HSSFWorkbook(); // 声明一个工作薄 // 生成一个表格 @@ -111,6 +124,33 @@ public class AreaMerchantTradeAnalysisImpl implements AreaMerchantTradeAnalysis{ font2.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); // 把字体应用到当前的样式 style2.setFont(font2); + + HSSFCellStyle style3 = workbook.createCellStyle(); + style3.setFillForegroundColor(HSSFColor.WHITE.index); + style3.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); + style3.setBorderBottom(HSSFCellStyle.BORDER_THIN); + style3.setBorderLeft(HSSFCellStyle.BORDER_THIN); + style3.setBorderRight(HSSFCellStyle.BORDER_THIN); + style3.setBorderTop(HSSFCellStyle.BORDER_THIN); + style3.setAlignment(HSSFCellStyle.ALIGN_CENTER); + HSSFFont font3 = workbook.createFont(); + font3.setFontHeightInPoints((short) 12); + font3.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); + font3.setColor(HSSFColor.RED.index); + style3.setFont(font3); + HSSFCellStyle style4 = workbook.createCellStyle(); + style4.setFillForegroundColor(HSSFColor.WHITE.index); + style4.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); + style4.setBorderBottom(HSSFCellStyle.BORDER_THIN); + style4.setBorderLeft(HSSFCellStyle.BORDER_THIN); + style4.setBorderRight(HSSFCellStyle.BORDER_THIN); + style4.setBorderTop(HSSFCellStyle.BORDER_THIN); + style4.setAlignment(HSSFCellStyle.ALIGN_CENTER); + HSSFFont font4 = workbook.createFont(); + font4.setFontHeightInPoints((short) 12); + font4.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); + font4.setColor(HSSFColor.GREEN.index); + style4.setFont(font4); HSSFRow row0 = sheet.createRow(0); HSSFCell cell00 = row0.createCell(0); HSSFCell cell01 = row0.createCell(1); @@ -124,6 +164,9 @@ public class AreaMerchantTradeAnalysisImpl implements AreaMerchantTradeAnalysis{ HSSFCell cell09 = row0.createCell(9); HSSFCell cell10 = row0.createCell(10); HSSFCell cell11 = row0.createCell(11); + HSSFCell cell12 = row0.createCell(12); + HSSFCell cell13 = row0.createCell(13); + HSSFCell cell14 = row0.createCell(14); cell00.setCellStyle(style); cell01.setCellStyle(style); cell02.setCellStyle(style); @@ -136,6 +179,9 @@ public class AreaMerchantTradeAnalysisImpl implements AreaMerchantTradeAnalysis{ cell09.setCellStyle(style); cell10.setCellStyle(style); cell11.setCellStyle(style); + cell12.setCellStyle(style); + cell13.setCellStyle(style); + cell14.setCellStyle(style); HSSFRichTextString text00 = new HSSFRichTextString("Partner Code"); HSSFRichTextString text01 = new HSSFRichTextString("Short name"); @@ -144,11 +190,14 @@ public class AreaMerchantTradeAnalysisImpl implements AreaMerchantTradeAnalysis{ HSSFRichTextString text04 = new HSSFRichTextString("Suburb"); HSSFRichTextString text05 = new HSSFRichTextString("Industry"); HSSFRichTextString text06 = new HSSFRichTextString("Amount"); - HSSFRichTextString text07 = new HSSFRichTextString("Orders"); - HSSFRichTextString text08 = new HSSFRichTextString("Alipay Amount"); - HSSFRichTextString text09 = new HSSFRichTextString("Alipay Orders"); - HSSFRichTextString text10 = new HSSFRichTextString("Wechat Amount"); - HSSFRichTextString text11 = new HSSFRichTextString("Wechat Orders"); + HSSFRichTextString text07 = new HSSFRichTextString("Last Cycle"); + HSSFRichTextString text08 = new HSSFRichTextString("Orders"); + HSSFRichTextString text09 = new HSSFRichTextString("Alipay Amount"); + HSSFRichTextString text10 = new HSSFRichTextString("Last Cycle"); + HSSFRichTextString text11 = new HSSFRichTextString("Alipay Orders"); + HSSFRichTextString text12 = new HSSFRichTextString("Wechat Amount"); + HSSFRichTextString text13 = new HSSFRichTextString("Last Cycle"); + HSSFRichTextString text14 = new HSSFRichTextString("Wechat Orders"); cell00.setCellValue(text00); cell01.setCellValue(text01); cell02.setCellValue(text02); @@ -161,10 +210,13 @@ public class AreaMerchantTradeAnalysisImpl implements AreaMerchantTradeAnalysis{ cell09.setCellValue(text09); cell10.setCellValue(text10); cell11.setCellValue(text11); + cell12.setCellValue(text12); + cell13.setCellValue(text13); + cell14.setCellValue(text14); JSONObject sysConfig = sysConfigManager.getSysConfig(); String json = sysConfig.getString("royalpayindustry.json"); JSONArray jsonArray = JSONObject.parseArray(json); - for (int i = 0; i < clientAmount.size(); i++) { + for (int i = 0; i < allAmount.size(); i++) { HSSFRow row = sheet.createRow(i + 1); HSSFCell cell0 = row.createCell(0); HSSFCell cell1 = row.createCell(1); @@ -178,6 +230,9 @@ public class AreaMerchantTradeAnalysisImpl implements AreaMerchantTradeAnalysis{ HSSFCell cell9 = row.createCell(9); HSSFCell cel10 = row.createCell(10); HSSFCell cel11 = row.createCell(11); + HSSFCell cel12 = row.createCell(12); + HSSFCell cel13 = row.createCell(13); + HSSFCell cel14 = row.createCell(14); cell0.setCellStyle(style2); cell1.setCellStyle(style2); cell2.setCellStyle(style2); @@ -185,24 +240,94 @@ public class AreaMerchantTradeAnalysisImpl implements AreaMerchantTradeAnalysis{ cell4.setCellStyle(style2); cell5.setCellStyle(style2); cell6.setCellStyle(style2); - cell7.setCellStyle(style2); cell8.setCellStyle(style2); cell9.setCellStyle(style2); - cel10.setCellStyle(style2); cel11.setCellStyle(style2); - String industry = getRoyalpayIindustry(clientAmount.get(i).getString("royalpayindustry"),jsonArray); - HSSFRichTextString text0 = new HSSFRichTextString(clientAmount.get(i).getString("client_moniker")); - HSSFRichTextString text1 = new HSSFRichTextString(clientAmount.get(i).getString("short_name")); - HSSFRichTextString text2 = new HSSFRichTextString(clientAmount.get(i).getString("bd_user_name")); - HSSFRichTextString text3 = new HSSFRichTextString(clientAmount.get(i).getString("state")); - HSSFRichTextString text4 = new HSSFRichTextString(clientAmount.get(i).getString("suburb")); + cel12.setCellStyle(style2); + cel14.setCellStyle(style2); + JSONObject thisAmount =clientAmount.get(i); + NumberFormat percent = NumberFormat.getPercentInstance(); + BigDecimal lastTotal = new BigDecimal(1); + BigDecimal alipayTotal = new BigDecimal(1); + BigDecimal wechatToatl = new BigDecimal(1); + + if(thisAmount.containsKey("old_total")){ + if(thisAmount.getBigDecimal("total").compareTo(BigDecimal.ZERO)==0){ + lastTotal = new BigDecimal(-1); + if(thisAmount.getBigDecimal("old_total").compareTo(BigDecimal.ZERO) == 0){ + lastTotal = BigDecimal.ZERO; + } + } + if(thisAmount.getBigDecimal("total").compareTo(BigDecimal.ZERO)>0 && thisAmount.getBigDecimal("old_total").compareTo(BigDecimal.ZERO)>0) { + lastTotal = (thisAmount.getBigDecimal("total").subtract(thisAmount.getBigDecimal("old_total"))).divide(thisAmount.getBigDecimal("old_total"), 4, BigDecimal.ROUND_HALF_UP); + } + }else { + if(thisAmount.getBigDecimal("total").compareTo(BigDecimal.ZERO) == 0){ + lastTotal = BigDecimal.ZERO; + } + } + if(thisAmount.containsKey("old_alipay_total")){ + if(thisAmount.getBigDecimal("alipay_total").compareTo(BigDecimal.ZERO)==0){ + alipayTotal = new BigDecimal(-1); + if(thisAmount.getBigDecimal("old_alipay_total").compareTo(BigDecimal.ZERO) == 0){ + alipayTotal = BigDecimal.ZERO; + } + } + if(thisAmount.getBigDecimal("alipay_total").compareTo(BigDecimal.ZERO)>0 && thisAmount.getBigDecimal("old_alipay_total").compareTo(BigDecimal.ZERO)>0){ + alipayTotal = (thisAmount.getBigDecimal("alipay_total").subtract(thisAmount.getBigDecimal("old_alipay_total"))).divide(thisAmount.getBigDecimal("old_alipay_total"),4,BigDecimal.ROUND_HALF_UP); + } + }else { + if(thisAmount.getBigDecimal("alipay_total").compareTo(BigDecimal.ZERO) == 0){ + alipayTotal = BigDecimal.ZERO; + } + } + + if(thisAmount.containsKey("old_wechat_toatl")){ + if(thisAmount.getBigDecimal("wechat_toatl").compareTo(BigDecimal.ZERO)==0){ + wechatToatl = new BigDecimal(-1); + if(thisAmount.getBigDecimal("old_wechat_toatl").compareTo(BigDecimal.ZERO) == 0){ + wechatToatl = BigDecimal.ZERO; + } + } + if(thisAmount.getBigDecimal("wechat_toatl").compareTo(BigDecimal.ZERO)>0 && thisAmount.getBigDecimal("old_wechat_toatl").compareTo(BigDecimal.ZERO)>0){ + wechatToatl = (thisAmount.getBigDecimal("wechat_toatl").subtract(thisAmount.getBigDecimal("old_wechat_toatl"))).divide(thisAmount.getBigDecimal("old_wechat_toatl"),4,BigDecimal.ROUND_HALF_UP); + } + }else { + if(thisAmount.getBigDecimal("wechat_toatl").compareTo(BigDecimal.ZERO) == 0){ + wechatToatl = BigDecimal.ZERO; + } + } + if(lastTotal.compareTo(BigDecimal.ZERO)>=0){ + cell7.setCellStyle(style4); + }else { + cell7.setCellStyle(style3); + } + if(alipayTotal.compareTo(BigDecimal.ZERO)>=0){ + cel10.setCellStyle(style4); + }else { + cel10.setCellStyle(style3); + } + if(wechatToatl.compareTo(BigDecimal.ZERO)>=0){ + cel13.setCellStyle(style4); + }else { + cel13.setCellStyle(style3); + } + String industry = getRoyalpayIindustry(thisAmount.getString("royalpayindustry"),jsonArray); + HSSFRichTextString text0 = new HSSFRichTextString(thisAmount.getString("client_moniker")); + HSSFRichTextString text1 = new HSSFRichTextString(thisAmount.getString("short_name")); + HSSFRichTextString text2 = new HSSFRichTextString(thisAmount.getString("bd_user_name")); + HSSFRichTextString text3 = new HSSFRichTextString(thisAmount.getString("state")); + HSSFRichTextString text4 = new HSSFRichTextString(thisAmount.getString("suburb")); HSSFRichTextString text5 = new HSSFRichTextString(industry == null?"":industry); - HSSFRichTextString text6 = new HSSFRichTextString(clientAmount.get(i).getString("total")); - HSSFRichTextString text7 = new HSSFRichTextString(clientAmount.get(i).getString("orders")); - HSSFRichTextString text8 = new HSSFRichTextString(clientAmount.get(i).getString("alipay_total")); - HSSFRichTextString text9 = new HSSFRichTextString(clientAmount.get(i).getString("alipay_order")); - HSSFRichTextString text_10 = new HSSFRichTextString(clientAmount.get(i).getString("wechat_toatl")); - HSSFRichTextString text_11 = new HSSFRichTextString(clientAmount.get(i).getString("wechat_order")); + HSSFRichTextString text6 = new HSSFRichTextString(thisAmount.getString("total")); + HSSFRichTextString text7 = new HSSFRichTextString(percent.format(lastTotal.doubleValue())); + HSSFRichTextString text8 = new HSSFRichTextString(thisAmount.getString("orders")); + HSSFRichTextString text9 = new HSSFRichTextString(thisAmount.getString("alipay_total")); + HSSFRichTextString text_10 = new HSSFRichTextString(percent.format(alipayTotal.doubleValue())); + HSSFRichTextString text_11 = new HSSFRichTextString(thisAmount.getString("alipay_order")); + HSSFRichTextString text_12 = new HSSFRichTextString(thisAmount.getString("wechat_toatl")); + HSSFRichTextString text_13 = new HSSFRichTextString(percent.format(wechatToatl.doubleValue())); + HSSFRichTextString text_14 = new HSSFRichTextString(thisAmount.getString("wechat_order")); cell0.setCellValue(text0); cell1.setCellValue(text1); cell2.setCellValue(text2); @@ -215,6 +340,9 @@ public class AreaMerchantTradeAnalysisImpl implements AreaMerchantTradeAnalysis{ cell9.setCellValue(text9); cel10.setCellValue(text_10); cel11.setCellValue(text_11); + cel12.setCellValue(text_12); + cel13.setCellValue(text_13); + cel14.setCellValue(text_14); } JSONObject parmerters = new JSONObject(); parmerters.put("dateFrom", StringUtils.isNotBlank(queryBean.getBegin()) ? queryBean.getBegin() : ""); @@ -232,7 +360,12 @@ public class AreaMerchantTradeAnalysisImpl implements AreaMerchantTradeAnalysis{ e.printStackTrace(); } } - + private JSONObject toAmount(JSONObject cycle, JSONObject amount) { + if(amount != null && cycle!= null){ + amount.putAll(cycle); + } + return amount; + } private String getRoyalpayIindustry(String industryMccCode,JSONArray jsonArray) { String industry = null; for(int i = 0;i getAreaMerchantTradeAnalysis(JSONObject params, PageBounds pageBounds); List countTradedClientsByDate(JSONObject parasm); + + List getAreaMerchantTradeByLastCycle(JSONObject parasm); } diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/mappers/TransactionAnalysisMapper.java b/src/main/java/au/com/royalpay/payment/manage/analysis/mappers/TransactionAnalysisMapper.java index 5d070545f..a60d93f7e 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/mappers/TransactionAnalysisMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/mappers/TransactionAnalysisMapper.java @@ -74,4 +74,6 @@ public interface TransactionAnalysisMapper { JSONObject getClientTransaction(JSONObject params); PageList getAreaMerchantAmountAnalysis(JSONObject params,PageBounds pagination); + + List getAreaMerchantAmountByCycle(JSONObject params); } diff --git a/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/CustomerAndOrdersStatisticsMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/CustomerAndOrdersStatisticsMapper.xml index 8213b5ba3..d97efacef 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/CustomerAndOrdersStatisticsMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/CustomerAndOrdersStatisticsMapper.xml @@ -358,10 +358,15 @@ + + + SELECT c.client_moniker,c.short_name,c.bd_user_name,sum(if(t.transaction_type='Credit',t.clearing_amount,0)) total, COUNT(DISTINCT t.order_id) orders, - c.suburb,c.state,c.royalpayindustry,sum(if(t.channel='Alipay',t.clearing_amount,0)) alipay_total, - sum(if(t.channel='Alipay'AND t.channel='AlipayOnline',1,0)) alipay_order,sum(if(t.channel='Wechat',t.clearing_amount,0)) wechat_toatl, + c.suburb,c.state,c.royalpayindustry,sum(if(t.channel='Alipay' OR t.channel='AlipayOnline',t.clearing_amount,0)) alipay_total, + sum(if(t.channel='Alipay'OR t.channel='AlipayOnline',1,0)) alipay_order,sum(if(t.channel='Wechat',t.clearing_amount,0)) wechat_toatl, sum(if(t.channel='Wechat',1,0)) wechat_order FROM pmt_transactions t INNER JOIN pmt_orders ord on ord.order_id = t.order_id @@ -824,4 +824,33 @@ GROUP BY c.client_id order by total desc + + + \ No newline at end of file