xuhy
2024-09-19 20cd42287efb95254ea788ce2b6d0c559e378e04
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDataGeneratorServiceImpl.java
@@ -90,11 +90,19 @@
        this.save(dataGenerator);
        long start = System.currentTimeMillis();
        // 查询所有的人数用餐标准
        List<TFoundationConfigVO> foundationConfigs = foundationConfigService.getList();
        List<TFoundationConfigVO> foundationConfigs = foundationConfigService.getList(dto.getShopId());
        // 查询所有桌子
        List<TBoard> boards = boardService.list();
        List<TBoard> boards = boardService.list(Wrappers.lambdaQuery(TBoard.class)
                .eq(TBoard::getShopId,dto.getShopId()));
        if(CollectionUtils.isEmpty(boards)){
            throw new ServiceException("请先添加桌台信息");
        }
        // 查询所有菜品
        List<TGoods> goods = goodsService.list();
        List<TGoods> goods = goodsService.list(Wrappers.lambdaQuery(TGoods.class)
                .eq(TGoods::getShopId,dto.getShopId()));
        if(CollectionUtils.isEmpty(goods)){
            throw new ServiceException("请先添加菜品信息");
        }
        // 循环待生成订单列表,添加到集合中,批量插入
        List<OrderMealGeneratorCountDTO> orderMealGeneratorCountDTOS = dto.getOrderMealGeneratorCountDTOS();
        List<TOrderMeal> orderMeals = new ArrayList<>();
@@ -136,18 +144,21 @@
                            tOrderMealGoods.setGoodsSalePrice(typeGood.getSalePrice());
                            tOrderMealGoods.setGoodsCount(1);
                            tOrderMealGoods.setTypeId(typeGood.getTypeId());
                            tOrderMealGoods.setGoodsId(typeGood.getId());
                            orderMealGoods.add(tOrderMealGoods);
                        }
                    }
                });
                orderMeal.setMealOrderGoods(orderMealGoods);
                orderMeal.setOrderMoney(orderMealGoods.stream().map(TOrderMealGoods::getGoodsSalePrice).reduce(BigDecimal::add).get());
                orderMeal.setPayMoney(orderMealGoods.stream().map(TOrderMealGoods::getGoodsSalePrice).reduce(BigDecimal::add).get());
                orderMeals.add(orderMeal);
                if(!CollectionUtils.isEmpty(orderMealGoods)){
                    orderMeal.setMealOrderGoods(orderMealGoods);
                    orderMeal.setOrderMoney(orderMealGoods.stream().map(TOrderMealGoods::getGoodsSalePrice).reduce(BigDecimal::add).get());
                    orderMeal.setPayMoney(orderMealGoods.stream().map(TOrderMealGoods::getGoodsSalePrice).reduce(BigDecimal::add).get());
                    orderMeals.add(orderMeal);
                }
            }
        }
        BigDecimal sumMoney = orderMeals.stream().map(TOrderMeal::getPayMoney).reduce(BigDecimal::add).get();
        if(sumMoney.compareTo(dto.getMinMoney()) >= 0 || sumMoney.compareTo(dto.getMaxMoney()) <= 0){
        if(sumMoney.compareTo(dto.getMinMoney()) >= 0 && sumMoney.compareTo(dto.getMaxMoney()) <= 0){
            int weiXin = getRandomPayType(orderMeals.size(), dto.getWeiXinProportion());
            int ali = getRandomPayType(orderMeals.size(), dto.getAliProportion());
            int card = getRandomPayType(orderMeals.size(), dto.getCardProportion());
@@ -221,6 +232,7 @@
            long end = System.currentTimeMillis() - start;
            System.err.println("相差时间========="+end);
        }else {
            this.removeById(dataGenerator);
            throw new ServiceException("数据生成不在营业额范围内");
        }
@@ -293,6 +305,7 @@
                    tOrderStockGoods.setSalePrice(v.get(0).getGoodsSalePrice());
                    tOrderStockGoods.setThisSalePrice(v.get(0).getThisSalePrice());
                    tOrderStockGoods.setGoodsPicture(v.get(0).getGoodsPicture());
                    tOrderStockGoods.setGoodsId(v.get(0).getGoodsId());
                    tOrderStockGoods.setStockCount(v.stream().mapToInt(TOrderSaleGoods::getGoodsCount).sum());
                    orderStockGoods.add(tOrderStockGoods);
                });
@@ -329,6 +342,7 @@
                    tOrderStockGoods.setSalePrice(v.get(0).getGoodsSalePrice());
                    tOrderStockGoods.setThisSalePrice(v.get(0).getThisSalePrice());
                    tOrderStockGoods.setGoodsPicture(v.get(0).getGoodsPicture());
                    tOrderStockGoods.setGoodsId(v.get(0).getGoodsId());
                    tOrderStockGoods.setStockCount(v.stream().mapToInt(TOrderSaleGoods::getGoodsCount).sum());
                    orderStockGoods.add(tOrderStockGoods);
                });
@@ -358,6 +372,7 @@
                    tOrderStockGoods.setSalePrice(v.get(0).getGoodsSalePrice());
                    tOrderStockGoods.setThisSalePrice(v.get(0).getThisSalePrice());
                    tOrderStockGoods.setGoodsPicture(v.get(0).getGoodsPicture());
                    tOrderStockGoods.setGoodsId(v.get(0).getGoodsId());
                    tOrderStockGoods.setStockCount(v.stream().mapToInt(TOrderSaleGoods::getGoodsCount).sum());
                    orderStockGoods1.add(tOrderStockGoods);
                });
@@ -387,6 +402,7 @@
                    tOrderStockGoods.setSalePrice(v.get(0).getGoodsSalePrice());
                    tOrderStockGoods.setThisSalePrice(v.get(0).getThisSalePrice());
                    tOrderStockGoods.setGoodsPicture(v.get(0).getGoodsPicture());
                    tOrderStockGoods.setGoodsId(v.get(0).getGoodsId());
                    tOrderStockGoods.setStockCount(v.stream().mapToInt(TOrderSaleGoods::getGoodsCount).sum());
                    orderStockGoods.add(tOrderStockGoods);
                });
@@ -439,13 +455,15 @@
            List<TOrderMeal> orderMeals = orderMealService.list(Wrappers.lambdaQuery(TOrderMeal.class)
                    .in(TOrderMeal::getGeneratorId, ids));
            List<Long> mealIds = orderMeals.stream().map(TOrderMeal::getId).collect(Collectors.toList());
            List<TOrderMealGoods> mealGoods = orderMealGoodsService.list(Wrappers.lambdaQuery(TOrderMealGoods.class)
                    .in(TOrderMealGoods::getOrderId, mealIds));
            for (TDataGeneratorVO tDataGeneratorVO : list) {
                List<Long> collect = orderMeals.stream().filter(e -> e.getGeneratorId().equals(tDataGeneratorVO.getId())).map(TOrderMeal::getId).collect(Collectors.toList());
                BigDecimal money = mealGoods.stream().filter(e -> collect.contains(e.getOrderId()))
                        .reduce(BigDecimal.ZERO, (x, y) -> x.add(y.getGoodsSalePrice().multiply(new BigDecimal(y.getGoodsCount()))), BigDecimal::add);
                tDataGeneratorVO.setTotalRevenue(money);
            if(!CollectionUtils.isEmpty(mealIds)){
                List<TOrderMealGoods> mealGoods = orderMealGoodsService.list(Wrappers.lambdaQuery(TOrderMealGoods.class)
                        .in(TOrderMealGoods::getOrderId, mealIds));
                for (TDataGeneratorVO tDataGeneratorVO : list) {
                    List<Long> collect = orderMeals.stream().filter(e -> e.getGeneratorId().equals(tDataGeneratorVO.getId())).map(TOrderMeal::getId).collect(Collectors.toList());
                    BigDecimal money = mealGoods.stream().filter(e -> collect.contains(e.getOrderId()))
                            .reduce(BigDecimal.ZERO, (x, y) -> x.add(y.getGoodsSalePrice().multiply(new BigDecimal(y.getGoodsCount()))), BigDecimal::add);
                    tDataGeneratorVO.setTotalRevenue(money);
                }
            }
        }else {
            List<TOrderSale> orderSales = orderSaleService.list(Wrappers.lambdaQuery(TOrderSale.class)
@@ -457,8 +475,10 @@
//                List<Long> collect = orderSales.stream().filter(e -> e.getGeneratorId().equals(tDataGeneratorVO.getId())).map(TOrderSale::getId).collect(Collectors.toList());
//                BigDecimal money = orderSaleGoods.stream().filter(e -> collect.contains(e.getOrderId()))
//                        .reduce(BigDecimal.ZERO, (x, y) -> x.add(y.getGoodsCostPrice().multiply(new BigDecimal(y.getGoodsCount()))), BigDecimal::add);
                BigDecimal money = orderSales.stream().map(TOrderSale::getPayMoney).reduce(BigDecimal::add).get();
                tDataGeneratorVO.setTotalRevenue(money);
                if(!CollectionUtils.isEmpty(orderSales)){
                    BigDecimal money = orderSales.stream().map(TOrderSale::getPayMoney).reduce(BigDecimal::add).get();
                    tDataGeneratorVO.setTotalRevenue(money);
                }
            }
        }
        pageInfo.setRecords(list);