Browse Source

feature:营养餐对账

wuyongyi 2 years ago
parent
commit
6c02eb0ced

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

@@ -365,7 +365,7 @@ public class DownloadRecordService {
      * @param itemList         统计map
      * @throws Exception
      */
-    public void createMealFileAndUploadOssAndSaveToDataBase(String fileName, int downloadRecordId, ExcelDataMap map, List<CustomExcelItem> itemList, int size) throws Exception {
+    public void createMealFileAndUploadOssAndSaveToDataBase(String fileName, int downloadRecordId, ExcelDataMap map, List<CustomExcelItem> itemList, int size, int bill) throws Exception {
         // 前缀(路径)
         String preLocalPath = ConstantDef.LOCAL_DOWNLOAD_FILE_PATH;
         // 后缀(下载时间和格式)
@@ -375,7 +375,7 @@ public class DownloadRecordService {
 
         // 生成本地文件
         ExcelStyleMap excelStyleMap = new ExcelStyleMap(new String[]{});
-        OutputStream ba = excelDownloadSrv.generateAndReturnExcelByteArrayOutputStreamWithStyle(fileName, localPath, map, excelStyleMap, itemList);
+        OutputStream ba = excelDownloadSrv.generateAndReturnExcelByteArrayOutputStreamWithStyle(fileName, localPath, map, excelStyleMap, itemList, bill);
 
         // 本地文件上传到oss,文件名带后缀
         String ossPath = String.format(ConstantDef.BIG_DATA_EXCEL_FILE_PATH, FormatUtil.formatDate(new Date(), "yyyy-MM"));

+ 182 - 34
src/main/java/com/ywt/mg/services/MealOrderService.java

@@ -15,7 +15,6 @@ 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;
@@ -412,9 +411,10 @@ public class MealOrderService {
             int size = userMealOrderViews.size();
 //         List<ExcelCollectPojo> itemList = getStatisticsData(size, payTotal);
 //         downloadRecordService.createFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map, itemList);
+            int bill = 0;
             List<CustomExcelItem> itemList = getStatisticsData(userMealOrderViews, shopList);
             downloadRecordService.createMealFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map,
-                    needStat ? itemList : null, size);
+                    needStat ? itemList : null, size, bill);
 
         } catch (Exception e) {
             logger.error("/mealOrder/downloadMealOrderList(): {}", e.getMessage(), e);
@@ -822,10 +822,10 @@ public class MealOrderService {
                 }
             }
 
-
-            List<CustomExcelItem> itemList = getStatisticsData(userMealOrderViews, shopList);
+            int bill = 1;
+            List<CustomExcelItem> itemList = getStatisticsBillData(userMealOrderViews, rowSize);
             downloadRecordService.createMealFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map,
-                     itemList, rowSize);
+                     itemList, rowSize, bill);
 
         } catch (Exception e) {
             logger.error("/mealOrder/downloadMealOrderBillsList(): {}", e.getMessage(), e);
@@ -841,35 +841,183 @@ public class MealOrderService {
         return new ArrayList<>();
     }
 
-    private List<ExcelCollectPojo> getStatisticsData(int size, int payTotal, int refundTotal, Map<String, Integer> statisticalDataMap) {
-        int startRows = size + 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)}));
-                }
-            }
-        }
+    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.getOrderAmount()))
+                        .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.getOrderAmount()))
+                        .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.getOrderAmount()))
+                        .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;
+        // 金币支付
+        customExcelItemList.add(new CustomExcelItem(startColumn + 1, startRows, "金币支付总额", null));
+        customExcelItemList.add(new CustomExcelItem(startColumn + 2, startRows,
+                FormatUtil.intShrink100ToStr(orders.stream()
+                        .mapToInt(v -> Checker.getIntegerValue(v.getCoinPayAmount()))
+                        .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.getCoinPayAmount()))
+                        .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.getCoinPayAmount()))
+                        .sum()), null));
+//        customExcelItemList.add(new CustomExcelItem(startColumn + 7, startRows, "金币点单成本", null));
+//        customExcelItemList.add(new CustomExcelItem(startColumn + 8, startRows, coinSinglePointCost, 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.getF2fPayAmount()))
+                        .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.getF2fPayAmount()))
+                        .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.getF2fPayAmount()))
+                        .sum()), null));
+//        customExcelItemList.add(new CustomExcelItem(startColumn + 7, startRows, "现场点单成本", null));
+//        customExcelItemList.add(new CustomExcelItem(startColumn + 8, startRows, p2fSinglePointCost, null));
+        startRows += 1;
+        // 洗碗费
+        // 目前只计算有金币支付的订单,不包括纯微信支付及现场支付订单。计算的规则是符合条件的订单的微信支付金额总和。
+        // 等同这个 SQL 语句:
+        // select sum(wechat_pay_amount) from nutrimeal.meal_order where deleted = 0 and pay_type = 4 and (refund_status is null or refund_status != 1) and wechat_pay_amount is not null ;
+        customExcelItemList.add(new CustomExcelItem(startColumn + 1, startRows, "2元洗碗费总额", null));
+        customExcelItemList.add(new CustomExcelItem(startColumn + 2, startRows,
+                FormatUtil.intShrink100ToStr(orders.stream()
+                        .filter(v -> OrderPayTypeEnum.COIN.getValue() == Checker.getIntegerValue(v.getPayType()) &&
+                                RefundStatusEnum.SUCCESS.getValue() != Checker.getIntegerValue(v.getRefundStatus()))
+                        .mapToInt(v -> Checker.getIntegerValue(v.getWechatPayAmount()))
+                        .sum()), null));
+        startRows += 2;
+        // v1.3.1_nfyybyfy 新增职工统计
+        // 职工支付
+        customExcelItemList.add(new CustomExcelItem(startColumn + 1, startRows, "职工支付总额", null));
+        customExcelItemList.add(new CustomExcelItem(startColumn + 2, startRows,
+                FormatUtil.intShrink100ToStr(orders.stream()
+                        .filter(v -> Checker.getIntegerValue(v.getStaffId()) > 0)
+                        .mapToInt(v -> Checker.getIntegerValue(v.getOrderAmount()))
+                        .sum()), null));
+        customExcelItemList.add(new CustomExcelItem(startColumn + 3, startRows, "退款总额", null));
+        customExcelItemList.add(new CustomExcelItem(startColumn + 4, startRows,
+                FormatUtil.intShrink100ToStr(orders.stream()
+                        .filter(v -> Checker.getIntegerValue(v.getStaffId()) > 0)
+                        .filter(v -> RefundStatusEnum.SUCCESS.getValue() == Checker.getIntegerValue(v.getRefundStatus()))
+                        .mapToInt(v -> Checker.getIntegerValue(v.getOrderAmount()))
+                        .sum()), null));
+        customExcelItemList.add(new CustomExcelItem(startColumn + 5, startRows, "实际支付总额", null));
+        customExcelItemList.add(new CustomExcelItem(startColumn + 6, startRows,
+                FormatUtil.intShrink100ToStr(orders.stream()
+                        .filter(v -> Checker.getIntegerValue(v.getStaffId()) > 0)
+                        .filter(v -> RefundStatusEnum.SUCCESS.getValue() != Checker.getIntegerValue(v.getRefundStatus()))
+                        .mapToInt(v -> Checker.getIntegerValue(v.getOrderAmount()))
+                        .sum()), null));
+        startRows += 1;
+        // 非职工支付
+        customExcelItemList.add(new CustomExcelItem(startColumn + 1, startRows, "非职工支付总额", null));
+        customExcelItemList.add(new CustomExcelItem(startColumn + 2, startRows,
+                FormatUtil.intShrink100ToStr(orders.stream()
+                        .filter(v -> Checker.getIntegerValue(v.getStaffId()) <= 0)
+                        .mapToInt(v -> Checker.getIntegerValue(v.getOrderAmount()))
+                        .sum()), null));
+        customExcelItemList.add(new CustomExcelItem(startColumn + 3, startRows, "退款总额", null));
+        customExcelItemList.add(new CustomExcelItem(startColumn + 4, startRows,
+                FormatUtil.intShrink100ToStr(orders.stream()
+                        .filter(v -> Checker.getIntegerValue(v.getStaffId()) <= 0)
+                        .filter(v -> RefundStatusEnum.SUCCESS.getValue() == Checker.getIntegerValue(v.getRefundStatus()))
+                        .mapToInt(v -> Checker.getIntegerValue(v.getOrderAmount()))
+                        .sum()), null));
+        customExcelItemList.add(new CustomExcelItem(startColumn + 5, startRows, "实际支付总额", null));
+        customExcelItemList.add(new CustomExcelItem(startColumn + 6, startRows,
+                FormatUtil.intShrink100ToStr(orders.stream()
+                        .filter(v -> Checker.getIntegerValue(v.getStaffId()) <= 0)
+                        .filter(v -> RefundStatusEnum.SUCCESS.getValue() != Checker.getIntegerValue(v.getRefundStatus()))
+                        .mapToInt(v -> Checker.getIntegerValue(v.getOrderAmount()))
+                        .sum()), null));
+        startRows += 2;
+
+
         return customExcelItemList;
     }
 }

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

@@ -447,7 +447,7 @@ public class RegisteredOrderService {
                 billEndTime = DateUtil.stringToDate(request.getRegisteredEndTime() + ConstantDef.BILL_TIME_END_FORMAT);
             }
             List<ExcelCollectPojo> itemList = getStatisticsData(size, billStartTime, billEndTime, registeredOrderList);
-            int bill = 1;
+            int bill = 0;
             downloadRecordService.createFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map, itemList, size, bill);
 
         } catch (Exception e) {

+ 8 - 5
src/main/java/com/ywt/mg/web/common/ExcelDownloadSrv.java

@@ -446,7 +446,7 @@ public class ExcelDownloadSrv {
      * @author Walker, added on 06/27/2019.
      */
     public OutputStream generateAndReturnExcelByteArrayOutputStreamWithStyle(String fileName, String path, ExcelDataMap data, ExcelStyleMap excelStyleMap,
-                                                                             List<CustomExcelItem> collectList) throws AppMessageException {
+                                                                             List<CustomExcelItem> collectList, int bill) throws AppMessageException {
         if (data == null || data.isEmpty()) {
             throw new AppMessageException("数据为空");
         }
@@ -543,10 +543,13 @@ public class ExcelDownloadSrv {
                             sheet.addCell(new Label(item.getColumn(), item.getRow() - sheetMaxSize * currentSheetIndex, item.getContent(), item.getCellFormat() == null ? cellFormat : item.getCellFormat()));
                             n = item.getRow() - sheetMaxSize * currentSheetIndex;
                         }
-                        n = n + 1;
-                        Label labelRemark = new Label(1, n, "注意:如果需把excel表导入院内系统, 可按需把上面的“数据汇总表格”和“支付渠道列”删除并保存后,再导入", cellFormat);
-                        sheet.mergeCells(1, n, 6, n);
-                        sheet.addCell(labelRemark);
+                        if (bill == 1) {
+
+                            n = n + 1;
+                            Label labelRemark = new Label(4, n, "注意:如果需把excel表导入院内系统, 可按需把上面的“数据汇总表格”和“支付渠道列”删除并保存后,再导入", cellFormat);
+                            sheet.mergeCells(4, n, 9, n);
+                            sheet.addCell(labelRemark);
+                        }
 
                     }
                     // 写入流