Przeglądaj źródła

feature:营养餐对账下载

wuyongyi 2 lat temu
rodzic
commit
19c1aa47c6

+ 57 - 81
src/main/java/com/ywt/mg/services/MealOrderService.java

@@ -15,6 +15,7 @@ import com.ywt.mg.domain.models.ExcelDataMap;
 import com.ywt.mg.domain.models.enums.*;
 import com.ywt.mg.domain.models.nutrimeal.MealOrderInfo;
 import com.ywt.mg.domain.models.pojo.CustomExcelItem;
+import com.ywt.mg.domain.models.pojo.ExcelCollectPojo;
 import com.ywt.mg.params.mealOrder.MealOrderListRequest;
 import com.ywt.mg.web.common.ExcelDownloadSrvOld;
 import org.slf4j.Logger;
@@ -723,6 +724,9 @@ public class MealOrderService {
 //                item.put("remark", m == null ? "" : (String) m.getOrDefault("refuseOrderRemark", ""));
                     int hid = Checker.getIntegerValue(p.getHospitalId());
                     list.add(info);
+
+
+
 //                item.put("hospitalId", hid);
 //                item.put("hospitalName", BizUtil.getHospitalNameByHospitalId(hid));
 //                item.put("pickupCode", Checker.getStringValue(p.getPickupCode()));
@@ -777,7 +781,18 @@ public class MealOrderService {
                                 rowSize++;
 //                            ExcelHelper.settingMainBodyLabelCell(sheet, cellFormat2, n, bodyStr);
 //                            n++;
-
+                                int paymentChannelInt = 0;
+                                if(p.getPayType() == OrderPayTypeEnum.WECHAT.getValue() || p.getPayType() == OrderPayTypeEnum.COIN.getValue()){
+                                    paymentChannelInt = 1;
+                                    String payKey = ConstantDef.PAY_KEY_PREFIX + paymentChannelInt;
+                                    int payValue = statisticalDataMap.getOrDefault(payKey, 0);
+                                    int amountInt = Checker.getIntegerValue(p.getWechatInt());
+                                    if (PaymentStatusEnum.Success.getDisplayName().equals(p.getPayStatus())) {
+                                        payTotal += amountInt;
+                                        payValue += amountInt;
+                                        statisticalDataMap.put(payKey, payValue);
+                                    }
+                                }
 
                             }
                         }
@@ -814,6 +829,17 @@ public class MealOrderService {
                                 map.getStringListSafely(col4).add(orderNo);
                                 map.getStringListSafely(col5).add(typeName);
                                 map.getStringListSafely(col6).add(OrderPayTypeEnum.valueOf(Checker.getIntegerValue(p.getPayType())).getDisplayName());
+                                int paymentChannelInt = 0;
+                                if(p.getPayType() == OrderPayTypeEnum.WECHAT.getValue() || p.getPayType() == OrderPayTypeEnum.COIN.getValue()){
+                                    paymentChannelInt = 1;
+                                    String refundKey = ConstantDef.REFUND_KEY_PREFIX + paymentChannelInt;
+                                    int refundValue = statisticalDataMap.getOrDefault(refundKey, 0);
+                                    int amountInt = Checker.getIntegerValue(p.getWechatInt());
+                                        refundTotal += amountInt;
+                                        refundValue += amountInt;
+                                        statisticalDataMap.put(refundKey, refundValue);
+
+                                }
                                 rowSize++;
                             }
                         }
@@ -823,8 +849,8 @@ public class MealOrderService {
             }
 
             int bill = 1;
-            List<CustomExcelItem> itemList = getStatisticsBillData(userMealOrderViews, rowSize);
-            downloadRecordService.createMealFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map,
+            List<ExcelCollectPojo> itemList = getStatisticsBillData(rowSize, payTotal, refundTotal, statisticalDataMap);
+            downloadRecordService.createFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map,
                      itemList, rowSize, bill);
 
         } catch (Exception e) {
@@ -841,84 +867,34 @@ public class MealOrderService {
         return new ArrayList<>();
     }
 
-    private List<CustomExcelItem> getStatisticsBillData(List<UserMealOrderView> orders, int startRows) {
-         startRows = startRows + 3;
-
-        int startColumn = 3;
-        List<CustomExcelItem> customExcelItemList = new ArrayList<>();
-        // 按店铺统计
-
-
-        /**
-         4、总成本=微信点单成本+金币点单成本+现场点单成本(也等于各个菜品成本价乘以份数的相加的总额) ;
-         5、微信点单成本:支付方式是”微信支付“的订单,其各个菜品成本价乘以份数的相加的总额(不包含退款订单) ;
-         金币点单成本:支付方式是”微信+金币“的订单,其各个菜品成本价乘以份数的相加的总额(不包含退款订单) ;
-         现场点单成本:支付方式是”现场支付“的订单,其各个菜品成本价乘以份数的相加的总额(不包含退款订单) ;*/
-
-        List<UserMealOrderView> wechatSinglePointCostList = orders.stream()
-                .filter(p -> p.getPayType() == OrderPayTypeEnum.WECHAT.getValue()
-                        && RefundStatusEnum.SUCCESS.getValue() != Checker.getIntegerValue(p.getRefundStatus()))
-                .collect(Collectors.toList());
-        int wechatSinglePointCostInt = orderDishService.getAllDishCostPriceSumByUserMealOrderViewList(wechatSinglePointCostList);
-        List<UserMealOrderView> coinSinglePointCostList = orders.stream()
-                .filter(p -> p.getPayType() == OrderPayTypeEnum.COIN.getValue()
-                        && RefundStatusEnum.SUCCESS.getValue() != Checker.getIntegerValue(p.getRefundStatus()))
-                .collect(Collectors.toList());
-        int coinSinglePointCostInt = orderDishService.getAllDishCostPriceSumByUserMealOrderViewList(coinSinglePointCostList);
-        List<UserMealOrderView> p2fSinglePointCostList = orders.stream()
-                .filter(p -> p.getPayType() == OrderPayTypeEnum.F2F.getValue()
-                        && RefundStatusEnum.SUCCESS.getValue() != Checker.getIntegerValue(p.getRefundStatus()))
-                .collect(Collectors.toList());
-        int p2fSinglePointCostInt = orderDishService.getAllDishCostPriceSumByUserMealOrderViewList(p2fSinglePointCostList);
-        String wechatSinglePointCost = FormatUtil.intShrink100ToStr(wechatSinglePointCostInt);
-        String coinSinglePointCost = FormatUtil.intShrink100ToStr(coinSinglePointCostInt);
-        String p2fSinglePointCost = FormatUtil.intShrink100ToStr(p2fSinglePointCostInt);
-        String allCost = FormatUtil.intShrink100ToStr(wechatSinglePointCostInt + coinSinglePointCostInt + p2fSinglePointCostInt);
-
-        // 总计
-        customExcelItemList.add(new CustomExcelItem(startColumn + 1, startRows, "支付总额", null));
-        customExcelItemList.add(new CustomExcelItem(startColumn + 2, startRows,
-                FormatUtil.intShrink100ToStr(orders.stream()
-                        .mapToInt(v -> Checker.getIntegerValue(v.getWechatPayAmount()))
-                        .sum()), null));
-        customExcelItemList.add(new CustomExcelItem(startColumn + 3, startRows, "退款总额", null));
-        customExcelItemList.add(new CustomExcelItem(startColumn + 4, startRows,
-                FormatUtil.intShrink100ToStr(orders.stream()
-                        .filter(v -> RefundStatusEnum.SUCCESS.getValue() == Checker.getIntegerValue(v.getRefundStatus()))
-                        .mapToInt(v -> Checker.getIntegerValue(v.getWechatPayAmount()))
-                        .sum()), null));
-        customExcelItemList.add(new CustomExcelItem(startColumn + 5, startRows, "实际支付总额", null));
-        customExcelItemList.add(new CustomExcelItem(startColumn + 6, startRows,
-                FormatUtil.intShrink100ToStr(orders.stream()
-                        .filter(v -> RefundStatusEnum.SUCCESS.getValue() != Checker.getIntegerValue(v.getRefundStatus()))
-                        .mapToInt(v -> Checker.getIntegerValue(v.getWechatPayAmount()))
-                        .sum()), null));
-//        customExcelItemList.add(new CustomExcelItem(startColumn + 7, startRows, "总成本", null));
-//        customExcelItemList.add(new CustomExcelItem(startColumn + 8, startRows, allCost, null));
-        startRows += 1;
-        // 微信支付
-        customExcelItemList.add(new CustomExcelItem(startColumn + 1, startRows, "微信支付总额", null));
-        customExcelItemList.add(new CustomExcelItem(startColumn + 2, startRows,
-                FormatUtil.intShrink100ToStr(orders.stream()
-                        .mapToInt(v -> Checker.getIntegerValue(v.getWechatPayAmount()))
-                        .sum()), null));
-        customExcelItemList.add(new CustomExcelItem(startColumn + 3, startRows, "微信退款总额", null));
-        customExcelItemList.add(new CustomExcelItem(startColumn + 4, startRows,
-                FormatUtil.intShrink100ToStr(orders.stream()
-                        .filter(v -> RefundStatusEnum.SUCCESS.getValue() == Checker.getIntegerValue(v.getRefundStatus()))
-                        .mapToInt(v -> Checker.getIntegerValue(v.getWechatPayAmount()))
-                        .sum()), null));
-        customExcelItemList.add(new CustomExcelItem(startColumn + 5, startRows, "微信实际支付总额", null));
-        customExcelItemList.add(new CustomExcelItem(startColumn + 6, startRows,
-                FormatUtil.intShrink100ToStr(orders.stream()
-                        .filter(v -> RefundStatusEnum.SUCCESS.getValue() != Checker.getIntegerValue(v.getRefundStatus()))
-                        .mapToInt(v -> Checker.getIntegerValue(v.getWechatPayAmount()))
-                        .sum()), null));
-//        customExcelItemList.add(new CustomExcelItem(startColumn + 7, startRows, "微信点单成本", null));
-//        customExcelItemList.add(new CustomExcelItem(startColumn + 8, startRows, wechatSinglePointCost, null));
-        startRows += 1;
-        // 金币支付
-
+    private List<ExcelCollectPojo> getStatisticsBillData(int startRows, int payTotal, int refundTotal, Map<String, Integer> statisticalDataMap) {
+        startRows = startRows + 3;
+        int startColumn = 0;
+
+        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)}));
+        PaymentChannelEnum[] paymentChannelList = PaymentChannelEnum.values();
+        startRows++;
+        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, 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)}));
+                }
+            }
+        }
 
         return customExcelItemList;
     }