diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/BDAnalysisServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/BDAnalysisServiceImpl.java index 96f113b02..9fadea1d5 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/BDAnalysisServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/BDAnalysisServiceImpl.java @@ -3,6 +3,7 @@ package au.com.royalpay.payment.manage.analysis.core.impls; import au.com.royalpay.payment.manage.analysis.beans.AnalysisBean; import au.com.royalpay.payment.manage.analysis.core.BDAnalysisService; import au.com.royalpay.payment.manage.analysis.mappers.BDAnalysisMapper; +import au.com.royalpay.payment.manage.analysis.mappers.TransactionAnalysisMapper; import au.com.royalpay.payment.manage.mappers.log.StatisticsBDSalesReportMapper; import au.com.royalpay.payment.tools.permission.enums.ManagerRole; import com.alibaba.fastjson.JSONArray; @@ -14,6 +15,7 @@ import org.apache.poi.hssf.usermodel.*; import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.util.CellRangeAddress; +import org.omg.PortableInterceptor.SYSTEM_EXCEPTION; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -40,6 +42,9 @@ public class BDAnalysisServiceImpl implements BDAnalysisService { @Resource private StatisticsBDSalesReportMapper bdSalesReportMapper; + @Resource + private TransactionAnalysisMapper transactionAnalysisMapper; + @Override public List getSalesAnalysis(JSONObject jsonObject) { @@ -59,7 +64,6 @@ public class BDAnalysisServiceImpl implements BDAnalysisService { SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); if (sd.format(jsonObject.getDate("end")).equals(sd.format(DateUtils.addDays(new Date(), 1)))) { jsonObject.put("begin", DateUtils.addDays(jsonObject.getDate("end"), -1)); -// jsonObject.put("end", DateUtils.addDays(jsonObject.getDate("end"), -2)); jsonObject.put("end",jsonObject.getDate("end")); List todaySaleList = bdAnalysisMapper.getBDSaleList(jsonObject); for (JSONObject todayBDSaleItem : todaySaleList) { @@ -194,7 +198,7 @@ public class BDAnalysisServiceImpl implements BDAnalysisService { List bdSaleList = bdAnalysisMapper.getOneDayBDSaleList(params); if (bdSaleList.size() != 0) { for (JSONObject item : bdSaleList) { - JSONObject existBDSalesReport = bdSalesReportMapper.findByBDIdAndLogDate(item.getString("bd_id"),beginTime); + JSONObject existBDSalesReport = bdSalesReportMapper.findByBDIdAndLogDate(item.getString("bd_id"),beginTime,0); if(existBDSalesReport==null){ JSONObject object = new JSONObject(item); object.put("log_id", UUID.randomUUID().toString()); @@ -207,6 +211,24 @@ public class BDAnalysisServiceImpl implements BDAnalysisService { existBDSalesReport.put("net_amount",item.getString("net_amount")); bdSalesReportMapper.update(existBDSalesReport); } + } + } + List orgSaleList= transactionAnalysisMapper.getOneDayOrgMerchantSaleList(params); + if (orgSaleList.size() != 0) { + for (JSONObject item : orgSaleList) { + JSONObject existOrgSalesReport = bdSalesReportMapper.findByBDIdAndLogDate(item.getString("bd_id"),beginTime,1); + if(existOrgSalesReport==null){ + JSONObject object = new JSONObject(item); + object.put("log_id", UUID.randomUUID().toString()); + object.put("log_date", beginTime); + object.put("create_time", new Date()); + bdSalesReportMapper.save(object); + }else{ + existOrgSalesReport.put("pay_amount",item.getString("pay_amount")); + existOrgSalesReport.put("refund_amount",item.getString("refund_amount")); + existOrgSalesReport.put("net_amount",item.getString("net_amount")); + bdSalesReportMapper.update(existOrgSalesReport); + } } } diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/OrgAnalysisServiceImp.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/OrgAnalysisServiceImp.java index af9119612..0d72739be 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/OrgAnalysisServiceImp.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/OrgAnalysisServiceImp.java @@ -52,13 +52,13 @@ public class OrgAnalysisServiceImp implements OrgAnalysisService { if (sd.format(params.getDate("end")).equals(sd.format(DateUtils.addDays(new Date(), 1)))) { params.put("begin", DateUtils.addDays(params.getDate("end"), -1)); params.put("end",params.getDate("end")); - List todayOrgTransaction = transactionAnalysisMapper.getOrgTransactionAnalysis(params); + List todayOrgTransaction = transactionAnalysisMapper.getOneDayOrgMerchantSaleList(params); if(todayOrgTransaction.size()!=0){ for (JSONObject todayOrgTransactionItem : todayOrgTransaction) { boolean flag = false; for (JSONObject orgTransaction : newOrgTransaction) { if (orgTransaction.getString("org_id").equals(todayOrgTransactionItem.getString("org_id"))) { - BigDecimal newAmount = orgTransaction.getBigDecimal("clearing_amount").add(todayOrgTransactionItem.getBigDecimal("amount")); + BigDecimal newAmount = orgTransaction.getBigDecimal("amount").add(todayOrgTransactionItem.getBigDecimal("clearing_amount")); orgTransaction.put("amount", newAmount); flag = true; } 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 bd09a889d..68a6317f3 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 @@ -93,4 +93,6 @@ public interface TransactionAnalysisMapper { * @return */ BigDecimal getCnyAmount(JSONObject params); + + List getOneDayOrgMerchantSaleList(JSONObject params); } diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/log/StatisticsBDSalesReportMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/log/StatisticsBDSalesReportMapper.java index eec5be137..35b7c4693 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/log/StatisticsBDSalesReportMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/log/StatisticsBDSalesReportMapper.java @@ -22,7 +22,7 @@ public interface StatisticsBDSalesReportMapper { List getPartnerAmountList(JSONObject params); - JSONObject findByBDIdAndLogDate(@Param("bd_id") String bd_id, @Param("log_date")Date beginTime); + JSONObject findByBDIdAndLogDate(@Param("bd_id") String bd_id, @Param("log_date")Date beginTime,@Param("isOrg") int isOrg); @AutoSql(type = SqlType.UPDATE) void update(JSONObject existBDSalesReport); diff --git a/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/BDAnalysisMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/BDAnalysisMapper.xml index cc7aca5c2..24e059359 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/BDAnalysisMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/BDAnalysisMapper.xml @@ -9,6 +9,7 @@ ifnull(SUM(if(temp.refund_id IS NOT NULL, if(temp.transaction_type='Debit', temp.clearing_amount, -temp.clearing_amount) * clinetBD.proportion, 0)), 0) refund_fee FROM( SELECT + trans.org_id, trans.client_id, trans.clearing_amount, trans.refund_id, @@ -18,25 +19,28 @@ WHERE (trans.transaction_type = 'Credit' OR trans.refund_id IS NOT NULL) AND trans.system_generate = 0 AND trans.channel !='Settlement' - + AND trans.channel != 'System' + AND trans.create_time >= #{begin} AND trans.create_time < #{end} ) AS temp + + INNER JOIN sys_org AS org + ON org.org_id = temp.org_id + AND org.is_valid = 1 + + AND org.org_id = #{org_id} + + INNER JOIN sys_client_bd AS clinetBD ON temp.client_id = clinetBD.client_id AND clinetBD.start_date <= temp.create_time AND clinetBD.is_valid = '1' AND (clinetBD.end_date IS NULL OR clinetBD.end_date > temp.create_time) - INNER JOIN sys_managers AS manage - ON manage.manager_id = clinetBD.bd_id - - AND manage.org_id = #{org_id} - - GROUP BY clinetBD.bd_id ORDER BY total DESC @@ -199,49 +203,50 @@ SELECT clinetBD.bd_name, clinetBD.bd_id, - manage.org_id, + org.org_id, org.type AS org_type, org.name AS org_name, - if(org.org_id=1,1,0) AS isOrg, - SUM( IF ( temp.transaction_type = 'Credit', temp.clearing_amount, -temp.clearing_amount )) clearing_amount, + 0 AS isOrg, + 0 AS clearing_amount, SUM(if(temp.transaction_type = 'Credit',temp.clearing_amount * clinetBD.proportion, -temp.clearing_amount * clinetBD.proportion)) pay_amount, ifnull(SUM(if(temp.refund_id IS NOT NULL, if(temp.transaction_type='Debit', temp.clearing_amount, -temp.clearing_amount) * clinetBD.proportion, 0)), 0) refund_amount, (SUM(if(temp.transaction_type = 'Credit', temp.clearing_amount * clinetBD.proportion, -temp.clearing_amount * clinetBD.proportion))) - (ifnull(SUM(if(temp.refund_id IS NOT NULL, if(temp.transaction_type='Debit', temp.clearing_amount, -temp.clearing_amount) * clinetBD.proportion, 0)), 0)) AS net_amount FROM( - SELECT - trans.client_id, - trans.clearing_amount, - trans.refund_id, - trans.transaction_type, - trans.create_time - FROM pmt_transactions AS trans - WHERE (trans.transaction_type = 'Credit' OR trans.refund_id IS NOT NULL) - AND trans.system_generate = 0 - AND trans.channel !='Settlement' - - AND trans.create_time >= #{begin} - - - AND trans.create_time < #{end} - - ) + SELECT + trans.org_id, + trans.client_id, + trans.clearing_amount, + trans.refund_id, + trans.transaction_type, + trans.create_time + FROM pmt_transactions AS trans + WHERE (trans.transaction_type = 'Credit' OR trans.refund_id IS NOT NULL) + AND trans.system_generate = 0 + AND trans.channel !='Settlement' + AND trans.channel != 'System' + + AND trans.create_time >= #{begin} + + + AND trans.create_time < #{end} + + ) AS temp - INNER JOIN sys_client_bd AS clinetBD - ON temp.client_id = clinetBD.client_id - AND clinetBD.start_date <= temp.create_time - AND clinetBD.is_valid = '1' - AND (clinetBD.end_date IS NULL OR clinetBD.end_date > temp.create_time) - INNER JOIN sys_managers AS manage - ON manage.manager_id = clinetBD.bd_id - AND manage.org_id IS NOT NULL + INNER JOIN sys_org AS org - ON org.org_id = manage.org_id + ON org.org_id = temp.org_id + AND org.is_valid = 1 AND manage.org_id = #{org_id} + INNER JOIN sys_client_bd AS clinetBD + ON temp.client_id = clinetBD.client_id + AND clinetBD.start_date <= temp.create_time + AND clinetBD.is_valid = '1' + AND (clinetBD.end_date IS NULL OR clinetBD.end_date > temp.create_time) + GROUP BY clinetBD.bd_id ORDER BY pay_amount DESC - diff --git a/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/TransactionAnalysisMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/TransactionAnalysisMapper.xml index 01e1d3351..8e83ce3af 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/TransactionAnalysisMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/TransactionAnalysisMapper.xml @@ -751,7 +751,10 @@ + SELECT + org.org_id AS org_id, + org.name AS org_name, + org.type AS org_type, + 1 AS isOrg, + SUM(IF( trans.transaction_type = 'Credit', trans.clearing_amount, - trans.clearing_amount )) AS clearing_amount, + 0 AS pay_amount, + 0 AS refund_amount, + 0 AS net_amount + FROM + pmt_transactions AS trans + INNER JOIN sys_org AS org ON trans.org_id = org.org_id + AND org.is_valid = 1 + AND org.type = 0 + AND org.citypartner = 1 + AND org.commission = 1 + + WHERE + trans.channel != 'Settlement' + AND trans.channel != 'System' + AND trans.system_generate = 0 + + AND org.org_id = #{org_id} + + + AND trans.create_time >= #{begin} + + + AND trans.create_time < #{end} + + + + GROUP BY + org.org_id + + \ No newline at end of file diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/log/StatisticsBDSalesReportMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/log/StatisticsBDSalesReportMapper.xml index 06acb7ace..f8b574cb2 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/log/StatisticsBDSalesReportMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/log/StatisticsBDSalesReportMapper.xml @@ -10,7 +10,7 @@ SUM(pay_amount) AS total, SUM(refund_amount) AS refund_fee FROM statistics_bd_sales - + WHERE isOrg = 0 AND org_id = #{org_id} @@ -27,7 +27,6 @@ AND org.org_id in #{org_id} - GROUP BY bd_id ORDER BY total DESC @@ -43,7 +42,7 @@ SUM(pay_amount) AS total, SUM(refund_amount) AS refund_fee FROM statistics_bd_sales - WHERE org_id !=1 + WHERE isOrg = 1 AND org_id = #{org_id} @@ -80,7 +79,7 @@ create_time, clearing_amount FROM statistics_bd_sales - WHERE bd_id = #{bd_id} AND log_date = #{log_date} + WHERE bd_id = #{bd_id} AND log_date = #{log_date} AND isOrg = #{isOrg} \ No newline at end of file