Browse Source

feature:押金,耗材,处方

wuyongyi 2 years ago
parent
commit
1d8da4b5de

+ 5 - 3
src/main/java/com/ywt/mg/services/DepositService.java

@@ -440,10 +440,12 @@ public class DepositService {
                         String type = ConstantDef.BILL_PAYMENT_STR;
                         // 交易流水号
                         String transactionId = "";
+                        transactionId = Checker.getStringValue(orderPaymentService.getTransactionIdByOrderId(orderPaymentList, Checker.getIntegerValue(p.getOrderId())));
                         OrderPayment orderPayment = orderPaymentList.stream().filter(o -> o.getOrderId().intValue() == p.getOrderId().intValue()).findFirst().orElse(null);
-                        if (orderPayment != null && !Checker.isNone(orderPayment.getTransactionId())) {
-                            transactionId = Checker.getStringValue(orderPayment.getTransactionId());
-                        }
+//                        if (orderPayment != null && !Checker.isNone(orderPayment.getTransactionId())) {
+//                            transactionId = Checker.getStringValue(orderPayment.getTransactionId());
+//                        }
+
                         // 交易金额
                         String totalStr = FormatUtil.intShrink100ToStr(p.getAmount());
                         // 交易时间

+ 56 - 44
src/main/java/com/ywt/mg/services/NatOrderService.java

@@ -219,24 +219,27 @@ public class NatOrderService {
                 map.getStringListSafely(col16).add(FormatUtil.createTimeFormatDetail(item.getConfirmTime()));
                 map.getStringListSafely(col17).add(Checker.getStringValue(item.getRemark()));
 
+                int payChanelInt = Checker.getIntegerValue(item.getPaymentChannel());
+
+                String payKey = ConstantDef.PAY_KEY_PREFIX + payChanelInt;
+                String refundKey = ConstantDef.REFUND_KEY_PREFIX + payChanelInt;
+                int payValue = statisticalDataMap.getOrDefault(payKey, 0);
+                int refundValue = statisticalDataMap.getOrDefault(refundKey, 0);
+                int amountInt = Checker.getIntegerValue(item.getAmount());
                 if (Checker.getIntegerValue(item.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()) {
-                    payTotal += Checker.getIntegerValue(item.getAmount());
+                    payTotal += amountInt;
+                    payValue += amountInt;
+                    statisticalDataMap.put(payKey, payValue);
                 }
                 if (Checker.getIntegerValue(item.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()) {
-                    refundTotal += Checker.getIntegerValue(item.getAmount());
+                    refundTotal += amountInt;
+                    refundValue += amountInt;
+                    statisticalDataMap.put(refundKey, refundValue);
                 }
 
-//                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);
+            List<ExcelCollectPojo> itemList = getStatisticsData(size, payTotal, refundTotal, statisticalDataMap);
             downloadRecordService.createFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map, itemList, size);
 
         } catch (Exception e) {
@@ -245,41 +248,30 @@ public class NatOrderService {
         }
     }
 
-    private List<ExcelCollectPojo> getStatisticsData(int size, int payTotal, int refundTotal, List<NatOrder> itemList) {
+    private List<ExcelCollectPojo> getStatisticsData(int size, int payTotal, int refundTotal, Map<String, Integer> statisticalDataMap) {
         int startRows = size + 3;
-        int startColumn = 3;
+        int startColumn = 0;
 
         List<ExcelCollectPojo> customExcelItemList = new ArrayList<>();
-        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)}));
-                    }
+        customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows + 1, new String[]{"支付总额", FormatUtil.intShrink100ToStr(payTotal)}));
+        customExcelItemList.add(new ExcelCollectPojo(startColumn + 3, startRows + 1, new String[]{"退款总额", FormatUtil.intShrink100ToStr(refundTotal)}));
+        customExcelItemList.add(new ExcelCollectPojo(startColumn + 5, startRows + 1, new String[]{"实际支付总额", FormatUtil.intShrink100ToStr(payTotal - refundTotal)}));
+        PaymentChannelEnum[] paymentChannelList = PaymentChannelEnum.values();
+        if (!Checker.isNone(paymentChannelList)) {
+            for (int i = 0, j = paymentChannelList.length; i < j; i++) {
+                int paymentChannel = paymentChannelList[i].getValue();
+                if (paymentChannel <= 0) continue;
+                String paymentChannelName = paymentChannelList[i].getDisplayName();
+                String payKey = ConstantDef.PAY_KEY_PREFIX + paymentChannel;
+                String refundKey = ConstantDef.REFUND_KEY_PREFIX + paymentChannel;
+                // 按支付渠道统计
+                int payValue = statisticalDataMap.getOrDefault(payKey, 0);
+                int refundValue = statisticalDataMap.getOrDefault(refundKey, 0);
+                if (payValue > 0 || refundValue > 0) {
+                    startRows += 1;
+                    customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows + 1, new String[]{paymentChannelName + "支付总额", FormatUtil.intShrink100ToStr(payValue)}));
+                    customExcelItemList.add(new ExcelCollectPojo(startColumn + 3, startRows + 2, new String[]{paymentChannelName + "退款总额", FormatUtil.intShrink100ToStr(refundValue)}));
+                    customExcelItemList.add(new ExcelCollectPojo(startColumn + 5, startRows + 5, new String[]{paymentChannelName + "实际支付总额", FormatUtil.intShrink100ToStr(payValue - refundValue)}));
                 }
             }
         }
@@ -299,6 +291,7 @@ public class NatOrderService {
             String[] columns = new String[]{col0, col1, col2, col3, col4, col5, col6};
             List<NatOrder> natOrderList = queryNatOrderList(request);
             ExcelDataMap map = new ExcelDataMap(columns);
+            Map<String, Integer> statisticalDataMap = new HashMap<>();
             int payTotal = 0, refundTotal = 0, realityTotal = 0, rowSize = 0;
             if (!Checker.isNone(natOrderList)) {
                 List<OrderPayment> orderPaymentList = orderPaymentService.getOrderPaymentListByNatOrderList(natOrderList);
@@ -343,6 +336,16 @@ public class NatOrderService {
                             }
                             map.getStringListSafely(col6).add(paymentChannel);
                             rowSize++;
+
+                            String payKey = ConstantDef.PAY_KEY_PREFIX + paymentChannelInt;
+                            int payValue = statisticalDataMap.getOrDefault(payKey, 0);
+                            int amountInt = Checker.getIntegerValue(p.getAmount());
+                            if (Checker.getIntegerValue(p.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()) {
+                                payTotal += amountInt;
+                                payValue += amountInt;
+                                statisticalDataMap.put(payKey, payValue);
+                            }
+
                         }
                     }
                 }
@@ -381,12 +384,21 @@ public class NatOrderService {
                             }
                             map.getStringListSafely(col6).add(paymentChannel);
                             rowSize++;
+
+                            String refundKey = ConstantDef.REFUND_KEY_PREFIX + paymentChannelInt;
+                            int refundValue = statisticalDataMap.getOrDefault(refundKey, 0);
+                            int amountInt = Checker.getIntegerValue(p.getAmount());
+                            if (Checker.getIntegerValue(p.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()) {
+                                refundTotal += amountInt;
+                                refundValue += amountInt;
+                                statisticalDataMap.put(refundKey, refundValue);
+                            }
                         }
                     }
                 }
             }
             int size = natOrderList.size();
-            List<ExcelCollectPojo> itemList = getStatisticsData(rowSize, payTotal, refundTotal, natOrderList);
+            List<ExcelCollectPojo> itemList = getStatisticsData(rowSize, payTotal, refundTotal, statisticalDataMap);
             downloadRecordService.createFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map, itemList, size);
         } catch (Exception e) {
             e.printStackTrace();

+ 74 - 140
src/main/java/com/ywt/mg/services/PrescriptionServices.java

@@ -376,15 +376,8 @@ public class PrescriptionServices {
 
             String[] columns = new String[]{col0, col1, col20, col2, col3, col4, col5, col6, col7, col8, col9, col10, col19,
                     col11, col12, col13, col14, col15, col16, col17, col18};
-            int payTotal = 0, refundTotal = 0, realTotal = 0,
-                    weChatPay = 0, weChatRefundTotal = 0, weChatRealTotal = 0,
-                    aliPay = 0, aliRefundTotal = 0, aliRealTotal = 0,
-                    cashPay = 0, cashRefundTotal = 0, cashRealTotal = 0,
-                    medicalCardPay = 0, medicalCardRefundTotal = 0, medicalCardRealTotal = 0,
-                    posPay = 0, posRefundTotal = 0, posRealTotal = 0,
-                    medicalInsurancePay = 0, medicalInsuranceRefundTotal = 0, medicalInsuranceRealTotal = 0,
-                    icbcPay = 0, icbcRefundTotal = 0, icbcRealTotal = 0,
-                    pharmacyPosPay = 0, pharmacyPosRefundTotal = 0, pharmacyPosTotal = 0;
+            int payTotal = 0, refundTotal = 0;
+            Map<String, Integer> statisticalDataMap = new HashMap<>();
             List<PrescriptionInfo> prescriptionInfoList = downloadPrescriptionlistNew(request);
             ExcelDataMap map = new ExcelDataMap(columns);
             if (!Checker.isNone(prescriptionInfoList)) {
@@ -437,54 +430,27 @@ public class PrescriptionServices {
                     int presStatus = Checker.getIntegerValue(p.getStatus());
                     int payChanelInt = Checker.getIntegerValue(p.getPaymentChannel());
 
-                    if (presStatus == PrescriptionInfoStatusEnum.HaveARefund.getValue()) {
-                        refundTotal += Checker.getIntegerValue(p.getTotalPrice());
-
-                        if (payChanelInt == PresPaymentChannelEnum.WeChat.getValue()) {
-                            weChatRefundTotal += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.AliPay.getValue()) {
-                            aliRefundTotal += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.Cash.getValue()) {
-                            cashRefundTotal += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.MedicalCard.getValue()) {
-                            medicalCardRefundTotal += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.POS.getValue()) {
-                            posRefundTotal += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.MedicalInsurance.getValue()) {
-                            medicalInsuranceRefundTotal += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.ICBC.getValue()) {
-                            icbcRefundTotal += Checker.getIntegerValue(p.getTotalPrice());
-                        }else if (payChanelInt == PresPaymentChannelEnum.PharmacyPOS.getValue()) {
-                            pharmacyPosRefundTotal += Checker.getIntegerValue(p.getTotalPrice());
-                        }
+                    String payKey = ConstantDef.PAY_KEY_PREFIX + payChanelInt;
+                    String refundKey = ConstantDef.REFUND_KEY_PREFIX + payChanelInt;
+                    int payValue = statisticalDataMap.getOrDefault(payKey, 0);
+                    int refundValue = statisticalDataMap.getOrDefault(refundKey, 0);
+                    int amountInt = Checker.getIntegerValue(p.getTotalPrice());
+                    if (Checker.getIntegerValue(p.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()) {
+                        payTotal += amountInt;
+                        payValue += amountInt;
+                        statisticalDataMap.put(payKey, payValue);
                     }
-                    if (paymentStatusInt == PaymentStatusEnum.Success.getValue()) {
-                        payTotal += Checker.getIntegerValue(p.getTotalPrice());
-
-                        if (payChanelInt == PresPaymentChannelEnum.WeChat.getValue()) {
-                            weChatPay += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.AliPay.getValue()) {
-                            aliPay += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.Cash.getValue()) {
-                            cashPay += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.MedicalCard.getValue()) {
-                            medicalCardPay += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.POS.getValue()) {
-                            posPay += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.MedicalInsurance.getValue()) {
-                            medicalInsurancePay += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.ICBC.getValue()) {
-                            icbcPay += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.PharmacyPOS.getValue()) {
-                             pharmacyPosPay+= Checker.getIntegerValue(p.getTotalPrice());
-                        }
+                    if (Checker.getIntegerValue(p.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()) {
+                        refundTotal += amountInt;
+                        refundValue += amountInt;
+                        statisticalDataMap.put(refundKey, refundValue);
                     }
 
                 }
 
             }
             int size = prescriptionInfoList.size();
-            List<ExcelCollectPojo> itemList = getStatisticsData(size, payTotal, refundTotal, prescriptionInfoList);
+            List<ExcelCollectPojo> itemList = getStatisticsData(size, payTotal, refundTotal, statisticalDataMap);
             downloadRecordService.createFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map, itemList, size);
 
 
@@ -556,51 +522,34 @@ public class PrescriptionServices {
         }
     }
 
-    private List<ExcelCollectPojo> getStatisticsData(int size, int payTotal, int refundTotal,  List<PrescriptionInfo> itemList) {
+    private List<ExcelCollectPojo> getStatisticsData(int size, int payTotal, int refundTotal, Map<String, Integer> statisticalDataMap) {
         int startRows = size + 3;
-        int startColumn = 3;
+        int startColumn = 0;
 
         List<ExcelCollectPojo> customExcelItemList = new ArrayList<>();
-        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(PrescriptionInfo::getPaymentChannel).collect(Collectors.toList());
-            integerList = integerList.stream().filter(p -> !Checker.isNone(p)).collect(Collectors.toList());
-            // 去重
-
-            List<PrescriptionInfo> paymentList = itemList;
-            List<PrescriptionInfo> 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(PrescriptionInfo::getTotalPrice).sum();
-                        int refundAmount = refundList.stream().filter(p -> Checker.getIntegerValue(p.getPaymentChannel()) == paymentChannel).mapToInt(PrescriptionInfo::getTotalPrice).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)}));
-                    }
+        customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows + 1, new String[]{"支付总额", FormatUtil.intShrink100ToStr(payTotal)}));
+        customExcelItemList.add(new ExcelCollectPojo(startColumn + 3, startRows + 1, new String[]{"退款总额", FormatUtil.intShrink100ToStr(refundTotal)}));
+        customExcelItemList.add(new ExcelCollectPojo(startColumn + 5, startRows + 1, new String[]{"实际支付总额", FormatUtil.intShrink100ToStr(payTotal - refundTotal)}));
+        PaymentChannelEnum[] paymentChannelList = PaymentChannelEnum.values();
+        if (!Checker.isNone(paymentChannelList)) {
+            for (int i = 0, j = paymentChannelList.length; i < j; i++) {
+                int paymentChannel = paymentChannelList[i].getValue();
+                if (paymentChannel <= 0) continue;
+                String paymentChannelName = paymentChannelList[i].getDisplayName();
+                String payKey = ConstantDef.PAY_KEY_PREFIX + paymentChannel;
+                String refundKey = ConstantDef.REFUND_KEY_PREFIX + paymentChannel;
+                // 按支付渠道统计
+                int payValue = statisticalDataMap.getOrDefault(payKey, 0);
+                int refundValue = statisticalDataMap.getOrDefault(refundKey, 0);
+                if (payValue > 0 || refundValue > 0) {
+                    startRows += 1;
+                    customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows + 1, new String[]{paymentChannelName + "支付总额", FormatUtil.intShrink100ToStr(payValue)}));
+                    customExcelItemList.add(new ExcelCollectPojo(startColumn + 3, startRows + 2, new String[]{paymentChannelName + "退款总额", FormatUtil.intShrink100ToStr(refundValue)}));
+                    customExcelItemList.add(new ExcelCollectPojo(startColumn + 5, startRows + 5, new String[]{paymentChannelName + "实际支付总额", FormatUtil.intShrink100ToStr(payValue - refundValue)}));
                 }
             }
         }
 
-
-
         return customExcelItemList;
     }
 
@@ -927,6 +876,7 @@ public class PrescriptionServices {
             request.setPaymentChannel(PaymentChannelEnum.WeChat.getValue() + "");
             List<PrescriptionInfo> prescriptionInfoList = downloadPrescriptionlistNew(request);
             ExcelDataMap map = new ExcelDataMap(columns);
+            Map<String, Integer> statisticalDataMap = new HashMap<>();
             int payTotal = 0, refundTotal = 0, rowSize = 0;
             if (!Checker.isNone(prescriptionInfoList)) {
 
@@ -967,6 +917,15 @@ public class PrescriptionServices {
                             map.getStringListSafely(col6).add(paymentChannel);
                             rowSize++;
 
+                            String payKey = ConstantDef.PAY_KEY_PREFIX + paymentChannelInt;
+                            int payValue = statisticalDataMap.getOrDefault(payKey, 0);
+                            int amountInt = Checker.getIntegerValue(p.getTotalPrice());
+                            if (Checker.getIntegerValue(p.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()) {
+                                payTotal += amountInt;
+                                payValue += amountInt;
+                                statisticalDataMap.put(payKey, payValue);
+                            }
+
                         }
                     }
                 }
@@ -975,7 +934,7 @@ public class PrescriptionServices {
                 // 得到退款的处方订单
                 List<PrescriptionInfo> refundPrescriptionInfoList = getRefundPrescriptionInfoList(prescriptionInfoList);
                 // 最后处理退款的部分
-                for (PrescriptionInfo p : prescriptionInfoList) {
+                for (PrescriptionInfo p : refundPrescriptionInfoList) {
                     if (!Checker.isNone(p) && Checker.getIntegerValue(p.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()) {
                         // "交易类型", "交易流水号", "交易金额", "交易时间", "订单号", "类型"
                         Date refundTime = Checker.getDateValue(p.getRefundTime());
@@ -1004,6 +963,15 @@ public class PrescriptionServices {
                             map.getStringListSafely(col5).add(typeName);
                             map.getStringListSafely(col6).add(paymentChannel);
                             rowSize++;
+
+                            String refundKey = ConstantDef.REFUND_KEY_PREFIX + paymentChannelInt;
+                            int refundValue = statisticalDataMap.getOrDefault(refundKey, 0);
+                            int amountInt = Checker.getIntegerValue(p.getTotalPrice());
+                            if (Checker.getIntegerValue(p.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()) {
+                                refundTotal += amountInt;
+                                refundValue += amountInt;
+                                statisticalDataMap.put(refundKey, refundValue);
+                            }
                         }
                     }
 
@@ -1024,7 +992,7 @@ public class PrescriptionServices {
                 }
             }
             int size = prescriptionInfoList.size();
-            List<ExcelCollectPojo> itemList = getStatisticsData(rowSize, payTotal, refundTotal, prescriptionInfoList);
+            List<ExcelCollectPojo> itemList = getStatisticsData(rowSize, payTotal, refundTotal, statisticalDataMap);
             downloadRecordService.createFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map, itemList, size);
         } catch (Exception e) {
             e.printStackTrace();
@@ -1063,16 +1031,9 @@ public class PrescriptionServices {
 
             String[] columns = new String[]{col0, col1, col20,  col2, col3, col4, col6, col7, col8, col9, col10,
                     col11, col12, col13, col14, col15, col16, col17, col18};
-            int payTotal = 0, refundTotal = 0, realTotal = 0,
-                    weChatPay = 0, weChatRefundTotal = 0, weChatRealTotal = 0,
-                    aliPay = 0, aliRefundTotal = 0, aliRealTotal = 0,
-                    cashPay = 0, cashRefundTotal = 0, cashRealTotal = 0,
-                    medicalCardPay = 0, medicalCardRefundTotal = 0, medicalCardRealTotal = 0,
-                    posPay = 0, posRefundTotal = 0, posRealTotal = 0,
-                    medicalInsurancePay = 0, medicalInsuranceRefundTotal = 0, medicalInsuranceRealTotal = 0,
-                    icbcPay = 0, icbcRefundTotal = 0, icbcRealTotal = 0,
-                    pharmacyPosPay = 0, pharmacyPosRefundTotal = 0, pharmacyPosTotal = 0;
+            int payTotal = 0, refundTotal = 0;
             List<PrescriptionInfo> prescriptionInfoList = queryAbverPrescriptionListNew(request);
+            Map<String, Integer> statisticalDataMap = new HashMap<>();
             ExcelDataMap map = new ExcelDataMap(columns);
             if (!Checker.isNone(prescriptionInfoList)) {
                 List<OrderPayment> orderPaymentList = orderPaymentService.getOrderPaymentListByPrescriptionInfoList(prescriptionInfoList);
@@ -1124,54 +1085,27 @@ public class PrescriptionServices {
                     int presStatus = Checker.getIntegerValue(p.getStatus());
                     int payChanelInt = Checker.getIntegerValue(p.getPaymentChannel());
 
-                    if (presStatus == PrescriptionInfoStatusEnum.HaveARefund.getValue()) {
-                        refundTotal += Checker.getIntegerValue(p.getTotalPrice());
-
-                        if (payChanelInt == PresPaymentChannelEnum.WeChat.getValue()) {
-                            weChatRefundTotal += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.AliPay.getValue()) {
-                            aliRefundTotal += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.Cash.getValue()) {
-                            cashRefundTotal += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.MedicalCard.getValue()) {
-                            medicalCardRefundTotal += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.POS.getValue()) {
-                            posRefundTotal += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.MedicalInsurance.getValue()) {
-                            medicalInsuranceRefundTotal += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.ICBC.getValue()) {
-                            icbcRefundTotal += Checker.getIntegerValue(p.getTotalPrice());
-                        }else if (payChanelInt == PresPaymentChannelEnum.PharmacyPOS.getValue()) {
-                            pharmacyPosRefundTotal += Checker.getIntegerValue(p.getTotalPrice());
-                        }
+                    String payKey = ConstantDef.PAY_KEY_PREFIX + payChanelInt;
+                    String refundKey = ConstantDef.REFUND_KEY_PREFIX + payChanelInt;
+                    int payValue = statisticalDataMap.getOrDefault(payKey, 0);
+                    int refundValue = statisticalDataMap.getOrDefault(refundKey, 0);
+                    int amountInt = Checker.getIntegerValue(p.getTotalPrice());
+                    if (Checker.getIntegerValue(p.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()) {
+                        payTotal += amountInt;
+                        payValue += amountInt;
+                        statisticalDataMap.put(payKey, payValue);
                     }
-                    if (paymentStatusInt == PaymentStatusEnum.Success.getValue()) {
-                        payTotal += Checker.getIntegerValue(p.getTotalPrice());
-
-                        if (payChanelInt == PresPaymentChannelEnum.WeChat.getValue()) {
-                            weChatPay += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.AliPay.getValue()) {
-                            aliPay += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.Cash.getValue()) {
-                            cashPay += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.MedicalCard.getValue()) {
-                            medicalCardPay += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.POS.getValue()) {
-                            posPay += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.MedicalInsurance.getValue()) {
-                            medicalInsurancePay += Checker.getIntegerValue(p.getTotalPrice());
-                        } else if (payChanelInt == PresPaymentChannelEnum.ICBC.getValue()) {
-                            icbcPay += Checker.getIntegerValue(p.getTotalPrice());
-                        }else if (payChanelInt == PresPaymentChannelEnum.PharmacyPOS.getValue()) {
-                            pharmacyPosPay += Checker.getIntegerValue(p.getTotalPrice());
-                        }
+                    if (Checker.getIntegerValue(p.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()) {
+                        refundTotal += amountInt;
+                        refundValue += amountInt;
+                        statisticalDataMap.put(refundKey, refundValue);
                     }
 
                 }
 
             }
             int size = prescriptionInfoList.size();
-            List<ExcelCollectPojo> itemList = getStatisticsData(size, payTotal, refundTotal, prescriptionInfoList);
+            List<ExcelCollectPojo> itemList = getStatisticsData(size, payTotal, refundTotal, statisticalDataMap);
             downloadRecordService.createFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map, itemList, size);