Browse Source

feature: 核酸,体检,押金

wuyongyi 2 năm trước cách đây
mục cha
commit
f429ca7945

+ 22 - 0
src/main/java/com/ywt/mg/params/checkupBooking/QueryCheckUpOrderListRequest.java

@@ -43,6 +43,12 @@ public class QueryCheckUpOrderListRequest extends PageRequest implements Seriali
     @ApiModelProperty(value = "判断医院后台还是公司后台")
     private int hosp;
 
+    @ApiModelProperty(value = "支付渠道", example = "")
+    private String paymentChannel;
+
+    @ApiModelProperty(value = "支付流水号", example = "")
+    private String paymentNo;
+
     public String getOrderNo() {
         return orderNo;
     }
@@ -138,4 +144,20 @@ public class QueryCheckUpOrderListRequest extends PageRequest implements Seriali
     public void setHosp(int hosp) {
         this.hosp = hosp;
     }
+
+    public String getPaymentChannel() {
+        return paymentChannel;
+    }
+
+    public void setPaymentChannel(String paymentChannel) {
+        this.paymentChannel = paymentChannel;
+    }
+
+    public String getPaymentNo() {
+        return paymentNo;
+    }
+
+    public void setPaymentNo(String paymentNo) {
+        this.paymentNo = paymentNo;
+    }
 }

+ 22 - 0
src/main/java/com/ywt/mg/params/natOrder/NatOrderListRequest.java

@@ -60,6 +60,12 @@ public class NatOrderListRequest implements Serializable {
     @ApiModelProperty(value = "对账时间查询截止时间")
     private String billEndTime;
 
+    @ApiModelProperty(value = "支付渠道", example = "")
+    private String paymentChannel;
+
+    @ApiModelProperty(value = "支付流水号", example = "")
+    private String paymentNo;
+
 
     public String getPaymentCode() {
         return paymentCode;
@@ -204,4 +210,20 @@ public class NatOrderListRequest implements Serializable {
     public void setBillEndTime(String billEndTime) {
         this.billEndTime = billEndTime;
     }
+
+    public String getPaymentChannel() {
+        return paymentChannel;
+    }
+
+    public void setPaymentChannel(String paymentChannel) {
+        this.paymentChannel = paymentChannel;
+    }
+
+    public String getPaymentNo() {
+        return paymentNo;
+    }
+
+    public void setPaymentNo(String paymentNo) {
+        this.paymentNo = paymentNo;
+    }
 }

+ 65 - 11
src/main/java/com/ywt/mg/services/CheckUpOrderService.java

@@ -5,6 +5,7 @@ import com.ywt.mg.core.utils.Checker;
 import com.ywt.mg.core.utils.DateUtil;
 import com.ywt.mg.core.utils.FormatUtil;
 import com.ywt.mg.domain.entities.CheckUpOrder;
+import com.ywt.mg.domain.entities.NatOrder;
 import com.ywt.mg.domain.entities.OrderPayment;
 import com.ywt.mg.domain.entities.RefundLog;
 import com.ywt.mg.domain.models.ConstantDef;
@@ -20,10 +21,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service
@@ -89,6 +87,20 @@ public class CheckUpOrderService {
                 paramList.add(hospitalIdInt);
             }
         }
+
+        String paymentChannel = request.getPaymentChannel();
+        if (!Checker.isNone(paymentChannel)) {
+            whereSql += " and ( payment_channel = ? ) ";
+            paramList.add(Integer.parseInt(paymentChannel));
+        }
+
+        String paymentNo = request.getPaymentNo();
+        if (!Checker.isNone(paymentNo)) {
+            whereSql += " and ( payment_no like ? ) ";
+            paramList.add("%" + paymentNo.trim() + "%");
+        }
+
+
         whereSql += "and deleted = 0 ";
 
         // 对账时间搜索
@@ -135,6 +147,7 @@ public class CheckUpOrderService {
             String col0 = "订单号";
             String col1 = "支付流水号";
             String col2 = "交易流水号";
+            String col11 = "支付渠道";
             String col3 = "患者姓名";
             String col4 = "性别";
             String col5 = "就诊ID";
@@ -144,7 +157,7 @@ public class CheckUpOrderService {
             String col9 = "支付时间";
             String col10 = "医院";
 
-            String[] columns = new String[]{col0, col1, col2, col3, col4, col5, col6, col7, col8, col9, col10};
+            String[] columns = new String[]{col0, col1, col2, col11, col3, col4, col5, col6, col7, col8, col9, col10};
             List<CheckUpOrder> list = queryCheckUpOrderListCommon(request);
             List<OrderPayment> orderPaymentList = orderPaymentService.getOrderPaymentListByCheckUpOrderList(list);
             ExcelDataMap map = new ExcelDataMap(columns);
@@ -171,13 +184,14 @@ public class CheckUpOrderService {
                         if (Checker.getIntegerValue(p.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()) {
                             refundTotal += Checker.getIntegerValue(p.getAmount());
                         }
-
+                        String paymentChannel = PaymentChannelEnum.getDisplayName(Checker.getIntegerValue(p.getPaymentChannel()));
                         // "订单号", "支付流水号", "交易流水号", "患者姓名", "性别", "就诊ID", "登记号", "金额", "支付状态", "支付时间"
 //                        String[] bodyStr = new String[]{orderNoValue, paymentNoValue, transactionId, patientNameValue, sexValue, admIdValue, regNoValue, amountValue, paymentStatusValue, paymentTimeValue, hospitalName};
                         // 写入excel的body
                         map.getStringListSafely(col0).add(orderNoValue);
                         map.getStringListSafely(col1).add(paymentNoValue);
                         map.getStringListSafely(col2).add(transactionId);
+                        map.getStringListSafely(col11).add(paymentChannel);
                         map.getStringListSafely(col3).add(patientNameValue);
                         map.getStringListSafely(col4).add(sexValue);
                         map.getStringListSafely(col5).add(admIdValue);
@@ -191,7 +205,7 @@ public class CheckUpOrderService {
                 }
             }
             int size = list.size();
-            List<ExcelCollectPojo> itemList = getStatisticsData(size, payTotal, refundTotal);
+            List<ExcelCollectPojo> itemList = getStatisticsData(size, payTotal, refundTotal, list);
             downloadRecordService.createFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map, itemList, size);
 
         } catch (Exception e) {
@@ -208,14 +222,54 @@ public class CheckUpOrderService {
      * @param refundTotal 退款金额
      * @return {@link List<ExcelCollectPojo> }
      */
-    private List<ExcelCollectPojo> getStatisticsData(int size, int payTotal, int refundTotal) {
+    private List<ExcelCollectPojo> getStatisticsData(int size, int payTotal, int refundTotal, List<CheckUpOrder> itemList) {
         int startRows = size + 3;
         int startColumn = 3;
 
         List<ExcelCollectPojo> customExcelItemList = new ArrayList<>();
-        customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows + 1, new String[]{"支付总额", FormatUtil.intShrink100ToStr(payTotal)}));
-        customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows + 2, new String[]{"退款总额", FormatUtil.intShrink100ToStr(refundTotal)}));
-        customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows + 3, new String[]{"实际支付金额", FormatUtil.intShrink100ToStr(payTotal - refundTotal)}));
+        customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows , new String[]{"支付总额", FormatUtil.intShrink100ToStr(payTotal)}));
+        customExcelItemList.add(new ExcelCollectPojo(startColumn + 3, startRows , new String[]{"退款总额", FormatUtil.intShrink100ToStr(refundTotal)}));
+        customExcelItemList.add(new ExcelCollectPojo(startColumn + 5, startRows , new String[]{"实际支付金额", FormatUtil.intShrink100ToStr(payTotal - refundTotal)}));
+
+//        startRows += 1;
+
+        if (!Checker.isNone(itemList)) {
+            List<Integer> integerList =  itemList.stream().map(CheckUpOrder::getPaymentChannel).collect(Collectors.toList());
+            integerList = integerList.stream().filter(p -> !Checker.isNone(p)).collect(Collectors.toList());
+            // 去重
+
+//            for (CheckUpOrder o : itemList){
+//                int payChannel = Checker.getIntegerValue(o.getPaymentChannel());
+//                integerList.add(payChannel);
+//            }
+            // 去重
+
+            List<CheckUpOrder> paymentList = itemList;
+            List<CheckUpOrder> refundList = itemList;
+
+
+            paymentList = paymentList.stream().filter(p -> Checker.getIntegerValue(p.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()).collect(Collectors.toList());
+            refundList = refundList.stream().filter(p -> Checker.getIntegerValue(p.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()).collect(Collectors.toList());
+
+
+            if (!Checker.isNone(integerList)) {
+                List<Integer> paymentChannelList = new ArrayList<Integer>(new TreeSet<Integer>(integerList));
+                if (!Checker.isNone(paymentChannelList)) {
+                    for (int i = 0, j = paymentChannelList.size(); i < j; i++) {
+                        int paymentChannel = paymentChannelList.get(i).intValue();
+                        if (paymentChannel <= 0) continue;
+                        startRows += 1;
+                        String paymentChannelName = PaymentChannelEnum.getDisplayName(paymentChannel);
+                        // 按支付渠道统计
+                        int paymentAmount = paymentList.stream().filter(p -> Checker.getIntegerValue(p.getPaymentChannel()) == paymentChannel).mapToInt(CheckUpOrder::getAmount).sum();
+                        int refundAmount = refundList.stream().filter(p -> Checker.getIntegerValue(p.getPaymentChannel()) == paymentChannel).mapToInt(CheckUpOrder::getAmount).sum();
+                        customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows, new String[]{paymentChannelName + "支付总额", FormatUtil.intShrink100ToStr(paymentAmount)}));
+                        customExcelItemList.add(new ExcelCollectPojo(startColumn + 3, startRows, new String[]{paymentChannelName + "退款总额", FormatUtil.intShrink100ToStr(refundAmount)}));
+                        customExcelItemList.add(new ExcelCollectPojo(startColumn + 5, startRows, new String[]{paymentChannelName + "实际支付金额", FormatUtil.intShrink100ToStr(paymentAmount - refundAmount)}));
+                    }
+                }
+            }
+        }
         return customExcelItemList;
     }
 

+ 106 - 13
src/main/java/com/ywt/mg/services/DepositService.java

@@ -2,25 +2,26 @@ package com.ywt.mg.services;
 
 import com.ywt.mg.core.PagedList;
 import com.ywt.mg.core.SqlHelper;
-import com.ywt.mg.core.utils.*;
+import com.ywt.mg.core.utils.Checker;
+import com.ywt.mg.core.utils.DateUtil;
+import com.ywt.mg.core.utils.FormatUtil;
+import com.ywt.mg.core.utils.PaymentChannelUtil;
 import com.ywt.mg.domain.entities.OrderPayment;
 import com.ywt.mg.domain.models.ConstantDef;
 import com.ywt.mg.domain.models.ExcelDataMap;
+import com.ywt.mg.domain.models.enums.PaymentChannelEnum;
 import com.ywt.mg.domain.models.enums.PaymentStatusEnum;
 import com.ywt.mg.domain.models.enums.TerminalEnum;
 import com.ywt.mg.domain.models.pojo.ExcelCollectPojo;
 import com.ywt.mg.params.deposit.DepositOrderInfo;
 import com.ywt.mg.params.deposit.QueryDepositListRequest;
-import com.ywt.mg.params.offline.DownloadOfflineListNewRequest;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
 @Service
 public class DepositService {
@@ -152,6 +153,7 @@ public class DepositService {
                         col11};
             }
             PagedList<DepositOrderInfo> list = queryDepositPageList(request);
+            Map<String, Integer> statisticalDataMap = new HashMap<>();
             ExcelDataMap map = new ExcelDataMap(columns);
             if (!Checker.isNone(list.getItems())) {
                 // 得到支付的记录日志(需要从 order_payment 获取 transaction_id 字段)
@@ -203,7 +205,7 @@ public class DepositService {
 ////                            p.getPatientMobile(), p.getCardNo(), amount, paymentChannel, paymentStatus, paymentTime};
 //                    }
 //                }
-                map = setExcelDataMap(orderPaymentList, list, map, hospitalId, hosp, request,
+                map = setExcelDataMap(orderPaymentList, list, map, hospitalId, hosp, request, statisticalDataMap,
                         col0,
                         col1,
                         col2,
@@ -222,7 +224,7 @@ public class DepositService {
                         request.setPageIndex(i);
                         list = queryDepositPageList(request);
                         orderPaymentList = orderPaymentService.getOrderPaymentListByDepositList(list.getItems());
-                        map = setExcelDataMap(orderPaymentList, list, map, hospitalId, hosp, request,
+                        map = setExcelDataMap(orderPaymentList, list, map, hospitalId, hosp, request, statisticalDataMap,
                                 col0,
                                 col1,
                                 col2,
@@ -241,7 +243,7 @@ public class DepositService {
 
             }
             int total = list.getTotal();
-            List<ExcelCollectPojo> itemList = new ArrayList<>();
+            List<ExcelCollectPojo> itemList = getStatisticsData(total, statisticalDataMap);
             downloadRecordService.createFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map, itemList, total);
         } catch (Exception e) {
             logger.error("/deposit/downloadDepositList(): {}", e.getMessage(), e);
@@ -266,7 +268,7 @@ public class DepositService {
         }
     }
 
-    private ExcelDataMap setExcelDataMap(List<OrderPayment> orderPaymentList, PagedList<DepositOrderInfo> list, ExcelDataMap map, int hospitalId, int hosp, QueryDepositListRequest request,
+    private ExcelDataMap setExcelDataMap(List<OrderPayment> orderPaymentList, PagedList<DepositOrderInfo> list, ExcelDataMap map, int hospitalId, int hosp, QueryDepositListRequest request, Map<String, Integer> statisticalDataMap,
                                          String col0,
                                          String col1,
                                          String col2,
@@ -325,6 +327,34 @@ public class DepositService {
 //                    String[] bodyStr = new String[]{p.getOrderNo(), p.getPaymentNo(), transactionId, hospitalName, terminal, p.getPatientName(),
 //                            p.getPatientMobile(), p.getCardNo(), amount, paymentChannel, paymentStatus, paymentTime};
             }
+            OrderPayment orderPayment = orderPaymentList.stream().filter(o -> o.getOrderId().intValue() == p.getOrderId().intValue()).findFirst().orElse(null);
+            int paymentChannelInt = orderPaymentService.getPaymentChannelIntByOrderPayment(orderPayment);
+//            int payTotal = statisticalDataMap.getOrDefault(),
+//                    refundTotal = 0;
+            String payKeyPrefix = "payTotal_", refundKeyPrefix = "refundTotal_";
+            String payKey = payKeyPrefix + paymentChannelInt;
+            String totalKey = "payTotal_" + 0;
+            String refundKey = refundKeyPrefix + paymentChannelInt;
+            int payValue = statisticalDataMap.getOrDefault(payKey, 0);
+            int payTotal = statisticalDataMap.getOrDefault(totalKey, 0);
+            int refundValue = statisticalDataMap.getOrDefault(refundKey, 0);
+            int amountInt = Checker.getIntegerValue(p.getAmount());
+            if (Checker.getIntegerValue(p.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()) {
+                payTotal += amountInt;
+                payValue += amountInt;
+                statisticalDataMap.put(payKey, payValue);
+                statisticalDataMap.put(totalKey, payTotal);
+            }
+
+            //押金没有退款功能
+//            refundTotal += 0;
+            refundValue += 0;
+            statisticalDataMap.put(refundKey, refundValue);
+//            if ((Checker.getIntegerValue(p.getS) & ConsultStatusEnum.Refund.getValue()) == ConsultStatusEnum.Refund.getValue()) {
+//                refundTotal += amountInt;
+//                refundValue += amountInt;
+//                statisticalDataMap.put(refundKey, refundValue);
+//            }
         }
         return map;
     }
@@ -342,23 +372,26 @@ public class DepositService {
 
             PagedList<DepositOrderInfo> depositPageList = queryDepositPageList(request);
             ExcelDataMap map = new ExcelDataMap(columns);
+
+            Map<String, Integer> statisticalDataMap = new HashMap<>();
             if (!Checker.isNone(depositPageList)) {
                 // 得到支付的记录日志(需要从 order_payment 获取 transaction_id 字段)
                 List<OrderPayment> orderPaymentList = orderPaymentService.getOrderPaymentListByDepositOrderInfoList(depositPageList.getItems());
                 int size = depositPageList.getTotalPage();
-                map = setBillDeposit(request, depositPageList, orderPaymentList, map,
+                map = setBillDeposit(request, depositPageList, orderPaymentList, map, statisticalDataMap,
                         col0,
                         col1,
                         col2,
                         col3,
                         col4,
                         col5);
+
                 if (size > 1) {
                     for (int i = 2; i <= size; i++) {
                         request.setPageIndex(i);
                         depositPageList = queryDepositPageList(request);
                         orderPaymentList = orderPaymentService.getOrderPaymentListByDepositList(depositPageList.getItems());
-                        map = setBillDeposit(request, depositPageList, orderPaymentList, map,
+                        map = setBillDeposit(request, depositPageList, orderPaymentList, map, statisticalDataMap,
                                 col0,
                                 col1,
                                 col2,
@@ -370,7 +403,7 @@ public class DepositService {
 
             }
             int total = depositPageList.getTotal();
-            List<ExcelCollectPojo> itemList = new ArrayList<>();
+            List<ExcelCollectPojo> itemList = getStatisticsData(total, statisticalDataMap);
             downloadRecordService.createFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map, itemList, total);
         } catch (Exception e) {
             logger.error("/deposit/downloadDepositBillList(): {}", e.getMessage(), e);
@@ -381,7 +414,7 @@ public class DepositService {
 
         private ExcelDataMap setBillDeposit (QueryDepositListRequest
         request, PagedList < DepositOrderInfo > depositPageList, List < OrderPayment > orderPaymentList, ExcelDataMap
-        map,
+        map, Map<String, Integer> statisticalDataMap,
                 String col0,
                 String col1,
                 String col2,
@@ -420,6 +453,29 @@ public class DepositService {
                         map.getStringListSafely(col4).add(orderNo);
                         map.getStringListSafely(col5).add(typeStr);
 
+//                        OrderPayment orderPayment = orderPaymentList.stream().filter(o -> o.getOrderId().intValue() == p.getOrderId().intValue()).findFirst().orElse(null);
+                        int paymentChannelInt = orderPaymentService.getPaymentChannelIntByOrderPayment(orderPayment);
+//            int payTotal = statisticalDataMap.getOrDefault(),
+//                    refundTotal = 0;
+                        String payKeyPrefix = "payTotal_", refundKeyPrefix = "refundTotal_";
+                        String payKey = payKeyPrefix + paymentChannelInt;
+                        String totalKey = "payTotal_" + 0;
+                        String refundKey = refundKeyPrefix + paymentChannelInt;
+                        int payValue = statisticalDataMap.getOrDefault(payKey, 0);
+                        int payTotal = statisticalDataMap.getOrDefault(totalKey, 0);
+                        int refundValue = statisticalDataMap.getOrDefault(refundKey, 0);
+                        int amountInt = Checker.getIntegerValue(p.getAmount());
+                        if (Checker.getIntegerValue(p.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()) {
+                            payTotal += amountInt;
+                            payValue += amountInt;
+                            statisticalDataMap.put(payKey, payValue);
+                            statisticalDataMap.put(totalKey, payTotal);
+                        }
+
+
+                        refundValue += 0;
+                        statisticalDataMap.put(refundKey, refundValue);
+
                     }
                 }
             }
@@ -427,4 +483,41 @@ public class DepositService {
 
         }
 
+
+    private List<ExcelCollectPojo> getStatisticsData(int size, Map<String, Integer> statisticalDataMap) {
+
+        int startRows = size + 3;
+        int startColumn = 3;
+
+
+        List<ExcelCollectPojo> customExcelItemList = new ArrayList<>();
+
+        String totalKey = "payTotal_" + 0;
+        String payKeyPrefix = "payTotal_";
+        int payTotal = statisticalDataMap.getOrDefault(totalKey, 0);
+        int refundTotal = 0;
+        customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows, new String[]{"支付总额", FormatUtil.intShrink100ToStr(payTotal)}));
+        customExcelItemList.add(new ExcelCollectPojo(startColumn + 3, startRows, new String[]{"退款总额", FormatUtil.intShrink100ToStr(refundTotal)}));
+        customExcelItemList.add(new ExcelCollectPojo(startColumn + 5, startRows, new String[]{"实际支付金额", FormatUtil.intShrink100ToStr(payTotal - refundTotal)}));
+        startRows += 1;
+
+
+        for (PaymentChannelEnum enumValue : PaymentChannelEnum.values()) {
+            int enumValueValue = enumValue.getValue();
+            if (enumValueValue < 0) continue;
+            int payValue = Checker.getIntegerValue(statisticalDataMap.get(payKeyPrefix + enumValueValue));
+            if (payValue != 0 && enumValueValue != 0) {
+                String payChannelStr = enumValue.getDisplayName();
+
+                customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows, new String[]{payChannelStr + "支付总额", FormatUtil.intShrink100ToStr(payValue)}));
+                customExcelItemList.add(new ExcelCollectPojo(startColumn + 3, startRows, new String[]{payChannelStr + "退款总额", FormatUtil.intShrink100ToStr(refundTotal)}));
+                customExcelItemList.add(new ExcelCollectPojo(startColumn + 5, startRows, new String[]{payChannelStr + "实际支付金额", FormatUtil.intShrink100ToStr(payValue - refundTotal)}));
+                startRows += 1;
+            }
+
+        }
+
+        return customExcelItemList;
     }
+
+}

+ 78 - 12
src/main/java/com/ywt/mg/services/NatOrderService.java

@@ -1,7 +1,10 @@
 package com.ywt.mg.services;
 
 import com.ywt.mg.core.SqlHelper;
-import com.ywt.mg.core.utils.*;
+import com.ywt.mg.core.utils.Checker;
+import com.ywt.mg.core.utils.DateUtil;
+import com.ywt.mg.core.utils.FormatUtil;
+import com.ywt.mg.core.utils.IdCardUtil;
 import com.ywt.mg.domain.entities.NatOrder;
 import com.ywt.mg.domain.entities.OrderPayment;
 import com.ywt.mg.domain.entities.RefundLog;
@@ -9,7 +12,6 @@ import com.ywt.mg.domain.models.ConstantDef;
 import com.ywt.mg.domain.models.ExcelDataMap;
 import com.ywt.mg.domain.models.enums.*;
 import com.ywt.mg.domain.models.pojo.ExcelCollectPojo;
-import com.ywt.mg.params.deposit.QueryDepositListRequest;
 import com.ywt.mg.params.natOrder.NatOrderListRequest;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -17,10 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service
@@ -104,6 +103,18 @@ public class NatOrderService {
             paramList.add(Integer.parseInt(paymentStatus));
         }
 
+        String paymentChannel = request.getPaymentChannel();
+        if (!Checker.isNone(paymentChannel)) {
+            whereSql += " and ( payment_channel = ? ) ";
+            paramList.add(Integer.parseInt(paymentChannel));
+        }
+
+        String paymentNo = request.getPaymentNo();
+        if (!Checker.isNone(paymentNo)) {
+            whereSql += " and ( payment_no like ? ) ";
+            paramList.add("%" + paymentNo.trim() + "%");
+        }
+
         String orderStatus = Checker.getStringValue(request.getOrderStatus());
         if (!Checker.isNull(orderStatus)) {
             int orderStatusInt = Integer.parseInt(orderStatus);
@@ -175,6 +186,8 @@ public class NatOrderService {
             List<NatOrder> list = queryNatOrderList(request);
             int payTotal = 0, refundTotal = 0, realityTotal = 0;
             List<OrderPayment> orderPaymentList = orderPaymentService.getOrderPaymentListByNatOrderList(list);
+            Map<String, Integer> statisticalDataMap = new HashMap<>();
+            ;
             for (NatOrder item : list) {
                 // 交易流水号
                 String transactionId = orderPaymentService.getTransactionIdByOrderId(orderPaymentList, Checker.getIntegerValue(item.getOrderId()));
@@ -212,9 +225,18 @@ public class NatOrderService {
                 if (Checker.getIntegerValue(item.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()) {
                     refundTotal += Checker.getIntegerValue(item.getAmount());
                 }
+
+//                int paymentChannelInt = Checker.getIntegerValue(item.getPaymentChannel());
+//                String payKeyPrefix = "payTotal_", refundKeyPrefix = "refundTotal_";
+//                String payKey = payKeyPrefix + paymentChannelInt;
+////                String totalKey = "payTotal_" + 0;
+//                String refundKey = refundKeyPrefix + paymentChannelInt;
+//                int payValue = statisticalDataMap.getOrDefault(payKey, 0);
+//                int refundValue = statisticalDataMap.getOrDefault(refundKey, 0);
+
             }
             int size = list.size();
-            List<ExcelCollectPojo> itemList = getStatisticsData(size, payTotal, refundTotal);
+            List<ExcelCollectPojo> itemList = getStatisticsData(size, payTotal, refundTotal, list);
             downloadRecordService.createFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map, itemList, size);
 
         } catch (Exception e) {
@@ -223,14 +245,51 @@ public class NatOrderService {
         }
     }
 
-    private List<ExcelCollectPojo> getStatisticsData(int size, int payTotal, int refundTotal) {
+    private List<ExcelCollectPojo> getStatisticsData(int size, int payTotal, int refundTotal, List<NatOrder> itemList) {
+
+
         int startRows = size + 3;
         int startColumn = 3;
 
         List<ExcelCollectPojo> customExcelItemList = new ArrayList<>();
-        customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows + 1, new String[]{"支付总额", FormatUtil.intShrink100ToStr(payTotal)}));
-        customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows + 2, new String[]{"退款总额", FormatUtil.intShrink100ToStr(refundTotal)}));
-        customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows + 3, new String[]{"实际支付金额", FormatUtil.intShrink100ToStr(payTotal - refundTotal)}));
+        customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows , new String[]{"支付总额", FormatUtil.intShrink100ToStr(payTotal)}));
+        customExcelItemList.add(new ExcelCollectPojo(startColumn + 3, startRows, new String[]{"退款总额", FormatUtil.intShrink100ToStr(refundTotal)}));
+        customExcelItemList.add(new ExcelCollectPojo(startColumn + 5, startRows, new String[]{"实际支付金额", FormatUtil.intShrink100ToStr(payTotal - refundTotal)}));
+
+
+        if (!Checker.isNone(itemList)) {
+
+            List<Integer> integerList = itemList.stream().map(NatOrder::getPaymentChannel).collect(Collectors.toList());
+            integerList = integerList.stream().filter(p -> !Checker.isNone(p)).collect(Collectors.toList());
+            // 去重
+
+            List<NatOrder> paymentList = itemList;
+            List<NatOrder> refundList = itemList;
+
+
+            paymentList = paymentList.stream().filter(p -> Checker.getIntegerValue(p.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()).collect(Collectors.toList());
+            refundList = refundList.stream().filter(p -> Checker.getIntegerValue(p.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()).collect(Collectors.toList());
+
+
+            if (!Checker.isNone(integerList)) {
+                List<Integer> paymentChannelList = new ArrayList<Integer>(new TreeSet<Integer>(integerList));
+                if (!Checker.isNone(paymentChannelList)) {
+                    for (int i = 0, j = paymentChannelList.size(); i < j; i++) {
+                        int paymentChannel = paymentChannelList.get(i).intValue();
+                        if (paymentChannel <= 0) continue;
+                        startRows += 1;
+                        String paymentChannelName = PaymentChannelEnum.getDisplayName(paymentChannel);
+                        // 按支付渠道统计
+                        int paymentAmount = paymentList.stream().filter(p -> Checker.getIntegerValue(p.getPaymentChannel()) == paymentChannel).mapToInt(NatOrder::getAmount).sum();
+                        int refundAmount = refundList.stream().filter(p -> Checker.getIntegerValue(p.getPaymentChannel()) == paymentChannel).mapToInt(NatOrder::getAmount).sum();
+                        customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows, new String[]{paymentChannelName + "支付总额", FormatUtil.intShrink100ToStr(paymentAmount)}));
+                        customExcelItemList.add(new ExcelCollectPojo(startColumn + 3, startRows, new String[]{paymentChannelName + "退款总额", FormatUtil.intShrink100ToStr(refundAmount)}));
+                        customExcelItemList.add(new ExcelCollectPojo(startColumn + 5, startRows, new String[]{paymentChannelName + "实际支付金额", FormatUtil.intShrink100ToStr(paymentAmount - refundAmount)}));
+                    }
+                }
+            }
+        }
+
         return customExcelItemList;
     }
 
@@ -245,6 +304,7 @@ public class NatOrderService {
             String[] columns = new String[]{col0, col1, col2, col3, col4, col5};
             List<NatOrder> natOrderList = queryNatOrderList(request);
             ExcelDataMap map = new ExcelDataMap(columns);
+            int payTotal = 0, refundTotal = 0, realityTotal = 0;
             if(!Checker.isNone(natOrderList)){
                 List<OrderPayment> orderPaymentList = orderPaymentService.getOrderPaymentListByNatOrderList(natOrderList);
                 // 得到退款的记录日志(需要从 refund_log 获取 refund_id 字段)
@@ -279,6 +339,9 @@ public class NatOrderService {
                             map.getStringListSafely(col3).add(paymentTimeStr);
                             map.getStringListSafely(col4).add(orderNo);
                             map.getStringListSafely(col5).add(typeStr);
+                            if (Checker.getIntegerValue(p.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()) {
+                                payTotal += Checker.getIntegerValue(p.getAmount());
+                            }
 
                         }
                     }
@@ -309,12 +372,15 @@ public class NatOrderService {
                             map.getStringListSafely(col4).add(orderNo);
                             map.getStringListSafely(col5).add(typeName);
 
+                            if (Checker.getIntegerValue(p.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()) {
+                                refundTotal += Checker.getIntegerValue(p.getAmount());
+                            }
                         }
                     }
                 }
             }
             int size = natOrderList.size();
-            List<ExcelCollectPojo> itemList = new ArrayList<>();
+            List<ExcelCollectPojo> itemList = getStatisticsData(size, payTotal, refundTotal, natOrderList);
             downloadRecordService.createFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map, itemList, size);
         } catch (Exception e) {
             e.printStackTrace();

+ 7 - 0
src/main/java/com/ywt/mg/services/OrderPaymentService.java

@@ -246,4 +246,11 @@ public class OrderPaymentService extends ServiceBase {
         }
         return "";
     }
+
+    public int getPaymentChannelIntByOrderPayment(OrderPayment orderPayment) {
+        if (orderPayment != null && !Checker.isNone(orderPayment.getPaymentChannel())) {
+            return orderPayment.getPaymentChannel();
+        }
+        return PaymentChannelEnum.UNKNOWN.getValue();
+    }
 }