Prechádzať zdrojové kódy

fix 调整挂号订单统计接口

DYH2020 2 rokov pred
rodič
commit
0a8b804f8b

+ 36 - 19
src/main/java/com/ywt/mg/services/RegisteredOrderService.java

@@ -357,7 +357,6 @@ public class RegisteredOrderService {
             }
             List<RegisteredOrder> registeredOrderList = queryRegisteredOrderList(request);
             List<RegisteredOrder> valueList = new ArrayList();
-            int payTotal = 0, refundTotal = 0;
             ExcelDataMap map = new ExcelDataMap(columns);
             if (!Checker.isNone(registeredOrderList)) {
 //                valueList.addAll(registeredOrderList.getItems());
@@ -396,12 +395,6 @@ public class RegisteredOrderService {
 //                    String[] bodyStr = {p.getOrderNo(), p.getPaymentNo(), transactionId, p.getPatientName(), patientMobile, cardNo,
 //                            p.getDoctorName(), p.getDeptName(), totalStr, registeredTime, source,
 //                            typeName, registeredStatus, paymentStatus, createTime, cancelRemark};
-                    if (Checker.getIntegerValue(p.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()) {
-                        payTotal += Checker.getIntegerValue(p.getTotal());
-                    }
-                    if (Checker.getIntegerValue(p.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()) {
-                        refundTotal += Checker.getIntegerValue(p.getTotal());
-                    }
                     if (hosp > 0) {
                         map.getStringListSafely(col0).add(p.getOrderNo());
                         map.getStringListSafely(col1).add(p.getPaymentNo());
@@ -440,7 +433,15 @@ public class RegisteredOrderService {
                 }
             }
             int size = registeredOrderList.size();
-            List<ExcelCollectPojo> itemList = getStatisticsData(size, payTotal, refundTotal, registeredOrderList);
+            Date billStartTime = null;
+            Date billEndTime = null;
+            if (!Checker.isNone(request.getRegisteredStartTime())) {
+                billStartTime = DateUtil.stringToDate(request.getRegisteredStartTime() + ConstantDef.BILL_TIME_START_FORMAT);
+            }
+            if (!Checker.isNone(request.getRegisteredEndTime())) {
+                billEndTime = DateUtil.stringToDate(request.getRegisteredEndTime() + ConstantDef.BILL_TIME_END_FORMAT);
+            }
+            List<ExcelCollectPojo> itemList = getStatisticsData(billStartTime, billEndTime, registeredOrderList);
             downloadRecordService.createFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map, itemList, size);
 
         } catch (Exception e) {
@@ -553,11 +554,25 @@ public class RegisteredOrderService {
         return backDate;
     }
 
-    private List<ExcelCollectPojo> getStatisticsData(int size, int payTotal, int refundTotal, List<RegisteredOrder> itemList) {
+    private List<ExcelCollectPojo> getStatisticsData(Date billStartTime, Date billEndTime, List<RegisteredOrder> itemList) {
+        List<ExcelCollectPojo> customExcelItemList = new ArrayList<>();
+        if (Checker.isNone(itemList)) return customExcelItemList;
+        int size = itemList.size();
+        List<RegisteredOrder> paymentList = itemList;
+        List<RegisteredOrder> refundList = itemList;
+        if (!Checker.isNone(billStartTime)) {
+            paymentList = paymentList.stream().filter(p -> !Checker.isNone(p.getPaymentTime()) && p.getPaymentTime().after(billStartTime)).collect(Collectors.toList());
+            refundList = refundList.stream().filter(p -> !Checker.isNone(p.getRefundTime()) && p.getRefundTime().after(billStartTime)).collect(Collectors.toList());
+        }
+        if (!Checker.isNone(billEndTime)) {
+            paymentList = paymentList.stream().filter(p -> !Checker.isNone(p.getPaymentTime()) && p.getPaymentTime().before(billEndTime)).collect(Collectors.toList());
+            refundList = refundList.stream().filter(p -> !Checker.isNone(p.getRefundTime()) && p.getRefundTime().before(billEndTime)).collect(Collectors.toList());
+        }
+        int payTotal = paymentList.stream().filter(p -> Checker.getIntegerValue(p.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()).mapToInt(RegisteredOrder::getTotal).sum();
+        int refundTotal = refundList.stream().filter(p -> Checker.getIntegerValue(p.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()).mapToInt(RegisteredOrder::getTotal).sum();
         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 + 3, startRows + 1, new String[]{"退款总额", FormatUtil.intShrink100ToStr(refundTotal)}));
         customExcelItemList.add(new ExcelCollectPojo(startColumn + 5, startRows + 1, new String[]{"实际支付金额", FormatUtil.intShrink100ToStr(payTotal - refundTotal)}));
@@ -571,8 +586,9 @@ public class RegisteredOrderService {
                     if (paymentChannel <= 0) continue;
                     startRows += 1;
                     String paymentChannelName = PaymentChannelEnum.getDisplayName(paymentChannel);
-                    int paymentAmount = itemList.stream().filter(p -> Checker.getIntegerValue(p.getPaymentChannel()) == paymentChannel && Checker.getIntegerValue(p.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()).mapToInt(RegisteredOrder::getTotal).sum();
-                    int refundAmount = itemList.stream().filter(p -> Checker.getIntegerValue(p.getPaymentChannel()) == paymentChannel && Checker.getIntegerValue(p.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()).mapToInt(RegisteredOrder::getTotal).sum();
+                    // 按支付渠道统计
+                    int paymentAmount = paymentList.stream().filter(p -> Checker.getIntegerValue(p.getPaymentChannel()) == paymentChannel).mapToInt(RegisteredOrder::getTotal).sum();
+                    int refundAmount = refundList.stream().filter(p -> Checker.getIntegerValue(p.getPaymentChannel()) == paymentChannel).mapToInt(RegisteredOrder::getTotal).sum();
                     customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows + 1, new String[]{paymentChannelName + "支付总额", FormatUtil.intShrink100ToStr(paymentAmount)}));
                     customExcelItemList.add(new ExcelCollectPojo(startColumn + 3, startRows + 1, new String[]{paymentChannelName + "退款总额", FormatUtil.intShrink100ToStr(refundAmount)}));
                     customExcelItemList.add(new ExcelCollectPojo(startColumn + 5, startRows + 1, new String[]{paymentChannelName + "实际支付金额", FormatUtil.intShrink100ToStr(paymentAmount - refundAmount)}));
@@ -597,13 +613,14 @@ public class RegisteredOrderService {
 
             List<RegisteredOrder> registeredOrderList = queryRegisteredOrderList(request);
             ExcelDataMap map = new ExcelDataMap(columns);
+            Date billStartTime = DateUtil.stringToDate(request.getBillStartTime() + ConstantDef.BILL_TIME_START_FORMAT);
+            Date billEndTime = DateUtil.stringToDate(request.getBillEndTime() + ConstantDef.BILL_TIME_END_FORMAT);
             if (!Checker.isNone(registeredOrderList)) {
                 List<OrderPayment> orderPaymentList = orderPaymentService.getOrderPaymentListByRegisteredOrderList(registeredOrderList);
                 // 得到退款的记录日志(需要从 refund_log 获取 refund_id 字段)
                 List<RefundLog> refundLogList = refundLogService.getRefundLogListByRegisteredOrderList(registeredOrderList);
                 List<RegisteredOrder> refundRegisteredOrderList = new ArrayList<>(getRefundRegisteredOrderList(registeredOrderList));
-                Date billStartTime = DateUtil.stringToDate(request.getBillStartTime() + ConstantDef.BILL_TIME_START_FORMAT);
-                Date billEndTime = DateUtil.stringToDate(request.getBillEndTime() + ConstantDef.BILL_TIME_END_FORMAT);
+
                 for (RegisteredOrder p : registeredOrderList) {
                     if (!Checker.isNone(p) && Checker.getIntegerValue(p.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()
                             && Checker.getIntegerValue(p.getTotal()) > 0
@@ -634,7 +651,6 @@ public class RegisteredOrderService {
                             map.getStringListSafely(col4).add(orderNo);
                             map.getStringListSafely(col5).add(typeName);
                             map.getStringListSafely(col6).add(paymentChannel);
-
                         }
                     }
                 }
@@ -655,21 +671,22 @@ public class RegisteredOrderService {
                             // 类型
                             int typeInt = Checker.getIntegerValue(p.getRegisteredType());
                             String typeName = RegisteredTypeEnum.valueOf(typeInt).getDisplayName();
+                            // 支付渠道
+                            int paymentChannelInt = Checker.getIntegerValue(p.getPaymentChannel());
+                            String paymentChannel = PaymentChannelEnum.getDisplayName(paymentChannelInt);
                             map.getStringListSafely(col0).add(type);
                             map.getStringListSafely(col1).add(transactionId);
                             map.getStringListSafely(col2).add(totalStr);
                             map.getStringListSafely(col3).add(refundTimeStr);
                             map.getStringListSafely(col4).add(orderNo);
                             map.getStringListSafely(col5).add(typeName);
-
-
+                            map.getStringListSafely(col6).add(paymentChannel);
                         }
                     }
                 }
-
             }
             int size = registeredOrderList.size();
-            List<ExcelCollectPojo> itemList = new ArrayList<>();
+            List<ExcelCollectPojo> itemList = getStatisticsData(billStartTime, billEndTime, registeredOrderList);
             downloadRecordService.createFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map, itemList, size);
 
         } catch (Exception e) {