소스 검색

feature:押金,体检,线下

wuyongyi 2 년 전
부모
커밋
4649a1b499

+ 77 - 46
src/main/java/com/ywt/mg/services/CheckUpOrderService.java

@@ -162,6 +162,7 @@ public class CheckUpOrderService {
             List<OrderPayment> orderPaymentList = orderPaymentService.getOrderPaymentListByCheckUpOrderList(list);
             ExcelDataMap map = new ExcelDataMap(columns);
             int payTotal = 0, refundTotal = 0;
+            Map<String, Integer> statisticalDataMap = new HashMap<>();
             if (!Checker.isNone(list)) {
                 for (CheckUpOrder p : list) {
                     if (!Checker.isNone(p)) {
@@ -201,11 +202,30 @@ public class CheckUpOrderService {
                         map.getStringListSafely(col9).add(paymentTimeValue);
                         map.getStringListSafely(col10).add(hospitalName);
 
+
+                        int payChanelInt = Checker.getIntegerValue(p.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(p.getAmount());
+                        if (Checker.getIntegerValue(p.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()) {
+                            payTotal += amountInt;
+                            payValue += amountInt;
+                            statisticalDataMap.put(payKey, payValue);
+                        }
+                        if (Checker.getIntegerValue(p.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()) {
+                            refundTotal += amountInt;
+                            refundValue += amountInt;
+                            statisticalDataMap.put(refundKey, refundValue);
+                        }
+
                     }
                 }
             }
             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) {
@@ -222,51 +242,30 @@ public class CheckUpOrderService {
      * @param refundTotal 退款金额
      * @return {@link List<ExcelCollectPojo> }
      */
-    private List<ExcelCollectPojo> getStatisticsData(int size, int payTotal, int refundTotal, List<CheckUpOrder> 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)}));
-
-//        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)}));
-                    }
+        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)}));
                 }
             }
         }
@@ -281,11 +280,14 @@ public class CheckUpOrderService {
             String col3 = "交易日期*";
             String col4 = "订单号";
             String col5 = "类型";
-            String[] columns = new String[]{col0, col1, col2, col3, col4, col5};
+            String col6 = "支付渠道";
+            String[] columns = new String[]{col0, col1, col2, col3, col4, col5, col6};
 
             request.setPaymentStatus(PaymentStatusEnum.Success.getValue() + "");
             List<CheckUpOrder> checkUpOrderList = queryCheckUpOrderListCommon(request);
             ExcelDataMap map = new ExcelDataMap(columns);
+            Map<String, Integer> statisticalDataMap = new HashMap<>();
+            int payTotal = 0, refundTotal = 0, realityTotal = 0, rowSize = 0;
             if (!Checker.isNone(checkUpOrderList)) {
                 // 得到支付的记录日志(需要从 order_payment 获取 transaction_id 字段)
                 List<OrderPayment> orderPaymentList = orderPaymentService.getOrderPaymentListByCheckUpOrderList(checkUpOrderList);
@@ -313,12 +315,27 @@ public class CheckUpOrderService {
                             // 类型
                             String typeStr = "体检缴费";
 //                            String[] bodyStr = {type, transactionId, totalStr, paymentTimeStr, orderNo, typeStr};
+
+                            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(paymentTimeStr);
                             map.getStringListSafely(col4).add(orderNo);
                             map.getStringListSafely(col5).add(typeStr);
+                            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);
+                            }
                         }
                     }
                 }
@@ -339,6 +356,9 @@ public class CheckUpOrderService {
                             // 订单号
                             String orderNo = Checker.getStringValue(p.getOrderNo());
                             // 类型
+                            int paymentChannelInt = Checker.getIntegerValue(p.getPaymentChannel());
+                            String paymentChannel = PaymentChannelEnum.getDisplayName(paymentChannelInt);
+
                             String typeName = "体检缴费";
                             map.getStringListSafely(col0).add(type);
                             map.getStringListSafely(col1).add(transactionId);
@@ -346,14 +366,25 @@ public class CheckUpOrderService {
                             map.getStringListSafely(col3).add(refundTimeStr);
                             map.getStringListSafely(col4).add(orderNo);
                             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.getAmount());
+                            if (Checker.getIntegerValue(p.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()) {
+                                refundTotal += amountInt;
+                                refundValue += amountInt;
+                                statisticalDataMap.put(refundKey, refundValue);
+                            }
 
-//                            String[] bodyStr = {type, transactionId, totalStr, refundTimeStr, orderNo, typeName};
                         }
                     }
                 }
             }
             int size = checkUpOrderList.size();
-            List<ExcelCollectPojo> itemList = new ArrayList<>();
+            List<ExcelCollectPojo> itemList = getStatisticsData(size, payTotal, refundTotal,statisticalDataMap);
             downloadRecordService.createFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map, itemList, size);
         } catch (Exception e) {
             logger.error("/checkUp/downloadCheckUpOrderBillList(): {}", e.getMessage(), e);

+ 1 - 2
src/main/java/com/ywt/mg/services/DepositService.java

@@ -464,8 +464,7 @@ public class DepositService {
 
 //                        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;

+ 4 - 8
src/main/java/com/ywt/mg/services/NatOrderService.java

@@ -178,7 +178,7 @@ public class NatOrderService {
 
     public void downloadNatOrderList(int downloadRecordId, String fileName, NatOrderListRequest request) {
         try {
-            String col1 = "订单号", col1_1 = "支付流水号", col1_1_1 = "交易流水号", col2 = "医院", col3 = "患者姓名", col4 = "身份证号", col5 = "年龄", col6 = "性别", col7 = "手机号";
+            String col1 = "订单号", col1_1 = "支付流水号", col1_1_1 = "交易流水号", col1_1_2 = "支付渠道", col2 = "医院", col3 = "患者姓名", col4 = "身份证号", col5 = "年龄", col6 = "性别", col7 = "手机号";
             String col8 = "缴费码", col9 = "疫苗码", col10 = "金额", col11 = "支付状态", col12 = "订单状态";
             String col13 = "支付时间", col14 = "退费时间", col15 = "预约时间", col16 = "执行时间", col17 = "备注";
             String[] columns = new String[]{col1, col1_1, col1_1_1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12, col13, col14, col15, col16, col17};
@@ -194,6 +194,9 @@ public class NatOrderService {
                 map.getStringListSafely(col1).add(Checker.getStringValue(item.getOrderNo()));
                 map.getStringListSafely(col1_1).add(Checker.getStringValue(item.getPaymentNo()));
                 map.getStringListSafely(col1_1_1).add(transactionId);
+                int paymentChannelInt = Checker.getIntegerValue(item.getPaymentChannel());
+                String paymentChannel = PaymentChannelEnum.getDisplayName(paymentChannelInt);
+                map.getStringListSafely(col1_1_2).add(paymentChannel);
                 map.getStringListSafely(col2).add(hospitalCacheService.getCacheHospitalNameByHospitalId(item.getHospitalId()));
                 map.getStringListSafely(col3).add(Checker.getStringValue(item.getPatientName()));
                 map.getStringListSafely(col4).add(Checker.getStringValue(item.getIdCard()));
@@ -331,9 +334,6 @@ 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());
-                            }
                             map.getStringListSafely(col6).add(paymentChannel);
                             rowSize++;
 
@@ -378,10 +378,6 @@ public class NatOrderService {
                             map.getStringListSafely(col3).add(refundTimeStr);
                             map.getStringListSafely(col4).add(orderNo);
                             map.getStringListSafely(col5).add(typeName);
-
-                            if (Checker.getIntegerValue(p.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()) {
-                                refundTotal += Checker.getIntegerValue(p.getAmount());
-                            }
                             map.getStringListSafely(col6).add(paymentChannel);
                             rowSize++;
 

+ 11 - 1
src/main/java/com/ywt/mg/services/OfflineNewService.java

@@ -8,6 +8,7 @@ import com.ywt.mg.core.utils.StringHelper;
 import com.ywt.mg.core.utils.serializers.JsonSerializer;
 import com.ywt.mg.domain.entities.DownloadRecord;
 import com.ywt.mg.domain.entities.OfflineConsultation;
+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.*;
@@ -58,6 +59,9 @@ public class OfflineNewService {
     @Autowired
     private RefundLogService refundLogService;
 
+    @Autowired
+    private OrderPaymentService orderPaymentService;
+
 
     public List<OfflineConsultation> queryDownloadOfflineList(DownloadOfflineListNewRequest request) {
         Map map = queryOfflineListCommon(request);
@@ -268,6 +272,8 @@ public class OfflineNewService {
             // 单元格
             String col0 = "订单号";
             String col1 = "支付流水号";
+            String col1_1 = "交易流水号";
+            String col1_2 = "支付渠道";
             String col2 = "患者姓名";
             String col3 = "患者手机号";
             String col4 = "身份证号";
@@ -282,7 +288,7 @@ public class OfflineNewService {
             String col13 = "退款时间";
             String col14 = "备注";
             String col15 = "来源";
-            String[] columns = new String[]{col0, col1, col2, col3, col4, col5, col6, col7, col8, col9, col10,
+            String[] columns = new String[]{col0, col1, col1_1, col1_2, col2, col3, col4, col5, col6, col7, col8, col9, col10,
                     col11, col12, col13, col14, col15};
             // 按条件查找记录
             int hospitalId = -1;
@@ -293,9 +299,13 @@ public class OfflineNewService {
             ExcelDataMap map = new ExcelDataMap(columns);
             if (!Checker.isNone(offlineList)) {
                 // 遍历
+                List<OrderPayment> orderPaymentList = orderPaymentService.getOrderPaymentListByOfflineConsultationList(offlineList);
                 for (OfflineConsultation v : offlineList) {
                     String orderNoStr = Checker.getStringValue(v.getOrderNo());
                     String paymentNoStr = Checker.getStringValue(v.getPaymentNo());
+                    OrderPayment orderPayment = orderPaymentService.getOrderPaymentByOrderId(orderPaymentList, Checker.getIntegerValue(v.getOrderId()));
+                    String transactionIdStr = orderPaymentService.getTransactionIdByOrderPayment(orderPayment);
+                    String paymentChannel = orderPaymentService.getPaymentChannelByOrderPayment(orderPayment);
                     String patientNameNoStr = Checker.getStringValue(v.getRealName());
                     String patientMobileStr = Checker.getStringValue(v.getMobile());
                     String idNoStr = Checker.getStringValue(v.getIdNo());

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

@@ -254,4 +254,30 @@ public class OrderPaymentService extends ServiceBase {
         return PaymentChannelEnum.UNKNOWN.getValue();
     }
 
+    public OrderPayment getOrderPaymentByOrderId(List<OrderPayment> orderPaymentList, int orderId) {
+        if (!Checker.isNone(orderPaymentList) && orderId > 0) {
+            return orderPaymentList.stream().filter(o -> Checker.getIntegerValue(o.getOrderId()) == orderId).findFirst().orElse(null);
+        }
+        return null;
+    }
+
+    public String getTransactionIdByOrderPayment(OrderPayment orderPayment) {
+        if (orderPayment != null && !Checker.isNone(orderPayment.getTransactionId())) {
+            return orderPayment.getTransactionId();
+        }
+        if (orderPayment != null
+                && Checker.getIntegerValue(orderPayment.getPaymentChannel()) != PaymentChannelEnum.WeChat.getValue()
+                && Checker.getIntegerValue(orderPayment.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()
+                && !Checker.isNone(orderPayment.getPaymentNo())) {
+            return orderPayment.getPaymentNo();
+        }
+        return "";
+    }
+
+    public String getPaymentChannelByOrderPayment(OrderPayment orderPayment) {
+        if (orderPayment != null && !Checker.isNone(orderPayment.getPaymentChannel())) {
+            return PaymentChannelEnum.getDisplayName(orderPayment.getPaymentChannel());
+        }
+        return PaymentChannelEnum.UNKNOWN.getDisplayName();
+    }
 }

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

@@ -469,9 +469,9 @@ public class OutpatientOrderService {
                 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)}));
+                    customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows, new String[]{paymentChannelName + "支付总额", FormatUtil.intShrink100ToStr(payValue)}));
+                    customExcelItemList.add(new ExcelCollectPojo(startColumn + 3, startRows , new String[]{paymentChannelName + "退款总额", FormatUtil.intShrink100ToStr(refundValue)}));
+                    customExcelItemList.add(new ExcelCollectPojo(startColumn + 5, startRows , new String[]{paymentChannelName + "实际支付总额", FormatUtil.intShrink100ToStr(payValue - refundValue)}));
                 }
             }
         }